Attached is a cleaned-up version using Erik's suggestion for emacsmode as a
property of Project. (Oh, and my comments have been de-slackified ;)
Additionally, has the toBoolean( null ) == false (instead of NPE) change/fix.
----- stephan
Generic Unix Computer Guy
[EMAIL PROTECTED] - http://www.einsurance.de
Office: +49 (89) �552 92 862 Handy: �+49 (179) 211 97 67
"...control is a degree of inhibition, and a system which is perfectly
inhibited is completely frozen." -- Alan W. Watts
Index: src/main/org/apache/tools/ant/Main.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.59
diff -u -r1.59 Main.java
--- src/main/org/apache/tools/ant/Main.java 5 Mar 2002 15:53:16 -0000 1.59
+++ src/main/org/apache/tools/ant/Main.java 25 Mar 2002 08:10:19 -0000
@@ -501,9 +501,9 @@
final Project project = new Project();
project.setCoreLoader(coreLoader);
+ project.setEmacsmode( this.emacsMode );
Throwable error = null;
-
try {
addBuildListeners(project);
@@ -655,11 +655,10 @@
else {
logger = new DefaultLogger();
}
-
logger.setMessageOutputLevel(msgOutputLevel);
logger.setOutputPrintStream(out);
logger.setErrorPrintStream(err);
- logger.setEmacsMode(emacsMode);
+ logger.setEmacsMode(emacsMode);
return logger;
}
Index: src/main/org/apache/tools/ant/Project.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.99
diff -u -r1.99 Project.java
--- src/main/org/apache/tools/ant/Project.java 5 Mar 2002 14:39:05 -0000 1.99
+++ src/main/org/apache/tools/ant/Project.java 25 Mar 2002 08:10:19 -0000
@@ -97,6 +97,8 @@
/** Message priority of "debug". */
public final static int MSG_DEBUG = 4;
+ private boolean emacsMode = false;
+
/**
* Constant for the "visiting" state, used when
* traversing a DFS of target dependencies.
@@ -224,8 +226,7 @@
* This involves setting the default task definitions and loading the
* system properties.
*
- * @exception BuildException if the default task list cannot be loaded
- */
+ * @exception BuildException if the default task list cannot be loaded */
public void init() throws BuildException {
setJavaVersionProperty();
@@ -321,6 +322,12 @@
* Must not be <code>null</code>.
*/
public void addBuildListener(BuildListener listener) {
+ if( listener instanceof org.apache.tools.ant.BuildLogger )
+ {
+ BuildLogger bl = (BuildLogger)listener;
+ bl.setEmacsMode( this.emacsMode );
+ // log( "Hey, Project["+getName()+"].addBuildListener() got a BuildLogger!", Project.MSG_DEBUG );
+ }
listeners.addElement(listener);
}
@@ -403,6 +410,7 @@
* Must not be <code>null</code>.
*/
public void setProperty(String name, String value) {
+ // System.out.println( "Project["+getName()+"].setProperty( ["+name+"], ["+value+"] )" );
// command line properties take precedence
if (null != userProperties.get(name)) {
log("Override ignored for user property " + name, MSG_VERBOSE);
@@ -1492,13 +1500,17 @@
* or <code>"yes"</code> is found, ignoring case.
*
* @param s The string to convert to a boolean value.
- * Must not be <code>null</code>.
+ * May be <code>null</code> (equals false).
*
* @return <code>true</code> if the given string is <code>"on"</code>,
* <code>"true"</code> or <code>"yes"</code>, or
* <code>false</code> otherwise.
*/
public static boolean toBoolean(String s) {
+ if( s == null ) { return false; } // added by [EMAIL PROTECTED]
+ // It seems reasonable, but i don't know if it breaks anything. i can't imagine any
+ // classes RELYING on a an NPE here.
+
return (s.equalsIgnoreCase("on") ||
s.equalsIgnoreCase("true") ||
s.equalsIgnoreCase("yes"));
@@ -1894,4 +1906,15 @@
BuildEvent event = new BuildEvent(task);
fireMessageLoggedEvent(event, message, priority);
}
+
+
+ public void setEmacsmode( boolean b ) {
+ this.emacsMode = b;
+ }
+
+ // yes, Erik, Recorder uses this!
+ public boolean getEmacsmode() {
+ return this.emacsMode;
+ }
+
}
Index: src/main/org/apache/tools/ant/taskdefs/Recorder.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Recorder.java,v
retrieving revision 1.9
diff -u -r1.9 Recorder.java
--- src/main/org/apache/tools/ant/taskdefs/Recorder.java 3 Mar 2002 01:46:20 -0000 1.9
+++ src/main/org/apache/tools/ant/taskdefs/Recorder.java 25 Mar 2002 08:10:19 -0000
@@ -98,6 +98,7 @@
/** The list of recorder entries. */
private static Hashtable recorderEntries = new Hashtable();
+ private boolean emacsMode = false;
//////////////////////////////////////////////////////////////////////
// CONSTRUCTORS / INITIALIZERS
@@ -105,6 +106,35 @@
// ACCESSOR METHODS
/**
+ * If set to true, this object will not prefix output with [taskname].
+ * Well, it THINKS it won't, but that's actually up to another object to
+ * implement, so this is just a request. It will ask nicely, and we'll see what happens.
+ * setEmacsmode() is called once when setProject() is called, and will be called
+ * an additional time if 'emacsmode="..."' is set in this object's XML definition..
+ * <br><br>What that all really means is:
+ *<br><br>
+ * IF the -emacs command-line parm was passed, that will override the default
+ * value for this setting (false) IF this object's XML representation does
+ * NOT specifya preference. If it specifies any preference, that will take precendent.
+ * over the command-line parameter.
+ *<br><br>
+ *<code>ant -emacs</code> behaves like so:<br>
+ *<code><recorder/></code> = setEmacsmode( true )<br>
+ *<code><recorder emacsmode='false'/></code> = setEmacsmode( false ), because a
+ * specified preference always takes precendence over the global setting.<br>
+ *<br><br>
+ */
+ public void setEmacsmode( boolean b ) {
+ this.emacsMode = b;
+ }
+ /**
+ * Duh.
+ */
+ public boolean getEmacsmode() {
+ return this.emacsMode;
+ }
+
+ /**
* Sets the name of the file to log to, and the name of the recorder entry.
* @param fname File name of logfile.
*/
@@ -167,6 +197,7 @@
// get the recorder entry
RecorderEntry recorder = getRecorder( filename, getProject() );
+ recorder.setEmacsMode( this.getEmacsmode() );
// set the values on the recorder
recorder.setMessageOutputLevel( loglevel );
recorder.setRecordState( start );
@@ -199,6 +230,15 @@
}
/**
+ * Reimplemented for internal reasons. No effect on the API.
+ */
+ public void setProject( Project p ) {
+ super.setProject( p );
+ if( p == null ) { return; }
+ this.setEmacsmode( p.getEmacsmode() );
+ }
+
+ /**
* Gets the recorder that's associated with the passed in name.
* If the recorder doesn't exist, then a new one is created.
*/
@@ -209,6 +249,7 @@
// create a recorder entry
try {
entry = new RecorderEntry( name );
+ entry.setEmacsMode( this.getEmacsmode() );
PrintStream out = null;
if ( append == null ) {
out = new PrintStream(
Index: src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java,v
retrieving revision 1.5
diff -u -r1.5 RecorderEntry.java
--- src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java 8 Jan 2002 22:39:36 -0000 1.5
+++ src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java 25 Mar 2002 08:10:19 -0000
@@ -95,6 +95,11 @@
*/
private long targetStartTime = 0l;
+ /**
+ *
+ */
+ private boolean emacsMode = false;
+
//////////////////////////////////////////////////////////////////////
// CONSTRUCTORS / INITIALIZERS
@@ -102,6 +107,10 @@
* @param name The name of this recorder (used as the filename).
*
*/
+ public RecorderEntry()
+ {
+ this( null );
+ }
protected RecorderEntry( String name ) {
filename = name;
}
@@ -145,15 +154,16 @@
}
public void targetStarted(BuildEvent event) {
- log( ">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG );
- log( StringUtils.LINE_SEP + event.getTarget().getName() + ":", Project.MSG_INFO );
+ log( "targetStarted( project=[" + event.getProject().getName() + "] )", Project.MSG_INFO );
+ log( ">> TARGET STARTED -- " + (emacsMode ? "" : event.getTarget().getName()), Project.MSG_DEBUG );
+ log( StringUtils.LINE_SEP + (emacsMode ? "" : event.getTarget().getName() + ": " ), Project.MSG_INFO );
targetStartTime = System.currentTimeMillis();
}
public void targetFinished(BuildEvent event) {
- log( "<< TARGET FINISHED -- " + event.getTarget(), Project.MSG_DEBUG );
+ log( "<< TARGET FINISHED -- " + (emacsMode ? "" : event.getTarget().getName()), Project.MSG_DEBUG );
String time = formatTime( System.currentTimeMillis() - targetStartTime );
- log( event.getTarget() + ": duration " + time, Project.MSG_VERBOSE );
+ log( (emacsMode ? "" : event.getTarget().getName() + ": ")+"duration " + time, Project.MSG_VERBOSE );
out.flush();
}
@@ -168,14 +178,13 @@
public void messageLogged(BuildEvent event) {
log( "--- MESSAGE LOGGED", Project.MSG_DEBUG );
-
StringBuffer buf = new StringBuffer();
- if ( event.getTask() != null ) {
- String name = "[" + event.getTask().getTaskName() + "]";
+ if ( !emacsMode && event.getTask() != null ) {
+ String name = "[" + event.getTask().getTaskName() + "] ";
/** @todo replace 12 with DefaultLogger.LEFT_COLUMN_SIZE */
- for ( int i = 0; i < (12 - name.length()); i++ ) {
+ for ( int i = 0; i < (12 - name.length()); i++ ) {
buf.append( " " );
- } // for
+ } // for
buf.append( name );
} // if
buf.append( event.getMessage() );
@@ -205,7 +214,7 @@
}
public void setEmacsMode(boolean emacsMode) {
- throw new java.lang.RuntimeException("Method setEmacsMode() not yet implemented.");
+ this.emacsMode = emacsMode;
}
public void setErrorPrintStream(PrintStream err) {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>