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.

BuildArgParserTestCase.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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 junit.framework.TestCase;
  16. import org.aspectj.ajdt.internal.core.builder.*;
  17. import org.aspectj.bridge.CountingMessageHandler;
  18. import org.aspectj.bridge.IMessage;
  19. import org.aspectj.bridge.IMessageHandler;
  20. import org.aspectj.bridge.IMessageHolder;
  21. import org.aspectj.bridge.MessageHandler;
  22. import org.aspectj.bridge.MessageWriter;
  23. import org.aspectj.testing.util.TestUtil;
  24. import org.aspectj.org.eclipse.jdt.core.compiler.InvalidInputException;
  25. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  26. /**
  27. * Some black-box test is happening here.
  28. */
  29. public class BuildArgParserTestCase extends TestCase {
  30. private static final String TEST_DIR = AjdtAjcTests.TESTDATA_PATH + File.separator + "ajc" + File.separator;
  31. private MessageWriter messageWriter = new MessageWriter(new PrintWriter(System.out), false);
  32. public BuildArgParserTestCase(String name) {
  33. super(name);
  34. }
  35. private AjBuildConfig genBuildConfig(String[] args, IMessageHandler handler) {
  36. return new BuildArgParser(handler).genBuildConfig(args);
  37. }
  38. public void testDefaultClasspathAndTargetCombo() throws Exception {
  39. String ENTRY = "1.jar" + File.pathSeparator + "2.jar";
  40. final String classpath = System.getProperty("java.class.path");
  41. try {
  42. System.setProperty("java.class.path", ENTRY); // see finally below
  43. BuildArgParser parser = new BuildArgParser(messageWriter);
  44. AjBuildConfig config = parser.genBuildConfig(new String[] { });
  45. /*String err = */parser.getOtherMessages(true);
  46. //!!!assertTrue(err, null == err);
  47. assertTrue(
  48. config.getClasspath().toString(),
  49. config.getClasspath().contains("1.jar"));
  50. assertTrue(
  51. config.getClasspath().toString(),
  52. config.getClasspath().contains("2.jar"));
  53. config = genBuildConfig(new String[] { "-1.3" }, messageWriter);
  54. // these errors are deffered to the compiler now
  55. //err = parser.getOtherMessages(true);
  56. //!!!assertTrue(err, null == err);
  57. assertTrue(
  58. config.getClasspath().toString(),
  59. config.getClasspath().contains("1.jar"));
  60. assertTrue(
  61. config.getClasspath().toString(),
  62. config.getClasspath().contains("2.jar"));
  63. parser = new BuildArgParser(messageWriter);
  64. config = parser.genBuildConfig(new String[] { "-1.3" });
  65. /*err = */parser.getOtherMessages(true);
  66. //!!!assertTrue(err, null == err);
  67. assertTrue(
  68. config.getClasspath().toString(),
  69. config.getClasspath().contains("1.jar"));
  70. assertTrue(
  71. config.getClasspath().toString(),
  72. config.getClasspath().contains("2.jar"));
  73. config = genBuildConfig(new String[] {
  74. "-classpath", ENTRY, "-1.4" }, messageWriter);
  75. // these errors are deffered to the compiler now
  76. //err = parser.getOtherMessages(true);
  77. //assertTrue("expected errors for missing jars", null != err);
  78. List cp = config.getClasspath();
  79. boolean jar1Found = false;
  80. boolean jar2Found = false;
  81. for (Iterator iter = cp.iterator(); iter.hasNext();) {
  82. String element = (String) iter.next();
  83. if (element.indexOf("1.jar") != -1) jar1Found = true;
  84. if (element.indexOf("2.jar") != -1) jar2Found = true;
  85. }
  86. assertTrue(
  87. config.getClasspath().toString(),
  88. jar1Found);
  89. assertTrue(
  90. config.getClasspath().toString(),
  91. jar2Found);
  92. } finally {
  93. // do finally to avoid messing up classpath for other tests
  94. System.setProperty("java.class.path", classpath);
  95. String setPath = System.getProperty("java.class.path");
  96. String m = "other tests will fail - classpath not reset";
  97. assertEquals(m, classpath, setPath);
  98. }
  99. }
  100. public void testPathResolutionFromConfigArgs() {
  101. String FILE_PATH = "@" + TEST_DIR + "configWithClasspathExtdirsBootCPArgs.lst";
  102. AjBuildConfig config = genBuildConfig(new String[] { FILE_PATH }, messageWriter);
  103. List classpath = config.getFullClasspath();
  104. // note that empty or corrupt jars are NOT included in the classpath
  105. // should have three entries, resolved relative to location of .lst file
  106. assertEquals("Three entries in classpath",3,classpath.size());
  107. Iterator cpIter = classpath.iterator();
  108. try {
  109. assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"xyz").getCanonicalPath(),cpIter.next());
  110. assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"myextdir" + File.separator + "dummy.jar").getCanonicalPath(),cpIter.next());
  111. assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"abc.jar").getCanonicalPath(),cpIter.next());
  112. List files = config.getFiles();
  113. assertEquals("Two source files",2,files.size());
  114. Iterator fIter = files.iterator();
  115. assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"Abc.java").getCanonicalFile(),fIter.next());
  116. assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"xyz"+File.separator+"Def.aj").getCanonicalFile(),fIter.next());
  117. } catch (IOException ex) {
  118. fail("Test case failure attempting to create canonical path: " + ex);
  119. }
  120. }
  121. public void testAjOptions() throws InvalidInputException {
  122. AjBuildConfig config = genBuildConfig(new String[] { "-Xlint" }, messageWriter);
  123. assertTrue(
  124. "default options",
  125. config.getLintMode().equals(AjBuildConfig.AJLINT_DEFAULT));
  126. }
  127. public void testAspectpath() throws InvalidInputException {
  128. final String SOURCE_JAR = AjdtAjcTests.TESTDATA_PATH + "/testclasses.jar";
  129. final String SOURCE_JARS = AjdtAjcTests.TESTDATA_PATH + "/testclasses.jar" + File.pathSeparator
  130. + "../weaver/testdata/tracing.jar" + File.pathSeparator
  131. + "../weaver/testdata/dummyAspect.jar";
  132. AjBuildConfig config = genBuildConfig(new String[] {
  133. "-aspectpath", SOURCE_JAR },
  134. messageWriter);
  135. assertTrue(((File)config.getAspectpath().get(0)).getName(), ((File)config.getAspectpath().get(0)).getName().equals("testclasses.jar"));
  136. config = genBuildConfig(new String[] {
  137. "-aspectpath", SOURCE_JARS },
  138. messageWriter);
  139. assertTrue("size", + config.getAspectpath().size() == 3);
  140. }
  141. public void testInJars() throws InvalidInputException {
  142. final String SOURCE_JAR = AjdtAjcTests.TESTDATA_PATH + "/testclasses.jar";
  143. final String SOURCE_JARS = AjdtAjcTests.TESTDATA_PATH + "/testclasses.jar" + File.pathSeparator
  144. + "../weaver/testdata/tracing.jar" + File.pathSeparator
  145. + "../weaver/testdata/dummyAspect.jar";
  146. AjBuildConfig config = genBuildConfig(new String[] {
  147. "-injars", SOURCE_JAR },
  148. messageWriter);
  149. //XXX don't let this remain in both places in beta1
  150. // assertTrue(
  151. // "" + config.getAjOptions().get(AjCompilerOptions.OPTION_InJARs),
  152. // config.getAjOptions().get(AjCompilerOptions.OPTION_InJARs).equals(CompilerOptions.PRESERVE));
  153. assertTrue(((File)config.getInJars().get(0)).getName(), ((File)config.getInJars().get(0)).getName().equals("testclasses.jar"));
  154. config = genBuildConfig(new String[] {
  155. "-injars", SOURCE_JARS },
  156. messageWriter);
  157. assertTrue("size", + config.getInJars().size() == 3);
  158. }
  159. public void testBadInJars() throws InvalidInputException {
  160. final String SOURCE_JARS = AjdtAjcTests.TESTDATA_PATH + "/testclasses.jar" + File.pathSeparator + "b.far" + File.pathSeparator + "c.jar";
  161. AjBuildConfig config = genBuildConfig(new String[] {
  162. "-injars", SOURCE_JARS },
  163. messageWriter);
  164. assertTrue("size: " + config.getInJars().size(), config.getInJars().size() == 1);
  165. }
  166. public void testBadPathToSourceFiles() {
  167. CountingMessageHandler countingHandler = new CountingMessageHandler(messageWriter);
  168. /*AjBuildConfig config = */genBuildConfig(new String[]{ "inventedDir/doesntexist/*.java"},countingHandler);
  169. assertTrue("Expected an error for the invalid path.",countingHandler.numMessages(IMessage.ERROR,false)==1);
  170. }
  171. public void testMultipleSourceRoots() throws InvalidInputException, IOException {
  172. final String SRCROOT_1 = AjdtAjcTests.TESTDATA_PATH + "/src1/p1";
  173. final String SRCROOT_2 = AjdtAjcTests.TESTDATA_PATH + "/ajc";
  174. AjBuildConfig config = genBuildConfig(new String[] {
  175. "-sourceroots", SRCROOT_1 + File.pathSeparator + SRCROOT_2 },
  176. messageWriter);
  177. assertEquals(getCanonicalPath(new File(SRCROOT_1)), ((File)config.getSourceRoots().get(0)).getAbsolutePath());
  178. Collection expectedFiles = Arrays.asList(new File[] {
  179. new File(SRCROOT_1+File.separator+"A.java").getCanonicalFile(),
  180. new File(SRCROOT_1+File.separator+"Foo.java").getCanonicalFile(),
  181. new File(SRCROOT_2+File.separator+"A.java").getCanonicalFile(),
  182. new File(SRCROOT_2+File.separator+"B.java").getCanonicalFile(),
  183. new File(SRCROOT_2+File.separator+"X.aj").getCanonicalFile(),
  184. new File(SRCROOT_2+File.separator+"Y.aj").getCanonicalFile(),
  185. new File(SRCROOT_2+File.separator+"pkg"+File.separator+"Hello.java").getCanonicalFile(),
  186. });
  187. //System.out.println(config.getFiles());
  188. TestUtil.assertSetEquals(expectedFiles, config.getFiles());
  189. }
  190. /**
  191. * @param file
  192. * @return String
  193. */
  194. private String getCanonicalPath(File file) {
  195. String ret = "";
  196. try {
  197. ret = file.getCanonicalPath();
  198. } catch (IOException ioEx) {
  199. fail("Unable to canonicalize " + file + " : " + ioEx);
  200. }
  201. return ret;
  202. }
  203. public void testSourceRootDir() throws InvalidInputException, IOException {
  204. final String SRCROOT = AjdtAjcTests.TESTDATA_PATH + "/ajc";
  205. AjBuildConfig config = genBuildConfig(new String[] {
  206. "-sourceroots", SRCROOT },
  207. messageWriter);
  208. assertEquals(getCanonicalPath(new File(SRCROOT)), ((File)config.getSourceRoots().get(0)).getAbsolutePath());
  209. Collection expectedFiles = Arrays.asList(new File[] {
  210. new File(SRCROOT+File.separator+"A.java").getCanonicalFile(),
  211. new File(SRCROOT+File.separator+"B.java").getCanonicalFile(),
  212. new File(SRCROOT+File.separator+"X.aj").getCanonicalFile(),
  213. new File(SRCROOT+File.separator+"Y.aj").getCanonicalFile(),
  214. new File(SRCROOT+File.separator+"pkg"+File.separator+"Hello.java").getCanonicalFile(),
  215. });
  216. //System.out.println(config.getFiles());
  217. TestUtil.assertSetEquals(expectedFiles, config.getFiles());
  218. }
  219. public void testBadSourceRootDir() throws InvalidInputException {
  220. AjBuildConfig config = genBuildConfig(new String[] {
  221. "-sourceroots",
  222. AjdtAjcTests.TESTDATA_PATH + "/mumbleDoesNotExist" + File.pathSeparator
  223. + AjdtAjcTests.TESTDATA_PATH + "/ajc" },
  224. messageWriter);
  225. assertTrue(config.getSourceRoots().toString(), config.getSourceRoots().size() == 1);
  226. config = genBuildConfig(new String[] {
  227. "-sourceroots" },
  228. messageWriter);
  229. assertTrue("" + config.getSourceRoots(), config.getSourceRoots().size() == 0);
  230. }
  231. //??? we've decided not to make this an error
  232. public void testSourceRootDirWithFiles() throws InvalidInputException, IOException {
  233. final String SRCROOT = AjdtAjcTests.TESTDATA_PATH + "/ajc/pkg";
  234. AjBuildConfig config = genBuildConfig(new String[] {
  235. "-sourceroots", SRCROOT, AjdtAjcTests.TESTDATA_PATH + "/src1/A.java"},
  236. messageWriter);
  237. assertEquals(getCanonicalPath(new File(SRCROOT)), ((File)config.getSourceRoots().get(0)).getAbsolutePath());
  238. Collection expectedFiles = Arrays.asList(new File[] {
  239. new File(SRCROOT+File.separator+"Hello.java").getCanonicalFile(),
  240. new File(AjdtAjcTests.TESTDATA_PATH +File.separator+"src1"+File.separator+"A.java").getCanonicalFile(),
  241. });
  242. TestUtil.assertSetEquals(expectedFiles, config.getFiles());
  243. }
  244. public void testExtDirs() throws Exception {
  245. final String DIR = AjdtAjcTests.TESTDATA_PATH;
  246. AjBuildConfig config = genBuildConfig(new String[] {
  247. "-extdirs", DIR },
  248. messageWriter);
  249. assertTrue(config.getClasspath().toString(), config.getClasspath().contains(
  250. new File(DIR + File.separator + "testclasses.jar").getCanonicalPath()
  251. ));
  252. }
  253. public void testBootclasspath() throws InvalidInputException {
  254. final String PATH = "mumble" + File.separator + "rt.jar";
  255. AjBuildConfig config = genBuildConfig(new String[] {
  256. "-bootclasspath", PATH },
  257. messageWriter);
  258. assertTrue("Should find '" + PATH + "' contained in the first entry of '" + config.getBootclasspath().toString(),
  259. ((String)config.getBootclasspath().get(0)).indexOf(PATH) != -1);
  260. config = genBuildConfig(new String[] {
  261. },
  262. messageWriter);
  263. assertTrue(config.getBootclasspath().toString(), !config.getBootclasspath().get(0).equals(PATH));
  264. }
  265. public void testOutputJar() throws InvalidInputException {
  266. final String OUT_JAR = AjdtAjcTests.TESTDATA_PATH + "/testclasses.jar";
  267. AjBuildConfig config = genBuildConfig(new String[] {
  268. "-outjar", OUT_JAR },
  269. messageWriter);
  270. //XXX don't let this remain in both places in beta1
  271. // assertTrue(
  272. // "will generate: " + config.getAjOptions().get(AjCompilerOptions.OPTION_OutJAR),
  273. // config.getAjOptions().get(AjCompilerOptions.OPTION_OutJAR).equals(CompilerOptions.GENERATE));
  274. assertEquals(
  275. getCanonicalPath(new File(OUT_JAR)),config.getOutputJar().getAbsolutePath());
  276. File nonExistingJar = new File(AjdtAjcTests.TESTDATA_PATH + "/mumbleDoesNotExist.jar");
  277. config = genBuildConfig(new String[] {
  278. "-outjar", nonExistingJar.getAbsolutePath() },
  279. messageWriter);
  280. assertEquals(
  281. getCanonicalPath(nonExistingJar),
  282. config.getOutputJar().getAbsolutePath());
  283. nonExistingJar.delete();
  284. }
  285. //XXX shouldn't need -1.4 to get this to pass
  286. public void testCombinedOptions() throws InvalidInputException {
  287. AjBuildConfig config = genBuildConfig(new String[] { "-Xlint:error", "-target", "1.4"}, messageWriter);
  288. assertTrue(
  289. "target set",
  290. config.getOptions().targetJDK == CompilerOptions.JDK1_4);
  291. assertTrue(
  292. "Xlint option set",
  293. config.getLintMode().equals(AjBuildConfig.AJLINT_ERROR));
  294. }
  295. public void testOutputDirectorySetting() throws InvalidInputException {
  296. AjBuildConfig config = genBuildConfig(new String[] { "-d", TEST_DIR }, messageWriter);
  297. assertTrue(
  298. new File(config.getOutputDir().getPath()).getAbsolutePath() + " ?= " +
  299. new File(TEST_DIR).getAbsolutePath(),
  300. config.getOutputDir().getAbsolutePath().equals((new File(TEST_DIR)).getAbsolutePath()));
  301. }
  302. public void testClasspathSetting() throws InvalidInputException {
  303. String ENTRY = "1.jar" + File.pathSeparator + "2.jar";
  304. AjBuildConfig config = genBuildConfig(new String[] { "-classpath", ENTRY }, messageWriter);
  305. List cp = config.getClasspath();
  306. boolean jar1Found = false;
  307. boolean jar2Found = false;
  308. for (Iterator iter = cp.iterator(); iter.hasNext();) {
  309. String element = (String) iter.next();
  310. if (element.indexOf("1.jar") != -1) jar1Found = true;
  311. if (element.indexOf("2.jar") != -1) jar2Found = true;
  312. }
  313. assertTrue(
  314. config.getClasspath().toString(),
  315. jar1Found);
  316. assertTrue(
  317. config.getClasspath().toString(),
  318. jar2Found);
  319. }
  320. public void testArgInConfigFile() throws InvalidInputException {
  321. String FILE_PATH = "@" + TEST_DIR + "configWithArgs.lst";
  322. String OUT_PATH = "bin";
  323. AjBuildConfig config = genBuildConfig(new String[] { FILE_PATH }, messageWriter);
  324. assertNotNull(config);
  325. File outputDir = config.getOutputDir();
  326. assertNotNull(outputDir);
  327. assertEquals(outputDir.getPath(), OUT_PATH);
  328. }
  329. public void testNonExistentConfigFile() throws IOException {
  330. String FILE_PATH = "@" + TEST_DIR + "../bug-40257/d1/test.lst";
  331. AjBuildConfig config = genBuildConfig(new String[] { FILE_PATH }, messageWriter);
  332. String a = new File(TEST_DIR + "../bug-40257/d1/A.java").getCanonicalPath();
  333. String b = new File(TEST_DIR + "../bug-40257/d1/d2/B.java").getCanonicalPath();
  334. String c = new File(TEST_DIR + "../bug-40257/d3/C.java").getCanonicalPath();
  335. List pathList = new ArrayList();
  336. for (Iterator it = config.getFiles().iterator(); it.hasNext(); ) {
  337. pathList.add(((File)it.next()).getCanonicalPath());
  338. }
  339. assertTrue(pathList.contains(a));
  340. assertTrue(pathList.contains(b));
  341. assertTrue(pathList.contains(c));
  342. }
  343. public void testXlint() throws InvalidInputException {
  344. // AjdtCommand command = new AjdtCommand();
  345. AjBuildConfig config = genBuildConfig(new String[] {"-Xlint"}, messageWriter);
  346. assertTrue("", config.getLintMode().equals(AjBuildConfig.AJLINT_DEFAULT));
  347. config = genBuildConfig(new String[] {"-Xlint:warn"}, messageWriter);
  348. assertTrue("", config.getLintMode().equals(AjBuildConfig.AJLINT_WARN));
  349. config = genBuildConfig(new String[] {"-Xlint:error"}, messageWriter);
  350. assertTrue("", config.getLintMode().equals(AjBuildConfig.AJLINT_ERROR));
  351. config = genBuildConfig(new String[] {"-Xlint:ignore"}, messageWriter);
  352. assertTrue("", config.getLintMode().equals(AjBuildConfig.AJLINT_IGNORE));
  353. }
  354. public void testXlintfile() throws InvalidInputException {
  355. String lintFile = AjdtAjcTests.TESTDATA_PATH + "/lintspec.properties";
  356. // String badLintFile = "lint.props";
  357. AjBuildConfig config = genBuildConfig(new String[] {"-Xlintfile", lintFile}, messageWriter);
  358. assertTrue(new File(lintFile).exists());
  359. assertEquals(getCanonicalPath(new File(lintFile)),config.getLintSpecFile().getAbsolutePath());
  360. }
  361. /**
  362. * The option '-1.5' are currently eaten by the AspectJ argument parser - since
  363. * the JDT compiler upon which we are based doesn't understand them - *this should change* when we
  364. * switch to a 1.5 compiler base. They are currently used to determine whether the weaver should
  365. * behave in a '1.5' way - for example autoboxing behaves differently when the 1.5 flag is specified.
  366. * Under 1.4 Integer != int
  367. * Under 1.5 Integer == int
  368. * (this applies to all primitive types)
  369. */
  370. public void testSource15() throws InvalidInputException {
  371. // AjBuildConfig config = genBuildConfig(new String[]{"-source","1.5"},messageWriter);
  372. // assertTrue("should be in 1.5 mode",config.getJave5Behaviour());
  373. AjBuildConfig config = genBuildConfig(new String[]{"-1.5"},messageWriter);
  374. assertTrue("should be in 1.5 mode",config.getBehaveInJava5Way());
  375. config = genBuildConfig(new String[]{"-source","1.4"},messageWriter);
  376. assertTrue("should not be in 1.5 mode",!config.getBehaveInJava5Way());
  377. assertTrue("should be in 1.4 mode",config.getOptions().sourceLevel == CompilerOptions.JDK1_4);
  378. config = genBuildConfig(new String[]{"-source","1.3"},messageWriter);
  379. assertTrue("should not be in 1.5 mode",!config.getBehaveInJava5Way());
  380. assertTrue("should be in 1.3 mode",config.getOptions().sourceLevel == CompilerOptions.JDK1_3);
  381. }
  382. public void testOptions() throws InvalidInputException {
  383. // AjdtCommand command = new AjdtCommand();
  384. String TARGET = "1.4";
  385. AjBuildConfig config = genBuildConfig(new String[] {"-target", TARGET, "-source", TARGET}, messageWriter);
  386. assertTrue(
  387. "target set",
  388. config.getOptions().targetJDK == CompilerOptions.JDK1_4);
  389. assertTrue(
  390. "source set",
  391. config.getOptions().sourceLevel == CompilerOptions.JDK1_4);
  392. }
  393. public void testLstFileExpansion() throws IOException, FileNotFoundException, InvalidInputException {
  394. String FILE_PATH = TEST_DIR + "config.lst";
  395. String SOURCE_PATH_1 = "A.java";
  396. String SOURCE_PATH_2 = "B.java";
  397. // File f = new File(FILE_PATH);
  398. AjBuildConfig config = genBuildConfig(new String[] { "@" + FILE_PATH }, messageWriter);
  399. List resultList = config.getFiles();
  400. assertTrue("correct number of files", resultList.size() == 2);
  401. assertTrue(resultList.toString() + new File(TEST_DIR + SOURCE_PATH_1).getCanonicalFile(),
  402. resultList.contains(new File(TEST_DIR + SOURCE_PATH_1).getCanonicalFile()));
  403. assertTrue(resultList.toString() + SOURCE_PATH_2,
  404. resultList.contains(new File(TEST_DIR + SOURCE_PATH_2).getCanonicalFile()));
  405. }
  406. //??? do we need to remove this limitation
  407. // public void testArgInConfigFileAndRelativizingPathParam() throws InvalidInputException {
  408. // String FILE_PATH = "@" + TEST_DIR + "configWithArgs.lst";
  409. // String OUT_PATH = TEST_DIR + "bin";
  410. // AjBuildConfig config = genBuildConfig(new String[] { FILE_PATH });
  411. //
  412. // assertTrue(
  413. // config.getOutputDir().getPath() + " ?= " + OUT_PATH,
  414. // config.getOutputDir().getAbsolutePath().equals((new File(OUT_PATH)).getAbsolutePath()));
  415. // }
  416. public void testAjFileInclusion() throws InvalidInputException {
  417. genBuildConfig(new String[] { TEST_DIR + "X.aj", TEST_DIR + "Y.aj"}, messageWriter);
  418. }
  419. public void testOutxml () {
  420. IMessageHolder messageHolder = new MessageHandler();
  421. AjBuildConfig config = genBuildConfig(new String[] { "-outxml", "-showWeaveInfo" }, messageHolder);
  422. assertTrue("Warnings: " + messageHolder,!messageHolder.hasAnyMessage(IMessage.WARNING, true));
  423. assertEquals("Wrong outxml","META-INF/aop.xml",config.getOutxmlName());
  424. assertTrue("Following option currupted",config.getShowWeavingInformation());
  425. }
  426. public void testOutxmlfile () {
  427. IMessageHolder messageHolder = new MessageHandler();
  428. AjBuildConfig config = genBuildConfig(new String[] { "-outxmlfile", "custom/aop.xml", "-showWeaveInfo" }, messageHolder);
  429. assertTrue("Warnings: " + messageHolder,!messageHolder.hasAnyMessage(IMessage.WARNING, true));
  430. assertEquals("Wrong outxml","custom/aop.xml",config.getOutxmlName());
  431. assertTrue("Following option currupted",config.getShowWeavingInformation());
  432. }
  433. public void testNonstandardInjars() {
  434. AjBuildConfig config = setupNonstandardPath("-injars");
  435. assertEquals("bad path: " + config.getInJars(), 3, config.getInJars().size());
  436. }
  437. public void testNonstandardInpath() {
  438. AjBuildConfig config = setupNonstandardPath("-inpath");
  439. assertEquals("bad path: " + config.getInpath(), 3, config.getInpath().size());
  440. }
  441. public void testNonstandardAspectpath() {
  442. AjBuildConfig config = setupNonstandardPath("-aspectpath");
  443. assertEquals("bad path: " + config.getAspectpath(), 3, config.getAspectpath().size());
  444. }
  445. public void testNonstandardClasspath() throws IOException {
  446. AjBuildConfig config = setupNonstandardPath("-classpath");
  447. checkPathSubset(config.getClasspath());
  448. }
  449. public void testNonstandardBootpath() throws IOException {
  450. AjBuildConfig config = setupNonstandardPath("-bootclasspath");
  451. checkPathSubset(config.getBootclasspath());
  452. }
  453. private void checkPathSubset(List path) throws IOException {
  454. String files[] = { "aspectjJar.file", "jarChild", "parent.zip" };
  455. for (int i = 0; i < files.length; i++) {
  456. File file = new File(NONSTANDARD_JAR_DIR+files[i]);
  457. assertTrue("bad path: " + path, path.contains(file.getCanonicalPath()));
  458. }
  459. }
  460. public void testNonstandardOutjar() {
  461. final String OUT_JAR = NONSTANDARD_JAR_DIR + File.pathSeparator + "outputFile";
  462. AjBuildConfig config = genBuildConfig(new String[] {
  463. "-outjar", OUT_JAR },
  464. messageWriter);
  465. File newJar = new File(OUT_JAR);
  466. assertEquals(
  467. getCanonicalPath(newJar),config.getOutputJar().getAbsolutePath());
  468. newJar.delete();
  469. }
  470. public void testNonstandardOutputDirectorySetting() throws InvalidInputException {
  471. String filePath = AjdtAjcTests.TESTDATA_PATH + File.separator + "ajc.jar" + File.separator;
  472. File testDir = new File(filePath);
  473. AjBuildConfig config = genBuildConfig(new String[] { "-d", filePath }, messageWriter);
  474. assertEquals(testDir.getAbsolutePath(), config.getOutputDir().getAbsolutePath());
  475. }
  476. private static final String NONSTANDARD_JAR_DIR = AjdtAjcTests.TESTDATA_PATH + "/OutjarTest/folder.jar/";
  477. private AjBuildConfig setupNonstandardPath(String pathType) {
  478. String NONSTANDARD_PATH_ENTRY = NONSTANDARD_JAR_DIR+"aspectjJar.file" + File.pathSeparator + NONSTANDARD_JAR_DIR+"aspectJar.file" + File.pathSeparator + NONSTANDARD_JAR_DIR+"jarChild" + File.pathSeparator + NONSTANDARD_JAR_DIR+"parent.zip";
  479. return genBuildConfig(new String[] {
  480. pathType, NONSTANDARD_PATH_ENTRY },
  481. messageWriter);
  482. }
  483. protected void setUp() throws Exception {
  484. super.setUp();
  485. }
  486. protected void tearDown() throws Exception {
  487. super.tearDown();
  488. }
  489. }