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

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