summaryrefslogtreecommitdiffstats
path: root/ajdoc
diff options
context:
space:
mode:
authoracolyer <acolyer>2004-04-02 11:54:10 +0000
committeracolyer <acolyer>2004-04-02 11:54:10 +0000
commitfc1c15110e8a9cfafabad0dcc4c10445725c9fb2 (patch)
tree92060b15b1846e3069bef2d8cd93dba5b6f0362c /ajdoc
parent8362834a932f63a0ac5d25d52898b658d2fe2b81 (diff)
downloadaspectj-fc1c15110e8a9cfafabad0dcc4c10445725c9fb2.tar.gz
aspectj-fc1c15110e8a9cfafabad0dcc4c10445725c9fb2.zip
fixed so that failure is graceful under 1.3, and to avoid
calling main method in javadoc since this ends by calling System.exit. Solution is to use execute method instead (1.4 and above only).
Diffstat (limited to 'ajdoc')
-rw-r--r--ajdoc/src/org/aspectj/tools/ajdoc/JavadocExecutor.java37
-rw-r--r--ajdoc/src/org/aspectj/tools/ajdoc/Main.java6
2 files changed, 41 insertions, 2 deletions
diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/JavadocExecutor.java b/ajdoc/src/org/aspectj/tools/ajdoc/JavadocExecutor.java
index e654be7b0..15398761f 100644
--- a/ajdoc/src/org/aspectj/tools/ajdoc/JavadocExecutor.java
+++ b/ajdoc/src/org/aspectj/tools/ajdoc/JavadocExecutor.java
@@ -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
diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/Main.java b/ajdoc/src/org/aspectj/tools/ajdoc/Main.java
index 22d875ea5..ab78d66a9 100644
--- a/ajdoc/src/org/aspectj/tools/ajdoc/Main.java
+++ b/ajdoc/src/org/aspectj/tools/ajdoc/Main.java
@@ -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());