use of com.thoughtworks.qdox.JavaDocBuilder 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();
}
use of com.thoughtworks.qdox.JavaDocBuilder in project maven-plugins by apache.
the class FixJavadocMojoTest method testJavadocCommentJdk5.
/**
* @throws Throwable if any
*/
public void testJavadocCommentJdk5() throws Throwable {
String content = "/**" + EOL + " * Dummy Class." + EOL + " */" + EOL + "public class DummyClass" + EOL + "{" + EOL + " /**" + EOL + " * Dummy method." + EOL + " *" + EOL + " * @param <K> The Key type for the method" + EOL + " * @param <V> The Value type for the method" + EOL + " * @param name The name." + EOL + " * @return A map configured." + EOL + " */" + EOL + " public <K, V> java.util.Map<K, V> dummyMethod( String name )" + EOL + " {" + EOL + " return null;" + EOL + " }" + EOL + "}";
JavaDocBuilder builder = new JavaDocBuilder();
builder.setEncoding("UTF-8");
builder.addSource(new StringReader(content));
JavaClass[] classes = builder.getClasses();
JavaClass clazz = classes[0];
JavaMethod javaMethod = clazz.getMethods()[0];
String methodJavadoc = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "getJavadocComment", new Class[] { String.class, AbstractJavaEntity.class }, new Object[] { content, javaMethod });
assertEquals(" * Dummy method." + EOL + " *", methodJavadoc);
assertEquals(4, javaMethod.getTags().length);
AbstractFixJavadocMojo mojoInstance = new FixJavadocMojo();
setVariableValueToObject(mojoInstance, "fixTagsSplitted", new String[] { "all" });
DocletTag tag = javaMethod.getTags()[0];
String tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
assertEquals(" * @param <K> The Key type for the method", tagJavadoc);
tag = javaMethod.getTags()[1];
tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
assertEquals(" * @param <V> The Value type for the method", tagJavadoc);
tag = javaMethod.getTags()[2];
tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
assertEquals(" * @param name The name.", tagJavadoc);
tag = javaMethod.getTags()[3];
tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
assertEquals(" * @return A map configured.", tagJavadoc);
}
Aggregations