List of usage examples for org.apache.maven.artifact.resolver ArtifactResolver resolveTransitively
@Deprecated
ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts, Artifact originatingArtifact,
Map<String, Artifact> managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter)
throws ArtifactResolutionException, ArtifactNotFoundException;
From source file:br.com.anteros.restdoc.maven.plugin.util.ResourceResolver.java
License:Apache License
@SuppressWarnings("unchecked") private static List<String> resolveAndUnpack(final List<Artifact> artifacts, final SourceResolverConfig config, final List<String> validClassifiers, final boolean propagateErrors) throws ArtifactResolutionException, ArtifactNotFoundException { // NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually // resolve transitively...this is just used to aggregate resolution failures into a single // exception. final Set<Artifact> artifactSet = new LinkedHashSet<Artifact>(artifacts); final Artifact pomArtifact = config.project().getArtifact(); final ArtifactRepository localRepo = config.localRepository(); final List<ArtifactRepository> remoteRepos = config.project().getRemoteArtifactRepositories(); final ArtifactMetadataSource metadataSource = config.artifactMetadataSource(); final ArtifactFilter filter = config.filter(); ArtifactFilter resolutionFilter = null; if (filter != null) { // Wrap the filter in a ProjectArtifactFilter in order to always include the pomArtifact for resolution. // NOTE that this is necessary, b/c the -sources artifacts are added dynamically to the pomArtifact // and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has // to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved. resolutionFilter = new ProjectArtifactFilter(pomArtifact, filter); }/*w w w .j ava 2 s .c o m*/ final ArtifactResolver resolver = config.artifactResolver(); @SuppressWarnings("rawtypes") Map managed = config.project().getManagedVersionMap(); final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(artifactSet, pomArtifact, managed, localRepo, remoteRepos, metadataSource, resolutionFilter); final List<String> result = new ArrayList<String>(artifacts.size()); for (final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts()) { if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) { continue; } final File d = new File(config.outputBasedir(), a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier()); if (!d.exists()) { d.mkdirs(); } try { final UnArchiver unArchiver = config.archiverManager().getUnArchiver(a.getType()); unArchiver.setDestDirectory(d); unArchiver.setSourceFile(a.getFile()); unArchiver.extract(); result.add(d.getAbsolutePath()); } catch (final NoSuchArchiverException e) { if (propagateErrors) { throw new ArtifactResolutionException( "Failed to retrieve valid un-archiver component: " + a.getType(), a, e); } } catch (final ArchiverException e) { if (propagateErrors) { throw new ArtifactResolutionException("Failed to unpack: " + a.getId(), a, e); } } } return result; }