}
} 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");
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 {
// 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
}
}
+ 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);
}
- 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()
));
}
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[] {
},
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 {
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: ";
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;
}
}
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) {