Search in sources :

Example 1 with ParseException

use of com.thoughtworks.qdox.parser.ParseException 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 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<File>();
    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.");
            }
        }
    }
    JavaDocBuilder builder = new JavaDocBuilder();
    builder.getClassLibrary().addClassLoader(getProjectClassLoader());
    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 : ParseException(com.thoughtworks.qdox.parser.ParseException) File(java.io.File) LinkedList(java.util.LinkedList) JavaDocBuilder(com.thoughtworks.qdox.JavaDocBuilder)

Aggregations

JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)1 ParseException (com.thoughtworks.qdox.parser.ParseException)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1