List of usage examples for org.apache.maven.artifact.resolver ArtifactResolutionRequest ArtifactResolutionRequest
public ArtifactResolutionRequest()
From source file:br.com.uggeri.maven.builder.mojo.DependencyResolver.java
private ArtifactResolutionRequest createArtifactResolutionRequest(Artifact artifact, ArtifactRepository localRepo, List<ArtifactRepository> remoteRepos) { ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest(); resolutionRequest.setArtifact(artifact); resolutionRequest.setLocalRepository(localRepo); resolutionRequest.setRemoteRepositories(remoteRepos); return resolutionRequest; }
From source file:ch.ifocusit.livingdoc.plugin.baseMojo.AbstractGlossaryMojo.java
License:Apache License
private void loadSourcesDependency(JavaProjectBuilder javaDocBuilder, Artifact sourcesArtifact) { // create request ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(sourcesArtifact); // resolve deps ArtifactResolutionResult result = repositorySystem.resolve(request); // load source file into javadoc builder result.getArtifacts().forEach(artifact -> { try {/*from w w w .ja v a2 s .c o m*/ JarFile jarFile = new JarFile(artifact.getFile()); for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = (JarEntry) entries.nextElement(); String name = entry.getName(); if (name.endsWith(".java") && !name.endsWith("/package-info.java")) { javaDocBuilder.addSource( new URL("jar:" + artifact.getFile().toURI().toURL().toString() + "!/" + name)); } } } catch (Exception e) { getLog().warn("Unable to load jar source " + artifact + " : " + e.getMessage()); } }); }
From source file:com.bugvm.maven.plugin.AbstractBugVMMojo.java
License:Apache License
protected Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException { ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact);/*from w ww .j a v a2s. com*/ if (artifact.isSnapshot()) { request.setForceUpdate(true); } request.setLocalRepository(localRepository); final List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories(); request.setRemoteRepositories(remoteRepositories); getLog().debug("Resolving artifact " + artifact); ArtifactResolutionResult result = artifactResolver.resolve(request); if (!result.isSuccess()) { throw new MojoExecutionException("Unable to resolve artifact: " + artifact); } Collection<Artifact> resolvedArtifacts = result.getArtifacts(); artifact = (Artifact) resolvedArtifacts.iterator().next(); return artifact; }
From source file:com.clearstorydata.maven.plugins.shadediff.mojo.ShadeDiffMojo.java
License:Apache License
private ArtifactResolutionResult resolveShadedJarToExclude(ShadedJarExclusion excludedShadedJar) throws MojoExecutionException { Artifact excludedShadedJarArtifact = this.factory.createArtifactWithClassifier( excludedShadedJar.getGroupId(), excludedShadedJar.getArtifactId(), excludedShadedJar.getVersion(), "jar", excludedShadedJar.getClassifier() == null ? "" : excludedShadedJar.getClassifier()); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(excludedShadedJarArtifact); request.setRemoteRepositories(remoteRepositories); request.setLocalRepository(localRepository); ArtifactResolutionResult result = artifactResolver.resolve(request); for (Exception ex : result.getExceptions()) { getLog().error(ex);/* w w w. jav a 2s . c o m*/ } if (result.hasExceptions()) { throw new MojoExecutionException("Artifact resolution failed"); } return result; }
From source file:com.comoyo.maven.plugins.emjar.EmJarMojo.java
License:Apache License
/** * Get artifact containing the EmJar class loader itself. *//*from ww w . j a v a2 s . c o m*/ private Artifact getEmJarArtifact() throws MojoExecutionException { final Artifact artifact = repositorySystem.createArtifact(pluginDescriptor.getGroupId(), "emjar", pluginDescriptor.getVersion(), "jar"); getLog().info("Using emjar " + artifact); ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact) .setRemoteRepositories(remoteRepositories); ArtifactResolutionResult result = repositorySystem.resolve(request); if (!result.isSuccess()) { throw new MojoExecutionException( "Unable to resolve dependency on EmJar loader artifact, sorry: " + result.toString()); } Set<Artifact> artifacts = result.getArtifacts(); if (artifacts.size() != 1) { throw new MojoExecutionException("Unexpected number of artifacts returned when resolving EmJar loader (" + artifacts.size() + ")"); } return artifacts.iterator().next(); }
From source file:com.edugility.maven.Artifacts.java
License:Open Source License
/** * Returns an unmodifiable, non-{@code null} {@link Collection} of * {@link Artifact}s, each element of which is a non-{@code null} * {@link Artifact} that represents either the supplied {@link * MavenProject} itself or a {@linkplain MavenProject#getArtifacts() * dependency of it}.// w w w.j av a 2 s.co m * * <p>The returned {@link Artifact} {@link Collection} will be * sorted in topological order, from an {@link Artifact} with no * dependencies as the first element, to the {@link Artifact} * representing the {@link MavenProject} itself as the last.</p> * * <p>All {@link Artifact}s that are not {@linkplain * Object#equals(Object) equal to} the return value of {@link * MavenProject#getArtifact() project.getArtifact()} will be * {@linkplain ArtifactResolver#resolve(ArtifactResolutionRequest) * resolved} if they are not already {@linkplain * Artifact#isResolved() resolved}. No guarantee of {@linkplain * Artifact#isResolved() resolution status} is made of the * {@linkplain MavenProject#getArtifact() project * <code>Artifact</code>}, which in normal—possibly * all?—cases will be unresolved.</p> * * @param project the {@link MavenProject} for which resolved {@link * Artifact}s should be returned; must not be {@code null} * * @param dependencyGraphBuilder the {@link DependencyGraphBuilder} * instance that will calculate the dependency graph whose postorder * traversal will yield the {@link Artifact}s to be resolved; must * not be {@code null} * * @param filter an {@link ArtifactFilter} used during {@linkplain * DependencyGraphBuilder#buildDependencyGraph(MavenProject, * ArtifactFilter) dependency graph assembly}; may be {@code null} * * @param resolver an {@link ArtifactResolver} that will use the <a * href="http://maven.apache.org/ref/3.0.5/maven-compat/apidocs/src-html/org/apache/maven/artifact/resolver/DefaultArtifactResolver.html#line.335">Maven * 3.0.5 <code>Artifact</code> resolution algorithm</a> to resolve * {@link Artifact}s returned by the {@link * DependencyGraphBuilder#buildDependencyGraph(MavenProject, * ArtifactFilter)} method; must not be {@code null} * * @param localRepository an {@link ArtifactRepository} representing * the local Maven repository in effect; may be {@code null} * * @return a non-{@code null}, {@linkplain * Collections#unmodifiableCollection(Collection) unmodifiable} * {@link Collection} of non-{@code null} {@link Artifact} instances * * @exception IllegalArgumentException if {@code project}, {@code * dependencyGraphBuilder} or {@code resolver} is {@code null} * * @exception ArtifactResolutionException if there were problems * {@linkplain ArtifactResolver#resolve(ArtifactResolutionRequest) * resolving} {@link Artifact} instances * * @exception DependencyGraphBuilderException if there were problems * {@linkplain * DependencyGraphBuilder#buildDependencyGraph(MavenProject, * ArtifactFilter) building the dependency graph} * * @see ArtifactResolver#resolve(ArtifactResolutionRequest) * * @see DependencyGraphBuilder#buildDependencyGraph(MavenProject, * ArtifactFilter) */ public Collection<? extends Artifact> getArtifactsInTopologicalOrder(final MavenProject project, final DependencyGraphBuilder dependencyGraphBuilder, final ArtifactFilter filter, final ArtifactResolver resolver, final ArtifactRepository localRepository) throws DependencyGraphBuilderException, ArtifactResolutionException { final Logger logger = this.getLogger(); if (logger != null && logger.isLoggable(Level.FINER)) { logger.entering(this.getClass().getName(), "getArtifactsInTopologicalOrder", new Object[] { project, dependencyGraphBuilder, filter, resolver, localRepository }); } if (project == null) { throw new IllegalArgumentException("project", new NullPointerException("project")); } if (dependencyGraphBuilder == null) { throw new IllegalArgumentException("dependencyGraphBuilder", new NullPointerException("dependencyGraphBuilder")); } if (resolver == null) { throw new IllegalArgumentException("resolver", new NullPointerException("resolver")); } List<Artifact> returnValue = null; final DependencyNode projectNode = dependencyGraphBuilder.buildDependencyGraph(project, filter); assert projectNode != null; final CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor(); projectNode.accept(visitor); final Collection<? extends DependencyNode> nodes = visitor.getNodes(); if (nodes == null || nodes.isEmpty()) { if (logger != null && logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, this.getClass().getName(), "getArtifactsInTopologicalOrder", "No dependency nodes encountered"); } } else { final Artifact projectArtifact = project.getArtifact(); returnValue = new ArrayList<Artifact>(); for (final DependencyNode node : nodes) { if (node != null) { Artifact artifact = node.getArtifact(); if (artifact != null) { if (!artifact.isResolved()) { if (logger != null && logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, this.getClass().getName(), "getArtifactsInTopologicalOrder", "Artifact {0} is unresolved", artifact); } if (artifact.equals(projectArtifact)) { // First see if the artifact is the project artifact. // If so, then it by definition won't be able to be // resolved, because it's being built. if (logger != null && logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, this.getClass().getName(), "getArtifactsInTopologicalOrder", "Artifact {0} resolved to project artifact: {1}", new Object[] { artifact, projectArtifact }); } artifact = projectArtifact; } else { // See if the project's associated artifact map // contains a resolved version of this artifact. The // artifact map contains all transitive dependency // artifacts of the project. Each artifact in the map // is guaranteed to be resolved. @SuppressWarnings("unchecked") final Map<String, Artifact> artifactMap = project.getArtifactMap(); if (artifactMap != null && !artifactMap.isEmpty()) { final Artifact mapArtifact = artifactMap .get(new StringBuilder(artifact.getGroupId()).append(":") .append(artifact.getArtifactId()).toString()); if (mapArtifact != null) { if (logger != null && logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, this.getClass().getName(), "getArtifactsInTopologicalOrder", "Artifact {0} resolved from project artifact map: {1}", new Object[] { artifact, mapArtifact }); } artifact = mapArtifact; } } if (!artifact.isResolved()) { // Finally, perform manual artifact resolution. final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setLocalRepository(localRepository); @SuppressWarnings("unchecked") final List<ArtifactRepository> remoteRepositories = project .getRemoteArtifactRepositories(); request.setRemoteRepositories(remoteRepositories); if (logger != null && logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, this.getClass().getName(), "getArtifactsInTopologicalOrder", "Resolving artifact {0} using ArtifactResolutionRequest {1}", new Object[] { artifact, request }); } final ArtifactResolutionResult result = resolver.resolve(request); if (result == null || !result.isSuccess()) { this.handleArtifactResolutionError(request, result); } else { @SuppressWarnings("unchecked") final Collection<? extends Artifact> resolvedArtifacts = (Set<? extends Artifact>) result .getArtifacts(); if (resolvedArtifacts == null || resolvedArtifacts.isEmpty()) { if (logger != null && logger.isLoggable(Level.WARNING)) { logger.logp(Level.WARNING, this.getClass().getName(), "getArtifactsInTopologicalOrder", "Artifact resolution failed silently for artifact {0}", artifact); } } else { final Artifact resolvedArtifact = resolvedArtifacts.iterator().next(); if (resolvedArtifact != null) { assert resolvedArtifact.isResolved(); artifact = resolvedArtifact; } else if (logger != null && logger.isLoggable(Level.WARNING)) { logger.logp(Level.WARNING, this.getClass().getName(), "getArtifactsInTopologicalOrder", "Artifact resolution failed silently for artifact {0}", artifact); } } } } } } if (artifact != null) { returnValue.add(artifact); } } } } if (!returnValue.isEmpty()) { Collections.reverse(returnValue); Collections.sort(returnValue, scopeComparator); } } if (returnValue == null) { returnValue = Collections.emptyList(); } else { returnValue = Collections.unmodifiableList(returnValue); } if (logger != null && logger.isLoggable(Level.FINER)) { logger.exiting(this.getClass().getName(), "getArtifactsInTopologicalOrder", returnValue); } return returnValue; }
From source file:com.github.jrh3k5.mojo.flume.AbstractFlumeAgentsMojo.java
License:Apache License
/** * Convert an {@link Artifact} into an {@link ArtifactResolutionRequest}. * /*from w w w. ja va2 s. c o m*/ * @param artifact * The {@link Artifact} to be converted into a resolution request. * @return An {@link ArtifactResolutionRequest} made out of the given artifact. */ private ArtifactResolutionRequest toRequest(Artifact artifact) { final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); return request; }
From source file:com.github.s4u.plugins.PGPVerifyMojo.java
License:Apache License
/** * Create ArtifactResolutionRequest for asc file corresponding to artifact. * * @param artifact artifact/*from ww w . ja v a 2s. com*/ * @return new ArtifactResolutionRequest */ private ArtifactResolutionRequest getArtifactResolutionRequestForAsc(Artifact artifact) { Artifact aAsc = repositorySystem.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType() + ".asc", artifact.getClassifier()); ArtifactResolutionRequest rreq = new ArtifactResolutionRequest(); rreq.setArtifact(aAsc); rreq.setResolveTransitively(false); rreq.setLocalRepository(localRepository); rreq.setRemoteRepositories(pomRemoteRepositories); return rreq; }
From source file:com.github.s4u.plugins.PGPVerifyMojo.java
License:Apache License
/** * Create ArtifactResolutionRequest for pom file corresponding to artifact. * * @param artifact artifact/*w ww . jav a2 s .c o m*/ * @return new ArtifactResolutionRequest */ private ArtifactResolutionRequest getArtifactResolutionRequestForPom(Artifact artifact) { Artifact aAsc = repositorySystem.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "pom", artifact.getClassifier()); ArtifactResolutionRequest rreq = new ArtifactResolutionRequest(); rreq.setArtifact(aAsc); rreq.setResolveTransitively(false); rreq.setLocalRepository(localRepository); rreq.setRemoteRepositories(pomRemoteRepositories); return rreq; }
From source file:com.jayway.maven.plugins.android.common.ArtifactResolverHelper.java
License:Open Source License
/** * Resolves an artifact to a particular repository. * * @param artifact Artifact to resolve//w ww.j av a2 s.c om * @return fully resolved artifact. */ private Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException { final ArtifactResolutionRequest artifactResolutionRequest = new ArtifactResolutionRequest(); artifactResolutionRequest.setArtifact(artifact); if (remoteArtifactRepositories != null && !remoteArtifactRepositories.isEmpty()) { artifactResolutionRequest.setRemoteRepositories(remoteArtifactRepositories); } final ArtifactResolutionResult resolutionResult = this.artifactResolver.resolve(artifactResolutionRequest); log.debug("Resolving : " + artifact); if (resolutionResult.getArtifacts().size() == 0) { throw new MojoExecutionException("Could not resolve artifact " + artifact + ". Please install it with \"mvn install:install-file ...\" or deploy it to a repository " + "with \"mvn deploy:deploy-file ...\""); } if (resolutionResult.getArtifacts().size() > 1) { log.debug("Resolved artifacts : " + resolutionResult.getArtifacts()); throw new MojoExecutionException("Could not resolve artifact " + artifact + " to single target. Found the following possible options : " + resolutionResult.getArtifacts()); } final Artifact resolvedArtifact = resolutionResult.getArtifacts().iterator().next(); log.debug("Resolved : " + resolvedArtifact); return resolvedArtifact; }