KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > tools > ajdoc > Main


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22 package org.aspectj.tools.ajdoc;
23
24 /**
25  * Entry point for ajdoc.
26  *
27  * @author Jeff Palm
28  */

29 public class Main {
30     /**
31      * value returned from execute(..)
32      * when the JDK tools are not supported
33      */

34     public static final int PLATFORM_ERROR = 3;
35
36     /**
37      * Call {@link #execute} and exit with
38      * its exit code.
39      *
40      * @param args Command line arguments.
41      */

42     public static void main(String JavaDoc[] args) {
43         System.exit(execute(args));
44     }
45
46     /**
47      * Programmatic entry without calling <code>System.exit</code>,
48      * returning the result of {@link Ajdoc#execute(String[])}.
49      *
50      * @param args Command line arguments.
51      * @return PLATFORM_ERROR if platformErrorMessage() is not null
52      * or the result of calling {@link Ajdoc#execute(String[])}.
53      * @throw Error if bad platform - look at message
54      */

55     public static int execute(String JavaDoc[] args) {
56         int result = 0;
57         String JavaDoc platformError = platformErrorMessage();
58         if (null != platformError) {
59             result = PLATFORM_ERROR;
60             System.err.println(platformError);
61         } else {
62             Ajdoc me = new Ajdoc();
63             result = me.execute(args);
64         }
65         return result;
66     }
67
68     /**
69      * Generate version error message if we cannot run in this VM
70      * or using this class path.
71      * @return null if no error or String describing error otherwise
72      */

73     public static String JavaDoc platformErrorMessage() {
74         // todo: stolen from ajc.Main
75
boolean failed = false;
76         final String JavaDoc[] versions = new String JavaDoc[]
77         { "java.lang.reflect.Proxy" // 1.3: failed if class not found
78
// permit users to run in 1.4 iff using 1.3 tools.jar
79
//, "java.lang.CharSequence" // 1.4: failed if class found
80
};
81         for (int i = 0; i < versions.length; i++) {
82             try {
83                 Class.forName(versions[i]);
84                 failed = (i == 1);
85             } catch (ClassNotFoundException JavaDoc cnfe) {
86                 failed = (i == 0);
87             } catch (Error JavaDoc err) {
88                 failed = (i == 0);
89             }
90             if (failed) {
91                 String JavaDoc version = "(unknown version)";
92                 try { version = System.getProperty("java.version"); }
93                 catch (Throwable JavaDoc t) { } // ignore
94
return "Ajdoc requires J2SE 1.3; not java " + version;
95             }
96         }
97         // now looking for tools.jar
98
try {
99             Class.forName("com.sun.javadoc.RootDoc"); // may be version error
100
Class.forName("com.sun.javadoc.Type"); // not in 1.4
101
} catch (ClassNotFoundException JavaDoc cnfe) {
102             // System.err.println(cnfe.getMessage());
103
// cnfe.printStackTrace(System.err); // XXX
104
return "Requires tools.jar from J2SE 1.3 (not 1.2 or 1.4) be on the class path";
105         } catch (Error JavaDoc err) { // probably wrong version of the class
106
// System.err.println(err.getMessage());
107
// err.printStackTrace(System.err); // XXX
108
return "Requires tools.jar from J2SE 1.3 (not 1.2 or 1.4) be on the class path";
109         }
110         return null;
111     }
112 }
113
Popular Tags