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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.tools.ajbrowser;
  14. import java.lang.reflect.InvocationTargetException;
  15. import java.lang.reflect.Method;
  16. /**
  17. * Run ajbrowser if 0+ .lst file arguments, and ajc otherwise.
  18. */
  19. public class Main {
  20. /**
  21. * Run ajbrowser if args contains only .lst files and ajc otherwise.
  22. *
  23. * @param args the String[] of args to interpret
  24. */
  25. public static void main(String[] args) {
  26. if (!compilerMain(args)) {
  27. BrowserManager.getDefault().init(args, true);
  28. }
  29. }
  30. /**
  31. * Invoke the compiler if there are arguments and some are not .lst files.
  32. *
  33. * @return false if compiler was not invoked and the browser main should be
  34. */
  35. static boolean compilerMain(String[] args) {
  36. if ((null == args) || (0 == args.length)) {
  37. return false;
  38. }
  39. int numConfigFiles = 0;
  40. for (String arg : args) {
  41. if ((null != arg) && arg.endsWith(".lst")) {
  42. numConfigFiles++;
  43. }
  44. }
  45. if (numConfigFiles != args.length) {
  46. try {
  47. Class<?> ajc = Class.forName("org.aspectj.tools.ajc.Main");
  48. Method main = ajc.getMethod("main", new Class[] { String[].class });
  49. main.invoke(null, new Object[] { args });
  50. return true;
  51. } catch (ClassNotFoundException e) {
  52. report(e);
  53. } catch (NoSuchMethodException e) {
  54. report(e);
  55. } catch (IllegalAccessException e) {
  56. report(e);
  57. } catch (InvocationTargetException e) {
  58. report(e.getTargetException());
  59. }
  60. }
  61. return false;
  62. }
  63. private static void report(Throwable t) {
  64. t.printStackTrace(System.err);
  65. }
  66. }