Example usage for org.apache.maven.artifact.resolver ArtifactResolutionResult getArtifacts

List of usage examples for org.apache.maven.artifact.resolver ArtifactResolutionResult getArtifacts

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver ArtifactResolutionResult getArtifacts.

Prototype

public Set<Artifact> getArtifacts() 

Source Link

Usage

From source file:br.com.anteros.restdoc.maven.plugin.util.ResourceResolver.java

License:Apache License

@SuppressWarnings("unchecked")
private static List<String> resolveAndUnpack(final List<Artifact> artifacts, final SourceResolverConfig config,
        final List<String> validClassifiers, final boolean propagateErrors)
        throws ArtifactResolutionException, ArtifactNotFoundException {
    // NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually 
    // resolve transitively...this is just used to aggregate resolution failures into a single 
    // exception.
    final Set<Artifact> artifactSet = new LinkedHashSet<Artifact>(artifacts);
    final Artifact pomArtifact = config.project().getArtifact();
    final ArtifactRepository localRepo = config.localRepository();
    final List<ArtifactRepository> remoteRepos = config.project().getRemoteArtifactRepositories();
    final ArtifactMetadataSource metadataSource = config.artifactMetadataSource();

    final ArtifactFilter filter = config.filter();
    ArtifactFilter resolutionFilter = null;
    if (filter != null) {
        // Wrap the filter in a ProjectArtifactFilter in order to always include the pomArtifact for resolution.
        // NOTE that this is necessary, b/c the -sources artifacts are added dynamically to the pomArtifact
        // and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has
        // to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved.
        resolutionFilter = new ProjectArtifactFilter(pomArtifact, filter);
    }/*from w w  w  .  ja  va 2 s .c o  m*/

    final ArtifactResolver resolver = config.artifactResolver();

    @SuppressWarnings("rawtypes")
    Map managed = config.project().getManagedVersionMap();

    final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(artifactSet, pomArtifact,
            managed, localRepo, remoteRepos, metadataSource, resolutionFilter);

    final List<String> result = new ArrayList<String>(artifacts.size());
    for (final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts()) {
        if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
            continue;
        }

        final File d = new File(config.outputBasedir(),
                a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier());

        if (!d.exists()) {
            d.mkdirs();
        }

        try {
            final UnArchiver unArchiver = config.archiverManager().getUnArchiver(a.getType());

            unArchiver.setDestDirectory(d);
            unArchiver.setSourceFile(a.getFile());

            unArchiver.extract();

            result.add(d.getAbsolutePath());
        } catch (final NoSuchArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException(
                        "Failed to retrieve valid un-archiver component: " + a.getType(), a, e);
            }
        } catch (final ArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException("Failed to unpack: " + a.getId(), a, e);
            }
        }
    }

    return result;
}

From source file:ch.ifocusit.livingdoc.plugin.baseMojo.AbstractGlossaryMojo.java

License:Apache License

private void loadSourcesDependency(JavaProjectBuilder javaDocBuilder, Artifact sourcesArtifact) {
    // create request
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(sourcesArtifact);

    // resolve deps
    ArtifactResolutionResult result = repositorySystem.resolve(request);

    // load source file into javadoc builder
    result.getArtifacts().forEach(artifact -> {
        try {/*from ww  w. ja  va  2 s.  co  m*/
            JarFile jarFile = new JarFile(artifact.getFile());
            for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) {
                JarEntry entry = (JarEntry) entries.nextElement();
                String name = entry.getName();
                if (name.endsWith(".java") && !name.endsWith("/package-info.java")) {
                    javaDocBuilder.addSource(
                            new URL("jar:" + artifact.getFile().toURI().toURL().toString() + "!/" + name));
                }
            }
        } catch (Exception e) {
            getLog().warn("Unable to load jar source " + artifact + " : " + e.getMessage());
        }
    });
}

From source file:com.baidu.jprotobuf.mojo.PreCompileMojo.java

License:Apache License

/**
 * Resolve the executable dependencies for the specified project
 * //from  w  w  w.  jav  a  2s .co  m
 * @param executablePomArtifact the project's POM
 * @return a set of Artifacts
 * @throws MojoExecutionException if a failure happens
 */
private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact)
        throws MojoExecutionException {

    Set<Artifact> executableDependencies;
    try {
        MavenProject executableProject = this.projectBuilder.buildFromRepository(executablePomArtifact,
                this.remoteRepositories, this.localRepository);

        // get all of the dependencies for the executable project
        List<Dependency> dependencies = executableProject.getDependencies();

        // make Artifacts of all the dependencies
        Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts(this.artifactFactory,
                dependencies, null, null, null);

        // not forgetting the Artifact of the project itself
        dependencyArtifacts.add(executableProject.getArtifact());

        // resolve all dependencies transitively to obtain a comprehensive list of assemblies
        ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts,
                executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories,
                metadataSource, null, Collections.emptyList());
        executableDependencies = result.getArtifacts();
    } catch (Exception ex) {
        throw new MojoExecutionException("Encountered problems resolving dependencies of the executable "
                + "in preparation for its execution.", ex);
    }

    return executableDependencies;
}

From source file:com.bugvm.maven.plugin.AbstractBugVMMojo.java

License:Apache License

protected Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException {

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);/*from   w  w  w .jav  a2 s . c  o m*/
    if (artifact.isSnapshot()) {
        request.setForceUpdate(true);
    }
    request.setLocalRepository(localRepository);
    final List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
    request.setRemoteRepositories(remoteRepositories);

    getLog().debug("Resolving artifact " + artifact);

    ArtifactResolutionResult result = artifactResolver.resolve(request);
    if (!result.isSuccess()) {
        throw new MojoExecutionException("Unable to resolve artifact: " + artifact);
    }
    Collection<Artifact> resolvedArtifacts = result.getArtifacts();
    artifact = (Artifact) resolvedArtifacts.iterator().next();
    return artifact;
}

From source file:com.clearstorydata.maven.plugins.shadediff.mojo.ShadeDiffMojo.java

License:Apache License

public void execute() throws MojoExecutionException {

    try {/*from   w ww .  java 2s  . com*/

        Plugin shadePlugin = lookupPlugin("org.apache.maven.plugins:maven-shade-plugin");
        if (shadePlugin == null) {
            getLog().info("maven-shade-plugin not found, skipping shade-diff execution");
            return;
        }

        if (excludeShadedJars == null) {
            getLog().info(
                    "No shaded jars specified to exclude the contents of, skipping " + "shade-diff execution");
            return;
        }

        Map<String, String> idToVersion = new HashMap<String, String>();

        for (Artifact artifact : project.getArtifacts()) {
            idToVersion.put(getIdWithoutVersion(artifact), artifact.getVersion());
        }

        Set<String> excludes = new TreeSet<String>();

        for (ShadedJarExclusion excludedShadedJar : excludeShadedJars) {
            ArtifactResolutionResult resolutionResult = resolveShadedJarToExclude(excludedShadedJar);
            if (resolutionResult.getArtifacts().isEmpty()) {
                throw new MojoExecutionException("Could not resolve shaded jar artifact to exclude: "
                        + "groupId=" + excludedShadedJar.getGroupId() + ", " + "artifactId="
                        + excludedShadedJar.getArtifactId() + ", " + "version=" + excludedShadedJar.getVersion()
                        + ", " + "classifier=" + excludedShadedJar.getClassifier());
            }
            for (Artifact excludedShadedJarArtifact : resolutionResult.getArtifacts()) {
                ZipFile zip = new ZipFile(excludedShadedJarArtifact.getFile().getPath());
                ZipEntry entry = zip.getEntry(SHADED_JAR_CONTENTS_ENTRY);
                if (entry != null) {
                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(zip.getInputStream(entry)));
                    String line;
                    while ((line = reader.readLine()) != null) {
                        String[] items = line.split(":");
                        if (items.length < 4 || items.length > 5) {
                            getLog().warn(
                                    "Invalid full artifact ID line from " + excludedShadedJarArtifact.getId()
                                            + "'s list of " + "included jars, skipping: " + line);
                            continue;
                        }
                        String groupId = items[0];
                        String artifactId = items[1];
                        String type = items[2];
                        String classifier = items.length == 5 ? items[3] : "";
                        String version = items[items.length - 1];
                        Artifact shadedJarDep = factory.createArtifactWithClassifier(groupId, artifactId,
                                version, type, classifier);
                        String groupArtifactType = getIdWithoutVersion(shadedJarDep);
                        String projectDepVersion = idToVersion.get(groupArtifactType);
                        if (projectDepVersion != null && shadedJarDep.getVersion().equals(projectDepVersion)) {
                            String exclude = shadedJarDep.getGroupId() + ":" + shadedJarDep.getArtifactId()
                                    + ":*";
                            if (!excludes.contains(exclude)) {
                                excludes.add(exclude);
                                getLog().info("Excluding from shaded jar: " + exclude + " (already included in "
                                        + excludedShadedJarArtifact.getId() + ")");
                            }
                        }
                    }
                } else {
                    // We make this a build failure, because this indicates that the shaded jar was not
                    // built correctly.
                    throw new MojoExecutionException("No contents entry " + SHADED_JAR_CONTENTS_ENTRY
                            + " found in " + excludedShadedJarArtifact.getFile().getPath());
                }
            }
        }
        if (!excludes.isEmpty()) {
            String joinedExcludes = Joiner.on(",").join(excludes);
            project.getProperties().setProperty("maven.shade.plugin.additionalExcludes", joinedExcludes);
        }
    } catch (IOException ex) {
        getLog().error(ex);
        throw new MojoExecutionException("IOException", ex);
    }

}

From source file:com.comoyo.maven.plugins.emjar.EmJarMojo.java

License:Apache License

/**
 * Get artifact containing the EmJar class loader itself.
 *///ww  w .j a  v  a 2  s  . co m
private Artifact getEmJarArtifact() throws MojoExecutionException {
    final Artifact artifact = repositorySystem.createArtifact(pluginDescriptor.getGroupId(), "emjar",
            pluginDescriptor.getVersion(), "jar");

    getLog().info("Using emjar " + artifact);
    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact)
            .setRemoteRepositories(remoteRepositories);
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    if (!result.isSuccess()) {
        throw new MojoExecutionException(
                "Unable to resolve dependency on EmJar loader artifact, sorry: " + result.toString());
    }

    Set<Artifact> artifacts = result.getArtifacts();
    if (artifacts.size() != 1) {
        throw new MojoExecutionException("Unexpected number of artifacts returned when resolving EmJar loader ("
                + artifacts.size() + ")");
    }
    return artifacts.iterator().next();
}

From source file:com.cubeia.maven.plugin.firebase.FirebaseRunPlugin.java

License:Apache License

@SuppressWarnings("unchecked")
private Collection<Artifact> getTransitive(Artifact ours)
        throws ArtifactResolutionException, ArtifactNotFoundException {
    ArtifactResolutionResult result = artifactResolver.resolveTransitively(Collections.singleton(ours),
            project.getArtifact(), Collections.EMPTY_MAP, localRepository, remoteRepositories, metadataSource,
            null, Collections.EMPTY_LIST);
    return result.getArtifacts();
}

From source file:com.edugility.maven.Artifacts.java

License:Open Source License

/**
 * Returns an unmodifiable, non-{@code null} {@link Collection} of
 * {@link Artifact}s, each element of which is a non-{@code null}
 * {@link Artifact} that represents either the supplied {@link
 * MavenProject} itself or a {@linkplain MavenProject#getArtifacts()
 * dependency of it}.//from   w w  w .  j  av  a2  s .  com
 *
 * <p>The returned {@link Artifact} {@link Collection} will be
 * sorted in topological order, from an {@link Artifact} with no
 * dependencies as the first element, to the {@link Artifact}
 * representing the {@link MavenProject} itself as the last.</p>
 *
 * <p>All {@link Artifact}s that are not {@linkplain
 * Object#equals(Object) equal to} the return value of {@link
 * MavenProject#getArtifact() project.getArtifact()} will be
 * {@linkplain ArtifactResolver#resolve(ArtifactResolutionRequest)
 * resolved} if they are not already {@linkplain
 * Artifact#isResolved() resolved}.  No guarantee of {@linkplain
 * Artifact#isResolved() resolution status} is made of the
 * {@linkplain MavenProject#getArtifact() project
 * <code>Artifact</code>}, which in normal&mdash;possibly
 * all?&mdash;cases will be unresolved.</p>
 *
 * @param project the {@link MavenProject} for which resolved {@link
 * Artifact}s should be returned; must not be {@code null}
 *
 * @param dependencyGraphBuilder the {@link DependencyGraphBuilder}
 * instance that will calculate the dependency graph whose postorder
 * traversal will yield the {@link Artifact}s to be resolved; must
 * not be {@code null}
 *
 * @param filter an {@link ArtifactFilter} used during {@linkplain
 * DependencyGraphBuilder#buildDependencyGraph(MavenProject,
 * ArtifactFilter) dependency graph assembly}; may be {@code null}
 *
 * @param resolver an {@link ArtifactResolver} that will use the <a
 * href="http://maven.apache.org/ref/3.0.5/maven-compat/apidocs/src-html/org/apache/maven/artifact/resolver/DefaultArtifactResolver.html#line.335">Maven
 * 3.0.5 <code>Artifact</code> resolution algorithm</a> to resolve
 * {@link Artifact}s returned by the {@link
 * DependencyGraphBuilder#buildDependencyGraph(MavenProject,
 * ArtifactFilter)} method; must not be {@code null}
 *
 * @param localRepository an {@link ArtifactRepository} representing
 * the local Maven repository in effect; may be {@code null}
 *
 * @return a non-{@code null}, {@linkplain
 * Collections#unmodifiableCollection(Collection) unmodifiable}
 * {@link Collection} of non-{@code null} {@link Artifact} instances
 *
 * @exception IllegalArgumentException if {@code project}, {@code
 * dependencyGraphBuilder} or {@code resolver} is {@code null}
 *
 * @exception ArtifactResolutionException if there were problems
 * {@linkplain ArtifactResolver#resolve(ArtifactResolutionRequest)
 * resolving} {@link Artifact} instances
 *
 * @exception DependencyGraphBuilderException if there were problems
 * {@linkplain
 * DependencyGraphBuilder#buildDependencyGraph(MavenProject,
 * ArtifactFilter) building the dependency graph}
 *
 * @see ArtifactResolver#resolve(ArtifactResolutionRequest)
 *
 * @see DependencyGraphBuilder#buildDependencyGraph(MavenProject,
 * ArtifactFilter)
 */
public Collection<? extends Artifact> getArtifactsInTopologicalOrder(final MavenProject project,
        final DependencyGraphBuilder dependencyGraphBuilder, final ArtifactFilter filter,
        final ArtifactResolver resolver, final ArtifactRepository localRepository)
        throws DependencyGraphBuilderException, ArtifactResolutionException {
    final Logger logger = this.getLogger();
    if (logger != null && logger.isLoggable(Level.FINER)) {
        logger.entering(this.getClass().getName(), "getArtifactsInTopologicalOrder",
                new Object[] { project, dependencyGraphBuilder, filter, resolver, localRepository });
    }
    if (project == null) {
        throw new IllegalArgumentException("project", new NullPointerException("project"));
    }
    if (dependencyGraphBuilder == null) {
        throw new IllegalArgumentException("dependencyGraphBuilder",
                new NullPointerException("dependencyGraphBuilder"));
    }
    if (resolver == null) {
        throw new IllegalArgumentException("resolver", new NullPointerException("resolver"));
    }

    List<Artifact> returnValue = null;

    final DependencyNode projectNode = dependencyGraphBuilder.buildDependencyGraph(project, filter);
    assert projectNode != null;
    final CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();
    projectNode.accept(visitor);
    final Collection<? extends DependencyNode> nodes = visitor.getNodes();

    if (nodes == null || nodes.isEmpty()) {
        if (logger != null && logger.isLoggable(Level.FINE)) {
            logger.logp(Level.FINE, this.getClass().getName(), "getArtifactsInTopologicalOrder",
                    "No dependency nodes encountered");
        }

    } else {
        final Artifact projectArtifact = project.getArtifact();

        returnValue = new ArrayList<Artifact>();

        for (final DependencyNode node : nodes) {
            if (node != null) {
                Artifact artifact = node.getArtifact();
                if (artifact != null) {

                    if (!artifact.isResolved()) {
                        if (logger != null && logger.isLoggable(Level.FINE)) {
                            logger.logp(Level.FINE, this.getClass().getName(), "getArtifactsInTopologicalOrder",
                                    "Artifact {0} is unresolved", artifact);
                        }

                        if (artifact.equals(projectArtifact)) {
                            // First see if the artifact is the project artifact.
                            // If so, then it by definition won't be able to be
                            // resolved, because it's being built.
                            if (logger != null && logger.isLoggable(Level.FINE)) {
                                logger.logp(Level.FINE, this.getClass().getName(),
                                        "getArtifactsInTopologicalOrder",
                                        "Artifact {0} resolved to project artifact: {1}",
                                        new Object[] { artifact, projectArtifact });
                            }
                            artifact = projectArtifact;

                        } else {
                            // See if the project's associated artifact map
                            // contains a resolved version of this artifact.  The
                            // artifact map contains all transitive dependency
                            // artifacts of the project.  Each artifact in the map
                            // is guaranteed to be resolved.
                            @SuppressWarnings("unchecked")
                            final Map<String, Artifact> artifactMap = project.getArtifactMap();
                            if (artifactMap != null && !artifactMap.isEmpty()) {
                                final Artifact mapArtifact = artifactMap
                                        .get(new StringBuilder(artifact.getGroupId()).append(":")
                                                .append(artifact.getArtifactId()).toString());
                                if (mapArtifact != null) {
                                    if (logger != null && logger.isLoggable(Level.FINE)) {
                                        logger.logp(Level.FINE, this.getClass().getName(),
                                                "getArtifactsInTopologicalOrder",
                                                "Artifact {0} resolved from project artifact map: {1}",
                                                new Object[] { artifact, mapArtifact });
                                    }
                                    artifact = mapArtifact;
                                }
                            }

                            if (!artifact.isResolved()) {
                                // Finally, perform manual artifact resolution.
                                final ArtifactResolutionRequest request = new ArtifactResolutionRequest();
                                request.setArtifact(artifact);
                                request.setLocalRepository(localRepository);
                                @SuppressWarnings("unchecked")
                                final List<ArtifactRepository> remoteRepositories = project
                                        .getRemoteArtifactRepositories();
                                request.setRemoteRepositories(remoteRepositories);

                                if (logger != null && logger.isLoggable(Level.FINE)) {
                                    logger.logp(Level.FINE, this.getClass().getName(),
                                            "getArtifactsInTopologicalOrder",
                                            "Resolving artifact {0} using ArtifactResolutionRequest {1}",
                                            new Object[] { artifact, request });
                                }

                                final ArtifactResolutionResult result = resolver.resolve(request);
                                if (result == null || !result.isSuccess()) {
                                    this.handleArtifactResolutionError(request, result);
                                } else {
                                    @SuppressWarnings("unchecked")
                                    final Collection<? extends Artifact> resolvedArtifacts = (Set<? extends Artifact>) result
                                            .getArtifacts();
                                    if (resolvedArtifacts == null || resolvedArtifacts.isEmpty()) {
                                        if (logger != null && logger.isLoggable(Level.WARNING)) {
                                            logger.logp(Level.WARNING, this.getClass().getName(),
                                                    "getArtifactsInTopologicalOrder",
                                                    "Artifact resolution failed silently for artifact {0}",
                                                    artifact);
                                        }
                                    } else {
                                        final Artifact resolvedArtifact = resolvedArtifacts.iterator().next();
                                        if (resolvedArtifact != null) {
                                            assert resolvedArtifact.isResolved();
                                            artifact = resolvedArtifact;
                                        } else if (logger != null && logger.isLoggable(Level.WARNING)) {
                                            logger.logp(Level.WARNING, this.getClass().getName(),
                                                    "getArtifactsInTopologicalOrder",
                                                    "Artifact resolution failed silently for artifact {0}",
                                                    artifact);
                                        }
                                    }
                                }
                            }

                        }
                    }

                    if (artifact != null) {
                        returnValue.add(artifact);
                    }
                }
            }
        }
        if (!returnValue.isEmpty()) {
            Collections.reverse(returnValue);
            Collections.sort(returnValue, scopeComparator);
        }
    }
    if (returnValue == null) {
        returnValue = Collections.emptyList();
    } else {
        returnValue = Collections.unmodifiableList(returnValue);
    }
    if (logger != null && logger.isLoggable(Level.FINER)) {
        logger.exiting(this.getClass().getName(), "getArtifactsInTopologicalOrder", returnValue);
    }
    return returnValue;
}

From source file:com.elasticgrid.maven.DeployMojo.java

License:Open Source License

@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException, MojoFailureException {
    File oar = new File(oarFileName);
    getLog().info("Deploying oar " + oar.getName() + "...");
    // TODO: copy the OAR to the dropBucket
    ArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
    try {/*www. ja v a2  s . c  o m*/
        ArtifactResolutionResult result = resolver.resolveTransitively(dependencies, project.getArtifact(),
                localRepository, remoteRepositories, artifactMetadataSource, filter);
        Set<Artifact> artifacts = result.getArtifacts();

        for (Artifact artifact : artifacts) {
            getLog().info("Detected dependency: " + artifact + " available in " + artifact.getFile());
            // TODO: this is where the actual copy to the remote maven repository should occur!
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoFailureException(e, "Can't resolve artifact", "Can't resolve artifact");
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException(e, "Can't find artifact", "Can't find artifact");
    }

    List<Artifact> attachments = project.getAttachedArtifacts();
    getLog().info("Found " + attachments.size() + " attachments");
    for (Artifact artifact : attachments) {
        getLog().info("Detected attachment: " + artifact + " available in " + artifact.getFile());
        // TODO: copy the artifacts to the maven repo too!
    }
}

From source file:com.getperka.flatpack.apidoc.ApidocMojo.java

License:Apache License

@SuppressWarnings({ "restriction", "unchecked" })
private void extractDocStrings() throws MojoFailureException {
    Artifact jar = factory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(),
            "compile", "jar");
    Set<Artifact> artifacts;
    try {// w  w w  .j  av a2 s. c om
        ArtifactResolutionResult res = artifactResolver.resolveTransitively(project.getDependencyArtifacts(),
                jar, remoteRepositories, localRepository, source);
        artifacts = res.getArtifacts();
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException("Could not resolve jar", e);
    } catch (ArtifactResolutionException e) {
        throw new MojoFailureException("Could not resolve jar", e);
    }
    getLog().debug("Resolved " + artifacts.toString());
    List<String> args = new ArrayList<String>();

    StringBuilder sb = new StringBuilder();
    for (Artifact a : artifacts) {
        sb.append(File.pathSeparatorChar).append(a.getFile().getAbsolutePath());
    }

    args.add("-classpath");
    args.add(sb.substring(1));
    args.add("-doclet");
    args.add(docletClass);
    args.add("-sourcepath");
    args.add(sourceDirectory.getAbsolutePath());
    args.add("-subpackages");
    args.add(subpackages);
    args.add("-d");
    args.add(outputDirectory.getAbsolutePath());

    int ret = com.sun.tools.javadoc.Main.execute(args.toArray(new String[args.size()]));
    if (ret != 0) {
        throw new MojoFailureException("Javadoc tool returned status code " + ret);
    }

    Resource resource = new Resource();
    resource.setDirectory(outputDirectory.getPath());
    project.addResource(resource);

    buildContext.refresh(outputDirectory);
}