Index: src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
===================================================================
--- src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java (revision 681517)
+++ src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java (working copy)
@@ -813,33 +813,23 @@
}
/**
- * Auto-detect the class names of the implementation of com.sun.tools.doclets.Taglet class from a
- * given jar file.
- *
- * Note: JAVA_HOME/lib/tools.jar is a requirement to find
- * com.sun.tools.doclets.Taglet class.
- *
- * @param jarFile not null
- * @return the list of com.sun.tools.doclets.Taglet class names from a given jarFile.
- * @throws IOException if jarFile is invalid or not found, or if the JAVA_HOME/lib/tools.jar
- * is not found.
- * @throws ClassNotFoundException if any
- * @throws NoClassDefFoundError if any
+ * Gets the path to the tools.jar which is used to load the taglet class. Note: This
+ * JAR is only available for JDKs on Windows, Linux and Solaris, it is not not present on Mac OS X.
+ *
+ * @return The path to the tools.jar, never null.
+ * @throws IOException If the path could not be determined (although the platform has tools.jar).
+ * @throws UnsupportedOperationException If the underlying OS has no tools.jar.
*/
- protected static List getTagletClassNames( File jarFile )
- throws IOException, ClassNotFoundException, NoClassDefFoundError
+ static File getToolsJar()
+ throws IOException
{
- File jdkHome = null;
- if ( SystemUtils.IS_OS_MAC_OSX )
+ if ( SystemUtils.IS_OS_MAC )
{
- jdkHome = SystemUtils.getJavaHome();
+ throw new UnsupportedOperationException( "tools.jar does not exist on Mac OS" );
}
- else
- {
- jdkHome = SystemUtils.getJavaHome().getParentFile();
- }
- if ( !jdkHome.exists() || !jdkHome.isDirectory() )
+ File jdkHome = SystemUtils.getJavaHome().getParentFile();
+ if ( !jdkHome.isDirectory() )
{
Properties env = CommandLineUtils.getSystemEnvVars();
String javaHome = env.getProperty( "JAVA_HOME" );
@@ -849,26 +839,57 @@
throw new IOException( "The environment variable JAVA_HOME is not correctly set." );
}
jdkHome = new File( javaHome );
- if ( !jdkHome.exists() || !jdkHome.isDirectory() )
+ if ( !jdkHome.isDirectory() )
{
throw new IOException( "The environment variable JAVA_HOME=" + javaHome
+ " doesn't exist or is not a valid directory." );
}
}
- // Needed to find com.sun.tools.doclets.Taglet class
File tools = new File( jdkHome, "lib/tools.jar" );
- if ( !tools.exists() || !tools.isFile() )
+ if ( !tools.isFile() )
{
throw new IOException( "tools.jar '" + tools + "' was not found or is invalid." );
}
+ return tools;
+ }
+
+ /**
+ * Auto-detect the class names of the implementation of com.sun.tools.doclets.Taglet class from a
+ * given jar file.
+ *
+ * Note: JAVA_HOME/lib/tools.jar is a requirement to find
+ * com.sun.tools.doclets.Taglet class (excluding Mac OS).
+ *
+ * @param jarFile not null
+ * @return the list of com.sun.tools.doclets.Taglet class names from a given jarFile.
+ * @throws IOException if jarFile is invalid or not found, or if the JAVA_HOME/lib/tools.jar
+ * is not found.
+ * @throws ClassNotFoundException if any
+ * @throws NoClassDefFoundError if any
+ */
+ protected static List getTagletClassNames( File jarFile )
+ throws IOException, ClassNotFoundException, NoClassDefFoundError
+ {
List classes = getClassNamesFromJar( jarFile );
- ClassLoader cl = new URLClassLoader( new URL[] { jarFile.toURI().toURL(), tools.toURI().toURL() }, null );
+ ClassLoader cl;
+ try
+ {
+ File tools = getToolsJar();
+ cl = new URLClassLoader( new URL[] { jarFile.toURI().toURL(), tools.toURI().toURL() }, null );
+ }
+ catch ( UnsupportedOperationException e )
+ {
+ // on Mac, the doclet class should be part of the bootstrap class loader
+ cl = new URLClassLoader( new URL[] { jarFile.toURI().toURL() }, null );
+ }
+
+ Class tagletClass = cl.loadClass( "com.sun.tools.doclets.Taglet" );
+
List tagletClasses = new ArrayList();
- Class tagletClass = cl.loadClass( "com.sun.tools.doclets.Taglet" );
for ( Iterator it = classes.iterator(); it.hasNext(); )
{
String s = (String) it.next();
Index: src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java
===================================================================
--- src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java (revision 681517)
+++ src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java (working copy)
@@ -19,8 +19,10 @@
* under the License.
*/
+import java.io.File;
import java.util.regex.PatternSyntaxException;
+import org.apache.commons.lang.SystemUtils;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Settings;
@@ -249,4 +251,33 @@
cmdLine = JavadocUtil.hideProxyPassword( cmdLine, null );
assertFalse( cmdLine.indexOf( "-J-Dhttp.proxyPassword=\"****\"" ) != -1 );
}
+
+ /**
+ * Method to test the search for tools.jar.
+ *
+ * @throws Exception if any
+ */
+ public void testGetToolsJar()
+ throws Exception
+ {
+ if ( SystemUtils.IS_OS_MAC )
+ {
+ try
+ {
+ JavadocUtil.getToolsJar();
+ fail( "no tools.jar on Mac, should have failed" );
+ }
+ catch ( UnsupportedOperationException e )
+ {
+ assertTrue( true );
+ }
+ }
+ else
+ {
+ File jarFile = JavadocUtil.getToolsJar();
+ assertNotNull( jarFile );
+ assertTrue( jarFile.isFile() );
+ }
+ }
+
}