You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Laird Nelson <lj...@gmail.com> on 2014/04/21 22:08:33 UTC
maven-javadoc-plugin unit tests: require JAVA_HOME?
(Wasn't sure if this belonged on the Maven dev list or on the users list;
happy to carry the discussion on elsewhere if appropriate.)
I'm doing some Java 8 compatibility work on the maven-javadoc-plugin
locally and have discovered that the JavadocReportTest test requires a
JAVA_HOME environment variable to be set for all of its tests to pass.
One exemplary test that easily shows this behavior:
/**
* Test to find the javadoc executable when <code>java.home</code> is
not in the JDK_HOME. In this case, try to
* use the <code>JAVA_HOME</code> environment variable.
*
* @throws Exception if any
*/
public void testToFindJavadoc()
throws Exception
{
String oldJreHome = System.getProperty( "java.home" );
System.setProperty( "java.home", "foo/bar" );
File testPom = new File( unit,
"javaHome-test/javaHome-test-plugin-config.xml" );
JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom
);
mojo.execute(); // <-- unhandled IOException when JAVA_HOME is not
set
System.setProperty( "java.home", oldJreHome );
}
Was this deliberate? This test will error out if JAVA_HOME is not set
thanks to AbstractJavadocMojo, which uses it as a fallback:
//
----------------------------------------------------------------------
// Try to find javadocExe from JAVA_HOME environment variable
//
----------------------------------------------------------------------
if ( !javadocExe.exists() || !javadocExe.isFile() )
{
Properties env = CommandLineUtils.getSystemEnvVars();
String javaHome = env.getProperty( "JAVA_HOME" );
if ( StringUtils.isEmpty( javaHome ) )
{
throw new IOException( "The environment variable JAVA_HOME
is not correctly set." ); // <-- responsible for the test error described
in this email
}
if ( ( !new File( javaHome ).getCanonicalFile().exists() ) || (
new File( javaHome ).getCanonicalFile().isFile() ) )
{
throw new IOException(
"The environment variable JAVA_HOME=" + javaHome + "
doesn't exist or is not a valid directory." );
}
javadocExe = new File( javaHome + File.separator + "bin",
javadocCommand );
}
So the test in question deliberately sets the java.home System property to
a bozo value ("foo/bar"), and then the test errors out because the fallback
code does not detect a JAVA_HOME environment variable.
Is this worth a bug, or...?
Best,
Laird
--
http://about.me/lairdnelson