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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 Common Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/cpl-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. System.setSecurityManager( new SecurityManager() {
  38. public void checkExit(int status) {
  39. if (status == 0) {
  40. throw new SecurityException();
  41. }
  42. else {
  43. System.setSecurityManager(defaultSecurityManager);
  44. //System.out.println("Error: javadoc exited unexpectedly");
  45. System.exit(0);
  46. throw new SecurityException();
  47. }
  48. }
  49. public void checkPermission( java.security.Permission permission ) {
  50. if ( defaultSecurityManager != null )
  51. defaultSecurityManager.checkPermission( permission );
  52. }
  53. public void checkPermission( java.security.Permission permission,
  54. Object context ) {
  55. if ( defaultSecurityManager != null )
  56. defaultSecurityManager.checkPermission( permission, context );
  57. }
  58. } );
  59. try {
  60. // for JDK 1.4 and above call the execute method...
  61. Class jdMainClass = com.sun.tools.javadoc.Main.class;
  62. Method executeMethod = null;
  63. try {
  64. Class[] paramTypes = new Class[] {String[].class};
  65. executeMethod = jdMainClass.getMethod("execute", paramTypes);
  66. } catch (NoSuchMethodException e) {
  67. com.sun.tools.javadoc.Main.main(javadocargs);
  68. // throw new UnsupportedOperationException("ajdoc requires a tools library from JDK 1.4 or later.");
  69. }
  70. try {
  71. executeMethod.invoke(null, new Object[] {javadocargs});
  72. } catch (IllegalArgumentException e1) {
  73. throw new RuntimeException("Failed to invoke javadoc");
  74. } catch (IllegalAccessException e1) {
  75. throw new RuntimeException("Failed to invoke javadoc");
  76. } catch (InvocationTargetException e1) {
  77. throw new RuntimeException("Failed to invoke javadoc");
  78. }
  79. // main method is documented as calling System.exit() - which stops us dead in our tracks
  80. //com.sun.tools.javadoc.Main.main( javadocargs );
  81. }
  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. }