From: acolyer Date: Thu, 5 Aug 2004 17:31:56 +0000 (+0000) Subject: fix for Bugzilla Bug 42573 X-Git-Tag: for_ajdt1_1_12~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=648c0f4d15d9ab6bac9deef010a1b66824cd8da1;p=aspectj.git fix for Bugzilla Bug 42573 .lst file entries not resolved relative to list file: {boot}classpath, extdirs, --- diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index 3928ddc44..167c2f718 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -503,21 +503,48 @@ public class BuildArgParser extends Main { } } else if (arg.equals("-bootclasspath")) { if (args.size() > nextArgIndex) { - bootclasspath = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(); + String bcpArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(); + StringBuffer bcp = new StringBuffer(); + StringTokenizer strTok = new StringTokenizer(bcpArg,File.pathSeparator); + while (strTok.hasMoreTokens()) { + bcp.append(makeFile(strTok.nextToken())); + if (strTok.hasMoreTokens()) { + bcp.append(File.pathSeparator); + } + } + bootclasspath = bcp.toString(); args.remove(args.get(nextArgIndex)); } else { showError("-bootclasspath requires classpath entries"); } } else if (arg.equals("-classpath")) { if (args.size() > nextArgIndex) { - classpath = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(); + String cpArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(); + StringBuffer cp = new StringBuffer(); + StringTokenizer strTok = new StringTokenizer(cpArg,File.pathSeparator); + while (strTok.hasMoreTokens()) { + cp.append(makeFile(strTok.nextToken())); + if (strTok.hasMoreTokens()) { + cp.append(File.pathSeparator); + } + } + classpath = cp.toString(); args.remove(args.get(nextArgIndex)); } else { showError("-classpath requires classpath entries"); } } else if (arg.equals("-extdirs")) { if (args.size() > nextArgIndex) { - extdirs = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(); + String extdirsArg = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(); + StringBuffer ed = new StringBuffer(); + StringTokenizer strTok = new StringTokenizer(extdirsArg,File.pathSeparator); + while (strTok.hasMoreTokens()) { + ed.append(makeFile(strTok.nextToken())); + if (strTok.hasMoreTokens()) { + ed.append(File.pathSeparator); + } + } + extdirs = ed.toString(); args.remove(args.get(nextArgIndex)); } else { showError("-extdirs requires list of external directories"); diff --git a/org.aspectj.ajdt.core/testdata/ajc/configWithClasspathExtdirsBootCPArgs.lst b/org.aspectj.ajdt.core/testdata/ajc/configWithClasspathExtdirsBootCPArgs.lst new file mode 100644 index 000000000..2df53fa0d --- /dev/null +++ b/org.aspectj.ajdt.core/testdata/ajc/configWithClasspathExtdirsBootCPArgs.lst @@ -0,0 +1,9 @@ +-classpath +abc.jar +-bootclasspath +xyz +-extdirs +myextdir +Abc.java +xyz/Def.aj + diff --git a/org.aspectj.ajdt.core/testdata/ajc/myextdir/dummy.jar b/org.aspectj.ajdt.core/testdata/ajc/myextdir/dummy.jar new file mode 100644 index 000000000..e69de29bb diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java index 94f41ffba..58ebc3f26 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java @@ -42,7 +42,7 @@ public class BuildArgParserTestCase extends TestCase { return new BuildArgParser(handler).genBuildConfig(args); } - public void testDefaultClasspathAndTargetCombo() throws InvalidInputException { + public void testDefaultClasspathAndTargetCombo() throws Exception { String ENTRY = "1.jar" + File.pathSeparator + "2.jar"; final String classpath = System.getProperty("java.class.path"); try { @@ -85,12 +85,20 @@ public class BuildArgParserTestCase extends TestCase { // these errors are deffered to the compiler now //err = parser.getOtherMessages(true); //assertTrue("expected errors for missing jars", null != err); + List cp = config.getClasspath(); + boolean jar1Found = false; + boolean jar2Found = false; + for (Iterator iter = cp.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + if (element.indexOf("1.jar") != -1) jar1Found = true; + if (element.indexOf("2.jar") != -1) jar2Found = true; + } assertTrue( config.getClasspath().toString(), - config.getClasspath().contains("1.jar")); + jar1Found); assertTrue( config.getClasspath().toString(), - config.getClasspath().contains("2.jar")); + jar2Found); } finally { // do finally to avoid messing up classpath for other tests @@ -101,6 +109,29 @@ public class BuildArgParserTestCase extends TestCase { } } + public void testPathResolutionFromConfigArgs() { + String FILE_PATH = "@" + TEST_DIR + "configWithClasspathExtdirsBootCPArgs.lst"; + AjBuildConfig config = genBuildConfig(new String[] { FILE_PATH }, messageWriter); + List classpath = config.getClasspath(); + // should have three entries, resolved relative to location of .lst file + assertEquals("Three entries in classpath",3,classpath.size()); + Iterator cpIter = classpath.iterator(); + try { + assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"xyz").getCanonicalPath(),cpIter.next()); + assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"myextdir" + File.separator + "dummy.jar").getCanonicalPath(),cpIter.next()); + assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"abc.jar").getCanonicalPath(),cpIter.next()); + List files = config.getFiles(); + assertEquals("Two source files",2,files.size()); + Iterator fIter = files.iterator(); + assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"Abc.java").getCanonicalFile(),fIter.next()); + assertEquals("Should be relative to TESTDIR",new File(TEST_DIR+File.separator+"xyz"+File.separator+"Def.aj").getCanonicalFile(),fIter.next()); + + } catch (IOException ex) { + fail("Test case failure attempting to create canonical path: " + ex); + } + + } + public void testAjOptions() throws InvalidInputException { AjBuildConfig config = genBuildConfig(new String[] { "-Xlint" }, messageWriter); @@ -254,13 +285,13 @@ public class BuildArgParserTestCase extends TestCase { } - public void testExtDirs() throws InvalidInputException { + public void testExtDirs() throws Exception { final String DIR = AjdtAjcTests.TESTDATA_PATH; AjBuildConfig config = genBuildConfig(new String[] { "-extdirs", DIR }, messageWriter); assertTrue(config.getClasspath().toString(), config.getClasspath().contains( - new File(DIR + File.separator + "testclasses.jar").getAbsolutePath() + new File(DIR + File.separator + "testclasses.jar").getCanonicalPath() )); } @@ -269,7 +300,7 @@ public class BuildArgParserTestCase extends TestCase { AjBuildConfig config = genBuildConfig(new String[] { "-bootclasspath", PATH }, messageWriter); - assertTrue(config.getClasspath().toString(), config.getClasspath().get(0).equals(PATH)); + assertTrue(config.getClasspath().toString(), ((String)config.getClasspath().get(0)).indexOf(PATH) != -1); config = genBuildConfig(new String[] { }, @@ -327,13 +358,20 @@ public class BuildArgParserTestCase extends TestCase { String ENTRY = "1.jar" + File.pathSeparator + "2.jar"; AjBuildConfig config = genBuildConfig(new String[] { "-classpath", ENTRY }, messageWriter); + List cp = config.getClasspath(); + boolean jar1Found = false; + boolean jar2Found = false; + for (Iterator iter = cp.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + if (element.indexOf("1.jar") != -1) jar1Found = true; + if (element.indexOf("2.jar") != -1) jar2Found = true; + } assertTrue( config.getClasspath().toString(), - config.getClasspath().contains("1.jar")); - + jar1Found); assertTrue( config.getClasspath().toString(), - config.getClasspath().contains("2.jar")); + jar2Found); } public void testArgInConfigFile() throws InvalidInputException { diff --git a/util/src/org/aspectj/util/ConfigParser.java b/util/src/org/aspectj/util/ConfigParser.java index 59ce90b94..4f4e0e2ba 100644 --- a/util/src/org/aspectj/util/ConfigParser.java +++ b/util/src/org/aspectj/util/ConfigParser.java @@ -20,6 +20,7 @@ import java.io.*; public class ConfigParser { Location location; + protected File relativeDirectory = null; protected List files = new LinkedList(); private boolean fileParsed = false; protected static String CONFIG_MSG = "build config error: "; @@ -69,7 +70,10 @@ public class ConfigParser { location = new SourceLocation(configFile, lineNum); showError("error reading config file: " + e.toString()); } + File oldRelativeDirectory = relativeDirectory; // for nested arg files; + relativeDirectory = configFile.getParentFile(); parseArgs(args); + relativeDirectory = oldRelativeDirectory; fileParsed = true; } @@ -203,7 +207,11 @@ public class ConfigParser { } public File makeFile(String name) { - return makeFile(getCurrentDir(), name); + if (relativeDirectory != null) { + return makeFile(relativeDirectory,name); + } else { + return makeFile(getCurrentDir(), name); + } } private File makeFile(File dir, String name) {