From 3fd5393e99cef2d28ced46f804a3ae53f915bf3c Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Fri, 3 Oct 2003 01:40:48 +0000 Subject: [PATCH] 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 --- docs/manual/running.html | 17 ++++++----- src/main/org/apache/tools/ant/Main.java | 38 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/docs/manual/running.html b/docs/manual/running.html index ca2d7bdca..2ef471dd0 100644 --- a/docs/manual/running.html +++ b/docs/manual/running.html @@ -78,20 +78,21 @@ those without a description are listed as

Command-line Options Summary

ant [options] [target [target2 [target3] ...]]
 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
   -diagnostics           print information that might be helpful to
                          diagnose or report problems.
   -quiet, -q             be extra quiet
   -verbose, -v           be extra verbose
-  -debug                 print debugging information
-  -emacs                 produce logging information without adornments
-  -lib             specifies a path to search for jars and classes
+  -debug, -d             print debugging information
+  -emacs, -e             produce logging information without adornments
+  -lib <path>            specifies a path to search for jars and classes
   -logfile <file>        use given file for log
     -l     <file>                ''
   -logger <classname>    the class which is to perform logging
   -listener <classname>  add an instance of class as a project listener
+  -noinput               do not allow interactive input
   -buildfile <file>      use given buildfile
     -file    <file>              ''
     -f       <file>              ''
@@ -101,8 +102,10 @@ Options:
   -propertyfile <name>   load all properties from file with -D
                          properties taking precedence
   -inputhandler <class>  the class which will handle input requests
-  -find <file>           search for buildfile towards the root of the
-                         filesystem and use it
+  -find <file>           (s)earch for buildfile towards the root of
+    -s  <file>           the filesystem and use it
+  -nice  number          A niceness value for the main thread:
+                         1 (lowest) to 10 (highest); 5 is the default                         
 

For more information about -logger and -listener see diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index b5492dd20..e5fc19780 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -152,6 +152,11 @@ public class Main implements AntMain { */ private static boolean isLogFileUsed = false; + /** + * optional thread priority + */ + private Integer threadPriority=null; + /** * Prints the message of the Throwable if it (the message) is not * null. @@ -434,6 +439,23 @@ public class Main implements AntMain { } } else if (arg.equals("-k") || arg.equals("-keep-going")) { 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.MAX_PRIORITY) { + throw new BuildException( + "Niceness value is out of the range 1-10"); + } } else if (arg.startsWith("-")) { // we don't have any more args to recognize! String msg = "Unknown argument: " + arg; @@ -632,9 +654,23 @@ public class Main implements AntMain { System.setOut(new PrintStream(new DemuxOutputStream(project, false))); System.setErr(new PrintStream(new DemuxOutputStream(project, true))); + if (!projectHelp) { 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.setUserProperty("ant.version", getAntVersion()); @@ -826,6 +862,8 @@ public class Main implements AntMain { msg.append(" -inputhandler the class which will handle input requests" + lSep); msg.append(" -find (s)earch for buildfile towards the root of" + lSep); msg.append(" -s 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()); }