Search in sources :

Example 76 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.

the class AbstractDependencyMojo method newResolveArtifactProjectBuildingRequest.

/**
 * @return Returns a new ProjectBuildingRequest populated from the current session and the current project remote
 *         repositories, used to resolve artifacts.
 */
public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest() {
    ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
    buildingRequest.setRemoteRepositories(remoteRepositories);
    return buildingRequest;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 77 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.

the class GetMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("Skipping plugin execution");
        return;
    }
    if (coordinate.getArtifactId() == null && artifact == null) {
        throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
    }
    if (artifact != null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length < 3 || tokens.length > 5) {
            throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        coordinate.setGroupId(tokens[0]);
        coordinate.setArtifactId(tokens[1]);
        coordinate.setVersion(tokens[2]);
        if (tokens.length >= 4) {
            coordinate.setType(tokens[3]);
        }
        if (tokens.length == 5) {
            coordinate.setClassifier(tokens[4]);
        }
    }
    ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
    if (pomRemoteRepositories != null) {
        repoList.addAll(pomRemoteRepositories);
    }
    if (remoteRepositories != null) {
        // Use the same format as in the deploy plugin id::layout::url
        List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
        for (String repo : repos) {
            repoList.add(parseRepository(repo, always));
        }
    }
    try {
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(repoList);
        if (transitive) {
            getLog().info("Resolving " + coordinate + " with transitive dependencies");
            dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
        } else {
            getLog().info("Resolving " + coordinate);
            artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
        }
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    } catch (DependencyResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 78 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.

the class DefaultDependencyResolverTest method test_getDependencySetResolutionRequirements.

public void test_getDependencySetResolutionRequirements() throws DependencyResolutionException {
    final DependencySet ds1 = new DependencySet();
    ds1.setScope(Artifact.SCOPE_COMPILE);
    ds1.setUseTransitiveDependencies(false);
    final DependencySet ds2 = new DependencySet();
    ds2.setScope(Artifact.SCOPE_SYSTEM);
    ds2.setUseTransitiveDependencies(false);
    final MavenProject project = createMavenProject("main-group", "main-artifact", "1", null);
    final ResolutionManagementInfo info = new ResolutionManagementInfo(project);
    final Assembly assembly = new Assembly();
    ProjectBuildingRequest buildingRequest = newMavenSession(project).getProjectBuildingRequest();
    resolver.updateDependencySetResolutionRequirements(ds1, info, AssemblyId.createAssemblyId(assembly), buildingRequest, project);
    assertTrue(info.isResolutionRequired());
    assertFalse(info.isResolvedTransitively());
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_COMPILE));
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_SYSTEM));
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_PROVIDED));
    assertFalse(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_RUNTIME));
    assertFalse(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_TEST));
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MavenProject(org.apache.maven.project.MavenProject) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 79 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.

the class CopyDependenciesMojo method getResolvedPomArtifact.

protected Artifact getResolvedPomArtifact(Artifact artifact) {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(artifact.getGroupId());
    coordinate.setArtifactId(artifact.getArtifactId());
    coordinate.setVersion(artifact.getVersion());
    coordinate.setExtension("pom");
    Artifact pomArtifact = null;
    // Resolve the pom artifact using repos
    try {
        ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
        pomArtifact = getArtifactResolver().resolveArtifact(buildingRequest, coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        getLog().info(e.getMessage());
    }
    return pomArtifact;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 80 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.

the class TreeMojo method execute.

// Mojo methods -----------------------------------------------------------
/*
     * @see org.apache.maven.plugin.Mojo#execute()
     */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("Skipping plugin execution");
        return;
    }
    try {
        String dependencyTreeString;
        // TODO: note that filter does not get applied due to MSHARED-4
        ArtifactFilter artifactFilter = createResolvingArtifactFilter();
        if (verbose) {
            // To fix we probably need a different DependencyCollector in Aether, which doesn't remove nodes which
            // have already been resolved.
            getLog().info("Verbose not supported since maven-dependency-plugin 3.0");
        }
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setProject(project);
        // non-verbose mode use dependency graph component, which gives consistent results with Maven version
        // running
        rootNode = dependencyGraphBuilder.buildDependencyGraph(buildingRequest, artifactFilter, reactorProjects);
        dependencyTreeString = serializeDependencyTree(rootNode);
        if (outputFile != null) {
            DependencyUtil.write(dependencyTreeString, outputFile, this.appendOutput, getLog());
            getLog().info("Wrote dependency tree to: " + outputFile);
        } else {
            DependencyUtil.log(dependencyTreeString, getLog());
        }
    } catch (DependencyGraphBuilderException exception) {
        throw new MojoExecutionException("Cannot build project dependency graph", exception);
    } catch (IOException exception) {
        throw new MojoExecutionException("Cannot serialise project dependency graph", exception);
    }
}
Also used : StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) StrictPatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyGraphBuilderException(org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException) IOException(java.io.IOException) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Aggregations

ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)81 File (java.io.File)40 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)37 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)28 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)28 Artifact (org.apache.maven.artifact.Artifact)25 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)22 MavenProject (org.apache.maven.project.MavenProject)22 MavenSession (org.apache.maven.execution.MavenSession)17 IOException (java.io.IOException)14 LegacySupport (org.apache.maven.plugin.LegacySupport)13 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)12 ArrayList (java.util.ArrayList)9 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)8 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)8 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)7 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)7 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)7 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)7 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7