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

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