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 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 javax.tools.DocumentationTool;
  16. import javax.tools.DocumentationTool.DocumentationTask;
  17. import javax.tools.JavaFileObject;
  18. import javax.tools.StandardJavaFileManager;
  19. import javax.tools.ToolProvider;
  20. import java.lang.reflect.InvocationTargetException;
  21. import java.util.List;
  22. /**
  23. * @author Mik Kersten
  24. */
  25. class JavadocRunner {
  26. static void callJavadoc(String[] javadocArgs) {
  27. try {
  28. Class.forName("com.sun.tools.javadoc.Main")
  29. .getMethod("execute", String[].class)
  30. .invoke(null, new Object[] { javadocArgs });
  31. }
  32. catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
  33. throw new RuntimeException("Failed to invoke javadoc", e);
  34. }
  35. }
  36. public static void callJavadocViaToolProvider(Iterable<String> options, List<String> files) {
  37. DocumentationTool docTool = ToolProvider.getSystemDocumentationTool();
  38. StandardJavaFileManager fileManager = docTool.getStandardFileManager(null, null, null);
  39. Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjects(files.toArray(new String[0]));
  40. DocumentationTask task = docTool.getTask(
  41. null, // default output writer (System.err)
  42. null, // default file manager
  43. null, // default diagnostic listener
  44. null, // default doclet class
  45. options,
  46. fileObjects
  47. );
  48. task.call();
  49. }
  50. }