Browse Source

Make the buildfile searching only start on demand, introduced a new

command line argument -file.

Suggested by:	Jose  Alberto Fernandez <JFernandez@viquity.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268167 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
a9cc5fd794
3 changed files with 27 additions and 17 deletions
  1. +6
    -0
      WHATSNEW
  2. +1
    -0
      docs/index.html
  3. +20
    -17
      src/main/org/apache/tools/ant/Main.java

+ 6
- 0
WHATSNEW View File

@@ -1,6 +1,12 @@
Changes from Ant 1.2 to the current sources 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: Other changes:
-------------- --------------




+ 1
- 0
docs/index.html View File

@@ -202,6 +202,7 @@ Options:
-logger &lt;classname&gt; the class which is to perform logging -logger &lt;classname&gt; the class which is to perform logging
-listener &lt;classname&gt; add an instance of class as a project listener -listener &lt;classname&gt; add an instance of class as a project listener
-buildfile &lt;file&gt; use given buildfile -buildfile &lt;file&gt; use given buildfile
-find &lt;file&gt; search for buildfile towards the root of the filesystem and use it
-D&lt;property&gt;=&lt;value&gt; use value for given property</pre> -D&lt;property&gt;=&lt;value&gt; use value for given property</pre>
<h3>Examples</h3> <h3>Examples</h3>
<blockquote> <blockquote>


+ 20
- 17
src/main/org/apache/tools/ant/Main.java View File

@@ -161,6 +161,8 @@ public class Main {


protected Main(String[] args) throws BuildException { protected Main(String[] args) throws BuildException {


String searchForThis = null;

// cycle through given args // cycle through given args


for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
@@ -238,7 +240,7 @@ public class Main {
if (posEq > 0) { if (posEq > 0) {
value = name.substring(posEq+1); value = name.substring(posEq+1);
name = name.substring(0, posEq); name = name.substring(0, posEq);
} else if (i < args.length)
} else if (i < args.length-1)
value = args[++i]; value = args[++i];


definedProps.put(name, value); definedProps.put(name, value);
@@ -253,6 +255,13 @@ public class Main {
} else if (arg.equals("-projecthelp")) { } else if (arg.equals("-projecthelp")) {
// set the flag to display the targets and quit // set the flag to display the targets and quit
projectHelp = true; 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("-")) { } else if (arg.startsWith("-")) {
// we don't have any more args to recognize! // we don't have any more args to recognize!
String msg = "Unknown arg: " + arg; String msg = "Unknown arg: " + arg;
@@ -267,9 +276,13 @@ public class Main {
} }


// if buildFile was not specified on the command line, // if buildFile was not specified on the command line,
// then search for it
if (buildFile == null) { 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 // make sure buildfile exists
@@ -289,18 +302,6 @@ public class Main {
readyToRun = true; readyToRun = true;
} }


/**
* Helper to get the parent file for a given filename.
*
* <P>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. * 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 * @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) { if (msgOutputLevel >= Project.MSG_INFO) {
System.out.println("Searching for " + suffix + " ..."); System.out.println("Searching for " + suffix + " ...");
} }


File parent = getParentFile(suffix);
File parent = new File(new File(start).getAbsolutePath());
File file = new File(parent, suffix); File file = new File(parent, suffix);
// check if the target file exists in the current directory // check if the target file exists in the current directory
@@ -503,6 +504,8 @@ public class Main {
msg.append(" -listener <classname> add an instance of class as a project listener" + lSep); msg.append(" -listener <classname> add an instance of class as a project listener" + lSep);
msg.append(" -buildfile <file> use given buildfile" + lSep); msg.append(" -buildfile <file> use given buildfile" + lSep);
msg.append(" -D<property>=<value> use value for given property" + lSep); msg.append(" -D<property>=<value> use value for given property" + lSep);
msg.append(" -find <file> search for buildfile towards the root of the file" + lSep);
msg.append(" system and use it" + lSep);
System.out.println(msg.toString()); System.out.println(msg.toString());
} }




Loading…
Cancel
Save