You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Main.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * Entry point for ajdoc.
  25. *
  26. * @author Jeff Palm
  27. */
  28. public class Main {
  29. /**
  30. * value returned from execute(..)
  31. * when the JDK tools are not supported
  32. */
  33. public static final int PLATFORM_ERROR = 3;
  34. /**
  35. * Call {@link #execute} and exit with
  36. * its exit code.
  37. *
  38. * @param args Command line arguments.
  39. */
  40. public static void main(String[] args) {
  41. System.exit(execute(args));
  42. }
  43. /**
  44. * Programmatic entry without calling <code>System.exit</code>,
  45. * returning the result of {@link Ajdoc#execute(String[])}.
  46. *
  47. * @param args Command line arguments.
  48. * @return PLATFORM_ERROR if platformErrorMessage() is not null
  49. * or the result of calling {@link Ajdoc#execute(String[])}.
  50. * @throw Error if bad platform - look at message
  51. */
  52. public static int execute(String[] args) {
  53. int result = 0;
  54. String platformError = platformErrorMessage();
  55. if (null != platformError) {
  56. result = PLATFORM_ERROR;
  57. System.err.println(platformError);
  58. } else {
  59. Ajdoc me = new Ajdoc();
  60. result = me.execute(args);
  61. }
  62. return result;
  63. }
  64. /**
  65. * Generate version error message if we cannot run in this VM
  66. * or using this class path.
  67. * @return null if no error or String describing error otherwise
  68. */
  69. public static String platformErrorMessage() {
  70. // todo: stolen from ajc.Main
  71. boolean failed = false;
  72. final String[] versions = new String[]
  73. { "java.lang.reflect.Proxy" // 1.3: failed if class not found
  74. // permit users to run in 1.4 iff using 1.3 tools.jar
  75. //, "java.lang.CharSequence" // 1.4: failed if class found
  76. };
  77. for (int i = 0; i < versions.length; i++) {
  78. try {
  79. Class.forName(versions[i]);
  80. failed = (i == 1);
  81. } catch (ClassNotFoundException cnfe) {
  82. failed = (i == 0);
  83. } catch (Error err) {
  84. failed = (i == 0);
  85. }
  86. if (failed) {
  87. String version = "(unknown version)";
  88. try { version = System.getProperty("java.version"); }
  89. catch (Throwable t) { } // ignore
  90. return "Ajdoc requires J2SE 1.3; not java " + version;
  91. }
  92. }
  93. // now looking for tools.jar
  94. try {
  95. Class.forName("com.sun.javadoc.RootDoc"); // may be version error
  96. Class.forName("com.sun.javadoc.Type"); // not in 1.4
  97. } catch (ClassNotFoundException cnfe) {
  98. // System.err.println(cnfe.getMessage());
  99. // cnfe.printStackTrace(System.err); // XXX
  100. return "Requires tools.jar from J2SE 1.3 (not 1.2 or 1.4) be on the class path";
  101. } catch (Error err) { // probably wrong version of the class
  102. // System.err.println(err.getMessage());
  103. // err.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. }
  106. return null;
  107. }
  108. }