Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Options.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*******************************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Alexandre Vasseur initial implementation
  11. *******************************************************************************/
  12. package org.aspectj.weaver.loadtime;
  13. import org.aspectj.bridge.IMessage;
  14. import org.aspectj.bridge.IMessageHandler;
  15. import org.aspectj.bridge.Message;
  16. import org.aspectj.util.LangUtil;
  17. import java.util.Collections;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. /**
  21. * A class that hanldes LTW options.
  22. * Note: AV - I choosed to not reuse AjCompilerOptions and alike since those implies too many dependancies on
  23. * jdt and ajdt modules.
  24. *
  25. * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
  26. */
  27. public class Options {
  28. private final static String OPTION_15 = "-1.5";
  29. private final static String OPTION_lazyTjp = "-XlazyTjp";
  30. private final static String OPTION_noWarn = "-nowarn";
  31. private final static String OPTION_noWarnNone = "-warn:none";
  32. private final static String OPTION_proceedOnError = "-proceedOnError";
  33. private final static String OPTION_verbose = "-verbose";
  34. private final static String OPTION_debug = "-debug";
  35. private final static String OPTION_reweavable = "-Xreweavable";//notReweavable is default for LTW
  36. private final static String OPTION_noinline = "-Xnoinline";
  37. private final static String OPTION_addSerialVersionUID = "-XaddSerialVersionUID";
  38. private final static String OPTION_hasMember = "-XhasMember";
  39. private final static String OPTION_pinpoint = "-Xdev:pinpoint";
  40. private final static String OPTION_showWeaveInfo = "-showWeaveInfo";
  41. private final static String OPTIONVALUED_messageHandler = "-XmessageHandlerClass:";
  42. private static final String OPTIONVALUED_Xlintfile = "-Xlintfile:";
  43. private static final String OPTIONVALUED_Xlint = "-Xlint:";
  44. private static final String OPTIONVALUED_joinpoints = "-Xjoinpoints:";
  45. private static final String OPTIONVALUED_Xset = "-Xset:";
  46. public static WeaverOption parse(String options, ClassLoader laoder, IMessageHandler imh) {
  47. WeaverOption weaverOption = new WeaverOption(imh);
  48. if (LangUtil.isEmpty(options)) {
  49. return weaverOption;
  50. }
  51. // the first option wins
  52. List flags = LangUtil.anySplit(options, " ");
  53. Collections.reverse(flags);
  54. // do a first round on the message handler since it will report the options themselves
  55. for (Iterator iterator = flags.iterator(); iterator.hasNext();) {
  56. String arg = (String) iterator.next();
  57. if (arg.startsWith(OPTIONVALUED_messageHandler)) {
  58. if (arg.length() > OPTIONVALUED_messageHandler.length()) {
  59. String handlerClass = arg.substring(OPTIONVALUED_messageHandler.length()).trim();
  60. try {
  61. Class handler = Class.forName(handlerClass, false, laoder);
  62. weaverOption.messageHandler = ((IMessageHandler) handler.newInstance());
  63. } catch (Throwable t) {
  64. weaverOption.messageHandler.handleMessage(
  65. new Message(
  66. "Cannot instantiate message handler " + handlerClass,
  67. IMessage.ERROR,
  68. t,
  69. null
  70. )
  71. );
  72. }
  73. }
  74. }
  75. }
  76. // configure the other options
  77. for (Iterator iterator = flags.iterator(); iterator.hasNext();) {
  78. String arg = (String) iterator.next();
  79. if (arg.equals(OPTION_15)) {
  80. weaverOption.java5 = true;
  81. } else if (arg.equalsIgnoreCase(OPTION_lazyTjp)) {
  82. weaverOption.lazyTjp = true;
  83. } else if (arg.equalsIgnoreCase(OPTION_noinline)) {
  84. weaverOption.noInline = true;
  85. } else if (arg.equalsIgnoreCase(OPTION_addSerialVersionUID)) {
  86. weaverOption.addSerialVersionUID=true;
  87. } else if (arg.equalsIgnoreCase(OPTION_noWarn) || arg.equalsIgnoreCase(OPTION_noWarnNone)) {
  88. weaverOption.noWarn = true;
  89. } else if (arg.equalsIgnoreCase(OPTION_proceedOnError)) {
  90. weaverOption.proceedOnError = true;
  91. } else if (arg.equalsIgnoreCase(OPTION_reweavable)) {
  92. weaverOption.notReWeavable = false;
  93. } else if (arg.equalsIgnoreCase(OPTION_showWeaveInfo)) {
  94. weaverOption.showWeaveInfo = true;
  95. } else if (arg.equalsIgnoreCase(OPTION_hasMember)) {
  96. weaverOption.hasMember = true;
  97. } else if (arg.startsWith(OPTIONVALUED_joinpoints)) {
  98. if (arg.length()>OPTIONVALUED_joinpoints.length())
  99. weaverOption.optionalJoinpoints = arg.substring(OPTIONVALUED_joinpoints.length()).trim();
  100. } else if (arg.equalsIgnoreCase(OPTION_verbose)) {
  101. weaverOption.verbose = true;
  102. } else if (arg.equalsIgnoreCase(OPTION_debug)) {
  103. weaverOption.debug = true;
  104. } else if (arg.equalsIgnoreCase(OPTION_pinpoint)) {
  105. weaverOption.pinpoint = true;
  106. } else if (arg.startsWith(OPTIONVALUED_messageHandler)) {
  107. ;// handled in first round
  108. } else if (arg.startsWith(OPTIONVALUED_Xlintfile)) {
  109. if (arg.length() > OPTIONVALUED_Xlintfile.length()) {
  110. weaverOption.lintFile = arg.substring(OPTIONVALUED_Xlintfile.length()).trim();
  111. }
  112. } else if (arg.startsWith(OPTIONVALUED_Xlint)) {
  113. if (arg.length() > OPTIONVALUED_Xlint.length()) {
  114. weaverOption.lint = arg.substring(OPTIONVALUED_Xlint.length()).trim();
  115. }
  116. } else if (arg.startsWith(OPTIONVALUED_Xset)) {
  117. if (arg.length() > OPTIONVALUED_Xlint.length()) {
  118. weaverOption.xSet = arg.substring(OPTIONVALUED_Xset.length()).trim();
  119. }
  120. } else {
  121. weaverOption.messageHandler.handleMessage(
  122. new Message(
  123. "Cannot configure weaver with option '" + arg + "': unknown option",
  124. IMessage.WARNING,
  125. null,
  126. null
  127. )
  128. );
  129. }
  130. }
  131. // refine message handler configuration
  132. if (weaverOption.noWarn) {
  133. weaverOption.messageHandler.ignore(IMessage.WARNING);
  134. }
  135. if (weaverOption.verbose) {
  136. weaverOption.messageHandler.dontIgnore(IMessage.INFO);
  137. }
  138. if (weaverOption.debug) {
  139. weaverOption.messageHandler.dontIgnore(IMessage.DEBUG);
  140. }
  141. if (weaverOption.showWeaveInfo) {
  142. weaverOption.messageHandler.dontIgnore(IMessage.WEAVEINFO);
  143. }
  144. return weaverOption;
  145. }
  146. public static class WeaverOption {
  147. boolean java5;
  148. boolean lazyTjp;
  149. boolean hasMember;
  150. String optionalJoinpoints;
  151. boolean noWarn;
  152. boolean proceedOnError;
  153. boolean verbose;
  154. boolean debug;
  155. boolean notReWeavable = true;//default to notReweavable for LTW (faster)
  156. boolean noInline;
  157. boolean addSerialVersionUID;
  158. boolean showWeaveInfo;
  159. boolean pinpoint;
  160. IMessageHandler messageHandler;
  161. String lint;
  162. String lintFile;
  163. String xSet;
  164. public WeaverOption(IMessageHandler imh) {
  165. // messageHandler = new DefaultMessageHandler();//default
  166. this.messageHandler = imh;
  167. }
  168. }
  169. }