org.apache.maven.project.artifact.MavenMetadataSource Java Examples

The following examples show how to use org.apache.maven.project.artifact.MavenMetadataSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArtifactUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example #2
Source File: ArtifactUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #3
Source File: PreCompileMojo.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: DefaultVersionsHelperTest.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
private DefaultVersionsHelper createHelper()
    throws MojoExecutionException
{
    return createHelper( new MavenMetadataSource() );
}