List of usage examples for org.apache.maven.artifact.resolver ArtifactResolutionException ArtifactResolutionException
public ArtifactResolutionException(String message, Artifact artifact, Throwable cause)
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); }//from www .j a va 2s .com 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; }
From source file:com.adviser.maven.GraphArtifactCollector.java
License:Apache License
private void recurse(ResolutionNode node, Map resolvedArtifacts, Map managedVersions, ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List listeners) throws CyclicDependencyException, ArtifactResolutionException, OverConstrainedVersionException { fireEvent(ResolutionListener.TEST_ARTIFACT, listeners, node); // TODO: use as a conflict resolver Object key = node.getKey();/* w ww. jav a 2s .c o m*/ if (managedVersions.containsKey(key)) { Artifact artifact = (Artifact) managedVersions.get(key); fireEvent(ResolutionListener.MANAGE_ARTIFACT, listeners, node, artifact); if (artifact.getVersion() != null) { node.getArtifact().setVersion(artifact.getVersion()); } if (artifact.getScope() != null) { node.getArtifact().setScope(artifact.getScope()); } } List previousNodes = (List) resolvedArtifacts.get(key); if (previousNodes != null) { node = checkPreviousNodes(node, listeners, previousNodes); } else { previousNodes = new ArrayList(); resolvedArtifacts.put(key, previousNodes); } previousNodes.add(node); if (node.isActive()) { fireEvent(ResolutionListener.INCLUDE_ARTIFACT, listeners, node); } // don't pull in the transitive deps of a system-scoped dependency. if (node.isActive() && !Artifact.SCOPE_SYSTEM.equals(node.getArtifact().getScope())) { fireEvent(ResolutionListener.PROCESS_CHILDREN, listeners, node); for (Iterator i = node.getChildrenIterator(); i.hasNext();) { ResolutionNode child = (ResolutionNode) i.next(); // We leave in optional ones, but don't pick up its dependencies if (!child.isResolved() && (!child.getArtifact().isOptional() || child.isChildOfRootNode())) { Artifact artifact = child.getArtifact(); try { if (artifact.getVersion() == null) { // set the recommended version // TODO: maybe its better to just pass the range // through to retrieval and use a transformation? ArtifactVersion version; version = getArtifactVersion(localRepository, remoteRepositories, source, artifact); artifact.selectVersion(version.toString()); fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child); } ResolutionGroup rGroup = source.retrieve(artifact, localRepository, remoteRepositories); // TODO might be better to have source.retreive() throw // a specific exception for this situation // and catch here rather than have it return null if (rGroup == null) { // relocated dependency artifact is declared // excluded, no need to add and recurse further continue; } child.addDependencies(rGroup.getArtifacts(), rGroup.getResolutionRepositories(), filter); } catch (CyclicDependencyException e) { // would like to throw this, but we have crappy stuff in // the repo fireEvent(ResolutionListener.OMIT_FOR_CYCLE, listeners, new ResolutionNode(e.getArtifact(), remoteRepositories, child)); } catch (ArtifactMetadataRetrievalException e) { artifact.setDependencyTrail(node.getDependencyTrail()); throw new ArtifactResolutionException( "Unable to get dependency information: " + e.getMessage(), artifact, e); } recurse(child, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter, listeners); } } fireEvent(ResolutionListener.FINISH_PROCESSING_CHILDREN, listeners, node); } }
From source file:hudson.maven.artifact.transform.SnapshotTransformation.java
License:Apache License
public void transformForResolve(Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository) throws ArtifactResolutionException { // Only select snapshots that are unresolved (eg 1.0-SNAPSHOT, not 1.0-20050607.123456) if (artifact.isSnapshot() && artifact.getBaseVersion().equals(artifact.getVersion())) { try {//from ww w . j ava2s . com String version = resolveVersion(artifact, localRepository, remoteRepositories); artifact.updateVersion(version, localRepository); } catch (RepositoryMetadataResolutionException e) { throw new ArtifactResolutionException(e.getMessage(), artifact, e); } } }
From source file:npanday.executable.impl.NetPluginExecutableFactoryImpl.java
License:Apache License
/** * Returns the path of the artifact within the private application base. * * * * @param artifact the artifact to find the path of. This value should not be null. * @param outputDir/*from w w w . j a v a 2 s. c om*/ * @return the path of the artifact within the private application base or null if either of the specified * parameters is null */ private File getPrivateApplicationBaseFileFor(Artifact artifact, File outputDir) throws ArtifactResolutionException { if (artifact == null) { getLogger().warn("NPANDAY-040-003: Artifact is null - Cannot get application file."); return null; } outputDir.mkdir(); String filename = artifact.getArtifactId() + "." + artifact.getArtifactHandler().getExtension(); File targetFile = new File(outputDir, filename); try { FileUtils.copyFile(artifact.getFile(), targetFile); } catch (IOException ioe) { throw new ArtifactResolutionException("NPANDAY-1005-0001: Error copying dependency", artifact, ioe); } return targetFile; }
From source file:npanday.resolver.NPandayDependencyResolution.java
License:Apache License
public Set<Artifact> require(MavenProject project, ArtifactRepository localRepository, ArtifactFilter filter) throws ArtifactResolutionException { long startTime = System.currentTimeMillis(); artifactResolver.initializeWithFilter(filter); if (getLogger().isDebugEnabled()) { getLogger().debug("NPANDAY-148-007: Resolving dependencies for " + project.getArtifact()); }/* w ww. j a v a2 s.co m*/ try { if (project.getDependencyArtifacts() == null) { createArtifactsForMaven2BackCompat(project); } ArtifactResolutionResult result = artifactResolver.resolveTransitively(project.getDependencyArtifacts(), project.getArtifact(), project.getManagedVersionMap(), localRepository, project.getRemoteArtifactRepositories(), metaDataSource, filter); /* * WORKAROUND: transitive dependencies are not cached in MavenProject; in order to let * them "live" for following mojo executions, we'll add the custom resolved * dependencies to the projects DIRECT dependencies * */ Set<Artifact> dependencyArtifacts = new HashSet<Artifact>(project.getDependencyArtifacts()); addResolvedSpecialsToProjectDependencies(result, dependencyArtifacts); // Add custom contribute dependencies to maven project dependencies dependencyArtifacts.addAll(artifactResolver.getCustomDependenciesCache()); project.setDependencyArtifacts(dependencyArtifacts); Set<Artifact> resultRequire = Sets.newLinkedHashSet(result.getArtifacts()); resultRequire.addAll(artifactResolver.getCustomDependenciesCache()); if (getLogger().isInfoEnabled()) { long endTime = System.currentTimeMillis(); getLogger() .info("NPANDAY-148-009: Took " + (endTime - startTime) + "ms to resolve dependencies for " + project.getArtifact() + " with filter " + filter.toString()); } return resultRequire; } catch (ArtifactResolutionException e) { throw new ArtifactResolutionException("NPANDAY-148-001: Could not resolve project dependencies", project.getArtifact(), e); } catch (ArtifactNotFoundException e) { throw new ArtifactResolutionException("NPANDAY-148-002: Could not resolve project dependencies", project.getArtifact(), e); } catch (InvalidDependencyVersionException e) { throw new ArtifactResolutionException("NPANDAY-148-003: Could not resolve project dependencies", project.getArtifact(), e); } }
From source file:org.echocat.jomon.maven.boot.ArtifactBasedClassLoader.java
License:Mozilla Public License
@Nonnull private Set<Artifact> initArtifacts(@Nonnull ArtifactWithDependencies... artifacts) throws Exception { final Set<Artifact> result = initArtifacts(asList(artifacts)); for (final Artifact artifact : result) { try {//from w w w.j a v a2 s. c o m addURL(artifact.getFile().toURI().toURL()); } catch (final Exception e) { throw new ArtifactResolutionException("Could not create file url for artifact.", artifact, e); } } return result; }
From source file:org.nuxeo.build.maven.EmbeddedMavenClient.java
License:Open Source License
public void resolveDependencyTree(Artifact artifact, ArtifactFilter filter, ResolutionListener listener) throws ArtifactResolutionException, ProjectBuildingException { MavenProject project = mavenProjectBuilder.buildFromRepository(artifact, getRemoteRepositories(), localRepository);//from www . j a va 2 s . c o m @SuppressWarnings("rawtypes") Set dependencyArtifacts = project.getDependencyArtifacts(); if (dependencyArtifacts == null) { try { dependencyArtifacts = project.createArtifacts(artifactFactory, null, null); } catch (InvalidDependencyVersionException e) { throw new ArtifactResolutionException("Cannot set dependencies", artifact, e); } project.setDependencyArtifacts(dependencyArtifacts); } ArtifactCollector collector = new DefaultArtifactCollector(); collector.collect(dependencyArtifacts, project.getArtifact(), project.getManagedVersionMap(), localRepository, project.getRemoteArtifactRepositories(), artifactMetadataSource, filter, Collections.singletonList(listener)); }