Search in sources :

Example 1 with OrderedClassLibraryBuilder

use of com.thoughtworks.qdox.library.OrderedClassLibraryBuilder in project maven-plugins by apache.

the class AbstractFixJavadocMojo method getQdoxClasses.

/**
 * Calling Qdox to find {@link JavaClass} objects from the Maven project sources.
 * Ignore java class if Qdox has parsing errors.
 *
 * @return an array of {@link JavaClass} found by QDox
 * @throws IOException            if any
 * @throws MojoExecutionException if any
 */
private Collection<JavaClass> getQdoxClasses() throws IOException, MojoExecutionException {
    if ("pom".equalsIgnoreCase(project.getPackaging())) {
        getLog().warn("This project has 'pom' packaging, no Java sources is available.");
        return null;
    }
    List<File> javaFiles = new LinkedList<>();
    for (String sourceRoot : getProjectSourceRoots(project)) {
        File f = new File(sourceRoot);
        if (f.isDirectory()) {
            javaFiles.addAll(FileUtils.getFiles(f, includes, excludes, true));
        } else {
            if (getLog().isWarnEnabled()) {
                getLog().warn(f + " doesn't exist. Ignored it.");
            }
        }
    }
    ClassLibraryBuilder classLibraryBuilder = new OrderedClassLibraryBuilder();
    classLibraryBuilder.appendClassLoader(getProjectClassLoader());
    JavaProjectBuilder builder = new JavaProjectBuilder(classLibraryBuilder);
    builder.setEncoding(encoding);
    for (File f : javaFiles) {
        if (!f.getAbsolutePath().toLowerCase(Locale.ENGLISH).endsWith(".java") && getLog().isWarnEnabled()) {
            getLog().warn("'" + f + "' is not a Java file. Ignored it.");
            continue;
        }
        try {
            builder.addSource(f);
        } catch (ParseException e) {
            if (getLog().isWarnEnabled()) {
                getLog().warn("QDOX ParseException: " + e.getMessage() + ". Can't fix it.");
            }
        }
    }
    return builder.getClasses();
}
Also used : OrderedClassLibraryBuilder(com.thoughtworks.qdox.library.OrderedClassLibraryBuilder) OrderedClassLibraryBuilder(com.thoughtworks.qdox.library.OrderedClassLibraryBuilder) ClassLibraryBuilder(com.thoughtworks.qdox.library.ClassLibraryBuilder) JavaProjectBuilder(com.thoughtworks.qdox.JavaProjectBuilder) ParseException(com.thoughtworks.qdox.parser.ParseException) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

JavaProjectBuilder (com.thoughtworks.qdox.JavaProjectBuilder)1 ClassLibraryBuilder (com.thoughtworks.qdox.library.ClassLibraryBuilder)1 OrderedClassLibraryBuilder (com.thoughtworks.qdox.library.OrderedClassLibraryBuilder)1 ParseException (com.thoughtworks.qdox.parser.ParseException)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1