Example usage for org.aspectj.tools.ajdoc Main setOutputWorkingDir

List of usage examples for org.aspectj.tools.ajdoc Main setOutputWorkingDir

Introduction

In this page you can find the example usage for org.aspectj.tools.ajdoc Main setOutputWorkingDir.

Prototype

public static void setOutputWorkingDir(String fullyQulifiedOutputDir) 

Source Link

Document

Sets the output working dir to be \ajdocworkingdir Useful in testing to redirect the ajdocworkingdir to the sandbox

Usage

From source file:de.zalando.mojo.aspectj.AjcReportMojo.java

License:Open Source License

/**
 * Executes this ajdoc-report generation.
 *//*from  w  w w.ja va2  s .c o m*/
@SuppressWarnings("unchecked")
protected void executeReport(Locale locale) throws MavenReportException {
    getLog().info("Starting generating ajdoc");

    project.getCompileSourceRoots().add(basedir.getAbsolutePath() + "/" + aspectDirectory);
    project.getTestCompileSourceRoots().add(basedir.getAbsolutePath() + "/" + testAspectDirectory);

    List<String> arguments = new ArrayList<String>();
    // Add classpath
    arguments.add("-classpath");
    arguments.add(AjcHelper.createClassPath(project, pluginArtifacts, getClasspathDirectories()));

    arguments.addAll(ajcOptions);

    Set<String> includes;
    try {
        if (null != ajdtBuildDefFile) {
            includes = AjcHelper.getBuildFilesForAjdtFile(ajdtBuildDefFile, basedir);
        } else {
            includes = AjcHelper.getBuildFilesForSourceDirs(getSourceDirectories(), this.includes,
                    this.excludes);
        }
    } catch (MojoExecutionException e) {
        throw new MavenReportException("AspectJ Report failed", e);
    }

    // add target dir argument
    arguments.add("-d");
    arguments.add(StringUtils.replace(getOutputDirectory(), "//", "/"));

    arguments.addAll(includes);

    if (getLog().isDebugEnabled()) {
        StringBuilder command = new StringBuilder("Running : ajdoc ");
        for (String argument : arguments) {
            command.append(' ').append(argument);
        }
        getLog().debug(command);
    }

    // There seems to be a difference in classloading when calling 'mvn site' or 'mvn aspectj:aspectj-report'.
    // When calling mvn site, without the contextClassLoader set, you might see the next message:
    // javadoc: error - Cannot find doclet class com.sun.tools.doclets.standard.Standard
    ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

        // MASPECTJ-11: Make the ajdoc use the ${project.build.directory} directory for its intermediate folder.
        // The argument should be the absolute path to the parent directory of the "ajdocworkingdir" folder.
        Main.setOutputWorkingDir(buildDirectory.getAbsolutePath());

        // Now produce the JavaDoc.
        Main.main((String[]) arguments.toArray(new String[0]));
    } finally {
        Thread.currentThread().setContextClassLoader(oldContextClassLoader);
    }

}