Search in sources :

Example 1 with ProjectBuildingRequest

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

the class JavadocReportTest method testTaglets.

/**
     * Method to test the taglet artifact configuration
     *
     * @throws Exception if any
     */
public void testTaglets() throws Exception {
    // ----------------------------------------------------------------------
    // taglet-test: check if a taglet is used
    // ----------------------------------------------------------------------
    File testPom = new File(unit, "taglet-test/taglet-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 apidocs = new File(getBasedir(), "target/test/unit/taglet-test/target/site/apidocs");
    assertTrue(new File(apidocs, "index.html").exists());
    File appFile = new File(apidocs, "taglet/test/App.html");
    assertTrue(appFile.exists());
    String appString = readFile(appFile);
    assertTrue(appString.contains("<b>To Do:</b>"));
}
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 2 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.

the class AbstractFromConfigurationMojo method getArtifact.

/**
 * Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved
 * from the dependency list or from the DependencyManagement section of the pom.
 *
 * @param artifactItem containing information about artifact from plugin configuration.
 * @return Artifact object representing the specified file.
 * @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
 */
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
    Artifact artifact;
    try {
        // mdep-50 - rolledback for now because it's breaking some functionality.
        /*
             * List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
             * ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect( theSet, project
             * .getArtifact(), managedVersions, this.local, project.getRemoteArtifactRepositories(),
             * artifactMetadataSource, null, listeners ); Iterator iter =
             * artifactResolutionResult.getArtifactResolutionNodes().iterator(); while ( iter.hasNext() ) {
             * ResolutionNode node = (ResolutionNode) iter.next(); artifact = node.getArtifact(); }
             */
        ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
        if (localRepositoryDirectory != null) {
            buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryDirectory);
        }
        // Map dependency to artifact coordinate
        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
        coordinate.setGroupId(artifactItem.getGroupId());
        coordinate.setArtifactId(artifactItem.getArtifactId());
        coordinate.setVersion(artifactItem.getVersion());
        coordinate.setClassifier(artifactItem.getClassifier());
        final String extension;
        ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(artifactItem.getType());
        if (artifactHandler != null) {
            extension = artifactHandler.getExtension();
        } else {
            extension = artifactItem.getType();
        }
        coordinate.setExtension(extension);
        artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Unable to find/resolve artifact.", e);
    }
    return artifact;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.

the class CopyDependenciesMojo method getResolvedPomArtifact.

/**
 * @param artifact {@link Artifact}
 * @return {@link Artifact}
 */
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 4 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin 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)

Example 5 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.

the class ResolvePluginsMojo method resolvePluginArtifacts.

/**
 * This method resolves the plugin artifacts from the project.
 *
 * @return set of resolved plugin artifacts.
 * @throws ArtifactFilterException in case of an error.
 * @throws ArtifactResolverException in case of an error.
 */
protected Set<Artifact> resolvePluginArtifacts() throws ArtifactFilterException, ArtifactResolverException {
    final Set<Artifact> plugins = getProject().getPluginArtifacts();
    final Set<Artifact> reports = getProject().getReportArtifacts();
    Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    artifacts.addAll(reports);
    artifacts.addAll(plugins);
    final FilterArtifacts filter = getPluginArtifactsFilter();
    artifacts = filter.filter(artifacts);
    Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>(artifacts.size());
    // final ArtifactFilter filter = getPluginFilter();
    for (final Artifact artifact : new LinkedHashSet<Artifact>(artifacts)) {
        // if ( !filter.include( artifact ) )
        // {
        // final String logStr =
        // String.format( " Plugin SKIPPED: %s", DependencyUtil.getFormattedFileName( artifact, false ) );
        // 
        // if ( !silent )
        // {
        // this.getLog().info( logStr );
        // }
        // 
        // artifacts.remove( artifact );
        // continue;
        // }
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(this.remotePluginRepositories);
        // resolve the new artifact
        resolvedArtifacts.add(getArtifactResolver().resolveArtifact(buildingRequest, artifact).getArtifact());
    }
    return artifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) Artifact(org.apache.maven.artifact.Artifact) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

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