Search in sources :

Example 86 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project karaf by apache.

the class GenerateDescriptorMojo method resolveProject.

private MavenProject resolveProject(final Object artifact) throws MojoExecutionException {
    MavenProject resolvedProject = project;
    if (includeTransitiveVersionRanges) {
        resolvedProject = resolvedProjects.get(artifact);
        if (resolvedProject == null) {
            final ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
            // Fixes KARAF-4626; if the system properties are not transferred to the request,
            // test-feature-use-version-range-transfer-properties will fail
            request.setSystemProperties(System.getProperties());
            request.setResolveDependencies(true);
            request.setRemoteRepositories(project.getPluginArtifactRepositories());
            request.setLocalRepository(localRepo);
            request.setProfiles(new ArrayList<>(mavenSession.getRequest().getProfiles()));
            request.setActiveProfileIds(new ArrayList<>(mavenSession.getRequest().getActiveProfiles()));
            dependencyHelper.setRepositorySession(request);
            final Artifact pomArtifact = repoSystem.createArtifact(dependencyHelper.getGroupId(artifact), dependencyHelper.getArtifactId(artifact), dependencyHelper.getBaseVersion(artifact), "pom");
            try {
                resolvedProject = mavenProjectBuilder.build(pomArtifact, request).getProject();
                resolvedProjects.put(pomArtifact, resolvedProject);
            } catch (final ProjectBuildingException e) {
                throw new MojoExecutionException(format("Maven-project could not be built for artifact %s", pomArtifact), e);
            }
        }
    }
    return resolvedProject;
}
Also used : DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)86 File (java.io.File)43 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 MavenProject (org.apache.maven.project.MavenProject)24 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)22 MavenSession (org.apache.maven.execution.MavenSession)19 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 LinkedHashSet (java.util.LinkedHashSet)7 Properties (java.util.Properties)7 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)7 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)7 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)7