Summary:
Patches to Main, Project, Recorder and RecorderEntry to enable <record> tasks
to take advantage of the -emacs command-line flag. Also adds <record
emacsmode='boolean'.../> support. It's backwards-compatible except that it
fixes the bug that <record> didn't do emacs ;).
IF the -emacs command-line parm is passed, that will override the default
value for this setting (false) IF this object's XML representation does
NOT specify a preference. If it specifies any preference, that will take
precendent over the command-line parameter.
This supercedes any earlier patch i sent for this.
----- stephan
Generic Universal Computer Guy
[EMAIL PROTECTED] - http://www.einsurance.de
Office: +49 (89) �552 92 862 Handy: �+49 (179) 211 97 67
Student: "Master, you must teach me the way of liberation!"
Master: "Tell me who it is that binds you."
Student: "No one binds me!"
Master: "Then why do you seek liberation?"
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 01:27:28 -0000
@@ -502,8 +502,10 @@
final Project project = new Project();
project.setCoreLoader(coreLoader);
- Throwable error = null;
+ // quick hack to enable emacsMode in RecorderEntry ([EMAIL PROTECTED])
+ project.setProperty( Project.EMACS_MODE_FLAG, new java.lang.Boolean(this.emacsMode).toString() );
+ Throwable error = null;
try {
addBuildListeners(project);
@@ -655,11 +657,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 01:27:28 -0000
@@ -97,6 +97,15 @@
/** Message priority of "debug". */
public final static int MSG_DEBUG = 4;
+ /**
+ * Quick hack to enable emacsMode in RecorderEntry ([EMAIL PROTECTED])
+ * This is not in Main because Task doesn't need to know about Main, and i don't
+ * want to make it know about Main just to see this flag.
+ */
+ public final static String EMACS_MODE_FLAG = "ant.emacsmode";
+
+
+
/**
* Constant for the "visiting" state, used when
* traversing a DFS of target dependencies.
@@ -224,8 +233,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 +329,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( Project.toBoolean( getProperty( Project.EMACS_MODE_FLAG ) ) );
+ // log( "Hey, Project["+getName()+"].addBuildListener() got a BuildLogger!", Project.MSG_DEBUG );
+ }
listeners.addElement(listener);
}
@@ -403,6 +417,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 +1507,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"));
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 01:27:29 -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,37 @@
// 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. Anyway, it will ask nicely, and we'll see what happens, okay?
+ * setEmacsmode() is called once when setProject() is called, and setEmacsmode()
+ * is set to true if getProject().getProperty( Project.EMACS_MODE_FLAG ) != null.
+ * <br>What does all that really mean?
+ *<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>
+ * TODO: call on all RecorderEntry children???
+ * <br>
+ */
+ public void setEmacsmode( boolean b ) { // that sure irks me to not write setEmacsMode :/
+ 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 +199,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 +232,18 @@
}
/**
+ * Reimplemented for internal reasons. No effect on the API.
+ */
+ public void setProject( Project p ) {
+ super.setProject( p );
+ if( p == null ) { return; }
+ String s = p.getProperty( Project.EMACS_MODE_FLAG );
+ if( s != null ) {
+ this.setEmacsmode( Project.toBoolean( s ) );
+ }
+ }
+
+ /**
* 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 +254,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 01:27:29 -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]>