コード例 #1
0
  @NotNull
  private MavenServerExecutionResult createExecutionResult(
      File file, MavenExecutionResult result, DependencyNode rootNode) throws RemoteException {
    Collection<MavenProjectProblem> problems = MavenProjectProblem.createProblemsList();
    THashSet<MavenId> unresolvedArtifacts = new THashSet<MavenId>();

    validate(file, result.getExceptions(), problems, unresolvedArtifacts);

    MavenProject mavenProject = result.getMavenProject();
    if (mavenProject == null)
      return new MavenServerExecutionResult(null, problems, unresolvedArtifacts);

    MavenModel model =
        MavenModelConverter.convertModel(
            mavenProject.getModel(),
            mavenProject.getCompileSourceRoots(),
            mavenProject.getTestCompileSourceRoots(),
            mavenProject.getArtifacts(),
            (rootNode == null ? Collections.emptyList() : rootNode.getChildren()),
            mavenProject.getExtensionArtifacts(),
            getLocalRepositoryFile());

    RemoteNativeMavenProjectHolder holder = new RemoteNativeMavenProjectHolder(mavenProject);
    try {
      UnicastRemoteObject.exportObject(holder, 0);
    } catch (RemoteException e) {
      throw new RuntimeException(e);
    }

    Collection<String> activatedProfiles = collectActivatedProfiles(mavenProject);

    MavenServerExecutionResult.ProjectData data =
        new MavenServerExecutionResult.ProjectData(
            model,
            MavenModelConverter.convertToMap(mavenProject.getModel()),
            holder,
            activatedProfiles);
    return new MavenServerExecutionResult(data, problems, unresolvedArtifacts);
  }
コード例 #2
0
  @NotNull
  @Override
  public List<MavenArtifact> resolveTransitively(
      @NotNull List<MavenArtifactInfo> artifacts,
      @NotNull List<MavenRemoteRepository> remoteRepositories)
      throws RemoteException, MavenServerProcessCanceledException {

    try {
      Set<Artifact> toResolve = new LinkedHashSet<Artifact>();
      for (MavenArtifactInfo each : artifacts) {
        toResolve.add(createArtifact(each));
      }

      Artifact project =
          getComponent(ArtifactFactory.class).createBuildArtifact("temp", "temp", "666", "pom");

      Set<Artifact> res =
          getComponent(ArtifactResolver.class)
              .resolveTransitively(
                  toResolve,
                  project,
                  Collections.EMPTY_MAP,
                  myLocalRepository,
                  convertRepositories(remoteRepositories),
                  getComponent(ArtifactMetadataSource.class))
              .getArtifacts();

      return MavenModelConverter.convertArtifacts(
          res, new THashMap<Artifact, MavenArtifact>(), getLocalRepositoryFile());
    } catch (ArtifactResolutionException e) {
      Maven3ServerGlobals.getLogger().info(e);
    } catch (ArtifactNotFoundException e) {
      Maven3ServerGlobals.getLogger().info(e);
    } catch (Exception e) {
      throw rethrowException(e);
    }

    return Collections.emptyList();
  }
コード例 #3
0
  @Override
  public Collection<MavenArtifact> resolvePlugin(
      @NotNull MavenPlugin plugin,
      @NotNull List<MavenRemoteRepository> repositories,
      int nativeMavenProjectId,
      boolean transitive)
      throws RemoteException, MavenServerProcessCanceledException {
    try {
      Plugin mavenPlugin = new Plugin();
      mavenPlugin.setGroupId(plugin.getGroupId());
      mavenPlugin.setArtifactId(plugin.getArtifactId());
      mavenPlugin.setVersion(plugin.getVersion());
      MavenProject project = RemoteNativeMavenProjectHolder.findProjectById(nativeMavenProjectId);

      MavenExecutionRequest request =
          createRequest(
              null,
              Collections.<String>emptyList(),
              Collections.<String>emptyList(),
              Collections.<String>emptyList());

      DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
      RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);

      if (plugin.getVersion() == null) {
        PluginVersionRequest versionRequest =
            new DefaultPluginVersionRequest(
                mavenPlugin, repositorySystemSession, project.getRemotePluginRepositories());
        mavenPlugin.setVersion(
            getComponent(PluginVersionResolver.class).resolve(versionRequest).getVersion());
      }

      PluginDescriptor result =
          getComponent(MavenPluginManager.class)
              .getPluginDescriptor(
                  mavenPlugin, project.getRemotePluginRepositories(), repositorySystemSession);

      Map<MavenArtifactInfo, MavenArtifact> resolvedArtifacts =
          new THashMap<MavenArtifactInfo, MavenArtifact>();

      Artifact pluginArtifact = result.getPluginArtifact();

      MavenArtifactInfo artifactInfo =
          new MavenArtifactInfo(
              pluginArtifact.getGroupId(),
              pluginArtifact.getArtifactId(),
              pluginArtifact.getVersion(),
              pluginArtifact.getType(),
              null);

      resolveIfNecessary(artifactInfo, repositories, resolvedArtifacts);

      if (transitive) {
        // todo try to use parallel downloading
        for (Artifact each : result.getIntroducedDependencyArtifacts()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
        for (ComponentDependency each : result.getDependencies()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
      }

      return new THashSet<MavenArtifact>(resolvedArtifacts.values());
    } catch (Exception e) {
      Maven3ServerGlobals.getLogger().info(e);
      return Collections.emptyList();
    }
  }
コード例 #4
0
  @NotNull
  public MavenExecutionResult doResolveProject(
      @NotNull final File file,
      @NotNull final List<String> activeProfiles,
      final List<ResolutionListener> listeners)
      throws RemoteException {
    final MavenExecutionRequest request =
        createRequest(
            file, activeProfiles, Collections.<String>emptyList(), Collections.<String>emptyList());

    final AtomicReference<MavenExecutionResult> ref = new AtomicReference<MavenExecutionResult>();

    executeWithMavenSession(
        request,
        new Runnable() {
          @Override
          public void run() {
            try {
              // copied from DefaultMavenProjectBuilder.buildWithDependencies
              ProjectBuilder builder = getComponent(ProjectBuilder.class);
              ProjectBuildingResult buildingResult =
                  builder.build(new File(file.getPath()), request.getProjectBuildingRequest());
              // builder.calculateConcreteState(project, config, false);

              MavenProject project = buildingResult.getProject();

              // copied from DefaultLifecycleExecutor.execute
              // findExtensions(project);
              // end copied from DefaultLifecycleExecutor.execute

              // Artifact projectArtifact = project.getArtifact();
              // Map managedVersions = project.getManagedVersionMap();
              // ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
              project.setDependencyArtifacts(
                  project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
              //
              ArtifactResolver resolver = getComponent(ArtifactResolver.class);

              ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
              resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
              resolutionRequest.setArtifact(project.getArtifact());
              resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
              resolutionRequest.setLocalRepository(myLocalRepository);
              resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
              resolutionRequest.setListeners(listeners);

              resolutionRequest.setResolveRoot(false);
              resolutionRequest.setResolveTransitively(true);

              RepositorySystemSession repositorySession =
                  getComponent(LegacySupport.class).getRepositorySession();
              if (repositorySession instanceof DefaultRepositorySystemSession) {
                ((DefaultRepositorySystemSession) repositorySession)
                    .setTransferListener(new TransferListenerAdapter(myCurrentIndicator));

                if (myWorkspaceMap != null) {
                  ((DefaultRepositorySystemSession) repositorySession)
                      .setWorkspaceReader(new Maven3WorkspaceReader(myWorkspaceMap));
                }
              }

              ArtifactResolutionResult result = resolver.resolve(resolutionRequest);

              project.setArtifacts(result.getArtifacts());
              // end copied from DefaultMavenProjectBuilder.buildWithDependencies
              ref.set(new MavenExecutionResult(project, new ArrayList<Exception>()));
            } catch (Exception e) {
              ref.set(handleException(e));
            }
          }
        });

    return ref.get();
  }