public static Collection<Artifact> resolve( final ArtifactFactory artifactFactory, final ArtifactResolver artifactResolver, final ArtifactRepository localRepository, final ArtifactMetadataSource artifactMetadataSource, final Dependency[] dependencies, final MavenProject project) throws InvalidDependencyVersionException, ArtifactResolutionException, ArtifactNotFoundException { if (dependencies == null) { return Collections.emptyList(); } @SuppressWarnings("unchecked") final Set<Artifact> artifacts = MavenMetadataSource.createArtifacts( artifactFactory, Arrays.asList(dependencies), "runtime", null, project); for (Artifact artifact : artifacts) { artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); } final Set<Artifact> resolvedArtifacts = artifacts; return resolvedArtifacts; }
private Set<Artifact> resolveProjectDependencies(List<Dependency> dependencies) throws MojoExecutionException { Set<Artifact> resolvedArtifacts = new HashSet<>(); try { getLog().debug("Project dependencies: "+dependencies); // make Artifacts of all the dependencies Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, null, null, null); getLog().debug("Artifacts build from dependencies: "+dependencyArtifacts); for (Artifact dependencyArtifact : dependencyArtifacts) { artifactResolver.resolve(dependencyArtifact, this.remoteRepositories, this.localRepository); ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, dependencyArtifact, this.remoteRepositories, this.localRepository, this.metadataSource); resolvedArtifacts.addAll(result.getArtifacts()); } resolvedArtifacts.addAll(dependencyArtifacts); return resolvedArtifacts; } catch (Exception ex) { throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex); } }
/** * Determine all plugin dependencies relevant to the executable. Takes * includePlugins, and the executableDependency into consideration. * * @return a set of Artifact objects. (Empty set is returned if there are no * relevant plugin dependencies.) * @throws MojoExecutionException */ private Set<Artifact> determineRelevantPluginDependencies() throws MojoExecutionException { Set<Artifact> relevantDependencies; if (this.includePluginDependencies) { if (this.executableDependency == null) { getLog().debug("All Plugin Dependencies will be included."); relevantDependencies = new HashSet<Artifact>(this.pluginDependencies); } else { getLog().debug("Selected plugin Dependencies will be included."); Artifact executableArtifact = this.findExecutableArtifact(); Artifact executablePomArtifact = this.getExecutablePomArtifact(executableArtifact); relevantDependencies = this.resolveExecutableDependencies(executablePomArtifact, false); } } else { getLog().debug("Only Direct Plugin Dependencies will be included."); PluginDescriptor descriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); try { relevantDependencies = artifactResolver .resolveTransitively(MavenMetadataSource .createArtifacts(this.artifactFactory, descriptor.getPlugin().getDependencies(), null, null, null), this.project.getArtifact(), Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME), Collections.emptyList()) .getArtifacts(); } catch (Exception ex) { throw new MojoExecutionException("Encountered problems resolving dependencies of the plugin " + "in preparation for its execution.", ex); } } return relevantDependencies; }
private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact, boolean ignoreFailures) throws MojoExecutionException { Set<Artifact> executableDependencies = null; 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 runtime dependencies transitively to obtain a comprehensive list of assemblies ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME), Collections.emptyList()); executableDependencies = CastUtils.cast(result.getArtifacts()); } catch (Exception ex) { if (ignoreFailures) { getLog().debug("Ignoring maven resolving dependencies failure " + ex.getMessage()); } else { throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex); } } return executableDependencies; }
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.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, null, Collections.emptyList()); 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; }
/** * Resolve the executable dependencies for the specified project * * @param executablePomArtifact the project's POM * @return a set of Artifacts * @throws MojoExecutionException if a failure happens */ 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<Dependency> dependencies = executableProject.getDependencies(); // make Artifacts of all the dependencies Set<Artifact> dependencyArtifacts = 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.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, null, Collections.emptyList() ); executableDependencies = result.getArtifacts(); } catch ( Exception ex ) { throw new MojoExecutionException( "Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex ); } return executableDependencies; }
public static Collection<Artifact> resolveTransitively( final ArtifactFactory artifactFactory, final ArtifactResolver artifactResolver, final ArtifactRepository localRepository, final ArtifactMetadataSource artifactMetadataSource, final Dependency[] dependencies, final MavenProject project) throws InvalidDependencyVersionException, ArtifactResolutionException, ArtifactNotFoundException { if (dependencies == null) { return Collections.emptyList(); } @SuppressWarnings("unchecked") final Set<Artifact> artifacts = MavenMetadataSource.createArtifacts( artifactFactory, Arrays.asList(dependencies), "runtime", null, project); final ArtifactResolutionResult artifactResolutionResult = artifactResolver .resolveTransitively(artifacts, project.getArtifact(), project.getRemoteArtifactRepositories(), localRepository, artifactMetadataSource); @SuppressWarnings("unchecked") final Set<Artifact> resolvedArtifacts = artifactResolutionResult .getArtifacts(); return resolvedArtifacts; }
private DefaultVersionsHelper createHelper() throws MojoExecutionException { return createHelper( new MavenMetadataSource() ); }
private VersionsHelper createHelper() throws MojoExecutionException { return createHelper( new MavenMetadataSource() ); }
@Deprecated public Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter ) throws InvalidDependencyVersionException { return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope, filter, this ); }