public ArtifactResolutionResult resolveTransitively(
      Set<Artifact> artifacts,
      Artifact originatingArtifact,
      Map<String, Artifact> managedVersions,
      ArtifactRepository localRepository,
      List<ArtifactRepository> remoteRepositories,
      ArtifactMetadataSource source,
      ArtifactFilter filter,
      List<ResolutionListener> listeners,
      List<ConflictResolver> conflictResolvers)
      throws ArtifactResolutionException, ArtifactNotFoundException {
    ArtifactResolutionRequest request =
        new ArtifactResolutionRequest()
            .setArtifact(originatingArtifact)
            .setResolveRoot(false)
            // This is required by the surefire plugin
            .setArtifactDependencies(artifacts)
            .setManagedVersionMap(managedVersions)
            .setLocalRepository(localRepository)
            .setRemoteRepositories(remoteRepositories)
            .setCollectionFilter(filter)
            .setListeners(listeners);

    injectSession2(request, legacySupport.getSession());

    return resolveWithExceptions(request);
  }
Ejemplo n.º 2
0
  public <V> V execute(MavenProject project, ICallable<V> callable, IProgressMonitor monitor)
      throws CoreException {
    Deque<MavenExecutionContext> stack = threadLocal.get();
    if (stack == null) {
      stack = new ArrayDeque<MavenExecutionContext>();
      threadLocal.set(stack);
    }
    final MavenExecutionContext parent = stack.peek();

    if (this == parent) {
      // shortcut the setup logic, this is nested invocation of the same context
      return executeBare(project, callable, monitor);
    }

    // remember original configuration to "pop" the session stack properly
    final MavenExecutionRequest origRequest = request;
    final Map<String, Object> origContext = context;

    if (request == null && parent != null) {
      this.request = parent.request;
      this.context = new HashMap<String, Object>(parent.context);
    } else {
      this.context = new HashMap<String, Object>();
      if (request == null) {
        request = newExecutionRequest();
      }
      maven.populateDefaults(request);
      populateSystemProperties(request);
      setValue(CTX_LOCALREPOSITORY, request.getLocalRepository());
      final FilterRepositorySystemSession repositorySession =
          maven.createRepositorySession(request);
      setValue(CTX_REPOSITORYSESSION, repositorySession);
      if (parent != null) {
        repositorySession.setData(parent.getRepositorySession().getData());
      }
      final MavenExecutionResult result = new DefaultMavenExecutionResult();
      setValue(
          CTX_MAVENSESSION,
          new MavenSession(maven.getPlexusContainer(), repositorySession, request, result));
    }

    final LegacySupport legacySupport = maven.lookup(LegacySupport.class);
    final MavenSession origLegacySession =
        legacySupport.getSession(); // TODO validate == origSession

    stack.push(this);
    legacySupport.setSession(getSession());
    try {
      return executeBare(project, callable, monitor);
    } finally {
      stack.pop();
      if (stack.isEmpty()) {
        threadLocal.set(null); // TODO decide if this is useful
      }
      legacySupport.setSession(origLegacySession);
      request = origRequest;
      context = origContext;
    }
  }
  @Override
  protected void doExecute() throws MojoExecutionException, MojoFailureException {
    final MavenProject project = buildContext.getSession().getCurrentProject();

    @SuppressWarnings("unchecked")
    final Collection<Artifact> artifacts =
        (Collection<Artifact>) project.getContextValue("osgified-artifacts");

    final RepositorySystemSession session = buildContext.getRepositorySession();

    final InstallRequest installRequest = new InstallRequest();
    installRequest.setArtifacts(artifacts);
    try {
      repositorySystem.install(session, installRequest);
    } catch (InstallationException e) {
      throw pipe(e);
    }
  }
  public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
    DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
    RepositorySystemSession repositorySession = maven.newRepositorySession(request);

    request.getProjectBuildingRequest().setRepositorySession(repositorySession);

    MavenSession mavenSession =
        new MavenSession(
            myContainer, repositorySession, request, new DefaultMavenExecutionResult());
    LegacySupport legacySupport = getComponent(LegacySupport.class);

    MavenSession oldSession = legacySupport.getSession();

    legacySupport.setSession(mavenSession);
    try {
      runnable.run();
    } finally {
      legacySupport.setSession(oldSession);
    }
  }
  private ProjectBuildingRequest injectSession(ProjectBuildingRequest request) {
    MavenSession session = legacySupport.getSession();
    if (session != null) {
      request.setRepositorySession(session.getRepositorySession());
      request.setSystemProperties(session.getSystemProperties());
      if (request.getUserProperties().isEmpty()) {
        request.setUserProperties(session.getUserProperties());
      }

      MavenExecutionRequest req = session.getRequest();
      if (req != null) {
        request.setRemoteRepositories(req.getRemoteRepositories());
      }
    } else {
      Properties props = new Properties();
      EnvironmentUtils.addEnvVars(props);
      props.putAll(System.getProperties());
      request.setSystemProperties(props);
    }

    return request;
  }