Browse Source

Add -propertyfile command-line option.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271043 13f79535-47bb-0310-9956-ffa450edef68
master
Erik Hatcher 23 years ago
parent
commit
b57651f539
3 changed files with 62 additions and 15 deletions
  1. +4
    -0
      WHATSNEW
  2. +16
    -13
      docs/manual/running.html
  3. +42
    -2
      src/main/org/apache/tools/ant/Main.java

+ 4
- 0
WHATSNEW View File

@@ -139,6 +139,10 @@ Other changes:
* you can now specify environment variables in the <java> and <junit> tasks
if the fork attribute has been set to true.
* -propertyfile command-line option has been added to load an entire
property file just as -D properties are declared (as user properties).
-D properties take precedence over -propertyfile specified ones.

Changes from Ant 1.4 to Ant 1.4.1
===========================================


+ 16
- 13
docs/manual/running.html View File

@@ -62,19 +62,22 @@ if one was specified, followed by a list of those targets without one.</p>
<h3><a name="options">Command-line Options Summary</a></h3>
<pre>ant [options] [target [target2 [target3] ...]]
Options:
-help print this message
-projecthelp print project help information
-version print the version information and exit
-quiet be extra quiet
-verbose be extra verbose
-debug print debugging information
-emacs produce logging information without adornments
-logfile <i>file</i> use given file for log output
-logger <i>classname</i> the class that is to perform logging
-listener <i>classname</i> add an instance of class as a project listener
-buildfile <i>file</i> use specified buildfile
-find <i>file</i> search for buildfile towards the root of the filesystem and use the first one found
-D<i>property</i>=<i>value</i> set <i>property</i> to <i>value</i>
-help print this message
-projecthelp print project help information
-version print the version information and exit
-quiet be extra quiet
-verbose be extra verbose
-debug print debugging information
-emacs produce logging information without adornments
-logfile &lt;file&gt; use given file for log
-logger &lt;classname&gt; the class which is to perform logging
-listener &lt;classname&gt; add an instance of class as a project listener
-buildfile &lt;file&gt; use given buildfile
-D&lt;property&gt;=&lt;value&gt; use value for given property
-propertyfile &lt;name&gt; load all properties from file with -D
properties taking precedence
-find &lt;file&gt; search for buildfile towards the root of the
filesystem and use it
</pre>
<p>For more information about <code>-logger</code> and
<code>-listener</code> see the section <a


+ 42
- 2
src/main/org/apache/tools/ant/Main.java View File

@@ -55,6 +55,7 @@
package org.apache.tools.ant;

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -100,6 +101,9 @@ public class Main {

/** Names of classes to add as listeners to project */
private Vector listeners = new Vector(5);
/** File names of property files to load on startup */
private Vector propertyFiles = new Vector(5);

/**
* The Ant logger class. There may be only one logger. It will have the
@@ -294,6 +298,16 @@ public class Main {
} else {
searchForThis = DEFAULT_BUILD_FILENAME;
}
} else if (arg.startsWith("-propertyfile")) {
try {
propertyFiles.addElement(args[i+1]);
i++;
} catch (ArrayIndexOutOfBoundsException aioobe) {
String msg = "You must specify a property filename when " +
"using the -propertyfile argument";
System.out.println(msg);
return;
}
} else if (arg.startsWith("-")) {
// we don't have any more args to recognize!
String msg = "Unknown argument: " + arg;
@@ -304,9 +318,8 @@ public class Main {
// if it's no other arg, it may be the target
targets.addElement(arg);
}

}
// if buildFile was not specified on the command line,
if (buildFile == null) {
// but -find then search for it
@@ -332,6 +345,31 @@ public class Main {
throw new BuildException("Build failed");
}

// Load the property files specified by -propertyfile
for (int propertyFileIndex=0;
propertyFileIndex < propertyFiles.size();
propertyFileIndex++) {
String filename = (String) propertyFiles.elementAt(propertyFileIndex);
Properties props = new Properties();
try {
FileInputStream fis = new FileInputStream(filename);
props.load(fis);
}
catch (IOException e) {
System.out.println("Could not load property file "
+ filename + ": " + e.getMessage());
}
// ensure that -D properties take precedence
Enumeration propertyNames = props.propertyNames();
while (propertyNames.hasMoreElements()) {
String name = (String) propertyNames.nextElement();
if (definedProps.getProperty(name) == null) {
definedProps.put(name, props.getProperty(name));
}
}
}

readyToRun = true;
}

@@ -576,6 +614,8 @@ public class Main {
msg.append(" -listener <classname> add an instance of class as a project listener" + lSep);
msg.append(" -buildfile <file> use given buildfile" + lSep);
msg.append(" -D<property>=<value> use value for given property" + lSep);
msg.append(" -propertyfile <name> load all properties from file with -D" + lSep);
msg.append(" properties taking precedence" + lSep);
msg.append(" -find <file> search for buildfile towards the root of the" + lSep);
msg.append(" filesystem and use it" + lSep);
System.out.println(msg.toString());


Loading…
Cancel
Save