Search in sources :

Example 1 with JavadocPathArtifact

use of org.apache.maven.plugin.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<String>();
    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) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with JavadocPathArtifact

use of org.apache.maven.plugin.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<String>();
    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) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) InvalidDependencyVersionException(org.apache.maven.project.artifact.InvalidDependencyVersionException) 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.plugin.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.plugin.javadoc.options.BootclasspathArtifact)2 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)2 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)2 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)2 TagletArtifact (org.apache.maven.plugin.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 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 Resource (org.apache.maven.model.Resource)1