protected File[] getGwtUserJar() throws MojoExecutionException { checkGwtUserVersion(); Artifact gwtUserArtifact = getArtifact("com.google.gwt", "gwt-user"); Set<Artifact> artifacts = new HashSet<Artifact>(); ArtifactResolutionResult result = null; try { result = resolver.resolveTransitively( artifacts, gwtUserArtifact, remoteRepositories, localRepository, artifactMetadataSource); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Failed to resolve artifact", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Failed to resolve artifact", e); } Collection<Artifact> resolved = result.getArtifacts(); int i = 0; // FIXME gwt 2.3.0 don't declare dependency on javax.validation, should be fix in next release File[] files = new File[resolved.size() + 1 + 2]; files[i++] = gwtUserArtifact.getFile(); for (Artifact artifact : resolved) { files[i++] = artifact.getFile(); } files[i++] = getArtifact("javax.validation", "validation-api").getFile(); files[i++] = getArtifact("javax.validation", "validation-api", "sources").getFile(); return files; }
@SuppressWarnings("unchecked") private void prepareArtifacts() { try { // TODO: do only if artifacts are not resolved Set<Artifact> artifacts = new LinkedHashSet<Artifact>(); Map<String, Artifact> managedVersions = createManagedVersionMap(); List<ResolutionListener> listeners = new ArrayList<ResolutionListener>(); ArtifactResolutionResult resolveResult = artifactCollector.collect( getAllArtifacts(), project.getArtifact(), managedVersions, session.getLocalRepository(), project.getRemoteArtifactRepositories(), artifactMetadataSource, null, listeners); for (ResolutionNode node : (Set<ResolutionNode>) resolveResult.getArtifactResolutionNodes()) { if (!isReactorProject(node.getArtifact())) { artifactResolver.resolve( node.getArtifact(), node.getRemoteRepositories(), session.getLocalRepository()); artifacts.add(node.getArtifact()); } else { addProjectReferenceArtifact(node.getArtifact()); } } this.artifacts = artifacts; } catch (Exception e) { getLog().debug("[WarSync] " + e.getMessage(), e); getLog().error("[WarSync] " + e.getMessage()); } }
public void run() { ClassLoader old = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); resolve(artifact, remoteRepositories, session); } catch (ArtifactNotFoundException anfe) { // These are cases where the artifact just isn't present in any of the remote repositories // because it wasn't deployed, or it was deployed in the wrong place. synchronized (result) { result.addMissingArtifact(artifact); } } catch (ArtifactResolutionException e) { // This is really a wagon TransferFailedException so something went wrong after we // successfully // retrieved the metadata. synchronized (result) { result.addErrorArtifactException(e); } } finally { latch.countDown(); Thread.currentThread().setContextClassLoader(old); } }
@SuppressWarnings("unchecked") private Collection<Artifact> getNonTransitivePlugins(Set<Artifact> projectArtifacts) throws MojoExecutionException { Collection<Artifact> deps = new LinkedHashSet<Artifact>(); for (Artifact artifact : projectArtifacts) { Artifact pomArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), "pom"); Set<Artifact> result; try { MavenProject pomProject = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository); Set<Artifact> artifacts = pomProject.createArtifacts(artifactFactory, null, null); artifacts = filterOutSystemDependencies(artifacts); ArtifactResolutionResult arr = resolver.resolveTransitively( artifacts, pomArtifact, localRepository, remoteRepositories, artifactMetadataSource, null); result = arr.getArtifacts(); } catch (Exception e) { throw new MojoExecutionException( "Failed to resolve non-transitive deps " + e.getMessage(), e); } LinkedHashSet<Artifact> plugins = new LinkedHashSet<Artifact>(); plugins.addAll(filtterArtifacts(result, getFilters(null, null, "nexus-plugin", null))); plugins.addAll(filtterArtifacts(result, getFilters(null, null, "zip", "bundle"))); plugins.addAll(getNonTransitivePlugins(plugins)); if (!plugins.isEmpty()) { getLog() .debug( "Adding non-transitive dependencies for: " + artifact + " -\n" + plugins.toString().replace(',', '\n')); } deps.addAll(plugins); } return deps; }
Set<Artifact> getResolvedArtifactsFromUnresolvedDependencies( List<Dependency> unresolvedDependencies, boolean resolveTransitively) throws MojoExecutionException { final Set<Artifact> resolvedArtifacts = new HashSet<Artifact>(); // Artifact mojoArtifact = this.artifactFactory.createBuildArtifact(project.getGroupId(), // project.getArtifactId(), project.getVersion(), "pom"); /* * Resolve each artifact. This will get all transitive artifacts AND eliminate conflicts. */ final Set<Artifact> unresolvedArtifacts; // for (Dependency d : unresolvedDependencies) // System.out.println("dependency: " + d.toString()); try { unresolvedArtifacts = MavenMetadataSource.createArtifacts( this.artifactFactory, unresolvedDependencies, null, null, null); // for (Artifact artifact : unresolvedArtifacts) { // System.out.println("unresolved " + artifact.toString()); // } if (resolveTransitively) { ArtifactResolutionResult artifacts = artifactResolver.resolveTransitively( unresolvedArtifacts, project.getArtifact(), remoteRepositories, localRepository, artifactMetadataSource); resolvedArtifacts.addAll(artifacts.getArtifacts()); } else { // resolve each artifact individually for (Artifact artifact : unresolvedArtifacts) { artifactResolver.resolve(artifact, remoteRepositories, localRepository); resolvedArtifacts.add(artifact); } } } catch (Exception e) { throw new MojoExecutionException("Unable to complete configuring the build settings", e); } for (Artifact artifact : resolvedArtifacts) { System.out.println("matched " + artifact.toString()); } return resolvedArtifacts; }
private void addArtifact(SurefireBooter surefireBooter, Artifact surefireArtifact) throws ArtifactNotFoundException, ArtifactResolutionException { ArtifactResolutionResult result = resolveArtifact(null, surefireArtifact); for (Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); getLog() .debug( "Adding to surefire booter test classpath: " + artifact.getFile().getAbsolutePath()); surefireBooter.addSurefireBootClassPathUrl(artifact.getFile().getAbsolutePath()); } }
/** artifacts provided by bundles this project depends on */ private Set<String> getImportedArtifactKeys() throws MojoExecutionException { HashSet<String> keys = new HashSet<String>(); if (requireBundles != null) { for (int i = 0; i < requireBundles.length; i++) { MavenArtifactRef a = requireBundles[i]; ArtifactResolutionResult result = resolve(a, true); for (Artifact b : result.getArtifacts()) { keys.add(getArtifactKey(b.getGroupId(), b.getArtifactId(), b.getClassifier())); } } } return keys; }
/** * Detect if this artifact is already an osgi bundle. If it is, then we don't need to wrap it. The * best way to figure this out is to crack open the JAR and take a look at the manifest. * * @param artifact * @throws Exception */ protected boolean isBundle(Artifact artifact) throws Exception { // Resolve the artifact. ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact); ArtifactResolutionResult result = repositorySystem.resolve(request); // If not found, then assume it's a reactor dependency and therefore should be a bundle. if (result.getArtifacts().isEmpty()) { getLog() .info( "Artifact " + artifact.toString() + " not found in local repository, assuming reactor dependency."); //$NON-NLS-1$ // //$NON-NLS-2$ return true; } artifact = result.getArtifacts().iterator().next(); if (!artifact.getFile().isFile()) { throw new Exception( "Resolved artifact is not a file: " + artifact.getFile().getAbsolutePath()); // $NON-NLS-1$ } // Crack open the dependency JAR, read the manifest, check for osgi attributes. JarFile jf = null; try { jf = new JarFile(artifact.getFile()); Manifest manifest = jf.getManifest(); if (manifest == null) { getLog() .info( "Artifact " + artifact.toString() + " missing a manifest! Assuming not a bundle."); //$NON-NLS-1$ //$NON-NLS-2$ return false; } Attributes attributes = manifest.getMainAttributes(); if (attributes != null) { String value = attributes.getValue("Bundle-SymbolicName"); // $NON-NLS-1$ if (value != null && value.trim().length() > 0) { return true; } } } finally { jf.close(); } return false; }
/** * Resolves dependencies of a bundle <code>groupId:artifactId:version</code> * * @param groupId * @param artifactId * @param version */ @SuppressWarnings("unchecked") public ArtifactResolutionResult resolve( final String groupId, final String artifactId, final String version) { // final Artifact artifact = artifactFactory.createDependencyArtifact(groupId, artifactId, // VersionRange.createFromVersion(version), type, "", scope); final Artifact pomArtifact = getPomArtifact(groupId, artifactId, version); try { // load the pom as a MavenProject and get all of the dependencies for the project final MavenProject project = loadPomAsProject(projectBuilder, pomArtifact); final List dependencies = project.getDependencies(); // make Artifacts of all the dependencies and the project itself final Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts(artifactFactory, dependencies, null, null, null); dependencyArtifacts.add(project.getArtifact()); // create listener for monitoring the resolution process final List<RuntimeResolutionListener> listeners = new ArrayList<RuntimeResolutionListener>(); listeners.add(new RuntimeResolutionListener()); // resolve all dependencies transitively to obtain a comprehensive list of jars final ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencyArtifacts, pomArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories, metadataSource, null, listeners); if (debug) { for (final Object o : result.getArtifactResolutionNodes()) { System.out.println(o.toString()); } } return result; } catch (final Exception e) { throw new RuntimeException("Dependency Resolver failed", e); } }
private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact) throws MojoExecutionException { Set<Artifact> executableDependencies; try { MavenProject executableProject = this.projectBuilder.buildFromRepository( executablePomArtifact, this.remoteRepositories, this.localRepository); // get all of the dependencies for the executable project List<Artifact> dependencies = CastUtils.cast(executableProject.getDependencies()); // make Artifacts of all the dependencies Set<Artifact> dependencyArtifacts = CastUtils.cast( MavenMetadataSource.createArtifacts( this.artifactFactory, dependencies, null, null, null)); // not forgetting the Artifact of the project itself dependencyArtifacts.add(executableProject.getArtifact()); // resolve all dependencies transitively to obtain a comprehensive // list of assemblies ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencyArtifacts, executablePomArtifact, Collections.EMPTY_MAP, this.localRepository, this.remoteRepositories, metadataSource, null, Collections.EMPTY_LIST); executableDependencies = CastUtils.cast(result.getArtifacts()); } catch (Exception ex) { throw new MojoExecutionException( "Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex); } return executableDependencies; }
private void retrieveTransitiveDependencies(Set jarResourceArtifacts, List jarResources) throws ArtifactResolutionException, ArtifactNotFoundException { // this restricts to runtime and compile scope ScopeArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); ArtifactResolutionResult result = getArtifactResolver() .resolveTransitively( jarResourceArtifacts, getProject().getArtifact(), null, // managedVersions getLocalRepository(), getRemoteRepositories(), this.artifactMetadataSource, artifactFilter); Set transitiveResolvedArtifacts = result.getArtifacts(); if (getLog().isDebugEnabled()) { getLog().debug("transitively resolved artifacts = " + transitiveResolvedArtifacts); getLog().debug("jarResources = " + jarResources); getLog().debug("jarResourceArtifacts = " + jarResourceArtifacts); } // for each transitive dependency, wrap it in a JarResource and add it to the collection of // existing jar resources for (Iterator itr = transitiveResolvedArtifacts.iterator(); itr.hasNext(); ) { Artifact resolvedArtifact = (Artifact) itr.next(); // this whole double check is ugly as well as this method changing the input variable // we should really improve the way we collect the jarResources if (!jarResourceArtifacts.contains(resolvedArtifact)) { JarResource newJarResource = new JarResource(resolvedArtifact); if (!jarResources.contains(newJarResource)) { newJarResource.setOutputJarVersion(true); jarResources.add(newJarResource); } } } }
private void addProvider( SurefireBooter surefireBooter, String provider, String version, Artifact filteredArtifact) throws ArtifactNotFoundException, ArtifactResolutionException { Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", provider, VersionRange.createFromVersion(version), "jar", null, Artifact.SCOPE_TEST); ArtifactResolutionResult result = resolveArtifact(filteredArtifact, providerArtifact); for (Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); getLog().debug("Adding to surefire test classpath: " + artifact.getFile().getAbsolutePath()); surefireBooter.addSurefireClassPathUrl(artifact.getFile().getAbsolutePath()); } }
private ArtifactResolutionResult resolve(MavenArtifactRef a, boolean resolveTransitively) throws MojoExecutionException { Artifact artifact = repositorySystem.createArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion(), "jar"); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setLocalRepository(localRepository); request.setRemoteRepositories(remoteRepositories); request.setResolveRoot(true); request.setResolveTransitively(resolveTransitively); ArtifactResolutionResult result = repositorySystem.resolve(request); if (!result.isSuccess()) { throw new MojoExecutionException("Could not resolve extra classpath entry"); } result.setOriginatingArtifact(artifact); return result; }
/** * Resolves the given artifact to a maven project. * * @param artifact * @throws Exception */ protected MavenProject resolveProject(Artifact artifact) throws Exception { Artifact pomArtifact = repositorySystem.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "", "pom"); //$NON-NLS-1$ //$NON-NLS-2$ ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(pomArtifact); ArtifactResolutionResult resolved = repositorySystem.resolve(request); pomArtifact = resolved.getArtifacts().iterator().next(); InputStream contentStream = null; MavenProject project = null; try { contentStream = new FileInputStream(pomArtifact.getFile()); Model model = new MavenXpp3Reader().read(contentStream); project = new MavenProject(model); } finally { contentStream.close(); } return project; }
protected void addMvn2CompatResults( MavenProject project, List<Exception> exceptions, List<ResolutionListener> listeners, ArtifactRepository localRepository, Collection<MavenExecutionResult> executionResults) { ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest(); resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts()); resolutionRequest.setArtifact(project.getArtifact()); resolutionRequest.setManagedVersionMap(project.getManagedVersionMap()); resolutionRequest.setLocalRepository(localRepository); resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories()); resolutionRequest.setListeners(listeners); resolutionRequest.setResolveRoot(false); resolutionRequest.setResolveTransitively(true); ArtifactResolver resolver = getComponent(ArtifactResolver.class); ArtifactResolutionResult result = resolver.resolve(resolutionRequest); project.setArtifacts(result.getArtifacts()); executionResults.add(new MavenExecutionResult(project, exceptions)); }
/** * Create the transitive classpath. * * @return The dependent artifacts. * @throws MojoExecutionException If the classpath can't be found. */ public Set transitivelyResolvePomDependencies() throws MojoExecutionException { // make Artifacts of all the dependencies Set dependencyArtifacts; try { dependencyArtifacts = MavenMetadataSource.createArtifacts(artifactFactory, dependencies, null, null, null); } catch (InvalidDependencyVersionException e) { throw new MojoExecutionException("Invalid dependency", e); } // not forgetting the Artifact of the project itself dependencyArtifacts.add(project.getArtifact()); List listeners = Collections.EMPTY_LIST; // resolve all dependencies transitively to obtain a comprehensive list // of jars ArtifactResolutionResult result; try { result = artifactResolver.resolveTransitively( dependencyArtifacts, project.getArtifact(), Collections.EMPTY_MAP, localRepository, remoteRepositories, metadataSource, null, listeners); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve Artifact.", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to resolve Artifact.", e); } return result.getArtifacts(); }
/** * Returns the Set of APKLIB, AAR, APK (direct or transitive) dependencies of the supplied * artifact. * * <p>The project is searched until artifact is found and then the library dependencies are looked * for recursively. * * @param session MavenSession in which to resolve the artifacts. * @param repositorySystem RepositorySystem with which to resolve the artifacts. * @param artifact Artifact for whom to get the dependencies. * @return Set of APK, APKLIB and AAR dependencies. * @throws org.apache.maven.plugin.MojoExecutionException if it couldn't resolve any of the * dependencies. */ public Set<Artifact> getLibraryDependenciesFor( MavenSession session, RepositorySystem repositorySystem, Artifact artifact) throws MojoExecutionException { // Set a filter that should only return interesting artifacts. final ArtifactFilter filter = new ArtifactFilter() { @Override public boolean include(Artifact found) { final String type = found.getType(); return (type.equals(APKLIB) || type.equals(AAR) || type.equals(APK)); } }; log.debug("MavenSession = " + session + " repositorySystem = " + repositorySystem); final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setResolveRoot(false); // Don't include source artifact in result request.setResolveTransitively(true); // Include direct plus transitive dependencies. request.setServers(session.getRequest().getServers()); request.setMirrors(session.getRequest().getMirrors()); request.setProxies(session.getRequest().getProxies()); request.setLocalRepository(session.getLocalRepository()); request.setRemoteRepositories(session.getCurrentProject().getRemoteArtifactRepositories()); final ArtifactResolutionResult result = repositorySystem.resolve(request); final Set<Artifact> libraryDeps = new HashSet<Artifact>(); for (final Artifact depArtifact : result.getArtifacts()) { if (filter.include(depArtifact)) { libraryDeps.add(depArtifact); } } return libraryDeps; }
/** * Resolve project dependencies. Manual resolution is needed in order to avoid resoltion of * multiproject artifacts (if projects will be linked each other an installed jar is not needed) * and to avoid a failure when a jar is missing. * * @throws MojoExecutionException if dependencies can't be resolved * @return resoved IDE dependencies, with attached jars for non-reactor dependencies */ protected IdeDependency[] doDependencyResolution() throws MojoExecutionException { MavenProject project = getProject(); ArtifactRepository localRepo = getLocalRepository(); List dependencies = getProject().getDependencies(); // Collect the list of resolved IdeDependencies. List dependencyList = new ArrayList(); if (dependencies != null) { Map managedVersions = createManagedVersionMap( getArtifactFactory(), project.getId(), project.getDependencyManagement()); ArtifactResolutionResult artifactResolutionResult = null; try { List listeners = new ArrayList(); if (logger.isDebugEnabled()) { listeners.add(new DebugResolutionListener(logger)); } listeners.add(new WarningResolutionListener(logger)); artifactResolutionResult = artifactCollector.collect( getProjectArtifacts(), project.getArtifact(), managedVersions, localRepo, project.getRemoteArtifactRepositories(), getArtifactMetadataSource(), null, listeners); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog() .error( Messages.getString( "artifactresolution", new Object[] { // $NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); // if we are here artifactResolutionResult is null, create a project without dependencies // but don't fail // (this could be a reactor projects, we don't want to fail everything) return new IdeDependency[0]; } // keep track of added reactor projects in order to avoid duplicates Set emittedReactorProjectId = new HashSet(); for (Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i.hasNext(); ) { ResolutionNode node = (ResolutionNode) i.next(); Artifact art = node.getArtifact(); boolean isReactorProject = getUseProjectReferences() && isAvailableAsAReactorProject(art); // don't resolve jars for reactor projects if (!isReactorProject) { try { artifactResolver.resolve(art, node.getRemoteRepositories(), localRepository); } catch (ArtifactNotFoundException e) { getLog().debug(e.getMessage(), e); getLog() .warn( Messages.getString( "artifactdownload", new Object[] { // $NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog() .warn( Messages.getString( "artifactresolution", new Object[] { // $NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } } if (!isReactorProject || emittedReactorProjectId.add(art.getGroupId() + '-' + art.getArtifactId())) { IdeDependency dep = new IdeDependency( art.getGroupId(), art.getArtifactId(), art.getVersion(), isReactorProject, Artifact.SCOPE_TEST.equals(art.getScope()), Artifact.SCOPE_SYSTEM.equals(art.getScope()), Artifact.SCOPE_PROVIDED.equals(art.getScope()), art.getArtifactHandler().isAddedToClasspath(), art.getFile(), art.getType()); dependencyList.add(dep); } } // @todo a final report with the list of missingArtifacts? } IdeDependency[] deps = (IdeDependency[]) dependencyList.toArray(new IdeDependency[dependencyList.size()]); return deps; }
public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) { Artifact rootArtifact = request.getArtifact(); Set<Artifact> artifacts = request.getArtifactDependencies(); Map<String, Artifact> managedVersions = request.getManagedVersionMap(); List<ResolutionListener> listeners = request.getListeners(); ArtifactFilter collectionFilter = request.getCollectionFilter(); ArtifactFilter resolutionFilter = request.getResolutionFilter(); RepositorySystemSession session = getSession(request.getLocalRepository()); // TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i // have in the workspace if (source == null) { try { source = container.lookup(ArtifactMetadataSource.class); } catch (ComponentLookupException e) { // won't happen } } if (listeners == null) { listeners = new ArrayList<ResolutionListener>(); if (logger.isDebugEnabled()) { listeners.add(new DebugResolutionListener(logger)); } listeners.add(new WarningResolutionListener(logger)); } ArtifactResolutionResult result = new ArtifactResolutionResult(); // The root artifact may, or may not be resolved so we need to check before we attempt to // resolve. // This is often an artifact like a POM that is taken from disk and we already have hold of the // file reference. But this may be a Maven Plugin that we need to resolve from a remote // repository // as well as its dependencies. if (request.isResolveRoot() /* && rootArtifact.getFile() == null */) { try { resolve(rootArtifact, request.getRemoteRepositories(), session); } catch (ArtifactResolutionException e) { result.addErrorArtifactException(e); return result; } catch (ArtifactNotFoundException e) { result.addMissingArtifact(request.getArtifact()); return result; } } ArtifactResolutionRequest collectionRequest = request; if (request.isResolveTransitively()) { MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest(request); metadataRequest.setArtifact(rootArtifact); metadataRequest.setResolveManagedVersions(managedVersions == null); try { ResolutionGroup resolutionGroup = source.retrieve(metadataRequest); if (managedVersions == null) { managedVersions = resolutionGroup.getManagedVersions(); } Set<Artifact> directArtifacts = resolutionGroup.getArtifacts(); if (artifacts == null || artifacts.isEmpty()) { artifacts = directArtifacts; } else { List<Artifact> allArtifacts = new ArrayList<Artifact>(); allArtifacts.addAll(artifacts); allArtifacts.addAll(directArtifacts); Map<String, Artifact> mergedArtifacts = new LinkedHashMap<String, Artifact>(); for (Artifact artifact : allArtifacts) { String conflictId = artifact.getDependencyConflictId(); if (!mergedArtifacts.containsKey(conflictId)) { mergedArtifacts.put(conflictId, artifact); } } artifacts = new LinkedHashSet<Artifact>(mergedArtifacts.values()); } collectionRequest = new ArtifactResolutionRequest(request); collectionRequest.setServers(request.getServers()); collectionRequest.setMirrors(request.getMirrors()); collectionRequest.setProxies(request.getProxies()); collectionRequest.setRemoteRepositories(resolutionGroup.getResolutionRepositories()); } catch (ArtifactMetadataRetrievalException e) { ArtifactResolutionException are = new ArtifactResolutionException( "Unable to get dependency information for " + rootArtifact.getId() + ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e); result.addMetadataResolutionException(are); return result; } } if (artifacts == null || artifacts.isEmpty()) { if (request.isResolveRoot()) { result.addArtifact(rootArtifact); } return result; } // After the collection we will have the artifact object in the result but they will not be // resolved yet. result = artifactCollector.collect( artifacts, rootArtifact, managedVersions, collectionRequest, source, collectionFilter, listeners, null); // We have metadata retrieval problems, or there are cycles that have been detected // so we give this back to the calling code and let them deal with this information // appropriately. if (result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions()) { return result; } if (result.getArtifactResolutionNodes() != null) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); CountDownLatch latch = new CountDownLatch(result.getArtifactResolutionNodes().size()); for (ResolutionNode node : result.getArtifactResolutionNodes()) { Artifact artifact = node.getArtifact(); if (resolutionFilter == null || resolutionFilter.include(artifact)) { executor.execute( new ResolveTask( classLoader, latch, artifact, session, node.getRemoteRepositories(), result)); } else { latch.countDown(); } } try { latch.await(); } catch (InterruptedException e) { result.addErrorArtifactException( new ArtifactResolutionException("Resolution interrupted", rootArtifact, e)); } } // We want to send the root artifact back in the result but we need to do this after the other // dependencies // have been resolved. if (request.isResolveRoot()) { // Add the root artifact (as the first artifact to retain logical order of class path!) Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>(); allArtifacts.add(rootArtifact); allArtifacts.addAll(result.getArtifacts()); result.setArtifacts(allArtifacts); } return result; }