@Override public void addMarkers(IResource pomResource, String type, MavenExecutionResult result) { SourceLocation defaultSourceLocation = new SourceLocation(1, 0, 0); List<MavenProblemInfo> allProblems = new ArrayList<MavenProblemInfo>(); allProblems.addAll( toMavenProblemInfos(pomResource, defaultSourceLocation, result.getExceptions())); MavenProject mavenProject = result.getProject(); DependencyResolutionResult resolutionResult = result.getDependencyResolutionResult(); if (resolutionResult != null) { allProblems.addAll( toMavenProblemInfos( pomResource, defaultSourceLocation, resolutionResult.getCollectionErrors())); for (org.eclipse.aether.graph.Dependency dependency : resolutionResult.getUnresolvedDependencies()) { List<Exception> exceptions = resolutionResult.getResolutionErrors(dependency); if (exceptions != null && exceptions.size() > 0) { SourceLocation sourceLocation = SourceLocationHelper.findLocation(mavenProject, dependency); allProblems.addAll(toMavenProblemInfos(pomResource, sourceLocation, exceptions)); } } } if (mavenProject != null) { addMissingArtifactProblemInfos(mavenProject, defaultSourceLocation, allProblems); } addErrorMarkers(pomResource, type, allProblems); }
@Override public void resolveProjectDependencies( final IMavenProjectFacade facade, Set<Capability> capabilities, Set<RequiredCapability> requirements, final IProgressMonitor monitor) throws CoreException { long start = System.currentTimeMillis(); log.debug("Resolving dependencies for {}", facade.toString()); // $NON-NLS-1$ markerManager.deleteMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID); ProjectBuildingRequest configuration = getMaven().getExecutionContext().newProjectBuildingRequest(); configuration.setProject(facade.getMavenProject()); // TODO do we need this? configuration.setResolveDependencies(true); MavenExecutionResult mavenResult = getMaven().readMavenProject(facade.getPomFile(), configuration); markerManager.addMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID, mavenResult); if (!facade.getResolverConfiguration().shouldResolveWorkspaceProjects()) { return; } MavenProject mavenProject = facade.getMavenProject(); // dependencies // resolved dependencies for (Artifact artifact : mavenProject.getArtifacts()) { requirements.add( MavenRequiredCapability.createMavenArtifact( new ArtifactKey(artifact), artifact.getScope(), artifact.isOptional())); } // extension plugins (affect packaging type calculation) for (Plugin plugin : mavenProject.getBuildPlugins()) { if (plugin.isExtensions()) { ArtifactKey artifactKey = new ArtifactKey(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null); requirements.add( MavenRequiredCapability.createMavenArtifact( artifactKey, "plugin", false)); // $NON-NLS-1$ } } // missing dependencies DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult(); if (resolutionResult != null && resolutionResult.getUnresolvedDependencies() != null) { for (Dependency dependency : resolutionResult.getUnresolvedDependencies()) { org.eclipse.aether.artifact.Artifact artifact = dependency.getArtifact(); ArtifactKey dependencyKey = new ArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null); requirements.add( MavenRequiredCapability.createMavenArtifact( dependencyKey, dependency.getScope(), dependency.isOptional())); } } log.debug( "Resolved dependencies for {} in {} ms", facade.toString(), System.currentTimeMillis() - start); // $NON-NLS-1$ }