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.

JavadocRunner.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * Mik Kersten port to AspectJ 1.1+ code base
  13. * ******************************************************************/
  14. package org.aspectj.tools.ajdoc;
  15. import java.lang.reflect.InvocationTargetException;
  16. import java.lang.reflect.Method;
  17. /**
  18. * @author Mik Kersten
  19. */
  20. class JavadocRunner {
  21. static boolean has14ToolsAvailable() {
  22. try {
  23. Class jdMainClass = com.sun.tools.javadoc.Main.class;
  24. Class[] paramTypes = new Class[] { String[].class };
  25. jdMainClass.getMethod("execute", paramTypes);
  26. } catch (NoClassDefFoundError e) {
  27. return false;
  28. } catch (UnsupportedClassVersionError e) {
  29. return false;
  30. } catch (NoSuchMethodException e) {
  31. return false;
  32. }
  33. return true;
  34. }
  35. static void callJavadoc(String[] javadocargs) {
  36. // final SecurityManager defaultSecurityManager = System.getSecurityManager();
  37. //
  38. // System.setSecurityManager( new SecurityManager() {
  39. // public void checkExit(int status) {
  40. // if (status == 0) {
  41. // throw new SecurityException();
  42. // }
  43. // else {
  44. // System.setSecurityManager(defaultSecurityManager);
  45. // //System.out.println("Error: javadoc exited unexpectedly");
  46. // System.exit(0);
  47. // throw new SecurityException();
  48. // }
  49. // }
  50. // public void checkPermission( java.security.Permission permission ) {
  51. // if ( defaultSecurityManager != null )
  52. // defaultSecurityManager.checkPermission( permission );
  53. // }
  54. // public void checkPermission( java.security.Permission permission,
  55. // Object context ) {
  56. // if ( defaultSecurityManager != null )
  57. // defaultSecurityManager.checkPermission( permission, context );
  58. // }
  59. // } );
  60. try {
  61. // for JDK 1.4 and above call the execute method...
  62. Class jdMainClass = com.sun.tools.javadoc.Main.class;
  63. Method executeMethod = null;
  64. try {
  65. Class[] paramTypes = new Class[] { String[].class };
  66. executeMethod = jdMainClass.getMethod("execute", paramTypes);
  67. } catch (NoSuchMethodException e) {
  68. com.sun.tools.javadoc.Main.main(javadocargs);
  69. // throw new UnsupportedOperationException("ajdoc requires a tools library from JDK 1.4 or later.");
  70. }
  71. try {
  72. executeMethod.invoke(null, new Object[] { javadocargs });
  73. } catch (IllegalArgumentException e1) {
  74. throw new RuntimeException("Failed to invoke javadoc");
  75. } catch (IllegalAccessException e1) {
  76. throw new RuntimeException("Failed to invoke javadoc");
  77. } catch (InvocationTargetException e1) {
  78. throw new RuntimeException("Failed to invoke javadoc");
  79. }
  80. // main method is documented as calling System.exit() - which stops us dead in our tracks
  81. // com.sun.tools.javadoc.Main.main( javadocargs );
  82. } catch (SecurityException se) {
  83. // Do nothing since we expect it to be thrown
  84. // System.out.println( ">> se: " + se.getMessage() );
  85. }
  86. // Set the security manager back
  87. // System.setSecurityManager(defaultSecurityManager);
  88. }
  89. }