List of usage examples for org.apache.maven.artifact.resolver ArtifactResolutionRequest setLocalRepository
public ArtifactResolutionRequest setLocalRepository(ArtifactRepository localRepository)
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: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 a 2 s. c o m*/ 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);/*from www. j a v a2s.c o m*/ } if (result.hasExceptions()) { throw new MojoExecutionException("Artifact resolution failed"); } return result; }
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}./*from www. j a v a2 s. c o 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.s4u.plugins.PGPVerifyMojo.java
License:Apache License
/** * Create ArtifactResolutionRequest for asc file corresponding to artifact. * * @param artifact artifact/*w w w . j a va2 s . c om*/ * @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 w w.j a v a 2 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.tenderowls.opensource.haxemojos.components.NativeBootstrap.java
License:Apache License
private Artifact resolveArtifact(Artifact artifact, List<ArtifactRepository> artifactRepositories) throws Exception { if (artifact.isResolved() || artifact.getFile() != null) return artifact; ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact);/*from www . j a v a 2 s. c om*/ request.setLocalRepository(localRepository); request.setRemoteRepositories(artifactRepositories); ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request); if (!resolutionResult.isSuccess()) { if (artifact.getType().equals(TGZ)) { artifact = repositorySystem.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), TARGZ, artifact.getClassifier()); request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setLocalRepository(localRepository); request.setRemoteRepositories(project.getRemoteArtifactRepositories()); resolutionResult = repositorySystem.resolve(request); if (resolutionResult.isSuccess()) { return artifact; } } String message = "Failed to resolve artifact " + artifact; throw new Exception(message); } return artifact; }
From source file:com.universalmediaserver.external.AbstractExternalDependencyMojo.java
License:Apache License
/** * resolve the artifact in local or remote repository * * @param artifact the artifact to resolve * @return/*from www .j av a2 s . c om*/ * Whether or not the artifact was resolved */ protected boolean resolveArtifactItem(Artifact artifact) { // Determine if the artifact is already installed in an existing Maven repository ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setRemoteRepositories(remoteRepositories); request.setLocalRepository(localRepository); return artifactResolver.resolve(request).isSuccess(); }
From source file:com.yelbota.plugins.nd.DependencyHelper.java
License:Apache License
/** * Resolves native dependency artifact. First it checks plugin dependencies * compares they with getDefaultArtifactId() and getDefaultGroupId(), then method * tries to resolve from repositories using also getDefaultVersion(), getDefaultPackaging() * and getDefaultClassifier()./*w ww.j a v a2 s . co m*/ * * @param pluginArtifacts list of plugin dependencies (inject this with @parameter) * @param repositorySystem inject this with @parameter * @param localRepository inject this with @parameter * @param remoteRepositories inject this with @parameter * @return Native dependency artifact * @throws MojoFailureException */ public Artifact resolve(List<Artifact> pluginArtifacts, RepositorySystem repositorySystem, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) throws MojoFailureException { Artifact artifact = null; if (pluginArtifacts != null) { // Lookup plugin artifacts. for (Artifact pluginArtifact : pluginArtifacts) { boolean eqGroupId = pluginArtifact.getGroupId().equals(getDefaultGroupId()); boolean eqArtifactId = pluginArtifact.getArtifactId().equals(getDefaultArtifactId()); if (eqGroupId && eqArtifactId) { artifact = pluginArtifact; break; } } } if (artifact != null) { return artifact; } else { // Okay. Lets download sdk if (repositorySystem != null) { artifact = repositorySystem.createArtifactWithClassifier( getDefaultGroupId(), getDefaultArtifactId(), getDefaultVersion(), getDefaultPackaging(), getDefaultClassifier()); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setLocalRepository(localRepository); request.setRemoteRepositories(remoteRepositories); ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request); if (!resolutionResult.isSuccess()) { String message = "Failed to resolve artifact " + artifact; throw new ArtifactResolutionException(message, resolutionResult); } } return artifact; } }
From source file:io.fabric8.jube.maven.BuildMojo.java
License:Apache License
protected void unpackBaseImage(File buildDir, boolean useDefaultPrefix) throws Exception { String imageName = project.getProperties().getProperty(DOCKER_BASE_IMAGE_PROPERTY); Objects.notNull(imageName, DOCKER_BASE_IMAGE_PROPERTY); ImageMavenCoords baseImageCoords = ImageMavenCoords.parse(imageName, useDefaultPrefix); String coords = baseImageCoords.getAetherCoords(); Artifact artifact = repositorySystem.createArtifactWithClassifier(baseImageCoords.getGroupId(), baseImageCoords.getArtifactId(), baseImageCoords.getVersion(), baseImageCoords.getType(), baseImageCoords.getClassifier()); getLog().info("Resolving Jube image: " + artifact); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact);//from ww w .ja v a2 s . c o m request.setLocalRepository(localRepository); request.setRemoteRepositories(pomRemoteRepositories); ArtifactResolutionResult result = artifactResolver.resolve(request); if (!result.isSuccess()) { throw new ArtifactNotFoundException("Cannot download Jube image", artifact); } getLog().info("Resolved Jube image: " + artifact); if (artifact.getFile() != null) { File file = artifact.getFile(); getLog().info("File: " + file); if (!file.exists() || file.isDirectory()) { throw new MojoExecutionException( "Resolved file for " + coords + " is not a valid file: " + file.getAbsolutePath()); } getLog().info("Unpacking base image " + file.getAbsolutePath() + " to build dir: " + buildDir); Zips.unzip(new FileInputStream(file), buildDir); } }