overview of changes:

Project, Main, Recorder, RecorderEntry: 
-emacs command line parameter will apply to any Recorder which does not 
specify a preference for emacsmode. This was a pretty widely-spread change, 
but it's pretty low-impact.

Three very simple 
examples:
<record name="emacs.true" action="start" emacsmode='true'/>
<record name="emacs.default" action="start"/>
<record name="emacs.false" action="start" emacsmode='false'/>


Project.toBoolean():
If passed null, it now treats that as false. i hope that's not evil?


AbstractCvsTask:
Added support for cdata as cvs commands, one line per command. (Added ${} 
support in this patch.) (to do: add nested commands support, per 
Diane's suggestion.)

More details than strictly necessary can probably be found in my posts from 
earlier tonight.

patch (-u) attached.


----- [EMAIL PROTECTED]
http://qub.sourceforge.net  - http://radioaqtiph.sourceforge.net
http://www.countermoves.net - http://stephan.rootonfire.org
"Unix: the shell is your oyster."



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	22 Mar 2002 02:08:25 -0000
@@ -97,6 +97,13 @@
     /** Message priority of "debug". */
     public final static int MSG_DEBUG = 4;
 
+    /**
+     * Quick hack to enable emacsMode in RecorderEntry ([EMAIL PROTECTED])
+     */
+    public final static String EMACS_MODE_FLAG = "emacsMode";
+
+
+
     /** 
      * Constant for the "visiting" state, used when
      * traversing a DFS of target dependencies.
@@ -321,6 +328,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 +416,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 +1506,14 @@
      * 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; } // aded by [EMAIL PROTECTED] seems reasonable, but i don't know if it breaks anything.
         return (s.equalsIgnoreCase("on") ||
                 s.equalsIgnoreCase("true") ||
                 s.equalsIgnoreCase("yes"));
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	22 Mar 2002 02:08: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/taskdefs/AbstractCvsTask.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java,v
retrieving revision 1.2
diff -u -r1.2 AbstractCvsTask.java
--- src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java	7 Feb 2002 02:15:47 -0000	1.2
+++ src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java	22 Mar 2002 02:08:30 -0000
@@ -100,7 +100,8 @@
     /**
      * the CVS command to execute.
      */
-    private String command = "checkout";
+    private String default_command = "checkout";
+    private String command = default_command;
 
     /**
      * suppress information messages.
@@ -146,6 +147,16 @@
      */
     private boolean failOnError = false;
 
+    /**
+     * Please don't ask. ([EMAIL PROTECTED])
+     */
+    private boolean horribleCDataProcessingKludge = false;
+
+    /**
+     * see addText()
+     *
+     */
+	private String cdata = null;
 
     /**
      * Create accessors for the following, to allow different handling of
@@ -222,6 +233,54 @@
         return this.errorStream;
     }
 
+    /**
+This reads in any data set via addText() and treats each line as one cvs command,
+executing it via execute(). It is horribly inefficient because it calls execute()
+for every line, causing a lot of unnecessary object crunching. The simple fact is
+that i'm not yet comfortable enough with the Ant APIs yet to try to deal with
+CommandLine, Execute, etc. in a loop inside execute() itself. It would be much more
+efficient to do so, though.
+    */
+    protected synchronized void processCData() throws BuildException {
+	if( this.horribleCDataProcessingKludge ) {
+	    return;
+	    // this is cuz we keep re-running execute() from this function, which 
+	    // is going to try to re-run this function. i chose to put this wimp-out measure
+	    // here rather than deal with it in execute(). i know the extra function
+	    // calls to processCData() are overhead, but this is more maintainable.
+	    // [EMAIL PROTECTED]
+	}
+	if( this.cdata == null || this.cdata.length() < 1 ) return;
+	this.horribleCDataProcessingKludge = true;
+	java.util.StringTokenizer st = new java.util.StringTokenizer( this.cdata, org.apache.tools.ant.util.StringUtils.LINE_SEP );
+	String mycmd = null;
+	try {
+	    while( st.hasMoreElements() )
+	    {
+		mycmd = ((String)st.nextElement()).trim();
+		if( mycmd.length() < 1 ) continue;
+		if( mycmd.startsWith( ";" ) ) { continue; }
+		if( mycmd.startsWith( "#" ) ) { continue; }
+		mycmd = getProject().replaceProperties(mycmd);
+		log( "processCData() cvs command: ["+mycmd+"]", Project.MSG_DEBUG );
+ 		this.setCommand( mycmd );
+ 		this.execute();
+	    }
+	}
+	catch( BuildException e ) {
+	    this.horribleCDataProcessingKludge = false;
+	    throw( e );
+	}
+	catch( Exception e ) {
+	    this.horribleCDataProcessingKludge = false;
+	    throw new BuildException( e, location );
+	}
+	finally {
+	    this.horribleCDataProcessingKludge = false;
+	}
+	this.horribleCDataProcessingKludge = false; // just to be ABSOLUTELY certain.
+    }
+
     public void execute() throws BuildException {
 
         // XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
@@ -244,7 +303,7 @@
             toExecute.createArgument().setValue("-q");
         }
 
-        toExecute.createArgument().setLine(command);
+	toExecute.createArgument().setLine(command);
 
         //
         // get the other arguments.
@@ -308,19 +367,53 @@
         exe.setCommandline(toExecute.getCommandline());
         exe.setEnvironment(env.getVariables());
 
+	String warning = "ACHTUNG, BABY: proceeding only by the grace of failonerror='false': ";
         try {
-            log("Executing: " + executeToString(exe), Project.MSG_DEBUG);
-
-            int retCode = exe.execute();
+	    String actualCommandLine = this.executeToString(exe);
+	    log("Executing: " + actualCommandLine, Project.MSG_DEBUG);
+            int retCode = 0;
+	    if( this.command == null && cdata == null ) {
+		throw new BuildException( "No command and no command list set!", location );
+	    }
+	    if( this.command != null ) {
+		retCode = exe.execute();
+	    }
+	    if( retCode == 0 && this.cdata != null ) {
+		this.processCData();
+	    }
             /*Throw an exception if cvs exited with error. (Iulian)*/
             if(failOnError && retCode != 0) {
-                throw new BuildException("cvs exited with error code "+ retCode);
+                throw new BuildException("cvs exited with error code "+ retCode +
+					 org.apache.tools.ant.util.StringUtils.LINE_SEP+
+					 "Command line was ["+actualCommandLine+"]",
+					 location );
             }
         }
         catch (IOException e) {
-            throw new BuildException(e, location);
+	    if( failOnError ) {
+		throw new BuildException(e, location);
+	    }
+	    else {
+		log( warning+e.getMessage(), Project.MSG_INFO);
+	    }
+        }
+        catch (BuildException e) {
+	    if( failOnError ) {
+		throw( e );
+	    }
+	    else {
+		log( warning+e.getMessage(), Project.MSG_INFO);
+	    }
+        }
+        catch (Exception e) {
+	    if( failOnError ) {
+		throw new BuildException(e, location);
+	    }
+	    else {
+		log( warning+e.getMessage(), Project.MSG_INFO);
+	    }
         }
-        finally {
+	finally {
             //
             // condition used to be if(output == null) outputStream.close().  This is
             //      not appropriate.  Check if the stream itself is not null, then close().
@@ -330,7 +423,6 @@
                     outputStream.close();
                 } catch (IOException e) {}
             }
-
             if (errorStream != null) {
                 try {
                     errorStream.close();
@@ -349,17 +441,14 @@
             stringBuffer.append(" ");
         }
         String newLine = System.getProperty("line.separator");
-        stringBuffer.append(newLine);
-        stringBuffer.append(newLine);
-        stringBuffer.append("environment:");
-        stringBuffer.append(newLine);
-
-
         String[] variableArray = execute.getEnvironment();
 
         if(variableArray != null){
+	    stringBuffer.append(newLine);
+	    stringBuffer.append(newLine);
+	    stringBuffer.append("environment:");
+	    stringBuffer.append(newLine);
             for(int z=0; z<variableArray.length; z++){
-
                 stringBuffer.append(newLine);
                 stringBuffer.append("\t");
                 stringBuffer.append(variableArray[z]);
@@ -489,6 +578,22 @@
     public void setFailOnError(boolean failOnError) {
         this.failOnError = failOnError;
     }
-}
-
 
+    /**
+     * Accepts cvs commands, one command per line, and executes them in order after any
+     * other commands. Example:
+     * <code>
+     * <cvs>
+     * up -r 1.8 some/file
+     * status some/other/file
+     * ; comment lines, too.
+     * # and for Perl fans...
+     *</cvs>
+     * </code>
+     */
+    public void addText( String text ) {
+        this.cdata = text;
+	if( text == null ) return;
+	this.setCommand( null ); // this is a very lame workaround. Ask me someday. ([EMAIL PROTECTED])
+    }
+}
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	22 Mar 2002 02:08:31 -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) {
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	22 Mar 2002 02:08:31 -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(
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to