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

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