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.

BuildArgParser.java 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  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://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.ajc;
  13. import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
  14. import org.aspectj.ajdt.internal.core.builder.AjBuildConfig;
  15. import org.aspectj.bridge.*;
  16. import org.aspectj.org.eclipse.jdt.core.compiler.CategorizedProblem;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AptProblem;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.batch.Main;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  21. import org.aspectj.util.FileUtil;
  22. import org.aspectj.util.LangUtil;
  23. import org.aspectj.weaver.Constants;
  24. import org.aspectj.weaver.Dump;
  25. import org.aspectj.weaver.WeaverMessages;
  26. import java.io.File;
  27. import java.io.IOException;
  28. import java.io.PrintWriter;
  29. import java.io.StringWriter;
  30. import java.util.*;
  31. @SuppressWarnings("unchecked")
  32. public class BuildArgParser extends Main {
  33. private static final String BUNDLE_NAME = "org.aspectj.ajdt.ajc.messages";
  34. private static boolean LOADED_BUNDLE = false;
  35. static {
  36. Main.bundleName = BUNDLE_NAME;
  37. ResourceBundleFactory.getBundle(Locale.getDefault());
  38. if (!LOADED_BUNDLE) {
  39. LOADED_BUNDLE = true;
  40. }
  41. }
  42. /** to initialize super's PrintWriter but refer to underlying StringWriter */
  43. private static class StringPrintWriter extends PrintWriter {
  44. public final StringWriter stringWriter;
  45. StringPrintWriter(StringWriter sw) {
  46. super(sw);
  47. this.stringWriter = sw;
  48. }
  49. }
  50. /** @return multi-line String usage for the compiler */
  51. public static String getUsage() {
  52. return _bind("misc.usage", new String[] { _bind("compiler.name", (String[]) null) });
  53. }
  54. public static String getXOptionUsage() {
  55. return _bind("xoption.usage", new String[] { _bind("compiler.name", (String[]) null) });
  56. }
  57. /**
  58. * StringWriter sink for some errors. This only captures errors not handled by any IMessageHandler parameter and only when no
  59. * PrintWriter is set in the constructor. XXX This relies on (Sun's) implementation of StringWriter, which returns the actual
  60. * (not copy) internal StringBuffer.
  61. */
  62. private final StringBuffer errorSink;
  63. private IMessageHandler handler;
  64. /**
  65. * Overrides super's bundle.
  66. */
  67. public BuildArgParser(PrintWriter writer, IMessageHandler handler) {
  68. super(writer, writer, false, null, null);
  69. if (writer instanceof StringPrintWriter) {
  70. errorSink = ((StringPrintWriter) writer).stringWriter.getBuffer();
  71. } else {
  72. errorSink = null;
  73. }
  74. this.handler = handler;
  75. }
  76. /** Set up to capture messages using getOtherMessages(boolean) */
  77. public BuildArgParser(IMessageHandler handler) {
  78. this(new StringPrintWriter(new StringWriter()), handler);
  79. }
  80. /**
  81. * Generate build configuration for the input args, passing to handler any error messages.
  82. *
  83. * @param args the String[] arguments for the build configuration
  84. * @return AjBuildConfig per args, which will be invalid unless there are no handler errors.
  85. */
  86. public AjBuildConfig genBuildConfig(String[] args) {
  87. final AjBuildConfig config = new AjBuildConfig(this);
  88. populateBuildConfig(config, args, true, null);
  89. return config;
  90. }
  91. /**
  92. * Generate build configuration for the input arguments, passing to handler any error messages.
  93. *
  94. * @param args the String[] arguments for the build configuration
  95. * @param setClasspath determines if the classpath should be parsed and set on the build configuration
  96. * @param configFile can be null
  97. * @return AjBuildConfig per arguments, which will be invalid unless there are no handler errors.
  98. */
  99. public AjBuildConfig populateBuildConfig(AjBuildConfig buildConfig, String[] args, boolean setClasspath, File configFile) {
  100. Dump.saveCommandLine(args);
  101. buildConfig.setConfigFile(configFile);
  102. try {
  103. // sets filenames to be non-null in order to make sure that file parameters are ignored
  104. super.filenames = new String[] { "" };
  105. AjcConfigParser parser = new AjcConfigParser(buildConfig, handler);
  106. parser.parseCommandLine(args);
  107. boolean swi = buildConfig.getShowWeavingInformation();
  108. // Now jump through firey hoops to turn them on/off
  109. if (handler instanceof CountingMessageHandler) {
  110. IMessageHandler delegate = ((CountingMessageHandler) handler).delegate;
  111. if (swi) {
  112. delegate.dontIgnore(IMessage.WEAVEINFO);
  113. } else {
  114. delegate.ignore(IMessage.WEAVEINFO);
  115. }
  116. }
  117. boolean incrementalMode = buildConfig.isIncrementalMode() || buildConfig.isIncrementalFileMode();
  118. List<File> xmlfileList = new ArrayList<File>();
  119. xmlfileList.addAll(parser.getXmlFiles());
  120. List<File> fileList = new ArrayList<File>();
  121. List<File> files = parser.getFiles();
  122. if (!LangUtil.isEmpty(files)) {
  123. if (incrementalMode) {
  124. MessageUtil.error(handler, "incremental mode only handles source files using -sourceroots");
  125. } else {
  126. fileList.addAll(files);
  127. }
  128. }
  129. List<String> javaArgList = new ArrayList<String>();
  130. // disable all special eclipse warnings by default - why???
  131. // ??? might want to instead override getDefaultOptions()
  132. javaArgList.add("-warn:none");
  133. // these next four lines are some nonsense to fool the eclipse batch compiler
  134. // without these it will go searching for reasonable values from properties
  135. // TODO fix org.eclipse.jdt.internal.compiler.batch.Main so this hack isn't needed
  136. javaArgList.add("-classpath");
  137. javaArgList.add(parser.classpath == null ? System.getProperty("user.dir") : parser.classpath);
  138. javaArgList.add("-bootclasspath");
  139. javaArgList.add(parser.bootclasspath == null ? System.getProperty("user.dir") : parser.bootclasspath);
  140. javaArgList.addAll(parser.getUnparsedArgs());
  141. super.configure(javaArgList.toArray(new String[javaArgList.size()]));
  142. if (!proceed) {
  143. buildConfig.doNotProceed();
  144. return buildConfig;
  145. }
  146. if (buildConfig.getSourceRoots() != null) {
  147. for (Iterator i = buildConfig.getSourceRoots().iterator(); i.hasNext();) {
  148. fileList.addAll(collectSourceRootFiles((File) i.next()));
  149. }
  150. }
  151. buildConfig.setXmlFiles(xmlfileList);
  152. buildConfig.setFiles(fileList);
  153. if (destinationPath != null) { // XXX ?? unparsed but set?
  154. buildConfig.setOutputDir(new File(destinationPath));
  155. }
  156. if (setClasspath) {
  157. buildConfig.setClasspath(getClasspath(parser));
  158. buildConfig.setBootclasspath(getBootclasspath(parser));
  159. }
  160. if (incrementalMode && (0 == buildConfig.getSourceRoots().size())) {
  161. MessageUtil.error(handler, "specify a source root when in incremental mode");
  162. }
  163. /*
  164. * Ensure we don't overwrite injars, inpath or aspectpath with outjar bug-71339
  165. */
  166. File outjar = buildConfig.getOutputJar();
  167. if (outjar != null) {
  168. /* Search injars */
  169. for (Iterator i = buildConfig.getInJars().iterator(); i.hasNext();) {
  170. File injar = (File) i.next();
  171. if (injar.equals(outjar)) {
  172. String message = WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH);
  173. MessageUtil.error(handler, message);
  174. }
  175. }
  176. /* Search inpath */
  177. for (Iterator i = buildConfig.getInpath().iterator(); i.hasNext();) {
  178. File inPathElement = (File) i.next();
  179. if (!inPathElement.isDirectory() && inPathElement.equals(outjar)) {
  180. String message = WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH);
  181. MessageUtil.error(handler, message);
  182. }
  183. }
  184. /* Search aspectpath */
  185. for (Iterator i = buildConfig.getAspectpath().iterator(); i.hasNext();) {
  186. File pathElement = (File) i.next();
  187. if (!pathElement.isDirectory() && pathElement.equals(outjar)) {
  188. String message = WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH);
  189. MessageUtil.error(handler, message);
  190. }
  191. }
  192. }
  193. setDebugOptions();
  194. buildConfig.getOptions().set(options);
  195. } catch (IllegalArgumentException iae) {
  196. ISourceLocation location = null;
  197. if (buildConfig.getConfigFile() != null) {
  198. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  199. }
  200. IMessage m = new Message(iae.getMessage(), IMessage.ERROR, null, location);
  201. handler.handleMessage(m);
  202. }
  203. return buildConfig;
  204. }
  205. public void printVersion() {
  206. final String version = bind("misc.version", //$NON-NLS-1$
  207. new String[] { bind("compiler.name"), //$NON-NLS-1$
  208. Version.text + " - Built: " + Version.time_text, bind("compiler.version"), //$NON-NLS-1$
  209. bind("compiler.copyright") //$NON-NLS-1$
  210. });
  211. System.out.println(version);
  212. }
  213. @Override
  214. public void addExtraProblems(CategorizedProblem problem) {
  215. super.addExtraProblems(problem);
  216. if (problem instanceof AptProblem) {
  217. handler.handleMessage(newAptMessage((AptProblem)problem));
  218. }
  219. }
  220. private IMessage newAptMessage(AptProblem problem) {
  221. String message = problem.getMessage();
  222. boolean isError = problem.isError();
  223. if (problem._referenceContext != null) {
  224. return new Message(message,
  225. new EclipseSourceLocation(problem._referenceContext.compilationResult(), problem.getSourceStart(), problem.getSourceEnd()),
  226. isError);
  227. } else {
  228. return new Message(message, null, isError);
  229. }
  230. }
  231. @Override
  232. public void initializeAnnotationProcessorManager() {
  233. if (this.compilerOptions.complianceLevel < ClassFileConstants.JDK1_6 || !this.compilerOptions.processAnnotations)
  234. return;
  235. super.initializeAnnotationProcessorManager();
  236. }
  237. @Override
  238. public void printUsage() {
  239. System.out.println(getUsage());
  240. System.out.flush();
  241. }
  242. /**
  243. * Get messages not dumped to handler or any PrintWriter.
  244. *
  245. * @param flush if true, empty errors
  246. * @return null if none, String otherwise
  247. * @see BuildArgParser()
  248. */
  249. public String getOtherMessages(boolean flush) {
  250. if (null == errorSink) {
  251. return null;
  252. }
  253. String result = errorSink.toString().trim();
  254. if (0 == result.length()) {
  255. result = null;
  256. }
  257. if (flush) {
  258. errorSink.setLength(0);
  259. }
  260. return result;
  261. }
  262. private void setDebugOptions() {
  263. options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
  264. options.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
  265. options.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
  266. }
  267. private Collection collectSourceRootFiles(File dir) {
  268. return Arrays.asList(FileUtil.listFiles(dir, FileUtil.aspectjSourceFileFilter));
  269. }
  270. public List<String> getBootclasspath(AjcConfigParser parser) {
  271. List<String> ret = new ArrayList<String>();
  272. if (parser.bootclasspath == null) {
  273. addClasspath(System.getProperty("sun.boot.class.path", ""), ret);
  274. } else {
  275. addClasspath(parser.bootclasspath, ret);
  276. }
  277. return ret;
  278. }
  279. /**
  280. * If the classpath is not set, we use the environment's java.class.path, but remove the aspectjtools.jar entry from that list
  281. * in order to prevent wierd bootstrap issues (refer to bug#39959).
  282. */
  283. public List getClasspath(AjcConfigParser parser) {
  284. List ret = new ArrayList();
  285. // if (parser.bootclasspath == null) {
  286. // addClasspath(System.getProperty("sun.boot.class.path", ""), ret);
  287. // } else {
  288. // addClasspath(parser.bootclasspath, ret);
  289. // }
  290. String extdirs = parser.extdirs;
  291. if (extdirs == null) {
  292. extdirs = System.getProperty("java.ext.dirs", "");
  293. }
  294. addExtDirs(extdirs, ret);
  295. if (parser.classpath == null) {
  296. addClasspath(System.getProperty("java.class.path", ""), ret);
  297. List fixedList = new ArrayList();
  298. for (Iterator it = ret.iterator(); it.hasNext();) {
  299. String entry = (String) it.next();
  300. if (!entry.endsWith("aspectjtools.jar")) {
  301. fixedList.add(entry);
  302. }
  303. }
  304. ret = fixedList;
  305. } else {
  306. addClasspath(parser.classpath, ret);
  307. }
  308. // ??? eclipse seems to put outdir on the classpath
  309. // ??? we're brave and believe we don't need it
  310. return ret;
  311. }
  312. private void addExtDirs(String extdirs, List classpathCollector) {
  313. StringTokenizer tokenizer = new StringTokenizer(extdirs, File.pathSeparator);
  314. while (tokenizer.hasMoreTokens()) {
  315. // classpathCollector.add(tokenizer.nextToken());
  316. File dirFile = new File(tokenizer.nextToken());
  317. if (dirFile.canRead() && dirFile.isDirectory()) {
  318. File[] files = dirFile.listFiles(FileUtil.ZIP_FILTER);
  319. for (int i = 0; i < files.length; i++) {
  320. classpathCollector.add(files[i].getAbsolutePath());
  321. }
  322. } else {
  323. // XXX alert on invalid -extdirs entries
  324. }
  325. }
  326. }
  327. private void addClasspath(String classpath, List<String> classpathCollector) {
  328. StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
  329. while (tokenizer.hasMoreTokens()) {
  330. classpathCollector.add(tokenizer.nextToken());
  331. }
  332. }
  333. private class AjcConfigParser extends ConfigParser {
  334. private String bootclasspath = null;
  335. private String classpath = null;
  336. private String extdirs = null;
  337. private List unparsedArgs = new ArrayList();
  338. private AjBuildConfig buildConfig;
  339. private IMessageHandler handler;
  340. public AjcConfigParser(AjBuildConfig buildConfig, IMessageHandler handler) {
  341. this.buildConfig = buildConfig;
  342. this.handler = handler;
  343. }
  344. public List getUnparsedArgs() {
  345. return unparsedArgs;
  346. }
  347. /**
  348. * Extract AspectJ-specific options (except for argfiles). Caller should warn when sourceroots is empty but in incremental
  349. * mode. Signals warnings or errors through handler set in constructor.
  350. */
  351. public void parseOption(String arg, LinkedList args) { // XXX use ListIterator.remove()
  352. int nextArgIndex = args.indexOf(arg) + 1; // XXX assumes unique
  353. // trim arg?
  354. buildConfig.setXlazyTjp(true); // now default - MINOR could be pushed down and made default at a lower level
  355. if (LangUtil.isEmpty(arg)) {
  356. showWarning("empty arg found");
  357. } else if (arg.equals("-inpath")) {
  358. if (args.size() > nextArgIndex) {
  359. // buildConfig.getAjOptions().put(AjCompilerOptions.OPTION_Inpath, CompilerOptions.PRESERVE);
  360. List<File> inPath = buildConfig.getInpath();
  361. StringTokenizer st = new StringTokenizer(((ConfigParser.Arg) args.get(nextArgIndex)).getValue(),
  362. File.pathSeparator);
  363. while (st.hasMoreTokens()) {
  364. String filename = st.nextToken();
  365. File file = makeFile(filename);
  366. if (FileUtil.isZipFile(file)) {
  367. inPath.add(file);
  368. } else {
  369. if (file.isDirectory()) {
  370. inPath.add(file);
  371. } else {
  372. showWarning("skipping missing, empty or corrupt inpath entry: " + filename);
  373. }
  374. }
  375. }
  376. buildConfig.setInPath(inPath);
  377. args.remove(args.get(nextArgIndex));
  378. }
  379. } else if (arg.equals("-injars")) {
  380. if (args.size() > nextArgIndex) {
  381. // buildConfig.getAjOptions().put(AjCompilerOptions.OPTION_InJARs, CompilerOptions.PRESERVE);
  382. StringTokenizer st = new StringTokenizer(((ConfigParser.Arg) args.get(nextArgIndex)).getValue(),
  383. File.pathSeparator);
  384. while (st.hasMoreTokens()) {
  385. String filename = st.nextToken();
  386. File jarFile = makeFile(filename);
  387. if (FileUtil.isZipFile(jarFile)) {
  388. buildConfig.getInJars().add(jarFile);
  389. } else {
  390. File dirFile = makeFile(filename);
  391. if (dirFile.isDirectory()) {
  392. buildConfig.getInJars().add(dirFile);
  393. } else {
  394. showWarning("skipping missing, empty or corrupt injar: " + filename);
  395. }
  396. }
  397. }
  398. args.remove(args.get(nextArgIndex));
  399. }
  400. } else if (arg.equals("-aspectpath")) {
  401. if (args.size() > nextArgIndex) {
  402. StringTokenizer st = new StringTokenizer(((ConfigParser.Arg) args.get(nextArgIndex)).getValue(),
  403. File.pathSeparator);
  404. while (st.hasMoreTokens()) {
  405. String filename = st.nextToken();
  406. File jarFile = makeFile(filename);
  407. if (FileUtil.isZipFile(jarFile) || jarFile.isDirectory()) {
  408. buildConfig.getAspectpath().add(jarFile);
  409. } else {
  410. showWarning("skipping missing, empty or corrupt aspectpath entry: " + filename);
  411. }
  412. }
  413. args.remove(args.get(nextArgIndex));
  414. }
  415. } else if (arg.equals("-makeAjReflectable")) {
  416. buildConfig.setMakeReflectable(true);
  417. } else if (arg.equals("-sourceroots")) {
  418. if (args.size() > nextArgIndex) {
  419. List<File> sourceRoots = new ArrayList<File>();
  420. StringTokenizer st = new StringTokenizer(((ConfigParser.Arg) args.get(nextArgIndex)).getValue(),
  421. File.pathSeparator);
  422. while (st.hasMoreTokens()) {
  423. File f = makeFile(st.nextToken());
  424. if (f.isDirectory() && f.canRead()) {
  425. sourceRoots.add(f);
  426. } else {
  427. showError("bad sourceroot: " + f);
  428. }
  429. }
  430. if (0 < sourceRoots.size()) {
  431. buildConfig.setSourceRoots(sourceRoots);
  432. }
  433. args.remove(args.get(nextArgIndex));
  434. } else {
  435. showError("-sourceroots requires list of directories");
  436. }
  437. } else if (arg.equals("-outjar")) {
  438. if (args.size() > nextArgIndex) {
  439. // buildConfig.getAjOptions().put(AjCompilerOptions.OPTION_OutJAR, CompilerOptions.GENERATE);
  440. File jarFile = makeFile(((ConfigParser.Arg) args.get(nextArgIndex)).getValue());
  441. if (!jarFile.isDirectory()) {
  442. try {
  443. if (!jarFile.exists()) {
  444. jarFile.createNewFile();
  445. }
  446. buildConfig.setOutputJar(jarFile);
  447. } catch (IOException ioe) {
  448. showError("unable to create outjar file: " + jarFile);
  449. }
  450. } else {
  451. showError("invalid -outjar file: " + jarFile);
  452. }
  453. args.remove(args.get(nextArgIndex));
  454. } else {
  455. showError("-outjar requires jar path argument");
  456. }
  457. } else if (arg.equals("-outxml")) {
  458. buildConfig.setOutxmlName(org.aspectj.bridge.Constants.AOP_AJC_XML);
  459. } else if (arg.equals("-outxmlfile")) {
  460. if (args.size() > nextArgIndex) {
  461. String name = ((ConfigParser.Arg) args.get(nextArgIndex)).getValue();
  462. buildConfig.setOutxmlName(name);
  463. args.remove(args.get(nextArgIndex));
  464. } else {
  465. showError("-outxmlfile requires file name argument");
  466. }
  467. } else if (arg.equals("-log")) {
  468. // remove it as it's already been handled in org.aspectj.tools.ajc.Main
  469. args.remove(args.get(nextArgIndex));
  470. } else if (arg.equals("-messageHolder")) {
  471. // remove it as it's already been handled in org.aspectj.tools.ajc.Main
  472. args.remove(args.get(nextArgIndex));
  473. } else if (arg.equals("-incremental")) {
  474. buildConfig.setIncrementalMode(true);
  475. } else if (arg.equals("-XincrementalFile")) {
  476. if (args.size() > nextArgIndex) {
  477. File file = makeFile(((ConfigParser.Arg) args.get(nextArgIndex)).getValue());
  478. buildConfig.setIncrementalFile(file);
  479. if (!file.canRead()) {
  480. showError("bad -XincrementalFile : " + file);
  481. // if not created before recompile test, stop after first compile
  482. }
  483. args.remove(args.get(nextArgIndex));
  484. } else {
  485. showError("-XincrementalFile requires file argument");
  486. }
  487. } else if (arg.equals("-crossrefs")) {
  488. buildConfig.setGenerateCrossRefsMode(true);
  489. buildConfig.setGenerateModelMode(true);
  490. } else if (arg.startsWith("-checkRuntimeVersion:")) {
  491. String lcArg = arg.toLowerCase();
  492. if (lcArg.endsWith(":false")) {
  493. buildConfig.setCheckRuntimeVersion(false);
  494. } else if (lcArg.endsWith(":true")) {
  495. buildConfig.setCheckRuntimeVersion(true);
  496. } else {
  497. showError("bad value for -checkRuntimeVersion option, must be true or false");
  498. }
  499. } else if (arg.equals("-emacssym")) {
  500. buildConfig.setEmacsSymMode(true);
  501. buildConfig.setGenerateModelMode(true);
  502. } else if (arg.equals("-XjavadocsInModel")) {
  503. buildConfig.setGenerateModelMode(true);
  504. buildConfig.setGenerateJavadocsInModelMode(true);
  505. } else if (arg.equals("-Xdev:NoAtAspectJProcessing")) {
  506. buildConfig.setNoAtAspectJAnnotationProcessing(true);
  507. } else if (arg.equals("-XaddSerialVersionUID")) {
  508. buildConfig.setAddSerialVerUID(true);
  509. } else if (arg.equals("-xmlConfigured")) {
  510. buildConfig.setXmlConfigured(true);
  511. } else if (arg.equals("-Xdev:Pinpoint")) {
  512. buildConfig.setXdevPinpointMode(true);
  513. } else if (arg.startsWith("-Xjoinpoints:")) {
  514. buildConfig.setXJoinpoints(arg.substring(13));
  515. } else if (arg.equals("-noWeave") || arg.equals("-XnoWeave")) {
  516. showWarning("the noweave option is no longer required and is being ignored");
  517. } else if (arg.equals("-XterminateAfterCompilation")) {
  518. buildConfig.setTerminateAfterCompilation(true);
  519. } else if (arg.equals("-XserializableAspects")) {
  520. buildConfig.setXserializableAspects(true);
  521. } else if (arg.equals("-XlazyTjp")) {
  522. // do nothing as this is now on by default
  523. showWarning("-XlazyTjp should no longer be used, build tjps lazily is now the default");
  524. } else if (arg.startsWith("-Xreweavable")) {
  525. showWarning("-Xreweavable is on by default");
  526. if (arg.endsWith(":compress")) {
  527. showWarning("-Xreweavable:compress is no longer available - reweavable is now default");
  528. }
  529. } else if (arg.startsWith("-Xset:")) {
  530. buildConfig.setXconfigurationInfo(arg.substring(6));
  531. } else if (arg.startsWith("-aspectj.pushin=")) {
  532. // a little dirty but this should never be used in the IDE
  533. try {
  534. System.setProperty("aspectj.pushin", arg.substring(16));
  535. } catch (Exception e) {
  536. e.printStackTrace();
  537. }
  538. } else if (arg.startsWith("-XnotReweavable")) {
  539. buildConfig.setXnotReweavable(true);
  540. } else if (arg.equals("-XnoInline")) {
  541. buildConfig.setXnoInline(true);
  542. } else if (arg.equals("-XhasMember")) {
  543. buildConfig.setXHasMemberSupport(true);
  544. } else if (arg.startsWith("-showWeaveInfo")) {
  545. buildConfig.setShowWeavingInformation(true);
  546. } else if (arg.equals("-Xlintfile")) {
  547. if (args.size() > nextArgIndex) {
  548. File lintSpecFile = makeFile(((ConfigParser.Arg) args.get(nextArgIndex)).getValue());
  549. // XXX relax restriction on props file suffix?
  550. if (lintSpecFile.canRead() && lintSpecFile.getName().endsWith(".properties")) {
  551. buildConfig.setLintSpecFile(lintSpecFile);
  552. } else {
  553. showError("bad -Xlintfile file: " + lintSpecFile);
  554. buildConfig.setLintSpecFile(null);
  555. }
  556. args.remove(args.get(nextArgIndex));
  557. } else {
  558. showError("-Xlintfile requires .properties file argument");
  559. }
  560. } else if (arg.equals("-Xlint")) {
  561. // buildConfig.getAjOptions().put(
  562. // AjCompilerOptions.OPTION_Xlint,
  563. // CompilerOptions.GENERATE);
  564. buildConfig.setLintMode(AjBuildConfig.AJLINT_DEFAULT);
  565. } else if (arg.startsWith("-Xlint:")) {
  566. if (7 < arg.length()) {
  567. buildConfig.setLintMode(arg.substring(7));
  568. } else {
  569. showError("invalid lint option " + arg);
  570. }
  571. } else if (arg.equals("-bootclasspath")) {
  572. if (args.size() > nextArgIndex) {
  573. String bcpArg = ((ConfigParser.Arg) args.get(nextArgIndex)).getValue();
  574. StringBuffer bcp = new StringBuffer();
  575. StringTokenizer strTok = new StringTokenizer(bcpArg, File.pathSeparator);
  576. while (strTok.hasMoreTokens()) {
  577. bcp.append(makeFile(strTok.nextToken()));
  578. if (strTok.hasMoreTokens()) {
  579. bcp.append(File.pathSeparator);
  580. }
  581. }
  582. bootclasspath = bcp.toString();
  583. args.remove(args.get(nextArgIndex));
  584. } else {
  585. showError("-bootclasspath requires classpath entries");
  586. }
  587. } else if (arg.equals("-classpath") || arg.equals("-cp")) {
  588. if (args.size() > nextArgIndex) {
  589. String cpArg = ((ConfigParser.Arg) args.get(nextArgIndex)).getValue();
  590. StringBuffer cp = new StringBuffer();
  591. StringTokenizer strTok = new StringTokenizer(cpArg, File.pathSeparator);
  592. while (strTok.hasMoreTokens()) {
  593. cp.append(makeFile(strTok.nextToken()));
  594. if (strTok.hasMoreTokens()) {
  595. cp.append(File.pathSeparator);
  596. }
  597. }
  598. classpath = cp.toString();
  599. args.remove(args.get(nextArgIndex));
  600. } else {
  601. showError("-classpath requires classpath entries");
  602. }
  603. } else if (arg.equals("-extdirs")) {
  604. if (args.size() > nextArgIndex) {
  605. String extdirsArg = ((ConfigParser.Arg) args.get(nextArgIndex)).getValue();
  606. StringBuffer ed = new StringBuffer();
  607. StringTokenizer strTok = new StringTokenizer(extdirsArg, File.pathSeparator);
  608. while (strTok.hasMoreTokens()) {
  609. ed.append(makeFile(strTok.nextToken()));
  610. if (strTok.hasMoreTokens()) {
  611. ed.append(File.pathSeparator);
  612. }
  613. }
  614. extdirs = ed.toString();
  615. args.remove(args.get(nextArgIndex));
  616. } else {
  617. showError("-extdirs requires list of external directories");
  618. }
  619. // error on directory unless -d, -{boot}classpath, or -extdirs
  620. } else if (arg.equals("-d")) {
  621. dirLookahead(arg, args, nextArgIndex);
  622. // } else if (arg.equals("-classpath")) {
  623. // dirLookahead(arg, args, nextArgIndex);
  624. // } else if (arg.equals("-bootclasspath")) {
  625. // dirLookahead(arg, args, nextArgIndex);
  626. // } else if (arg.equals("-extdirs")) {
  627. // dirLookahead(arg, args, nextArgIndex);
  628. } else if (arg.equals("-proceedOnError")) {
  629. buildConfig.setProceedOnError(true);
  630. } else if (arg.equals("-processorpath")) { // -processorpath <directories and ZIP archives separated by pathseporator
  631. addPairToUnparsed(args, arg, nextArgIndex, "-processorpath requires list of external directories or zip archives");
  632. } else if (arg.equals("-processor")) { // -processor <class1[,class2,...]>
  633. addPairToUnparsed(args, arg, nextArgIndex, "-processor requires list of processors' classes");
  634. } else if (arg.equals("-s")) { // -s <dir> destination directory for generated source files
  635. addPairToUnparsed(args, arg, nextArgIndex, "-s requires directory");
  636. } else if (arg.equals("-classNames")) { // -classNames <className1[,className2,...]>
  637. addPairToUnparsed(args, arg, nextArgIndex, "-classNames requires list of classes");
  638. } else if (new File(arg).isDirectory()) {
  639. showError("dir arg not permitted: " + arg);
  640. } else if (arg.startsWith("-Xajruntimetarget")) {
  641. if (arg.endsWith(":1.2")) {
  642. buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_12);
  643. } else if (arg.endsWith(":1.5")) {
  644. buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_15);
  645. } else {
  646. showError("-Xajruntimetarget:<level> only supports a target level of 1.2 or 1.5");
  647. }
  648. } else if (arg.equals("-timers")) {
  649. buildConfig.setTiming(true);
  650. // swallow - it is dealt with in Main.runMain()
  651. } else if (arg.equals("-1.5")) {
  652. buildConfig.setBehaveInJava5Way(true);
  653. unparsedArgs.add("-1.5");
  654. // this would enable the '-source 1.5' to do the same as '-1.5' but doesnt sound quite right as
  655. // as an option right now as it doesnt mean we support 1.5 source code - people will get confused...
  656. } else if (arg.equals("-1.6")) {
  657. buildConfig.setBehaveInJava5Way(true);
  658. unparsedArgs.add("-1.6");
  659. } else if (arg.equals("-1.7")) {
  660. buildConfig.setBehaveInJava5Way(true);
  661. unparsedArgs.add("-1.7");
  662. } else if (arg.equals("-1.8")) {
  663. buildConfig.setBehaveInJava5Way(true);
  664. unparsedArgs.add("-1.8");
  665. } else if (arg.equals("-source")) {
  666. if (args.size() > nextArgIndex) {
  667. String level = ((ConfigParser.Arg) args.get(nextArgIndex)).getValue();
  668. if (level.equals("1.5") || level.equals("5") || level.equals("1.6") || level.equals("6") || level.equals("1.7")
  669. || level.equals("7") || level.equals("8") || level.equals("1.8")) {
  670. buildConfig.setBehaveInJava5Way(true);
  671. }
  672. unparsedArgs.add("-source");
  673. unparsedArgs.add(level);
  674. args.remove(args.get(nextArgIndex));
  675. }
  676. } else {
  677. // argfile, @file parsed by superclass
  678. // no eclipse options parsed:
  679. // -d args, -help (handled),
  680. // -classpath, -target, -1.3, -1.4, -source [1.3|1.4]
  681. // -nowarn, -warn:[...], -deprecation, -noImportError,
  682. // -g:[...], -preserveAllLocals,
  683. // -referenceInfo, -encoding, -verbose, -log, -time
  684. // -noExit, -repeat
  685. // (Actually, -noExit grabbed by Main)
  686. unparsedArgs.add(arg);
  687. }
  688. }
  689. protected void dirLookahead(String arg, LinkedList argList, int nextArgIndex) {
  690. unparsedArgs.add(arg);
  691. ConfigParser.Arg next = (ConfigParser.Arg) argList.get(nextArgIndex);
  692. String value = next.getValue();
  693. if (!LangUtil.isEmpty(value)) {
  694. if (new File(value).isDirectory()) {
  695. unparsedArgs.add(value);
  696. argList.remove(next);
  697. return;
  698. }
  699. }
  700. }
  701. public void showError(String message) {
  702. ISourceLocation location = null;
  703. if (buildConfig.getConfigFile() != null) {
  704. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  705. }
  706. IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.ERROR, null, location);
  707. handler.handleMessage(errorMessage);
  708. // MessageUtil.error(handler, CONFIG_MSG + message);
  709. }
  710. protected void showWarning(String message) {
  711. ISourceLocation location = null;
  712. if (buildConfig.getConfigFile() != null) {
  713. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  714. }
  715. IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.WARNING, null, location);
  716. handler.handleMessage(errorMessage);
  717. // MessageUtil.warn(handler, message);
  718. }
  719. protected File makeFile(File dir, String name) {
  720. name = name.replace('/', File.separatorChar);
  721. File ret = new File(name);
  722. if (dir == null || ret.isAbsolute()) {
  723. return ret;
  724. }
  725. try {
  726. dir = dir.getCanonicalFile();
  727. } catch (IOException ioe) {
  728. }
  729. return new File(dir, name);
  730. }
  731. private void addPairToUnparsed(LinkedList<Arg> args, String arg, int nextArgIndex, String errorMessage) {
  732. if (args.size() <= nextArgIndex) {
  733. showError(errorMessage);
  734. return;
  735. }
  736. final Arg nextArg = args.get(nextArgIndex);
  737. args.remove(nextArg);
  738. unparsedArgs.add(arg);
  739. unparsedArgs.add(nextArg.getValue());
  740. }
  741. private int indexOf(LinkedList<Arg> args, String arg) {
  742. int index = 0;
  743. for (Arg argument : args) {
  744. if (arg.equals(argument.getValue())) {
  745. return index;
  746. }
  747. index++;
  748. }
  749. return -1;
  750. }
  751. }
  752. }