Search in sources :

Example 1 with JavadocPathArtifact

use of org.apache.maven.plugins.javadoc.options.JavadocPathArtifact in project maven-plugins by apache.

the class AbstractJavadocMojo method getArtifactsAbsolutePath.

/**
 * Return the Javadoc artifact path and its transitive dependencies path from the local repository
 *
 * @param javadocArtifact not null
 * @return a list of locale artifacts absolute path
 * @throws MavenReportException if any
 */
private List<String> getArtifactsAbsolutePath(JavadocPathArtifact javadocArtifact) throws MavenReportException {
    if ((StringUtils.isEmpty(javadocArtifact.getGroupId())) && (StringUtils.isEmpty(javadocArtifact.getArtifactId())) && (StringUtils.isEmpty(javadocArtifact.getVersion()))) {
        return Collections.emptyList();
    }
    List<String> path = new ArrayList<>();
    try {
        Artifact artifact = createAndResolveArtifact(javadocArtifact);
        path.add(artifact.getFile().getAbsolutePath());
        DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
        coordinate.setGroupId(javadocArtifact.getGroupId());
        coordinate.setArtifactId(javadocArtifact.getArtifactId());
        coordinate.setVersion(javadocArtifact.getVersion());
        Iterable<ArtifactResult> deps = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), coordinate, ScopeFilter.including("compile", "provided"));
        for (ArtifactResult a : deps) {
            path.add(a.getArtifact().getFile().getAbsolutePath());
        }
        return path;
    } catch (ArtifactResolverException e) {
        throw new MavenReportException("Unable to resolve artifact:" + javadocArtifact, e);
    } catch (DependencyResolverException e) {
        throw new MavenReportException("Unable to resolve dependencies for:" + javadocArtifact, e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultDependableCoordinate(org.apache.maven.shared.dependencies.DefaultDependableCoordinate) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) BootclasspathArtifact(org.apache.maven.plugins.javadoc.options.BootclasspathArtifact) JavadocPathArtifact(org.apache.maven.plugins.javadoc.options.JavadocPathArtifact) ResourcesArtifact(org.apache.maven.plugins.javadoc.options.ResourcesArtifact) Artifact(org.apache.maven.artifact.Artifact) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) DocletArtifact(org.apache.maven.plugins.javadoc.options.DocletArtifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with JavadocPathArtifact

use of org.apache.maven.plugins.javadoc.options.JavadocPathArtifact in project maven-plugins by apache.

the class AbstractJavadocMojo method getResource.

/**
 * @param outputFile        not nul
 * @param inputResourceName a not null resource in <code>src/main/java</code>, <code>src/main/resources</code> or
 *                          <code>src/main/javadoc</code> or in the Javadoc plugin dependencies.
 * @return the resource file absolute path as String
 * @since 2.6
 */
private String getResource(File outputFile, String inputResourceName) {
    if (inputResourceName.startsWith("/")) {
        inputResourceName = inputResourceName.replaceFirst("//*", "");
    }
    List<String> classPath = new ArrayList<>();
    classPath.add(project.getBuild().getSourceDirectory());
    URL resourceURL = getResource(classPath, inputResourceName);
    if (resourceURL != null) {
        getLog().debug(inputResourceName + " found in the main src directory of the project.");
        return FileUtils.toFile(resourceURL).getAbsolutePath();
    }
    classPath.clear();
    List<Resource> resources = project.getBuild().getResources();
    for (Resource resource : resources) {
        classPath.add(resource.getDirectory());
    }
    resourceURL = getResource(classPath, inputResourceName);
    if (resourceURL != null) {
        getLog().debug(inputResourceName + " found in the main resources directories of the project.");
        return FileUtils.toFile(resourceURL).getAbsolutePath();
    }
    if (javadocDirectory.exists()) {
        classPath.clear();
        classPath.add(javadocDirectory.getAbsolutePath());
        resourceURL = getResource(classPath, inputResourceName);
        if (resourceURL != null) {
            getLog().debug(inputResourceName + " found in the main javadoc directory of the project.");
            return FileUtils.toFile(resourceURL).getAbsolutePath();
        }
    }
    classPath.clear();
    final String pluginId = "org.apache.maven.plugins:maven-javadoc-plugin";
    Plugin javadocPlugin = getPlugin(project, pluginId);
    if (javadocPlugin != null && javadocPlugin.getDependencies() != null) {
        List<Dependency> dependencies = javadocPlugin.getDependencies();
        for (Dependency dependency : dependencies) {
            JavadocPathArtifact javadocPathArtifact = new JavadocPathArtifact();
            javadocPathArtifact.setGroupId(dependency.getGroupId());
            javadocPathArtifact.setArtifactId(dependency.getArtifactId());
            javadocPathArtifact.setVersion(dependency.getVersion());
            Artifact artifact = null;
            try {
                artifact = createAndResolveArtifact(javadocPathArtifact);
            } catch (Exception e) {
                logError("Unable to retrieve the dependency: " + dependency + ". Ignored.", e);
            }
            if (artifact != null && artifact.getFile().exists()) {
                classPath.add(artifact.getFile().getAbsolutePath());
            }
        }
        resourceURL = getResource(classPath, inputResourceName);
        if (resourceURL != null) {
            getLog().debug(inputResourceName + " found in javadoc plugin dependencies.");
            try {
                JavadocUtil.copyResource(resourceURL, outputFile);
                return outputFile.getAbsolutePath();
            } catch (IOException e) {
                logError("IOException: " + e.getMessage(), e);
            }
        }
    }
    getLog().warn("Unable to find the resource '" + inputResourceName + "'. Using default Javadoc resources.");
    return null;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.maven.model.Resource) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) URL(java.net.URL) BootclasspathArtifact(org.apache.maven.plugins.javadoc.options.BootclasspathArtifact) JavadocPathArtifact(org.apache.maven.plugins.javadoc.options.JavadocPathArtifact) ResourcesArtifact(org.apache.maven.plugins.javadoc.options.ResourcesArtifact) Artifact(org.apache.maven.artifact.Artifact) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) DocletArtifact(org.apache.maven.plugins.javadoc.options.DocletArtifact) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) MalformedURLException(java.net.MalformedURLException) MavenReportException(org.apache.maven.reporting.MavenReportException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) JavadocPathArtifact(org.apache.maven.plugins.javadoc.options.JavadocPathArtifact) Plugin(org.apache.maven.model.Plugin)

Aggregations

ArrayList (java.util.ArrayList)2 Artifact (org.apache.maven.artifact.Artifact)2 BootclasspathArtifact (org.apache.maven.plugins.javadoc.options.BootclasspathArtifact)2 DocletArtifact (org.apache.maven.plugins.javadoc.options.DocletArtifact)2 JavadocPathArtifact (org.apache.maven.plugins.javadoc.options.JavadocPathArtifact)2 ResourcesArtifact (org.apache.maven.plugins.javadoc.options.ResourcesArtifact)2 TagletArtifact (org.apache.maven.plugins.javadoc.options.TagletArtifact)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)2 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 Dependency (org.apache.maven.model.Dependency)1 Plugin (org.apache.maven.model.Plugin)1