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

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