From 648c0f4d15d9ab6bac9deef010a1b66824cd8da1 Mon Sep 17 00:00:00 2001
From: acolyer <acolyer>
Date: Thu, 5 Aug 2004 17:31:56 +0000
Subject: fix for Bugzilla Bug 42573  	.lst file entries not resolved
 relative to list file: {boot}classpath, extdirs,

---
 .../src/org/aspectj/ajdt/ajc/BuildArgParser.java   | 33 +++++++++++--
 .../ajc/configWithClasspathExtdirsBootCPArgs.lst   |  9 ++++
 .../testdata/ajc/myextdir/dummy.jar                |  0
 .../aspectj/ajdt/ajc/BuildArgParserTestCase.java   | 56 ++++++++++++++++++----
 4 files changed, 86 insertions(+), 12 deletions(-)
 create mode 100644 org.aspectj.ajdt.core/testdata/ajc/configWithClasspathExtdirsBootCPArgs.lst
 create mode 100644 org.aspectj.ajdt.core/testdata/ajc/myextdir/dummy.jar

(limited to 'org.aspectj.ajdt.core')

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 {
-- 
cgit v1.2.3