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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.io.IOException;
  16. import java.lang.reflect.InvocationTargetException;
  17. import java.lang.reflect.Method;
  18. import org.aspectj.util.LangUtil;
  19. /**
  20. * @author Mik Kersten
  21. */
  22. class JavadocRunner {
  23. static boolean has14ToolsAvailable() {
  24. try {
  25. Class jdMainClass = com.sun.tools.javadoc.Main.class;
  26. Class[] paramTypes = new Class[] { String[].class };
  27. jdMainClass.getMethod("execute", paramTypes);
  28. } catch (NoClassDefFoundError e) {
  29. return false;
  30. } catch (UnsupportedClassVersionError e) {
  31. return false;
  32. } catch (NoSuchMethodException e) {
  33. return false;
  34. }
  35. return true;
  36. }
  37. static void callJavadoc(String[] javadocargs) {
  38. // final SecurityManager defaultSecurityManager = System.getSecurityManager();
  39. //
  40. // System.setSecurityManager( new SecurityManager() {
  41. // public void checkExit(int status) {
  42. // if (status == 0) {
  43. // throw new SecurityException();
  44. // }
  45. // else {
  46. // System.setSecurityManager(defaultSecurityManager);
  47. // //System.out.println("Error: javadoc exited unexpectedly");
  48. // System.exit(0);
  49. // throw new SecurityException();
  50. // }
  51. // }
  52. // public void checkPermission( java.security.Permission permission ) {
  53. // if ( defaultSecurityManager != null )
  54. // defaultSecurityManager.checkPermission( permission );
  55. // }
  56. // public void checkPermission( java.security.Permission permission,
  57. // Object context ) {
  58. // if ( defaultSecurityManager != null )
  59. // defaultSecurityManager.checkPermission( permission, context );
  60. // }
  61. // } );
  62. // Need to do something different on Java > 9 due to removal of standard doclet I think
  63. // if (LangUtil.is19VMOrGreater()) {
  64. // // Not visible according to module rules...
  65. // clazz = Class.forName("jdk.javadoc.internal.tool.Main");
  66. // }
  67. try {
  68. // for JDK 1.4 and above call the execute method...
  69. Class jdMainClass = com.sun.tools.javadoc.Main.class;
  70. Method executeMethod = null;
  71. try {
  72. Class[] paramTypes = new Class[] { String[].class };
  73. executeMethod = jdMainClass.getMethod("execute", paramTypes);
  74. } catch (NoSuchMethodException e) {
  75. com.sun.tools.javadoc.Main.main(javadocargs);
  76. // throw new UnsupportedOperationException("ajdoc requires a tools library from JDK 1.4 or later.");
  77. }
  78. try {
  79. executeMethod.invoke(null, new Object[] { javadocargs });
  80. } catch (IllegalArgumentException e1) {
  81. throw new RuntimeException("Failed to invoke javadoc");
  82. } catch (IllegalAccessException e1) {
  83. throw new RuntimeException("Failed to invoke javadoc");
  84. } catch (InvocationTargetException e1) {
  85. throw new RuntimeException("Failed to invoke javadoc");
  86. }
  87. // main method is documented as calling System.exit() - which stops us dead in our tracks
  88. // com.sun.tools.javadoc.Main.main( javadocargs );
  89. } catch (SecurityException se) {
  90. // Do nothing since we expect it to be thrown
  91. // System.out.println( ">> se: " + se.getMessage() );
  92. }
  93. // Set the security manager back
  94. // System.setSecurityManager(defaultSecurityManager);
  95. }
  96. }