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

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