Search in sources :

Example 51 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class AbstractJavadocMojo method getSourcePaths.

/**
 * Method to get the source paths. If no source path is specified in the parameter, the compile source roots
 * of the project will be used.
 *
 * @return a Collection of the project absolute source paths as <code>String</code>
 * @throws MavenReportException {@link MavenReportException}
 * @see JavadocUtil#pruneDirs(MavenProject, List)
 */
protected Map<String, Collection<String>> getSourcePaths() throws MavenReportException {
    Map<String, Collection<String>> mappedSourcePaths = new LinkedHashMap<>();
    if (StringUtils.isEmpty(sourcepath)) {
        Set<String> sourcePaths = new LinkedHashSet<>(JavadocUtil.pruneDirs(project, getProjectSourceRoots(project)));
        if (project.getExecutionProject() != null) {
            sourcePaths.addAll(JavadocUtil.pruneDirs(project, getExecutionProjectSourceRoots(project)));
        }
        /*
             * Should be after the source path (i.e. -sourcepath '.../src/main/java;.../src/main/javadoc') and
             * *not* the opposite. If not, the javadoc tool always copies doc files, even if -docfilessubdirs is
             * not setted.
             */
        if (getJavadocDirectory() != null) {
            File javadocDir = getJavadocDirectory();
            if (javadocDir.exists() && javadocDir.isDirectory()) {
                Collection<String> l = JavadocUtil.pruneDirs(project, Collections.singletonList(getJavadocDirectory().getAbsolutePath()));
                sourcePaths.addAll(l);
            }
        }
        mappedSourcePaths.put(ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()), sourcePaths);
        if (includeDependencySources) {
            mappedSourcePaths.putAll(getDependencySourcePaths());
        }
        if (isAggregator() && project.isExecutionRoot()) {
            for (MavenProject subProject : reactorProjects) {
                if (subProject != project) {
                    Collection<String> additionalSourcePaths = new ArrayList<>();
                    List<String> sourceRoots = getProjectSourceRoots(subProject);
                    if (subProject.getExecutionProject() != null) {
                        sourceRoots.addAll(getExecutionProjectSourceRoots(subProject));
                    }
                    ArtifactHandler artifactHandler = subProject.getArtifact().getArtifactHandler();
                    if ("java".equals(artifactHandler.getLanguage())) {
                        additionalSourcePaths.addAll(JavadocUtil.pruneDirs(subProject, sourceRoots));
                    }
                    if (getJavadocDirectory() != null) {
                        String javadocDirRelative = PathUtils.toRelative(project.getBasedir(), getJavadocDirectory().getAbsolutePath());
                        File javadocDir = new File(subProject.getBasedir(), javadocDirRelative);
                        if (javadocDir.exists() && javadocDir.isDirectory()) {
                            Collection<String> l = JavadocUtil.pruneDirs(subProject, Collections.singletonList(javadocDir.getAbsolutePath()));
                            additionalSourcePaths.addAll(l);
                        }
                    }
                    mappedSourcePaths.put(ArtifactUtils.versionlessKey(subProject.getGroupId(), subProject.getArtifactId()), additionalSourcePaths);
                }
            }
        }
    } else {
        Collection<String> sourcePaths = new ArrayList<>(Arrays.asList(JavadocUtil.splitPath(sourcepath)));
        sourcePaths = JavadocUtil.pruneDirs(project, sourcePaths);
        if (getJavadocDirectory() != null) {
            Collection<String> l = JavadocUtil.pruneDirs(project, Collections.singletonList(getJavadocDirectory().getAbsolutePath()));
            sourcePaths.addAll(l);
        }
        mappedSourcePaths.put(ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()), sourcePaths);
    }
    return mappedSourcePaths;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) Collection(java.util.Collection) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)51 File (java.io.File)26 Artifact (org.apache.maven.artifact.Artifact)26 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)23 VersionRange (org.apache.maven.artifact.versioning.VersionRange)17 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)10 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)10 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 MavenProject (org.apache.maven.project.MavenProject)6 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)6 ArrayList (java.util.ArrayList)5 Random (java.util.Random)4 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)4 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)4 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)4 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)4 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)4