Java 类org.apache.maven.project.artifact.MavenMetadataSource 实例源码

项目:maven-jaxb2-plugin    文件:ArtifactUtils.java   
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;
}
项目:lazydoc    文件:LazyDocMojo.java   
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);
    }
}
项目:Camel    文件:RunMojo.java   
/**
 * 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;
}
项目:Camel    文件:RunMojo.java   
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;
    }
项目:Camel    文件:RunMojo.java   
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;
    }
项目:exec-maven-plugin    文件:ExecJavaMojo.java   
/**
 * 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;
}
项目:maven-jaxb2-plugin    文件:ArtifactUtils.java   
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;
}
项目:jprotobuf    文件:PreCompileMojo.java   
/**
 * 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;
}
项目:camel-cdi    文件:RunMojo.java   
/**
 * 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;
}
项目:camel-cdi    文件:RunMojo.java   
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;
    }
项目:versions-maven-plugin    文件:DefaultVersionsHelperTest.java   
private DefaultVersionsHelper createHelper()
    throws MojoExecutionException
{
    return createHelper( new MavenMetadataSource() );
}
项目:versions-maven-plugin-svn-clone    文件:DefaultVersionsHelperTest.java   
private VersionsHelper createHelper()
    throws MojoExecutionException
{
    return createHelper( new MavenMetadataSource() );
}
项目:oceano    文件:MavenProject.java   
@Deprecated
public Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter )
    throws InvalidDependencyVersionException
{
    return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope, filter, this );
}