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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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");
  43. }
  44. public static String getXOptionUsage() {
  45. return Main.bind("xoption.usage");
  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. if (LangUtil.isEmpty(arg)) {
  331. showWarning("empty arg found");
  332. } else if (arg.equals("-inpath")) {;
  333. if (args.size() > nextArgIndex) {
  334. // buildConfig.getAjOptions().put(AjCompilerOptions.OPTION_Inpath, CompilerOptions.PRESERVE);
  335. List inPath = buildConfig.getInpath();
  336. StringTokenizer st = new StringTokenizer(
  337. ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(),
  338. File.pathSeparator);
  339. while (st.hasMoreTokens()) {
  340. String filename = st.nextToken();
  341. File file = makeFile(filename);
  342. if (file.exists() && FileUtil.hasZipSuffix(filename)) {
  343. inPath.add(file);
  344. } else {
  345. if (file.isDirectory()) {
  346. inPath.add(file);
  347. } else
  348. showError("bad inpath component: " + filename);
  349. }
  350. }
  351. buildConfig.setInPath(inPath);
  352. args.remove(args.get(nextArgIndex));
  353. }
  354. } else if (arg.equals("-injars")) {;
  355. if (args.size() > nextArgIndex) {
  356. // buildConfig.getAjOptions().put(AjCompilerOptions.OPTION_InJARs, CompilerOptions.PRESERVE);
  357. StringTokenizer st = new StringTokenizer(
  358. ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(),
  359. File.pathSeparator);
  360. while (st.hasMoreTokens()) {
  361. String filename = st.nextToken();
  362. File jarFile = makeFile(filename);
  363. if (jarFile.exists() && FileUtil.hasZipSuffix(filename)) {
  364. buildConfig.getInJars().add(jarFile);
  365. } else {
  366. File dirFile = makeFile(filename);
  367. if (dirFile.isDirectory()) {
  368. buildConfig.getInJars().add(dirFile);
  369. } else
  370. showError("bad injar: " + filename);
  371. }
  372. }
  373. args.remove(args.get(nextArgIndex));
  374. }
  375. } else if (arg.equals("-aspectpath")) {;
  376. if (args.size() > nextArgIndex) {
  377. StringTokenizer st = new StringTokenizer(
  378. ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(),
  379. File.pathSeparator);
  380. while (st.hasMoreTokens()) {
  381. String filename = st.nextToken();
  382. File jarFile = makeFile(filename);
  383. if (jarFile.exists() && FileUtil.hasZipSuffix(filename)) {
  384. buildConfig.getAspectpath().add(jarFile);
  385. } else {
  386. showError("bad aspectpath: " + filename);
  387. }
  388. }
  389. args.remove(args.get(nextArgIndex));
  390. }
  391. } else if (arg.equals("-sourceroots")) {
  392. if (args.size() > nextArgIndex) {
  393. List sourceRoots = new ArrayList();
  394. StringTokenizer st = new StringTokenizer(
  395. ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(),
  396. File.pathSeparator);
  397. while (st.hasMoreTokens()) {
  398. File f = makeFile(st.nextToken());
  399. if (f.isDirectory() && f.canRead()) {
  400. sourceRoots.add(f);
  401. } else {
  402. showError("bad sourceroot: " + f);
  403. }
  404. }
  405. if (0 < sourceRoots.size()) {
  406. buildConfig.setSourceRoots(sourceRoots);
  407. }
  408. args.remove(args.get(nextArgIndex));
  409. } else {
  410. showError("-sourceroots requires list of directories");
  411. }
  412. } else if (arg.equals("-outjar")) {
  413. if (args.size() > nextArgIndex) {
  414. // buildConfig.getAjOptions().put(AjCompilerOptions.OPTION_OutJAR, CompilerOptions.GENERATE);
  415. File jarFile = makeFile(((ConfigParser.Arg)args.get(nextArgIndex)).getValue());
  416. if (FileUtil.hasZipSuffix(jarFile)) {
  417. try {
  418. if (!jarFile.exists()) {
  419. jarFile.createNewFile();
  420. }
  421. buildConfig.setOutputJar(jarFile);
  422. } catch (IOException ioe) {
  423. showError("unable to create outjar file: " + jarFile);
  424. }
  425. } else {
  426. showError("invalid -outjar file: " + jarFile);
  427. }
  428. args.remove(args.get(nextArgIndex));
  429. } else {
  430. showError("-outjar requires jar path argument");
  431. }
  432. } else if (arg.equals("-incremental")) {
  433. buildConfig.setIncrementalMode(true);
  434. } else if (arg.equals("-XincrementalFile")) {
  435. if (args.size() > nextArgIndex) {
  436. File file = makeFile(((ConfigParser.Arg)args.get(nextArgIndex)).getValue());
  437. buildConfig.setIncrementalFile(file);
  438. if (!file.canRead()) {
  439. showError("bad -XincrementalFile : " + file);
  440. // if not created before recompile test, stop after first compile
  441. }
  442. args.remove(args.get(nextArgIndex));
  443. } else {
  444. showError("-XincrementalFile requires file argument");
  445. }
  446. } else if (arg.equals("-emacssym")) {
  447. buildConfig.setEmacsSymMode(true);
  448. buildConfig.setGenerateModelMode(true);
  449. } else if (arg.equals("-XjavadocsInModel")) {
  450. buildConfig.setGenerateModelMode(true);
  451. buildConfig.setGenerateJavadocsInModelMode(true);
  452. } else if (arg.equals("-noweave") || arg.equals( "-XnoWeave")) {
  453. buildConfig.setNoWeave(true);
  454. } else if (arg.equals("-XserializableAspects")) {
  455. buildConfig.setXserializableAspects(true);
  456. } else if (arg.equals("-XlazyTjp")) {
  457. buildConfig.setXlazyTjp(true);
  458. } else if (arg.startsWith("-Xreweavable")) {
  459. buildConfig.setXreweavable(true);
  460. if (arg.endsWith(":compress")) {
  461. buildConfig.setXreweavableCompressClasses(true);
  462. }
  463. } else if (arg.equals("-XnoInline")) {
  464. buildConfig.setXnoInline(true);
  465. } else if (arg.startsWith("-showWeaveInfo")) {
  466. buildConfig.setShowWeavingInformation(true);
  467. } else if (arg.equals("-Xlintfile")) {
  468. if (args.size() > nextArgIndex) {
  469. File lintSpecFile = makeFile(((ConfigParser.Arg)args.get(nextArgIndex)).getValue());
  470. // XXX relax restriction on props file suffix?
  471. if (lintSpecFile.canRead() && lintSpecFile.getName().endsWith(".properties")) {
  472. buildConfig.setLintSpecFile(lintSpecFile);
  473. } else {
  474. showError("bad -Xlintfile file: " + lintSpecFile);
  475. buildConfig.setLintSpecFile(null);
  476. }
  477. args.remove(args.get(nextArgIndex));
  478. } else {
  479. showError("-Xlintfile requires .properties file argument");
  480. }
  481. } else if (arg.equals("-Xlint")) {
  482. // buildConfig.getAjOptions().put(
  483. // AjCompilerOptions.OPTION_Xlint,
  484. // CompilerOptions.GENERATE);
  485. buildConfig.setLintMode(AjBuildConfig.AJLINT_DEFAULT);
  486. } else if (arg.startsWith("-Xlint:")) {
  487. if (7 < arg.length()) {
  488. buildConfig.setLintMode(arg.substring(7));
  489. } else {
  490. showError("invalid lint option " + arg);
  491. }
  492. } else if (arg.equals("-bootclasspath")) {
  493. if (args.size() > nextArgIndex) {
  494. String bcpArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  495. StringBuffer bcp = new StringBuffer();
  496. StringTokenizer strTok = new StringTokenizer(bcpArg,File.pathSeparator);
  497. while (strTok.hasMoreTokens()) {
  498. bcp.append(makeFile(strTok.nextToken()));
  499. if (strTok.hasMoreTokens()) {
  500. bcp.append(File.pathSeparator);
  501. }
  502. }
  503. bootclasspath = bcp.toString();
  504. args.remove(args.get(nextArgIndex));
  505. } else {
  506. showError("-bootclasspath requires classpath entries");
  507. }
  508. } else if (arg.equals("-classpath") || arg.equals("-cp")) {
  509. if (args.size() > nextArgIndex) {
  510. String cpArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  511. StringBuffer cp = new StringBuffer();
  512. StringTokenizer strTok = new StringTokenizer(cpArg,File.pathSeparator);
  513. while (strTok.hasMoreTokens()) {
  514. cp.append(makeFile(strTok.nextToken()));
  515. if (strTok.hasMoreTokens()) {
  516. cp.append(File.pathSeparator);
  517. }
  518. }
  519. classpath = cp.toString();
  520. args.remove(args.get(nextArgIndex));
  521. } else {
  522. showError("-classpath requires classpath entries");
  523. }
  524. } else if (arg.equals("-extdirs")) {
  525. if (args.size() > nextArgIndex) {
  526. String extdirsArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  527. StringBuffer ed = new StringBuffer();
  528. StringTokenizer strTok = new StringTokenizer(extdirsArg,File.pathSeparator);
  529. while (strTok.hasMoreTokens()) {
  530. ed.append(makeFile(strTok.nextToken()));
  531. if (strTok.hasMoreTokens()) {
  532. ed.append(File.pathSeparator);
  533. }
  534. }
  535. extdirs = ed.toString();
  536. args.remove(args.get(nextArgIndex));
  537. } else {
  538. showError("-extdirs requires list of external directories");
  539. }
  540. // error on directory unless -d, -{boot}classpath, or -extdirs
  541. } else if (arg.equals("-d")) {
  542. dirLookahead(arg, args, nextArgIndex);
  543. // } else if (arg.equals("-classpath")) {
  544. // dirLookahead(arg, args, nextArgIndex);
  545. // } else if (arg.equals("-bootclasspath")) {
  546. // dirLookahead(arg, args, nextArgIndex);
  547. // } else if (arg.equals("-extdirs")) {
  548. // dirLookahead(arg, args, nextArgIndex);
  549. } else if (arg.equals("-proceedOnError")) {
  550. buildConfig.setProceedOnError(true);
  551. } else if (new File(arg).isDirectory()) {
  552. showError("dir arg not permitted: " + arg);
  553. } else if (arg.equals("-1.5")) {
  554. buildConfig.setBehaveInJava5Way(true);
  555. unparsedArgs.add("-1.5");
  556. // this would enable the '-source 1.5' to do the same as '-1.5' but doesnt sound quite right as
  557. // as an option right now as it doesnt mean we support 1.5 source code - people will get confused...
  558. } else if (arg.equals("-source")) {
  559. if (args.size() > nextArgIndex) {
  560. String level = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  561. if (level.equals("1.5")){
  562. buildConfig.setBehaveInJava5Way(true);
  563. }
  564. unparsedArgs.add("-source");
  565. unparsedArgs.add(level);
  566. args.remove(args.get(nextArgIndex));
  567. }
  568. } else {
  569. // argfile, @file parsed by superclass
  570. // no eclipse options parsed:
  571. // -d args, -help (handled),
  572. // -classpath, -target, -1.3, -1.4, -source [1.3|1.4]
  573. // -nowarn, -warn:[...], -deprecation, -noImportError,
  574. // -g:[...], -preserveAllLocals,
  575. // -referenceInfo, -encoding, -verbose, -log, -time
  576. // -noExit, -repeat
  577. // (Actually, -noExit grabbed by Main)
  578. unparsedArgs.add(arg);
  579. }
  580. }
  581. protected void dirLookahead(String arg, LinkedList argList, int nextArgIndex) {
  582. unparsedArgs.add(arg);
  583. ConfigParser.Arg next = (ConfigParser.Arg) argList.get(nextArgIndex);
  584. String value = next.getValue();
  585. if (!LangUtil.isEmpty(value)) {
  586. if (new File(value).isDirectory()) {
  587. unparsedArgs.add(value);
  588. argList.remove(next);
  589. return;
  590. }
  591. }
  592. }
  593. public void showError(String message) {
  594. ISourceLocation location = null;
  595. if (buildConfig.getConfigFile() != null) {
  596. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  597. }
  598. IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.ERROR, null, location);
  599. handler.handleMessage(errorMessage);
  600. // MessageUtil.error(handler, CONFIG_MSG + message);
  601. }
  602. protected void showWarning(String message) {
  603. ISourceLocation location = null;
  604. if (buildConfig.getConfigFile() != null) {
  605. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  606. }
  607. IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.WARNING, null, location);
  608. handler.handleMessage(errorMessage);
  609. // MessageUtil.warn(handler, message);
  610. }
  611. protected File makeFile(File dir, String name) {
  612. name = name.replace('/', File.separatorChar);
  613. File ret = new File(name);
  614. if (dir == null || ret.isAbsolute()) return ret;
  615. try {
  616. dir = dir.getCanonicalFile();
  617. } catch (IOException ioe) { }
  618. return new File(dir, name);
  619. }
  620. }
  621. }