Search in sources :

Example 71 with ProjectBuildingRequest

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

the class JavadocReportTest method testTagletArtifacts.

/**
 * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
 *
 * @throws Exception if any
 */
public void testTagletArtifacts() throws Exception {
    File testPom = new File(unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    MavenSession session = spy(newMavenSession(mojo.project));
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    when(session.getRepositorySession()).thenReturn(repositorySession);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(session);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    File optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    String options = readFile(optionsFile);
    // count -taglet
    assertEquals(20, StringUtils.countMatches(options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusConfigurationTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusRequirementTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusComponentTaglet"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 72 with ProjectBuildingRequest

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

the class ShadeMojo method rewriteDependencyReducedPomIfWeHaveReduction.

private void rewriteDependencyReducedPomIfWeHaveReduction(List<Dependency> dependencies, boolean modified, List<Dependency> transitiveDeps, Model model) throws IOException, ProjectBuildingException, DependencyGraphBuilderException {
    if (modified) {
        for (int loopCounter = 0; modified; loopCounter++) {
            model.setDependencies(dependencies);
            if (generateUniqueDependencyReducedPom) {
                dependencyReducedPomLocation = File.createTempFile("dependency-reduced-pom-", ".xml", project.getBasedir());
                project.getProperties().setProperty("maven.shade.dependency-reduced-pom", dependencyReducedPomLocation.getAbsolutePath());
            } else {
                if (dependencyReducedPomLocation == null) {
                    // MSHADE-123: We can't default to 'target' because it messes up uses of ${project.basedir}
                    dependencyReducedPomLocation = new File(project.getBasedir(), "dependency-reduced-pom.xml");
                }
            }
            File f = dependencyReducedPomLocation;
            // Works for now, maybe there's a better algorithm where no for-loop is required
            if (loopCounter == 0) {
                getLog().info("Dependency-reduced POM written at: " + f.getAbsolutePath());
            }
            if (f.exists()) {
                // noinspection ResultOfMethodCallIgnored
                f.delete();
            }
            Writer w = WriterFactory.newXmlWriter(f);
            String replaceRelativePath = null;
            if (model.getParent() != null) {
                replaceRelativePath = model.getParent().getRelativePath();
            }
            if (model.getParent() != null) {
                File parentFile = new File(project.getBasedir(), model.getParent().getRelativePath()).getCanonicalFile();
                if (!parentFile.isFile()) {
                    parentFile = new File(parentFile, "pom.xml");
                }
                parentFile = parentFile.getCanonicalFile();
                String relPath = RelativizePath.convertToRelativePath(parentFile, f);
                model.getParent().setRelativePath(relPath);
            }
            try {
                PomWriter.write(w, model, true);
            } finally {
                if (model.getParent() != null) {
                    model.getParent().setRelativePath(replaceRelativePath);
                }
                w.close();
            }
            ProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
            projectBuildingRequest.setLocalRepository(localRepository);
            projectBuildingRequest.setRemoteRepositories(remoteArtifactRepositories);
            ProjectBuildingResult result = projectBuilder.build(f, projectBuildingRequest);
            getLog().debug("updateExcludesInDeps()");
            modified = updateExcludesInDeps(result.getProject(), dependencies, transitiveDeps);
        }
        project.setFile(dependencyReducedPomLocation);
    }
}
Also used : DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) File(java.io.File) Writer(java.io.Writer) PomWriter(org.apache.maven.plugins.shade.pom.PomWriter) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 73 with ProjectBuildingRequest

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

the class DefaultRepositoryAssembler method buildRemoteRepository.

public void buildRemoteRepository(File repositoryDirectory, RepositoryInfo repository, RepositoryBuilderConfigSource configSource) throws RepositoryAssemblyException {
    MavenProject project = configSource.getProject();
    ProjectBuildingRequest buildingRequest = configSource.getProjectBuildingRequest();
    Iterable<ArtifactResult> result = null;
    Collection<Dependency> dependencies = project.getDependencies();
    if (dependencies == null) {
        Logger logger = getLogger();
        if (logger.isDebugEnabled()) {
            logger.debug("dependency-artifact set for project: " + project.getId() + " is null. Skipping repository processing.");
        }
        return;
    }
    Collection<Dependency> managedDependencies = null;
    if (project.getDependencyManagement() != null) {
        managedDependencies = project.getDependencyManagement().getDependencies();
    }
    // Older Aether versions use an cache which can't be cleared. So can't delete repoDir and use it again.
    // Instead create a temporary repository, delete it at end (should be in a finally-block)
    File tempRepo = new File(repositoryDirectory.getParentFile(), repositoryDirectory.getName() + "_tmp");
    buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, tempRepo);
    try {
        result = dependencyResolver.resolveDependencies(buildingRequest, dependencies, managedDependencies, null);
    } catch (DependencyResolverException e) {
        throw new RepositoryAssemblyException("Error resolving artifacts: " + e.getMessage(), e);
    }
    ArtifactFilter filter = buildRepositoryFilter(repository, project);
    buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, repositoryDirectory);
    Map<String, GroupVersionAlignment> groupVersionAlignments = createGroupVersionAlignments(repository.getGroupVersionAlignments());
    assembleRepositoryArtifacts(buildingRequest, result, filter, groupVersionAlignments);
    if (repository.isIncludeMetadata()) {
    // assembleRepositoryMetadata( result, filter, centralRepository, targetRepository );
    }
    try {
        FileUtils.deleteDirectory(tempRepo);
    } catch (IOException e) {
    // noop
    }
}
Also used : DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) Logger(org.codehaus.plexus.logging.Logger) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) MavenProject(org.apache.maven.project.MavenProject) GroupVersionAlignment(org.apache.maven.plugins.assembly.repository.model.GroupVersionAlignment) File(java.io.File)

Example 74 with ProjectBuildingRequest

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

the class DefaultDependencyResolver method updateDependencySetResolutionRequirements.

void updateDependencySetResolutionRequirements(final DependencySet set, final ResolutionManagementInfo requirements, AssemblyId assemblyId, ProjectBuildingRequest buildingRequest, final MavenProject... projects) throws DependencyResolutionException {
    requirements.setResolutionRequired(true);
    requirements.setResolvedTransitively(set.isUseTransitiveDependencies());
    ScopeFilter scopeFilter = FilterUtils.newScopeFilter(set.getScope());
    requirements.setScopeFilter(scopeFilter);
    for (final MavenProject project : projects) {
        if (project == null) {
            continue;
        }
        Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
        if (dependencyArtifacts == null) {
            try {
                ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(buildingRequest);
                pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
                Iterable<ArtifactResult> artifactResults = dependencyResolver.resolveDependencies(pbr, project.getModel(), scopeFilter);
                dependencyArtifacts = new HashSet<Artifact>();
                for (ArtifactResult artifactResult : artifactResults) {
                    dependencyArtifacts.add(artifactResult.getArtifact());
                }
                project.setDependencyArtifacts(dependencyArtifacts);
            } catch (final DependencyResolverException e) {
                throw new DependencyResolutionException("Failed to create dependency artifacts for resolution. Assembly: " + assemblyId, e);
            }
        }
        requirements.addArtifacts(dependencyArtifacts);
        getLogger().debug("Dependencies for project: " + project.getId() + " are:\n" + StringUtils.join(dependencyArtifacts.iterator(), "\n"));
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ScopeFilter(org.apache.maven.shared.artifact.filter.resolve.ScopeFilter) MavenProject(org.apache.maven.project.MavenProject) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Artifact(org.apache.maven.artifact.Artifact) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Example 75 with ProjectBuildingRequest

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

the class AddDependencySetsTask method addDependencySet.

void addDependencySet(final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException {
    logger.debug("Processing DependencySet (output=" + dependencySet.getOutputDirectory() + ")");
    if (!dependencySet.isUseTransitiveDependencies() && dependencySet.isUseTransitiveFiltering()) {
        logger.warn("DependencySet has nonsensical configuration: useTransitiveDependencies == false " + "AND useTransitiveFiltering == true. Transitive filtering flag will be ignored.");
    }
    final Set<Artifact> dependencyArtifacts = resolveDependencyArtifacts(dependencySet);
    if (!unpackTransformsContent(dependencySet) && dependencyArtifacts.size() > 1) {
        checkMultiArtifactOutputConfig(dependencySet);
    }
    logger.debug("Adding " + dependencyArtifacts.size() + " dependency artifacts.");
    InputStreamTransformer fileSetTransformers = isUnpackWithOptions(dependencySet) ? ReaderFormatter.getFileSetTransformers(configSource, dependencySet.getUnpackOptions().isFiltered(), dependencySet.getUnpackOptions().getLineEnding()) : null;
    for (final Artifact depArtifact : dependencyArtifacts) {
        ProjectBuildingRequest pbr = getProjectBuildingRequest(configSource);
        MavenProject depProject;
        try {
            ProjectBuildingResult build = projectBuilder1.build(depArtifact, pbr);
            depProject = build.getProject();
        } catch (final ProjectBuildingException e) {
            logger.debug("Error retrieving POM of module-dependency: " + depArtifact.getId() + "; Reason: " + e.getMessage() + "\n\nBuilding stub project instance.");
            depProject = buildProjectStub(depArtifact);
        }
        if (NON_ARCHIVE_DEPENDENCY_TYPES.contains(depArtifact.getType())) {
            addNonArchiveDependency(depArtifact, depProject, dependencySet, archiver, configSource);
        } else {
            addNormalArtifact(dependencySet, depArtifact, depProject, archiver, configSource, fileSetTransformers);
        }
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) Artifact(org.apache.maven.artifact.Artifact)

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