use of org.apache.maven.plugins.javadoc.JavadocJar in project maven-plugins by apache.
the class JavadocJarTest method lookupMojo.
private JavadocJar lookupMojo(File testPom) throws Exception {
JavadocJar mojo = (JavadocJar) lookupMojo("jar", testPom);
MojoExecution mojoExec = new MojoExecution(new Plugin(), "javadoc", null);
setVariableValueToObject(mojo, "mojo", mojoExec);
MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId("GROUPID");
currentProject.setArtifactId("ARTIFACTID");
setVariableValueToObject(mojo, "session", newMavenSession(currentProject));
return mojo;
}
use of org.apache.maven.plugins.javadoc.JavadocJar in project maven-plugins by apache.
the class JavadocJarTest method testContinueIfFailOnErrorIsFalse.
public void testContinueIfFailOnErrorIsFalse() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/javadocjar-failonerror/javadocjar-failonerror-plugin-config.xml");
JavadocJar mojo = lookupMojo(testPom);
mojo.execute();
// check if the javadoc jar file was generated
File generatedFile = new File(getBasedir(), "target/test/unit/javadocjar-failonerror/target/javadocjar-failonerror-javadoc.jar");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
}
use of org.apache.maven.plugins.javadoc.JavadocJar in project maven-plugins by apache.
the class JavadocJarTest method testDefaultConfig.
/**
* Test when default configuration is provided
*
* @throws Exception if any
*/
public void testDefaultConfig() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/javadocjar-default/javadocjar-default-plugin-config.xml");
JavadocJar mojo = lookupMojo(testPom);
mojo.execute();
// check if the javadoc jar file was generated
File generatedFile = new File(getBasedir(), "target/test/unit/javadocjar-default/target/javadocjar-default-javadoc.jar");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
Set<String> set = new HashSet<>();
// validate contents of jar file
try (ZipFile jar = new ZipFile(generatedFile)) {
for (Enumeration<? extends ZipEntry> entries = jar.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = entries.nextElement();
set.add(entry.getName());
}
}
assertTrue(set.contains("stylesheet.css"));
JavadocVersion javadocVersion = (JavadocVersion) getVariableValueFromObject(mojo, "javadocRuntimeVersion");
if (javadocVersion.compareTo(JavadocVersion.parse("1.7")) < 0) {
assertTrue(set.contains("resources/inherit.gif"));
} else if (javadocVersion.compareTo(JavadocVersion.parse("1.8")) < 0) {
assertTrue(set.contains("resources/background.gif"));
} else {
// JDK8 has no resources anymore
assertFalse(set.contains("resources"));
}
assertTrue(set.contains("javadocjar/def/package-use.html"));
assertTrue(set.contains("javadocjar/def/package-tree.html"));
assertTrue(set.contains("javadocjar/def/package-summary.html"));
assertTrue(set.contains("javadocjar/def/package-frame.html"));
assertTrue(set.contains("javadocjar/def/class-use/AppSample.html"));
assertTrue(set.contains("index.html"));
assertTrue(set.contains("javadocjar/def/App.html"));
assertTrue(set.contains("javadocjar/def/AppSample.html"));
assertTrue(set.contains("javadocjar/def/class-use/App.html"));
assertFalse(set.contains(AbstractJavadocMojo.ARGFILE_FILE_NAME));
assertFalse(set.contains(AbstractJavadocMojo.FILES_FILE_NAME));
assertFalse(set.contains(AbstractJavadocMojo.OPTIONS_FILE_NAME));
assertFalse(set.contains(AbstractJavadocMojo.PACKAGES_FILE_NAME));
// check if the javadoc files were created
generatedFile = new File(getBasedir(), "target/test/unit/javadocjar-default/target/site/apidocs/javadocjar/def/App.html");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
generatedFile = new File(getBasedir(), "target/test/unit/javadocjar-default/target/site/apidocs/javadocjar/def/AppSample.html");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
}
use of org.apache.maven.plugins.javadoc.JavadocJar in project maven-plugins by apache.
the class JavadocJarTest method testInvalidDestdir.
/**
* Test when the specified destDir parameter has an invalid value
*
* @throws Exception if any
*/
public void testInvalidDestdir() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/javadocjar-invalid-destdir/javadocjar-invalid-destdir-plugin-config.xml");
JavadocJar mojo = lookupMojo(testPom);
mojo.execute();
// check if the javadoc jar file was generated
File generatedFile = new File(getBasedir(), "target/test/unit/javadocjar-invalid-destdir/target/javadocjar-invalid-destdir-javadoc.jar");
assertTrue(!FileUtils.fileExists(generatedFile.getAbsolutePath()));
}
use of org.apache.maven.plugins.javadoc.JavadocJar in project maven-plugins by apache.
the class JavadocJarTest method testIncludeMavenDescriptorWhenExplicitlyConfigured.
public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/javadocjar-archive-config/javadocjar-archive-config.xml");
JavadocJar mojo = lookupMojo(testPom);
mojo.execute();
// check if the javadoc jar file was generated
File generatedFile = new File(getBasedir(), "target/test/unit/javadocjar-archive-config/target/javadocjar-archive-config-javadoc.jar");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
// validate contents of jar file
ZipFile jar = new ZipFile(generatedFile);
Set<String> set = new HashSet<>();
for (Enumeration<? extends ZipEntry> entries = jar.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = entries.nextElement();
set.add(entry.getName());
}
jar.close();
List<String> expected = new ArrayList<>();
expected.add("META-INF/");
expected.add("META-INF/maven/");
expected.add("META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/");
expected.add("META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/");
expected.add("META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.xml");
expected.add("META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.properties");
for (int i = 0; i < expected.size(); i++) {
String entry = expected.get(i);
assertTrue("Expected jar to contain " + entry, set.contains(entry));
}
}
Aggregations