diff --git a/WHATSNEW b/WHATSNEW index 4c13ec83c..9ccb525b4 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -1,6 +1,12 @@ Changes from Ant 1.2 to the current sources =========================================== +Changes that could break older environments: +-------------------------------------------- + +* Ant doesn't search for the buildfile anymore, unless you use the new + -find argument. + Other changes: -------------- diff --git a/docs/index.html b/docs/index.html index 994eb7603..c92d3f62a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -202,6 +202,7 @@ Options: -logger <classname> the class which is to perform logging -listener <classname> add an instance of class as a project listener -buildfile <file> use given buildfile +-find <file> search for buildfile towards the root of the filesystem and use it -D<property>=<value> use value for given property
diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 53f62688c..41a032283 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -161,6 +161,8 @@ public class Main { protected Main(String[] args) throws BuildException { + String searchForThis = null; + // cycle through given args for (int i = 0; i < args.length; i++) { @@ -238,7 +240,7 @@ public class Main { if (posEq > 0) { value = name.substring(posEq+1); name = name.substring(0, posEq); - } else if (i < args.length) + } else if (i < args.length-1) value = args[++i]; definedProps.put(name, value); @@ -253,6 +255,13 @@ public class Main { } else if (arg.equals("-projecthelp")) { // set the flag to display the targets and quit projectHelp = true; + } else if (arg.equals("-find")) { + // eat up next arg if present, default to build.xml + if (i < args.length-1) { + searchForThis = args[++i]; + } else { + searchForThis = DEFAULT_BUILD_FILENAME; + } } else if (arg.startsWith("-")) { // we don't have any more args to recognize! String msg = "Unknown arg: " + arg; @@ -267,9 +276,13 @@ public class Main { } // if buildFile was not specified on the command line, - // then search for it if (buildFile == null) { - buildFile = findBuildFile(DEFAULT_BUILD_FILENAME); + // but -find then search for it + if (searchForThis != null) { + buildFile = findBuildFile(".", searchForThis); + } else { + buildFile = new File(DEFAULT_BUILD_FILENAME); + } } // make sure buildfile exists @@ -289,18 +302,6 @@ public class Main { readyToRun = true; } - /** - * Helper to get the parent file for a given filename. - * - *Added to simulate File.getParentFile() from JDK 1.2. - * - * @param filename File name - * @return Parent file or null if none - */ - private File getParentFile(String filename) { - return getParentFile(new File(filename)); - } - /** * Helper to get the parent file for a given file. * @@ -334,12 +335,12 @@ public class Main { * * @exception BuildException Failed to locate a build file */ - private File findBuildFile(String suffix) throws BuildException { + private File findBuildFile(String start, String suffix) throws BuildException { if (msgOutputLevel >= Project.MSG_INFO) { System.out.println("Searching for " + suffix + " ..."); } - File parent = getParentFile(suffix); + File parent = new File(new File(start).getAbsolutePath()); File file = new File(parent, suffix); // check if the target file exists in the current directory @@ -503,6 +504,8 @@ public class Main { msg.append(" -listener
add an instance of class as a project listener" + lSep); msg.append(" -buildfile use given buildfile" + lSep); msg.append(" -D = use value for given property" + lSep); + msg.append(" -find search for buildfile towards the root of the file" + lSep); + msg.append(" system and use it" + lSep); System.out.println(msg.toString()); }