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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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("-log")){
  434. // remove it as it's already been handled in org.aspectj.tools.ajc.Main
  435. args.remove(args.get(nextArgIndex));
  436. } else if (arg.equals("-incremental")) {
  437. buildConfig.setIncrementalMode(true);
  438. } else if (arg.equals("-XincrementalFile")) {
  439. if (args.size() > nextArgIndex) {
  440. File file = makeFile(((ConfigParser.Arg)args.get(nextArgIndex)).getValue());
  441. buildConfig.setIncrementalFile(file);
  442. if (!file.canRead()) {
  443. showError("bad -XincrementalFile : " + file);
  444. // if not created before recompile test, stop after first compile
  445. }
  446. args.remove(args.get(nextArgIndex));
  447. } else {
  448. showError("-XincrementalFile requires file argument");
  449. }
  450. } else if (arg.equals("-emacssym")) {
  451. buildConfig.setEmacsSymMode(true);
  452. buildConfig.setGenerateModelMode(true);
  453. } else if (arg.equals("-XjavadocsInModel")) {
  454. buildConfig.setGenerateModelMode(true);
  455. buildConfig.setGenerateJavadocsInModelMode(true);
  456. } else if (arg.equals("-Xdev:NoAtAspectJProcessing")) {
  457. buildConfig.setNoAtAspectJAnnotationProcessing(true);
  458. } else if (arg.equals("-Xdev:Pinpoint")) {
  459. buildConfig.setXdevPinpointMode(true);
  460. } else if (arg.equals("-noweave") || arg.equals( "-XnoWeave")) {
  461. buildConfig.setNoWeave(true);
  462. } else if (arg.equals("-XserializableAspects")) {
  463. buildConfig.setXserializableAspects(true);
  464. } else if (arg.equals("-XlazyTjp")) {
  465. // do nothing as this is now on by default
  466. showWarning("-XlazyTjp should no longer be used, build tjps lazily is now the default");
  467. } else if (arg.startsWith("-Xreweavable")) {
  468. showWarning("-Xreweavable is on by default");
  469. if (arg.endsWith(":compress")) {
  470. showWarning("-Xreweavable:compress is no longer available - reweavable is now default");
  471. }
  472. } else if (arg.startsWith("-XnotReweavable")) {
  473. buildConfig.setXnotReweavable(true);
  474. } else if (arg.equals("-XnoInline")) {
  475. buildConfig.setXnoInline(true);
  476. } else if (arg.equals("-XhasMember")) {
  477. buildConfig.setXHasMemberSupport(true);
  478. } else if (arg.startsWith("-showWeaveInfo")) {
  479. buildConfig.setShowWeavingInformation(true);
  480. } else if (arg.equals("-Xlintfile")) {
  481. if (args.size() > nextArgIndex) {
  482. File lintSpecFile = makeFile(((ConfigParser.Arg)args.get(nextArgIndex)).getValue());
  483. // XXX relax restriction on props file suffix?
  484. if (lintSpecFile.canRead() && lintSpecFile.getName().endsWith(".properties")) {
  485. buildConfig.setLintSpecFile(lintSpecFile);
  486. } else {
  487. showError("bad -Xlintfile file: " + lintSpecFile);
  488. buildConfig.setLintSpecFile(null);
  489. }
  490. args.remove(args.get(nextArgIndex));
  491. } else {
  492. showError("-Xlintfile requires .properties file argument");
  493. }
  494. } else if (arg.equals("-Xlint")) {
  495. // buildConfig.getAjOptions().put(
  496. // AjCompilerOptions.OPTION_Xlint,
  497. // CompilerOptions.GENERATE);
  498. buildConfig.setLintMode(AjBuildConfig.AJLINT_DEFAULT);
  499. } else if (arg.startsWith("-Xlint:")) {
  500. if (7 < arg.length()) {
  501. buildConfig.setLintMode(arg.substring(7));
  502. } else {
  503. showError("invalid lint option " + arg);
  504. }
  505. } else if (arg.equals("-bootclasspath")) {
  506. if (args.size() > nextArgIndex) {
  507. String bcpArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  508. StringBuffer bcp = new StringBuffer();
  509. StringTokenizer strTok = new StringTokenizer(bcpArg,File.pathSeparator);
  510. while (strTok.hasMoreTokens()) {
  511. bcp.append(makeFile(strTok.nextToken()));
  512. if (strTok.hasMoreTokens()) {
  513. bcp.append(File.pathSeparator);
  514. }
  515. }
  516. bootclasspath = bcp.toString();
  517. args.remove(args.get(nextArgIndex));
  518. } else {
  519. showError("-bootclasspath requires classpath entries");
  520. }
  521. } else if (arg.equals("-classpath") || arg.equals("-cp")) {
  522. if (args.size() > nextArgIndex) {
  523. String cpArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  524. StringBuffer cp = new StringBuffer();
  525. StringTokenizer strTok = new StringTokenizer(cpArg,File.pathSeparator);
  526. while (strTok.hasMoreTokens()) {
  527. cp.append(makeFile(strTok.nextToken()));
  528. if (strTok.hasMoreTokens()) {
  529. cp.append(File.pathSeparator);
  530. }
  531. }
  532. classpath = cp.toString();
  533. args.remove(args.get(nextArgIndex));
  534. } else {
  535. showError("-classpath requires classpath entries");
  536. }
  537. } else if (arg.equals("-extdirs")) {
  538. if (args.size() > nextArgIndex) {
  539. String extdirsArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  540. StringBuffer ed = new StringBuffer();
  541. StringTokenizer strTok = new StringTokenizer(extdirsArg,File.pathSeparator);
  542. while (strTok.hasMoreTokens()) {
  543. ed.append(makeFile(strTok.nextToken()));
  544. if (strTok.hasMoreTokens()) {
  545. ed.append(File.pathSeparator);
  546. }
  547. }
  548. extdirs = ed.toString();
  549. args.remove(args.get(nextArgIndex));
  550. } else {
  551. showError("-extdirs requires list of external directories");
  552. }
  553. // error on directory unless -d, -{boot}classpath, or -extdirs
  554. } else if (arg.equals("-d")) {
  555. dirLookahead(arg, args, nextArgIndex);
  556. // } else if (arg.equals("-classpath")) {
  557. // dirLookahead(arg, args, nextArgIndex);
  558. // } else if (arg.equals("-bootclasspath")) {
  559. // dirLookahead(arg, args, nextArgIndex);
  560. // } else if (arg.equals("-extdirs")) {
  561. // dirLookahead(arg, args, nextArgIndex);
  562. } else if (arg.equals("-proceedOnError")) {
  563. buildConfig.setProceedOnError(true);
  564. } else if (new File(arg).isDirectory()) {
  565. showError("dir arg not permitted: " + arg);
  566. } else if (arg.equals("-1.5")) {
  567. buildConfig.setBehaveInJava5Way(true);
  568. unparsedArgs.add("-1.5");
  569. // this would enable the '-source 1.5' to do the same as '-1.5' but doesnt sound quite right as
  570. // as an option right now as it doesnt mean we support 1.5 source code - people will get confused...
  571. } else if (arg.equals("-source")) {
  572. if (args.size() > nextArgIndex) {
  573. String level = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
  574. if (level.equals("1.5")){
  575. buildConfig.setBehaveInJava5Way(true);
  576. }
  577. unparsedArgs.add("-source");
  578. unparsedArgs.add(level);
  579. args.remove(args.get(nextArgIndex));
  580. }
  581. } else {
  582. // argfile, @file parsed by superclass
  583. // no eclipse options parsed:
  584. // -d args, -help (handled),
  585. // -classpath, -target, -1.3, -1.4, -source [1.3|1.4]
  586. // -nowarn, -warn:[...], -deprecation, -noImportError,
  587. // -g:[...], -preserveAllLocals,
  588. // -referenceInfo, -encoding, -verbose, -log, -time
  589. // -noExit, -repeat
  590. // (Actually, -noExit grabbed by Main)
  591. unparsedArgs.add(arg);
  592. }
  593. }
  594. protected void dirLookahead(String arg, LinkedList argList, int nextArgIndex) {
  595. unparsedArgs.add(arg);
  596. ConfigParser.Arg next = (ConfigParser.Arg) argList.get(nextArgIndex);
  597. String value = next.getValue();
  598. if (!LangUtil.isEmpty(value)) {
  599. if (new File(value).isDirectory()) {
  600. unparsedArgs.add(value);
  601. argList.remove(next);
  602. return;
  603. }
  604. }
  605. }
  606. public void showError(String message) {
  607. ISourceLocation location = null;
  608. if (buildConfig.getConfigFile() != null) {
  609. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  610. }
  611. IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.ERROR, null, location);
  612. handler.handleMessage(errorMessage);
  613. // MessageUtil.error(handler, CONFIG_MSG + message);
  614. }
  615. protected void showWarning(String message) {
  616. ISourceLocation location = null;
  617. if (buildConfig.getConfigFile() != null) {
  618. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  619. }
  620. IMessage errorMessage = new Message(CONFIG_MSG + message, IMessage.WARNING, null, location);
  621. handler.handleMessage(errorMessage);
  622. // MessageUtil.warn(handler, message);
  623. }
  624. protected File makeFile(File dir, String name) {
  625. name = name.replace('/', File.separatorChar);
  626. File ret = new File(name);
  627. if (dir == null || ret.isAbsolute()) return ret;
  628. try {
  629. dir = dir.getCanonicalFile();
  630. } catch (IOException ioe) { }
  631. return new File(dir, name);
  632. }
  633. }
  634. }