コード例 #1
1
  private void validate(
      File file,
      Collection<Exception> exceptions,
      Collection<MavenProjectProblem> problems,
      Collection<MavenId> unresolvedArtifacts)
      throws RemoteException {
    for (Exception each : exceptions) {
      Maven3ServerGlobals.getLogger().info(each);

      if (each instanceof InvalidProjectModelException) {
        ModelValidationResult modelValidationResult =
            ((InvalidProjectModelException) each).getValidationResult();
        if (modelValidationResult != null) {
          for (Object eachValidationProblem : modelValidationResult.getMessages()) {
            problems.add(
                MavenProjectProblem.createStructureProblem(
                    file.getPath(), (String) eachValidationProblem));
          }
        } else {
          problems.add(
              MavenProjectProblem.createStructureProblem(
                  file.getPath(), each.getCause().getMessage()));
        }
      } else if (each instanceof ProjectBuildingException) {
        String causeMessage =
            each.getCause() != null ? each.getCause().getMessage() : each.getMessage();
        problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), causeMessage));
      } else {
        problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getMessage()));
      }
    }
    unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds());
  }
コード例 #2
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);
  }