]> source.dussan.org Git - aspectj.git/commitdiff
fixed so that failure is graceful under 1.3, and to avoid
authoracolyer <acolyer>
Fri, 2 Apr 2004 11:54:10 +0000 (11:54 +0000)
committeracolyer <acolyer>
Fri, 2 Apr 2004 11:54:10 +0000 (11:54 +0000)
calling main method in javadoc since this ends by calling
System.exit. Solution is to use execute method instead
(1.4 and above only).

ajdoc/src/org/aspectj/tools/ajdoc/JavadocExecutor.java
ajdoc/src/org/aspectj/tools/ajdoc/Main.java

index e654be7b061d5611cc6eaca50c6a2db9b94c0194..15398761fd026a13af4b9184aeec3cc43f1b4c9d 100644 (file)
@@ -23,6 +23,8 @@ import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.StringReader;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 
 import java.util.*;
 
@@ -30,7 +32,19 @@ import java.util.*;
  * @author Mik Kersten
  */
 class JavadocExecutor {
-     static void callJavadoc( String[] javadocargs ) {
+       static boolean has14ToolsAvailable() {
+               Class jdMainClass = com.sun.tools.javadoc.Main.class;
+               try {
+                       Class[] paramTypes = new Class[] {String[].class};
+                       jdMainClass.getMethod("execute", paramTypes);
+               } catch (NoSuchMethodException e) {
+                       return false;
+               }
+               return true;
+       }
+       
+       
+     static void callJavadoc( String[] javadocargs ){
         final SecurityManager defaultSecurityManager = System.getSecurityManager();
 
         System.setSecurityManager( new SecurityManager() {
@@ -57,7 +71,26 @@ class JavadocExecutor {
             } );
 
         try {
-            com.sun.tools.javadoc.Main.main( javadocargs );
+               // for JDK 1.4 and above call the execute method...
+               Class jdMainClass = com.sun.tools.javadoc.Main.class;
+               Method executeMethod = null;
+                       try {
+                               Class[] paramTypes = new Class[] {String[].class};
+                               executeMethod = jdMainClass.getMethod("execute", paramTypes);
+                       } catch (NoSuchMethodException e) {
+                               throw new UnsupportedOperationException("ajdoc requires a tools library from JDK 1.4 or later.");
+                       }
+                       try {
+                               executeMethod.invoke(null, new Object[] {javadocargs});
+                       } catch (IllegalArgumentException e1) {
+                               throw new RuntimeException("Failed to invoke javadoc");
+                       } catch (IllegalAccessException e1) {
+                               throw new RuntimeException("Failed to invoke javadoc");
+                       } catch (InvocationTargetException e1) {
+                               throw new RuntimeException("Failed to invoke javadoc");
+                       }
+               // main method is documented as calling System.exit() - which stops us dead in our tracks
+            //com.sun.tools.javadoc.Main.main( javadocargs );
         }
         catch ( SecurityException se ) {
             // Do nothing since we expect it to be thrown
index 22d875ea5e774fd1af1ddd9bcb20ad3439832237..ab78d66a9fda0dc7c4bbef02bd0f07848a6d6883 100644 (file)
@@ -80,6 +80,12 @@ public class Main implements Config {
 
     public static void main(String[] args) {
        aborted = false;
+       
+       if (!JavadocExecutor.has14ToolsAvailable()) {
+               System.err.println("ajdoc requires a JDK 1.4 or later tools jar - exiting");
+               aborted = true;
+               return;
+       }
          
 //     System.err.println("> command invoked: " + Arrays.asList(args).toString());