]> source.dussan.org Git - aspectj.git/commitdiff
fix for Bugzilla Bug 42573
authoracolyer <acolyer>
Thu, 5 Aug 2004 17:31:56 +0000 (17:31 +0000)
committeracolyer <acolyer>
Thu, 5 Aug 2004 17:31:56 +0000 (17:31 +0000)
  .lst file entries not resolved relative to list file: {boot}classpath, extdirs,

org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java
org.aspectj.ajdt.core/testdata/ajc/configWithClasspathExtdirsBootCPArgs.lst [new file with mode: 0644]
org.aspectj.ajdt.core/testdata/ajc/myextdir/dummy.jar [new file with mode: 0644]
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java
util/src/org/aspectj/util/ConfigParser.java

index 3928ddc4413fac8a5afe20800a396fa486ec62bd..167c2f7185d996a7300659257ee2183e838a6673 100644 (file)
@@ -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 (file)
index 0000000..2df53fa
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
index 94f41ffba467afe13500dfb72287fcf8662b9d2f..58ebc3f26cee9aafc43bcbfaf6fa63ceedf484d4 100644 (file)
@@ -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 {
index 59ce90b949f49eba7035fdf10016bc245682ad59..4f4e0e2bace1de5d32c346784f7af6d4655aee86 100644 (file)
@@ -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) {