Browse Source

This is the first visible divergence ofAnt1.7 from 1.6...ant 1.7 has a -nice option that lets you lessen or increase the priority of the main thread. Useful for background builds, though since it doesnt propagate into forked code, not as useful as it could be.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275412 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 22 years ago
parent
commit
3fd5393e99
2 changed files with 48 additions and 7 deletions
  1. +10
    -7
      docs/manual/running.html
  2. +38
    -0
      src/main/org/apache/tools/ant/Main.java

+ 10
- 7
docs/manual/running.html View File

@@ -78,20 +78,21 @@ those without a <code>description</code> are listed as
<h3><a name="options">Command-line Options Summary</a></h3> <h3><a name="options">Command-line Options Summary</a></h3>
<pre>ant [options] [target [target2 [target3] ...]] <pre>ant [options] [target [target2 [target3] ...]]
Options: Options:
-help print this message
-projecthelp print project help information
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit -version print the version information and exit
-diagnostics print information that might be helpful to -diagnostics print information that might be helpful to
diagnose or report problems. diagnose or report problems.
-quiet, -q be extra quiet -quiet, -q be extra quiet
-verbose, -v be extra verbose -verbose, -v be extra verbose
-debug print debugging information
-emacs produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib &lt;path&gt; specifies a path to search for jars and classes
-logfile &lt;file&gt; use given file for log -logfile &lt;file&gt; use given file for log
-l &lt;file&gt; '' -l &lt;file&gt; ''
-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
-noinput do not allow interactive input
-buildfile &lt;file&gt; use given buildfile -buildfile &lt;file&gt; use given buildfile
-file &lt;file&gt; '' -file &lt;file&gt; ''
-f &lt;file&gt; '' -f &lt;file&gt; ''
@@ -101,8 +102,10 @@ Options:
-propertyfile &lt;name&gt; load all properties from file with -D -propertyfile &lt;name&gt; load all properties from file with -D
properties taking precedence properties taking precedence
-inputhandler &lt;class&gt; the class which will handle input requests -inputhandler &lt;class&gt; the class which will handle input requests
-find &lt;file&gt; search for buildfile towards the root of the
filesystem and use it
-find &lt;file&gt; (s)earch for buildfile towards the root of
-s &lt;file&gt; the filesystem and use it
-nice number A niceness value for the main thread:
1 (lowest) to 10 (highest); 5 is the default
</pre> </pre>
<p>For more information about <code>-logger</code> and <p>For more information about <code>-logger</code> and
<code>-listener</code> see <code>-listener</code> see


+ 38
- 0
src/main/org/apache/tools/ant/Main.java View File

@@ -152,6 +152,11 @@ public class Main implements AntMain {
*/ */
private static boolean isLogFileUsed = false; private static boolean isLogFileUsed = false;


/**
* optional thread priority
*/
private Integer threadPriority=null;

/** /**
* Prints the message of the Throwable if it (the message) is not * Prints the message of the Throwable if it (the message) is not
* <code>null</code>. * <code>null</code>.
@@ -434,6 +439,23 @@ public class Main implements AntMain {
} }
} else if (arg.equals("-k") || arg.equals("-keep-going")) { } else if (arg.equals("-k") || arg.equals("-keep-going")) {
keepGoingMode = true; keepGoingMode = true;
} else if (arg.equals("-nice")) {
try {
threadPriority=Integer.decode(args[i + 1]);
} catch (ArrayIndexOutOfBoundsException aioobe) {
throw new BuildException(
"You must supply a niceness value (1-10)"+
" after the -nice option");
} catch (NumberFormatException e) {
throw new BuildException("Unrecognized niceness value: " +
args[i + 1]);
}
i++;
if(threadPriority.intValue()<Thread.MIN_PRIORITY ||
threadPriority.intValue()>Thread.MAX_PRIORITY) {
throw new BuildException(
"Niceness value is out of the range 1-10");
}
} 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 argument: " + arg; String msg = "Unknown argument: " + arg;
@@ -632,9 +654,23 @@ public class Main implements AntMain {
System.setOut(new PrintStream(new DemuxOutputStream(project, false))); System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
System.setErr(new PrintStream(new DemuxOutputStream(project, true))); System.setErr(new PrintStream(new DemuxOutputStream(project, true)));



if (!projectHelp) { if (!projectHelp) {
project.fireBuildStarted(); project.fireBuildStarted();
} }

// set the thread priorities
if (threadPriority != null) {
try {
project.log("Setting Ant's thread priority to "
+ threadPriority,Project.MSG_VERBOSE);
Thread.currentThread().setPriority(threadPriority.intValue());
} catch (SecurityException swallowed) {
//we cannot set the priority here.
project.log("A security manager refused to set the -nice value");
}
}

project.init(); project.init();
project.setUserProperty("ant.version", getAntVersion()); project.setUserProperty("ant.version", getAntVersion());


@@ -826,6 +862,8 @@ public class Main implements AntMain {
msg.append(" -inputhandler <class> the class which will handle input requests" + lSep); msg.append(" -inputhandler <class> the class which will handle input requests" + lSep);
msg.append(" -find <file> (s)earch for buildfile towards the root of" + lSep); msg.append(" -find <file> (s)earch for buildfile towards the root of" + lSep);
msg.append(" -s <file> the filesystem and use it" + lSep); msg.append(" -s <file> the filesystem and use it" + lSep);
msg.append(" -nice number A niceness value for the main thread:" + lSep +
" 1 (lowest) to 10 (highest); 5 is the default" + lSep);
System.out.println(msg.toString()); System.out.println(msg.toString());
} }




Loading…
Cancel
Save