as well. Added -debug and Project.MSG_DEBUG to make -verbose less verbose. Many messages really rather belong into a DEBUG category. Submitted by: Jason Dillon <jason@planet57.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268009 13f79535-47bb-0310-9956-ffa450edef68master
@@ -79,6 +79,12 @@ on log output. | |||||
* project specific help can now be obtained with the -projecthelp option. | * project specific help can now be obtained with the -projecthelp option. | ||||
* Added a -debug option to make -verbose less verbose (and more useful) | |||||
* Ant will now search for a file named build.xml in the parent directory | |||||
and above (towards the root of the filesystem) if you didn't specify | |||||
-buildfile and there is no build.xml in the current directory. | |||||
Fixed bugs: | Fixed bugs: | ||||
----------- | ----------- | ||||
@@ -25,7 +25,7 @@ | |||||
<li>Dave Walend (<a href="mailto:dwalend@cs.tufts.edu">dwalend@cs.tufts.edu</a>)</li> | <li>Dave Walend (<a href="mailto:dwalend@cs.tufts.edu">dwalend@cs.tufts.edu</a>)</li> | ||||
</ul> | </ul> | ||||
<p>Version 1.2 - 2000/09/15</p> | |||||
<p>Version 1.2 - 2000/09/19</p> | |||||
<hr> | <hr> | ||||
<h2>Table of Contents</h2> | <h2>Table of Contents</h2> | ||||
@@ -166,10 +166,13 @@ shell script necessary to run execs on Unix.</p> | |||||
<h2><a name="running">Running Ant</a></h2> | <h2><a name="running">Running Ant</a></h2> | ||||
<p>Running Ant is simple, when you installed it as described in the previous | <p>Running Ant is simple, when you installed it as described in the previous | ||||
section. Just type <code>ant</code>.</p> | section. Just type <code>ant</code>.</p> | ||||
<p>When nothing is specified, Ant looks for a <code>build.xml</code> file in the | |||||
current directory. When found, it uses that file as a buildfile. To make Ant use | |||||
another buildfile, use the commandline option <i>-buildfile <file></i>, | |||||
where <i><file></i> is the buildfile you want to use.</p> | |||||
<p>When nothing is specified, Ant looks for a <code>build.xml</code> | |||||
file in the current directory. When found, it uses that file as a | |||||
buildfile, otherwise it searches in the parent directory and so on | |||||
until the root of the filesystem has been reached. To make Ant use | |||||
another buildfile, use the commandline option <i>-buildfile | |||||
<file></i>, where <i><file></i> is the buildfile you want | |||||
to use.</p> | |||||
<p>You can also set properties which override properties specified in the | <p>You can also set properties which override properties specified in the | ||||
buildfile (see the <a href="#property">property task</a>). | buildfile (see the <a href="#property">property task</a>). | ||||
This can be done with the <i>-D<property>=<value></i> | This can be done with the <i>-D<property>=<value></i> | ||||
@@ -192,6 +195,7 @@ Options: | |||||
-version print the version information and exit | -version print the version information and exit | ||||
-quiet be extra quiet | -quiet be extra quiet | ||||
-verbose be extra verbose | -verbose be extra verbose | ||||
-debug print debugging information | |||||
-emacs produce logging information without adornments | -emacs produce logging information without adornments | ||||
-logfile <file> use given file for log | -logfile <file> use given file for log | ||||
-logger <classname> the class which is to perform logging | -logger <classname> the class which is to perform logging | ||||
@@ -72,11 +72,14 @@ import java.util.*; | |||||
public class Main { | public class Main { | ||||
/** The default build file name */ | |||||
public static final String DEFAULT_BUILD_FILENAME = "build.xml"; | |||||
/** Our current message output status. Follows Project.MSG_XXX */ | /** Our current message output status. Follows Project.MSG_XXX */ | ||||
private int msgOutputLevel = Project.MSG_INFO; | private int msgOutputLevel = Project.MSG_INFO; | ||||
/** File that we are using for configuration */ | /** File that we are using for configuration */ | ||||
private File buildFile = new File("build.xml"); | |||||
private File buildFile; /** null */ | |||||
/** Stream that we are using for logging */ | /** Stream that we are using for logging */ | ||||
private PrintStream out = System.out; | private PrintStream out = System.out; | ||||
@@ -128,6 +131,7 @@ public class Main { | |||||
System.exit(0); | System.exit(0); | ||||
} | } | ||||
catch(Throwable exc) { | catch(Throwable exc) { | ||||
System.err.println(exc.getMessage()); | |||||
System.exit(1); | System.exit(1); | ||||
} | } | ||||
} | } | ||||
@@ -150,6 +154,9 @@ public class Main { | |||||
} else if (arg.equals("-verbose") || arg.equals("-v")) { | } else if (arg.equals("-verbose") || arg.equals("-v")) { | ||||
printVersion(); | printVersion(); | ||||
msgOutputLevel = Project.MSG_VERBOSE; | msgOutputLevel = Project.MSG_VERBOSE; | ||||
} else if (arg.equals("-debug")) { | |||||
printVersion(); | |||||
msgOutputLevel = Project.MSG_DEBUG; | |||||
} else if (arg.equals("-logfile") || arg.equals("-l")) { | } else if (arg.equals("-logfile") || arg.equals("-l")) { | ||||
try { | try { | ||||
File logFile = new File(args[i+1]); | File logFile = new File(args[i+1]); | ||||
@@ -236,8 +243,13 @@ public class Main { | |||||
} | } | ||||
// make sure buildfile exists | |||||
// if buildFile was not specified on the command line, | |||||
// then search for it | |||||
if (buildFile == null) { | |||||
buildFile = findBuildFile(DEFAULT_BUILD_FILENAME); | |||||
} | |||||
// make sure buildfile exists | |||||
if (!buildFile.exists()) { | if (!buildFile.exists()) { | ||||
System.out.println("Buildfile: " + buildFile + " does not exist!"); | System.out.println("Buildfile: " + buildFile + " does not exist!"); | ||||
throw new BuildException("Build failed"); | throw new BuildException("Build failed"); | ||||
@@ -254,6 +266,77 @@ 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. | |||||
* | |||||
* <P>Added to simulate File.getParentFile() from JDK 1.2. | |||||
* | |||||
* @param file File | |||||
* @return Parent file or null if none | |||||
*/ | |||||
private File getParentFile(File file) { | |||||
String filename = file.getAbsolutePath(); | |||||
file = new File(filename); | |||||
filename = file.getParent(); | |||||
if (filename != null && msgOutputLevel >= Project.MSG_VERBOSE) { | |||||
System.out.println("Searching in "+filename); | |||||
} | |||||
return (filename == null) ? null : new File(filename); | |||||
} | |||||
/** | |||||
* Search parent directories for the build file. | |||||
* | |||||
* <P>Takes the given target as a suffix to append to each | |||||
* parent directory in seach of a build file. Once the | |||||
* root of the file-system has been reached an exception | |||||
* is thrown. | |||||
* | |||||
* @param suffix Suffix filename to look for in parents. | |||||
* @return A handle to the build file | |||||
* | |||||
* @exception BuildException Failed to locate a build file | |||||
*/ | |||||
private File findBuildFile(String suffix) throws BuildException { | |||||
if (msgOutputLevel >= Project.MSG_INFO) { | |||||
System.out.println("Searching for " + suffix + " ..."); | |||||
} | |||||
File parent = getParentFile(suffix); | |||||
File file = new File(parent, suffix); | |||||
// check if the target file exists in the current directory | |||||
while (!file.exists()) { | |||||
// change to parent directory | |||||
parent = getParentFile(parent); | |||||
// if parent is null, then we are at the root of the fs, | |||||
// complain that we can't find the build file. | |||||
if (parent == null) { | |||||
throw new BuildException("Could not locate a build file!"); | |||||
} | |||||
// refresh our file handle | |||||
file = new File(parent, suffix); | |||||
} | |||||
return file; | |||||
} | |||||
/** | /** | ||||
* Executes the build. | * Executes the build. | ||||
*/ | */ | ||||
@@ -390,6 +473,7 @@ public class Main { | |||||
msg.append(" -version print the version information and exit" + lSep); | msg.append(" -version print the version information and exit" + lSep); | ||||
msg.append(" -quiet be extra quiet" + lSep); | msg.append(" -quiet be extra quiet" + lSep); | ||||
msg.append(" -verbose be extra verbose" + lSep); | msg.append(" -verbose be extra verbose" + lSep); | ||||
msg.append(" -debug print debugging information" + lSep); | |||||
msg.append(" -emacs produce logging information without adornments" + lSep); | msg.append(" -emacs produce logging information without adornments" + lSep); | ||||
msg.append(" -logfile <file> use given file for log" + lSep); | msg.append(" -logfile <file> use given file for log" + lSep); | ||||
msg.append(" -logger <classname> the class which is to perform logging" + lSep); | msg.append(" -logger <classname> the class which is to perform logging" + lSep); | ||||
@@ -76,6 +76,7 @@ public class Project { | |||||
public static final int MSG_WARN = 1; | public static final int MSG_WARN = 1; | ||||
public static final int MSG_INFO = 2; | public static final int MSG_INFO = 2; | ||||
public static final int MSG_VERBOSE = 3; | public static final int MSG_VERBOSE = 3; | ||||
public static final int MSG_DEBUG = 4; | |||||
// private set of constants to represent the state | // private set of constants to represent the state | ||||
// of a DFS of the Target dependencies | // of a DFS of the Target dependencies | ||||
@@ -238,13 +239,13 @@ public class Project { | |||||
if (null != userProperties.get(name)) | if (null != userProperties.get(name)) | ||||
return; | return; | ||||
log("Setting project property: " + name + " -> " + | log("Setting project property: " + name + " -> " + | ||||
value, MSG_VERBOSE); | |||||
value, MSG_DEBUG); | |||||
properties.put(name, value); | properties.put(name, value); | ||||
} | } | ||||
public void setUserProperty(String name, String value) { | public void setUserProperty(String name, String value) { | ||||
log("Setting ro project property: " + name + " -> " + | log("Setting ro project property: " + name + " -> " + | ||||
value, MSG_VERBOSE); | |||||
value, MSG_DEBUG); | |||||
userProperties.put(name, value); | userProperties.put(name, value); | ||||
properties.put(name, value); | properties.put(name, value); | ||||
} | } | ||||
@@ -294,7 +295,7 @@ public class Project { | |||||
public void addFilter(String token, String value) { | public void addFilter(String token, String value) { | ||||
if (token == null) return; | if (token == null) return; | ||||
log("Setting token to filter: " + token + " -> " | log("Setting token to filter: " + token + " -> " | ||||
+ value, MSG_VERBOSE); | |||||
+ value, MSG_DEBUG); | |||||
this.filters.put(token, value); | this.filters.put(token, value); | ||||
} | } | ||||
@@ -350,7 +351,7 @@ public class Project { | |||||
public void addTaskDefinition(String taskName, Class taskClass) { | public void addTaskDefinition(String taskName, Class taskClass) { | ||||
String msg = " +User task: " + taskName + " " + taskClass.getName(); | String msg = " +User task: " + taskName + " " + taskClass.getName(); | ||||
log(msg, MSG_VERBOSE); | |||||
log(msg, MSG_DEBUG); | |||||
taskClassDefinitions.put(taskName, taskClass); | taskClassDefinitions.put(taskName, taskClass); | ||||
} | } | ||||
@@ -360,7 +361,7 @@ public class Project { | |||||
public void addDataTypeDefinition(String typeName, Class typeClass) { | public void addDataTypeDefinition(String typeName, Class typeClass) { | ||||
String msg = " +User datatype: " + typeName + " " + typeClass.getName(); | String msg = " +User datatype: " + typeName + " " + typeClass.getName(); | ||||
log(msg, MSG_VERBOSE); | |||||
log(msg, MSG_DEBUG); | |||||
dataClassDefinitions.put(typeName, typeClass); | dataClassDefinitions.put(typeName, typeClass); | ||||
} | } | ||||
@@ -416,7 +417,7 @@ public class Project { | |||||
*/ | */ | ||||
public void addOrReplaceTarget(String targetName, Target target) { | public void addOrReplaceTarget(String targetName, Target target) { | ||||
String msg = " +Target: " + targetName; | String msg = " +Target: " + targetName; | ||||
log(msg, MSG_VERBOSE); | |||||
log(msg, MSG_DEBUG); | |||||
target.setProject(this); | target.setProject(this); | ||||
targets.put(targetName, target); | targets.put(targetName, target); | ||||
} | } | ||||
@@ -449,7 +450,7 @@ public class Project { | |||||
task.setTaskName(taskType); | task.setTaskName(taskType); | ||||
String msg = " +Task: " + taskType; | String msg = " +Task: " + taskType; | ||||
log (msg, MSG_VERBOSE); | |||||
log (msg, MSG_DEBUG); | |||||
return task; | return task; | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
String msg = "Could not create task of type: " | String msg = "Could not create task of type: " | ||||
@@ -484,7 +485,7 @@ public class Project { | |||||
o = ctor.newInstance(new Object[] {this}); | o = ctor.newInstance(new Object[] {this}); | ||||
} | } | ||||
String msg = " +DataType: " + typeName; | String msg = " +DataType: " + typeName; | ||||
log (msg, MSG_VERBOSE); | |||||
log (msg, MSG_DEBUG); | |||||
return o; | return o; | ||||
} catch (java.lang.reflect.InvocationTargetException ite) { | } catch (java.lang.reflect.InvocationTargetException ite) { | ||||
Throwable t = ite.getTargetException(); | Throwable t = ite.getTargetException(); | ||||