Search in sources :

Example 1 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class AbstractJavadocMojo method copyAdditionalJavadocResources.

/**
     * Method that copy additional Javadoc resources from given artifacts.
     *
     * @param anOutputDirectory the output directory
     * @throws MavenReportException if any
     * @see #resourcesArtifacts
     */
private void copyAdditionalJavadocResources(File anOutputDirectory) throws MavenReportException {
    Set<ResourcesArtifact> resourcesArtifacts = collectResourcesArtifacts();
    if (isEmpty(resourcesArtifacts)) {
        return;
    }
    UnArchiver unArchiver;
    try {
        unArchiver = archiverManager.getUnArchiver("jar");
    } catch (NoSuchArchiverException e) {
        throw new MavenReportException("Unable to extract resources artifact. " + "No archiver for 'jar' available.", e);
    }
    for (ResourcesArtifact item : resourcesArtifacts) {
        Artifact artifact;
        try {
            artifact = createAndResolveArtifact(item);
        } catch (ArtifactResolverException e) {
            throw new MavenReportException("Unable to resolve artifact:" + item, e);
        }
        unArchiver.setSourceFile(artifact.getFile());
        unArchiver.setDestDirectory(anOutputDirectory);
        // remove the META-INF directory from resource artifact
        IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
        selectors[0].setExcludes(new String[] { "META-INF/**" });
        unArchiver.setFileSelectors(selectors);
        getLog().info("Extracting contents of resources artifact: " + artifact.getArtifactId());
        try {
            unArchiver.extract();
        } catch (ArchiverException e) {
            throw new MavenReportException("Extraction of resources failed. Artifact that failed was: " + artifact.getArtifactId(), e);
        }
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) 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) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class AbstractJavadocMojo method addTagletsFromTagletArtifacts.

/**
     * Auto-detect taglets class name from <code>tagletArtifacts</code> and add them to arguments.
     *
     * @param arguments not null
     * @throws MavenReportException if any
     * @see JavadocUtil#getTagletClassNames(File)
     */
private void addTagletsFromTagletArtifacts(List<String> arguments) throws MavenReportException {
    Set<TagletArtifact> tArtifacts = new LinkedHashSet<TagletArtifact>();
    if (tagletArtifacts != null && tagletArtifacts.length > 0) {
        tArtifacts.addAll(Arrays.asList(tagletArtifacts));
    }
    if (includeDependencySources) {
        try {
            resolveDependencyBundles();
        } catch (IOException e) {
            throw new MavenReportException("Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e);
        }
        if (isNotEmpty(dependencyJavadocBundles)) {
            for (JavadocBundle bundle : dependencyJavadocBundles) {
                JavadocOptions options = bundle.getOptions();
                if (options != null && isNotEmpty(options.getTagletArtifacts())) {
                    tArtifacts.addAll(options.getTagletArtifacts());
                }
            }
        }
    }
    if (isEmpty(tArtifacts)) {
        return;
    }
    List<String> tagletsPath = new ArrayList<String>();
    for (TagletArtifact aTagletArtifact : tArtifacts) {
        if ((StringUtils.isNotEmpty(aTagletArtifact.getGroupId())) && (StringUtils.isNotEmpty(aTagletArtifact.getArtifactId())) && (StringUtils.isNotEmpty(aTagletArtifact.getVersion()))) {
            Artifact artifact;
            try {
                artifact = createAndResolveArtifact(aTagletArtifact);
            } catch (ArtifactResolverException e) {
                throw new MavenReportException("Unable to resolve artifact:" + aTagletArtifact, e);
            }
            tagletsPath.add(artifact.getFile().getAbsolutePath());
        }
    }
    tagletsPath = JavadocUtil.pruneFiles(tagletsPath);
    for (String tagletJar : tagletsPath) {
        if (!tagletJar.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
            continue;
        }
        List<String> tagletClasses;
        try {
            tagletClasses = JavadocUtil.getTagletClassNames(new File(tagletJar));
        } catch (IOException e) {
            if (getLog().isWarnEnabled()) {
                getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
            }
            if (getLog().isDebugEnabled()) {
                getLog().debug("IOException: " + e.getMessage(), e);
            }
            continue;
        } catch (ClassNotFoundException e) {
            if (getLog().isWarnEnabled()) {
                getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
            }
            if (getLog().isDebugEnabled()) {
                getLog().debug("ClassNotFoundException: " + e.getMessage(), e);
            }
            continue;
        } catch (NoClassDefFoundError e) {
            if (getLog().isWarnEnabled()) {
                getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
            }
            if (getLog().isDebugEnabled()) {
                getLog().debug("NoClassDefFoundError: " + e.getMessage(), e);
            }
            continue;
        }
        if (tagletClasses != null && !tagletClasses.isEmpty()) {
            for (String tagletClass : tagletClasses) {
                addArgIfNotEmpty(arguments, "-taglet", JavadocUtil.quotedArgument(tagletClass), SINCE_JAVADOC_1_4);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JavadocBundle(org.apache.maven.plugin.javadoc.resolver.JavadocBundle) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArrayList(java.util.ArrayList) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) IOException(java.io.IOException) 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) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 3 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class AbstractJavadocMojo method resolveDependency.

/**
     * @param dependency {@link Dependency}
     * @return {@link Artifact}
     * @throws MavenReportException
     */
public Artifact resolveDependency(Dependency dependency) throws MavenReportException {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(dependency.getGroupId());
    coordinate.setArtifactId(dependency.getArtifactId());
    coordinate.setVersion(dependency.getVersion());
    coordinate.setClassifier(dependency.getClassifier());
    coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
    try {
        return artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        throw new MavenReportException("artifact resolver problem - " + e.getMessage(), e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 4 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.

the class PurgeLocalRepositoryMojo method getFilteredResolvedArtifacts.

private Set<Artifact> getFilteredResolvedArtifacts(MavenProject theProject, List<Dependency> dependencies, TransformableFilter filter) {
    try {
        Iterable<ArtifactResult> results = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), theProject.getModel(), filter);
        Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
        for (ArtifactResult artResult : results) {
            resolvedArtifacts.add(artResult.getArtifact());
        }
        return resolvedArtifacts;
    } catch (DependencyResolverException e) {
        getLog().info("Unable to resolve all dependencies for: " + theProject.getGroupId() + ":" + theProject.getArtifactId() + ":" + theProject.getVersion() + ". Falling back to non-transitive mode for initial artifact resolution.");
    }
    Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
    ArtifactFilter artifactFilter = filter.transform(new ArtifactIncludeFilterTransformer());
    for (Dependency dependency : dependencies) {
        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
        coordinate.setGroupId(dependency.getGroupId());
        coordinate.setArtifactId(dependency.getArtifactId());
        coordinate.setVersion(dependency.getVersion());
        coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
        try {
            Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
            if (artifactFilter.include(artifact)) {
                resolvedArtifacts.add(artifact);
            }
        } catch (ArtifactResolverException e) {
            getLog().debug("Unable to resolve artifact: " + coordinate);
        }
    }
    return resolvedArtifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Example 5 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException 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)

Aggregations

ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)35 Artifact (org.apache.maven.artifact.Artifact)28 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)13 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)12 ArrayList (java.util.ArrayList)11 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)9 IOException (java.io.IOException)8 LinkedHashSet (java.util.LinkedHashSet)8 MavenReportException (org.apache.maven.reporting.MavenReportException)8 File (java.io.File)7 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)6 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)5 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)4 DefaultDependableCoordinate (org.apache.maven.shared.dependencies.DefaultDependableCoordinate)4 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)3 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)3 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)3