ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce P4Add.java P4Base.java P4Change.java P4Counter.java P4Delete.java P4Edit.java P4Have.java P4Label.java P4Reopen.java P4Revert.java P4Submit.java P4Sync.java P4Handler.java P4HandlerAdapter.java P4OutputHandler.java SimpleP4OutputHandler.java
Date Sun, 06 Jan 2002 02:30:44 GMT
donaldp     02/01/05 18:30:44

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce
                        P4Add.java P4Base.java P4Change.java P4Counter.java
                        P4Delete.java P4Edit.java P4Have.java P4Label.java
                        P4Reopen.java P4Revert.java P4Submit.java
                        P4Sync.java
  Removed:     proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce
                        P4Handler.java P4HandlerAdapter.java
                        P4OutputHandler.java SimpleP4OutputHandler.java
  Log:
  Started to move the perforce tasks towards the new Execute2  abstraction
  
  Revision  Changes    Path
  1.8       +12 -6     jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java
  
  Index: P4Add.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- P4Add.java	1 Jan 2002 09:13:46 -0000	1.7
  +++ P4Add.java	6 Jan 2002 02:30:43 -0000	1.8
  @@ -111,12 +111,12 @@
           throws TaskException
       {
   
  -        if( P4View != null )
  +        if( m_p4View != null )
           {
  -            addCmd = P4View;
  +            addCmd = m_p4View;
           }
   
  -        P4CmdOpts = ( m_changelist > 0 ) ? ( "-c " + m_changelist ) : "";
  +        m_p4CmdOpts = ( m_changelist > 0 ) ? ( "-c " + m_changelist ) : "";
   
           StringBuffer filelist = new StringBuffer();
   
  @@ -152,10 +152,16 @@
   
       }
   
  -    private void execP4Add( StringBuffer list )
  +    private void execP4Add( final StringBuffer list )
  +        throws TaskException
       {
  -        getLogger().info( "Execing add " + P4CmdOpts + " " + addCmd + list );
  +        if( getLogger().isInfoEnabled() )
  +        {
  +            final String message = "Execing add " + m_p4CmdOpts + " " + addCmd + list;
  +            getLogger().info( message );
  +        }
   
  -        execP4Command( "-s add " + P4CmdOpts + " " + addCmd + list, new SimpleP4OutputHandler(
this ) );
  +        final String command = "-s add " + m_p4CmdOpts + " " + addCmd + list;
  +        execP4Command( command, null );
       }
   }
  
  
  
  1.12      +94 -56    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java
  
  Index: P4Base.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- P4Base.java	23 Dec 2001 14:22:47 -0000	1.11
  +++ P4Base.java	6 Jan 2002 02:30:43 -0000	1.12
  @@ -9,8 +9,9 @@
   
   import java.io.IOException;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.exec.ExecOutputHandler;
   import org.apache.oro.text.perl.Perl5Util;
  -import org.apache.tools.ant.taskdefs.exec.Execute;
  +import org.apache.tools.ant.taskdefs.exec.Execute2;
   import org.apache.tools.ant.types.Commandline;
   
   /**
  @@ -26,31 +27,32 @@
    * @see P4Label
    * @see org.apache.tools.ant.taskdefs.Exec
    */
  -public abstract class P4Base extends org.apache.tools.ant.Task
  +public abstract class P4Base
  +    extends org.apache.tools.ant.Task
  +    implements ExecOutputHandler
   {
  -
       /**
        * Perl5 regexp in Java - cool eh?
        */
  -    protected Perl5Util util = null;
  +    protected Perl5Util util;
   
       //P4 runtime directives
       /**
        * Perforce Server Port (eg KM01:1666)
        */
  -    protected String P4Port = "";
  +    protected String m_p4Port = "";
       /**
        * Perforce Client (eg myclientspec)
        */
  -    protected String P4Client = "";
  +    protected String m_p4Client = "";
       /**
        * Perforce User (eg fbloggs)
        */
  -    protected String P4User = "";
  +    protected String m_p4User = "";
       /**
        * Perforce view for commands (eg //projects/foobar/main/source/... )
        */
  -    protected String P4View = "";
  +    protected String m_p4View = "";
   
       //P4 g-opts and cmd opts (rtfm)
       /**
  @@ -60,36 +62,38 @@
       /**
        * Perforce command opts. Forms half of low level API
        */
  -    protected String P4CmdOpts = "";
  +    protected String m_p4CmdOpts = "";
       /**
        * The OS shell to use (cmd.exe or /bin/sh)
        */
       protected String shell;
   
  +    private TaskException m_error;
  +
       public void setClient( String P4Client )
       {
  -        this.P4Client = "-c" + P4Client;
  +        this.m_p4Client = "-c" + P4Client;
       }
   
       public void setCmdopts( String P4CmdOpts )
       {
  -        this.P4CmdOpts = P4CmdOpts;
  +        this.m_p4CmdOpts = P4CmdOpts;
       }
   
       //Setters called by Ant
       public void setPort( String P4Port )
       {
  -        this.P4Port = "-p" + P4Port;
  +        this.m_p4Port = "-p" + P4Port;
       }
   
       public void setUser( String P4User )
       {
  -        this.P4User = "-u" + P4User;
  +        this.m_p4User = "-u" + P4User;
       }
   
       public void setView( String P4View )
       {
  -        this.P4View = P4View;
  +        this.m_p4View = P4View;
       }
   
       private void prepare()
  @@ -98,19 +102,19 @@
   
           //Get default P4 settings from environment - Mark would have done something cool
with
           //introspection here.....:-)
  -        String tmpprop;
  -        if( ( tmpprop = getProject().getProperty( "p4.port" ) ) != null )
  -            setPort( tmpprop );
  -        if( ( tmpprop = getProject().getProperty( "p4.client" ) ) != null )
  -            setClient( tmpprop );
  -        if( ( tmpprop = getProject().getProperty( "p4.user" ) ) != null )
  -            setUser( tmpprop );
  -    }
  -
  -    protected void execP4Command( String command )
  -        throws TaskException
  -    {
  -        execP4Command( command, null );
  +        Object tmpprop;
  +        if( ( tmpprop = getProperty( "p4.port" ) ) != null )
  +        {
  +            setPort( tmpprop.toString() );
  +        }
  +        if( ( tmpprop = getProperty( "p4.client" ) ) != null )
  +        {
  +            setClient( tmpprop.toString() );
  +        }
  +        if( ( tmpprop = getProperty( "p4.user" ) ) != null )
  +        {
  +            setUser( tmpprop.toString() );
  +        }
       }
   
       public void execute()
  @@ -123,36 +127,32 @@
   
       /**
        * Execute P4 command assembled by subclasses.
  -     *
  -     * @param command The command to run
  -     * @param handler A P4Handler to process any input and output
  -     * @exception TaskException Description of Exception
        */
  -    protected void execP4Command( String command, P4Handler handler )
  +    protected void execP4Command( final String command,
  +                                  ExecOutputHandler handler )
           throws TaskException
       {
           try
           {
  -
  -            Commandline commandline = new Commandline();
  -            commandline.setExecutable( "p4" );
  +            final Commandline cmd = new Commandline();
  +            cmd.setExecutable( "p4" );
   
               //Check API for these - it's how CVS does it...
  -            if( P4Port != null && P4Port.length() != 0 )
  +            if( m_p4Port != null && m_p4Port.length() != 0 )
               {
  -                commandline.createArgument().setValue( P4Port );
  +                cmd.createArgument().setValue( m_p4Port );
               }
  -            if( P4User != null && P4User.length() != 0 )
  +            if( m_p4User != null && m_p4User.length() != 0 )
               {
  -                commandline.createArgument().setValue( P4User );
  +                cmd.createArgument().setValue( m_p4User );
               }
  -            if( P4Client != null && P4Client.length() != 0 )
  +            if( m_p4Client != null && m_p4Client.length() != 0 )
               {
  -                commandline.createArgument().setValue( P4Client );
  +                cmd.createArgument().setValue( m_p4Client );
               }
  -            commandline.createArgument().setLine( command );
  +            cmd.createArgument().setLine( command );
   
  -            String[] cmdline = commandline.getCommandline();
  +            String[] cmdline = cmd.getCommandline();
               String cmdl = "";
               for( int i = 0; i < cmdline.length; i++ )
               {
  @@ -160,12 +160,14 @@
               }
   
               getLogger().debug( "Execing " + cmdl );
  -
               if( handler == null )
  -                handler = new SimpleP4OutputHandler( this );
  +            {
  +                handler = this;
  +            }
   
  -            final Execute exe = new Execute( handler );
  -            exe.setCommandline( commandline.getCommandline() );
  +            final Execute2 exe = new Execute2();
  +            exe.setExecOutputHandler( handler );
  +            exe.setCommandline( cmd.getCommandline() );
   
               try
               {
  @@ -175,21 +177,57 @@
               {
                   throw new TaskException( "Error", e );
               }
  -            finally
  +            if( null != m_error )
               {
  -                try
  -                {
  -                    handler.stop();
  -                }
  -                catch( Exception e )
  -                {
  -                }
  +                throw m_error;
               }
  -
  +        }
  +        catch( TaskException te )
  +        {
  +            throw te;
           }
           catch( Exception e )
           {
               throw new TaskException( "Problem exec'ing P4 command: " + e.getMessage() );
           }
  +    }
  +
  +    protected final void registerError( final TaskException error )
  +    {
  +        m_error = error;
  +        m_error.fillInStackTrace();
  +    }
  +
  +    /**
  +     * Receive notification about the process writing
  +     * to standard output.
  +     */
  +    public void stdout( final String line )
  +    {
  +        if( util.match( "/^exit/", line ) )
  +        {
  +            return;
  +        }
  +
  +        //Throw exception on errors (except up-to-date)
  +        //p4 -s is unpredicatable. For example a server down
  +        //does not return error: markup
  +        //
  +        //Some forms producing commands (p4 -s change -o) do tag the output
  +        //others don't.....
  +        //Others mark errors as info, for example edit a file
  +        //which is already open for edit.....
  +        //Just look for error: - catches most things....
  +
  +        if( util.match( "/error:/", line ) && !util.match( "/up-to-date/", line
) )
  +        {
  +            registerError( new TaskException( line ) );
  +        }
  +
  +        getLogger().info( util.substitute( "s/^.*: //", line ) );
  +    }
  +
  +    public void stderr( final String line )
  +    {
       }
   }
  
  
  
  1.7       +88 -75    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java
  
  Index: P4Change.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- P4Change.java	23 Dec 2001 14:22:47 -0000	1.6
  +++ P4Change.java	6 Jan 2002 02:30:43 -0000	1.7
  @@ -8,7 +8,6 @@
   package org.apache.tools.ant.taskdefs.optional.perforce;
   
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.tools.ant.Project;
   
   /**
    * P4Change - grab a new changelist from Perforce. P4Change creates a new
  @@ -19,97 +18,59 @@
    * @see P4Edit
    * @see P4Submit
    */
  -public class P4Change extends P4Base
  +public class P4Change
  +    extends P4Base
   {
  -
  -    protected String emptyChangeList = null;
  -    protected String description = "AutoSubmit By Ant";
  +    private String m_emptyChangeList;
  +    private String m_description = "AutoSubmit By Ant";
  +    private final StringBuffer m_changelistData = new StringBuffer();
  +    private boolean m_changelist;
   
       /*
        * Set Description Variable.
        */
  -    public void setDescription( String desc )
  +    public void setDescription( final String description )
       {
  -        this.description = desc;
  +        m_description = description;
       }
   
  -    public String getEmptyChangeList()
  +    private String getEmptyChangeList()
           throws TaskException
       {
  -        final StringBuffer stringbuf = new StringBuffer();
  +        m_changelist = true;
  +        execP4Command( "change -o", null );
  +        m_changelist = false;
   
  -        execP4Command( "change -o",
  -                       new P4HandlerAdapter()
  -                       {
  -                           public void process( String line )
  -                           {
  -                               if( !util.match( "/^#/", line ) )
  -                               {
  -                                   if( util.match( "/error/", line ) )
  -                                   {
  -
  -                                       getLogger().debug( "Client Error" );
  -                                       throw new TaskException( "Perforce Error, check
client settings and/or server" );
  -                                   }
  -                                   else if( util.match( "/<enter description here>/",
line ) )
  -                                   {
  -
  -                                       // we need to escape the description in case there
are /
  -                                       description = backslash( description );
  -                                       line = util.substitute( "s/<enter description
here>/" + description + "/", line );
  -
  -                                   }
  -                                   else if( util.match( "/\\/\\//", line ) )
  -                                   {
  -                                       //Match "//" for begining of depot filespec
  -                                       return;
  -                                   }
  -
  -                                   stringbuf.append( line );
  -                                   stringbuf.append( "\n" );
  -
  -                               }
  -                           }
  -                       } );
  +        return m_changelistData.toString();
  +    }
   
  -        return stringbuf.toString();
  +    /**
  +     * Receive notification about the process writing
  +     * to standard output.
  +     */
  +    public void stdout( final String line )
  +    {
  +        if( m_changelist )
  +        {
  +            changelist_stdout( line );
  +        }
  +        else
  +        {
  +            change_stdout( line );
  +        }
       }
   
       public void execute()
           throws TaskException
       {
  +        if( m_emptyChangeList == null )
  +        {
  +            m_emptyChangeList = getEmptyChangeList();
  +        }
   
  -        if( emptyChangeList == null )
  -            emptyChangeList = getEmptyChangeList();
  -        final Project myProj = getProject();
  -
  -        P4Handler handler =
  -            new P4HandlerAdapter()
  -            {
  -                public void process( String line )
  -                {
  -                    if( util.match( "/Change/", line ) )
  -                    {
  -
  -                        //Remove any non-numerical chars - should leave the change number
  -                        line = util.substitute( "s/[^0-9]//g", line );
  -
  -                        int changenumber = Integer.parseInt( line );
  -                        getLogger().info( "Change Number is " + changenumber );
  -                        setProperty( "p4.change", "" + changenumber );
  -
  -                    }
  -                    else if( util.match( "/error/", line ) )
  -                    {
  -                        throw new TaskException( "Perforce Error, check client settings
and/or server" );
  -                    }
  -
  -                }
  -            };
  -
  -        handler.setOutput( emptyChangeList );
  +        //handler.setOutput( m_emptyChangeList );
   
  -        execP4Command( "change -i", handler );
  +        execP4Command( "change -i", null );
       }
   
       /**
  @@ -122,7 +83,7 @@
        * @see < a href="http://jakarta.apache.org/oro/api/org/apache/oro/text/perl/Perl5Util.html#substitute(java.lang.String,%20java.lang.String)">
        *      Oro</a>
        */
  -    protected String backslash( String value )
  +    private String backslash( String value )
       {
           final StringBuffer buf = new StringBuffer( value.length() );
           final int len = value.length();
  @@ -138,4 +99,56 @@
           return buf.toString();
       }
   
  -}//EoF
  +    private void changelist_stdout( String line )
  +    {
  +        if( !util.match( "/^#/", line ) )
  +        {
  +            if( util.match( "/error/", line ) )
  +            {
  +                getLogger().debug( "Client Error" );
  +                registerError( new TaskException( "Perforce Error, check client settings
and/or server" ) );
  +            }
  +            else if( util.match( "/<enter description here>/", line ) )
  +            {
  +
  +                // we need to escape the description in case there are /
  +                m_description = backslash( m_description );
  +                line = util.substitute( "s/<enter description here>/" + m_description
+ "/", line );
  +
  +            }
  +            else if( util.match( "/\\/\\//", line ) )
  +            {
  +                //Match "//" for begining of depot filespec
  +                return;
  +            }
  +
  +            m_changelistData.append( line );
  +            m_changelistData.append( "\n" );
  +        }
  +    }
  +
  +    private void change_stdout( String line )
  +    {
  +        if( util.match( "/Change/", line ) )
  +        {
  +            //Remove any non-numerical chars - should leave the change number
  +            line = util.substitute( "s/[^0-9]//g", line );
  +
  +            final int changenumber = Integer.parseInt( line );
  +            getLogger().info( "Change Number is " + changenumber );
  +            try
  +            {
  +                setProperty( "p4.change", "" + changenumber );
  +            }
  +            catch( final TaskException te )
  +            {
  +                registerError( te );
  +            }
  +        }
  +        else if( util.match( "/error/", line ) )
  +        {
  +            final String message = "Perforce Error, check client settings and/or server";
  +            registerError( new TaskException( message ) );
  +        }
  +    }
  +}
  
  
  
  1.7       +59 -53    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
  
  Index: P4Counter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- P4Counter.java	23 Dec 2001 14:22:47 -0000	1.6
  +++ P4Counter.java	6 Jan 2002 02:30:43 -0000	1.7
  @@ -8,7 +8,6 @@
   package org.apache.tools.ant.taskdefs.optional.perforce;
   
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.tools.ant.Project;
   
   /**
    * P4Counter - Obtain or set the value of a counter. P4Counter can be used to
  @@ -20,48 +19,37 @@
    *
    * @author <a href="mailto:kirk@radik.com">Kirk Wylie</a>
    */
  -
  -public class P4Counter extends P4Base
  +public class P4Counter
  +    extends P4Base
   {
  -    public String counter = null;
  -    public String property = null;
  -    public boolean shouldSetValue = false;
  -    public boolean shouldSetProperty = false;
  -    public int value = 0;
  +    private String m_counter;
  +    private String m_property;
  +    private boolean m_shouldSetValue;
  +    private int m_value;
   
  -    public void setName( String counter )
  +    public void setName( final String counter )
       {
  -        this.counter = counter;
  +        m_counter = counter;
       }
   
  -    public void setProperty( String property )
  +    public void setProperty( final String property )
       {
  -        this.property = property;
  -        shouldSetProperty = true;
  +        m_property = property;
       }
   
  -    public void setValue( int value )
  +    public void setValue( final int value )
       {
  -        this.value = value;
  -        shouldSetValue = true;
  +        m_value = value;
  +        m_shouldSetValue = true;
       }
   
       public void execute()
           throws TaskException
       {
  +        validate();
   
  -        if( ( counter == null ) || counter.length() == 0 )
  -        {
  -            throw new TaskException( "No counter specified to retrieve" );
  -        }
  -
  -        if( shouldSetValue && shouldSetProperty )
  -        {
  -            throw new TaskException( "Cannot both set the value of the property and retrieve
the value of the property." );
  -        }
  -
  -        String command = "counter " + P4CmdOpts + " " + counter;
  -        if( !shouldSetProperty )
  +        String command = "counter " + m_p4CmdOpts + " " + m_counter;
  +        if( !shouldSetProperty() )
           {
               // NOTE kirk@radik.com 04-April-2001 -- If you put in the -s, you
               // have to start running through regular expressions here. Much easier
  @@ -69,38 +57,56 @@
               // and strip it later.
               command = "-s " + command;
           }
  -        if( shouldSetValue )
  +        if( m_shouldSetValue )
           {
  -            command += " " + value;
  +            command += " " + m_value;
           }
   
  -        if( shouldSetProperty )
  -        {
  -            final Project myProj = getProject();
  -
  -            P4Handler handler =
  -                new P4HandlerAdapter()
  -                {
  -                    public void process( String line )
  -                    {
  -                        getLogger().debug( "P4Counter retrieved line \"" + line + "\""
);
  -                        try
  -                        {
  -                            value = Integer.parseInt( line );
  -                            setProperty( property, "" + value );
  -                        }
  -                        catch( NumberFormatException nfe )
  -                        {
  -                            throw new TaskException( "Perforce error. Could not retrieve
counter value." );
  -                        }
  -                    }
  -                };
  +        execP4Command( command, null );
  +    }
   
  -            execP4Command( command, handler );
  +    public void stdout( final String line )
  +    {
  +        if( shouldSetProperty() )
  +        {
  +            super.stdout( line );
           }
           else
           {
  -            execP4Command( command, new SimpleP4OutputHandler( this ) );
  +            getLogger().debug( "P4Counter retrieved line \"" + line + "\"" );
  +            try
  +            {
  +                m_value = Integer.parseInt( line );
  +                setProperty( m_property, "" + m_value );
  +            }
  +            catch( final TaskException te )
  +            {
  +                registerError( te );
  +            }
  +            catch( NumberFormatException nfe )
  +            {
  +                final String message = "Perforce error. Could not retrieve counter value.";
  +                registerError( new TaskException( message ) );
  +            }
           }
  +    }
  +
  +    private void validate()
  +        throws TaskException
  +    {
  +        if( ( m_counter == null ) || m_counter.length() == 0 )
  +        {
  +            throw new TaskException( "No counter specified to retrieve" );
  +        }
  +
  +        if( m_shouldSetValue && shouldSetProperty() )
  +        {
  +            throw new TaskException( "Cannot both set the value of the property and retrieve
the value of the property." );
  +        }
  +    }
  +
  +    private boolean shouldSetProperty()
  +    {
  +        return ( null == m_property );
       }
   }
  
  
  
  1.4       +9 -3      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java
  
  Index: P4Delete.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- P4Delete.java	23 Dec 2001 06:31:59 -0000	1.3
  +++ P4Delete.java	6 Jan 2002 02:30:43 -0000	1.4
  @@ -34,9 +34,15 @@
           throws TaskException
       {
           if( change != null )
  -            P4CmdOpts = "-c " + change;
  -        if( P4View == null )
  +        {
  +            m_p4CmdOpts = "-c " + change;
  +        }
  +        if( m_p4View == null )
  +        {
               throw new TaskException( "No view specified to delete" );
  -        execP4Command( "-s delete " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(
this ) );
  +        }
  +
  +        final String command = "-s delete " + m_p4CmdOpts + " " + m_p4View;
  +        execP4Command( command, null );
       }
   }
  
  
  
  1.4       +9 -3      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java
  
  Index: P4Edit.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- P4Edit.java	23 Dec 2001 06:31:59 -0000	1.3
  +++ P4Edit.java	6 Jan 2002 02:30:43 -0000	1.4
  @@ -31,9 +31,15 @@
           throws TaskException
       {
           if( change != null )
  -            P4CmdOpts = "-c " + change;
  -        if( P4View == null )
  +        {
  +            m_p4CmdOpts = "-c " + change;
  +        }
  +        if( m_p4View == null )
  +        {
               throw new TaskException( "No view specified to edit" );
  -        execP4Command( "-s edit " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(
this ) );
  +        }
  +
  +        final String command = "-s edit " + m_p4CmdOpts + " " + m_p4View;
  +        execP4Command( command, null );
       }
   }
  
  
  
  1.4       +4 -3      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java
  
  Index: P4Have.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- P4Have.java	23 Dec 2001 06:31:59 -0000	1.3
  +++ P4Have.java	6 Jan 2002 02:30:43 -0000	1.4
  @@ -15,12 +15,13 @@
    *
    * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
    */
  -public class P4Have extends P4Base
  +public class P4Have
  +    extends P4Base
   {
  -
       public void execute()
           throws TaskException
       {
  -        execP4Command( "have " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler( this
) );
  +        final String command = "have " + m_p4CmdOpts + " " + m_p4View;
  +        execP4Command( command, null );
       }
   }
  
  
  
  1.5       +69 -89    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java
  
  Index: P4Label.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- P4Label.java	23 Dec 2001 14:22:47 -0000	1.4
  +++ P4Label.java	6 Jan 2002 02:30:43 -0000	1.5
  @@ -20,134 +20,114 @@
    *
    * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
    */
  -public class P4Label extends P4Base
  +public class P4Label
  +    extends P4Base
   {
  -    protected String desc;
  -    protected String lock;
  +    private String m_description;
  +    private String m_lock;
  +    private String m_name;
  +    private boolean m_getLabelSpec;
  +    private StringBuffer m_labelSpec;
   
  -    protected String name;
  -
  -    public void setDesc( String desc )
  +    public void setDesc( final String description )
       {
  -        this.desc = desc;
  +        m_description = description;
       }
   
  -    public void setLock( String lock )
  +    public void setLock( final String lock )
       {
  -        this.lock = lock;
  +        m_lock = lock;
       }
   
  -    public void setName( String name )
  +    public void setName( final String name )
       {
  -        this.name = name;
  +        m_name = name;
       }
   
  -    public void execute()
  -        throws TaskException
  +    public void stdout( String line )
       {
  -        getLogger().info( "P4Label exec:" );
  +        getLogger().debug( line );
   
  -        if( P4View == null || P4View.length() < 1 )
  +        if( null != m_labelSpec )
           {
  -            getLogger().warn( "View not set, assuming //depot/..." );
  -            P4View = "//depot/...";
  -        }
  +            if( util.match( "/^Options:/", line ) )
  +            {
  +                line = "Options: " + m_lock;
  +            }
   
  -        if( desc == null || desc.length() < 1 )
  -        {
  -            getLogger().warn( "Label Description not set, assuming 'AntLabel'" );
  -            desc = "AntLabel";
  +            m_labelSpec.append( line + "\n" );
           }
  +    }
   
  -        if( lock != null && !lock.equalsIgnoreCase( "locked" ) )
  -        {
  -            getLogger().warn( "lock attribute invalid - ignoring" );
  -        }
  +    public void execute()
  +        throws TaskException
  +    {
  +        getLogger().info( "P4Label exec:" );
   
  -        if( name == null || name.length() < 1 )
  -        {
  -            SimpleDateFormat formatter = new SimpleDateFormat( "yyyy.MM.dd-hh:mm" );
  -            Date now = new Date();
  -            name = "AntLabel-" + formatter.format( now );
  -            getLogger().warn( "name not set, assuming '" + name + "'" );
  -        }
  +        validate();
   
           //We have to create a unlocked label first
           String newLabel =
  -            "Label: " + name + "\n" +
  -            "Description: " + desc + "\n" +
  +            "Label: " + m_name + "\n" +
  +            "Description: " + m_description + "\n" +
               "Options: unlocked\n" +
  -            "View: " + P4View + "\n";
  +            "View: " + m_p4View + "\n";
   
  -        P4Handler handler =
  -            new P4HandlerAdapter()
  -            {
  -                public void process( String line )
  -                {
  -                    getLogger().debug( line );
  -                }
  -            };
  -
  -        handler.setOutput( newLabel );
  -
  -        execP4Command( "label -i", handler );
  -
  -        execP4Command( "labelsync -l " + name,
  -                       new P4HandlerAdapter()
  -                       {
  -                           public void process( String line )
  -                           {
  -                               getLogger().debug( line );
  -                           }
  -                       } );
  +        //handler.setOutput( newLabel );
  +        execP4Command( "label -i", null );
  +        execP4Command( "labelsync -l " + m_name, null );
   
  -        getLogger().info( "Created Label " + name + " (" + desc + ")" );
  +        getLogger().info( "Created Label " + m_name + " (" + m_description + ")" );
   
           //Now lock if required
  -        if( lock != null && lock.equalsIgnoreCase( "locked" ) )
  +        if( m_lock != null && m_lock.equalsIgnoreCase( "locked" ) )
           {
   
               getLogger().info( "Modifying lock status to 'locked'" );
   
  -            final StringBuffer labelSpec = new StringBuffer();
  -
               //Read back the label spec from perforce,
               //Replace Options
               //Submit back to Perforce
   
  -            handler =
  -                new P4HandlerAdapter()
  -                {
  -                    public void process( String line )
  -                    {
  -                        getLogger().debug( line );
  -
  -                        if( util.match( "/^Options:/", line ) )
  -                        {
  -                            line = "Options: " + lock;
  -                        }
  -
  -                        labelSpec.append( line + "\n" );
  -                    }
  -                };
  +            m_labelSpec = new StringBuffer();
  +            execP4Command( "label -o " + m_name, null );
  +            final String labelSpec = m_labelSpec.toString();
  +            getLogger().debug( labelSpec );
   
  -            execP4Command( "label -o " + name, handler );
  -            getLogger().debug( labelSpec.toString() );
  +            //reset labelSpec to null so output is not written to it anymore
  +            m_labelSpec = null;
   
               getLogger().debug( "Now locking label..." );
  -            handler =
  -                new P4HandlerAdapter()
  -                {
  -                    public void process( String line )
  -                    {
  -                        getLogger().debug( line );
  -                    }
  -                };
  +            //handler.setOutput( labelSpec );
  +            execP4Command( "label -i", null );
  +        }
  +    }
   
  -            handler.setOutput( labelSpec.toString() );
  -            execP4Command( "label -i", handler );
  +    private void validate()
  +    {
  +        if( m_p4View == null || m_p4View.length() < 1 )
  +        {
  +            getLogger().warn( "View not set, assuming //depot/..." );
  +            m_p4View = "//depot/...";
           }
   
  -    }
  +        if( m_description == null || m_description.length() < 1 )
  +        {
  +            getLogger().warn( "Label Description not set, assuming 'AntLabel'" );
  +            m_description = "AntLabel";
  +        }
  +
  +        if( m_lock != null && !m_lock.equalsIgnoreCase( "locked" ) )
  +        {
  +            getLogger().warn( "lock attribute invalid - ignoring" );
  +        }
   
  +        if( m_name == null || m_name.length() < 1 )
  +        {
  +            SimpleDateFormat formatter = new SimpleDateFormat( "yyyy.MM.dd-hh:mm" );
  +            Date now = new Date();
  +            m_name = "AntLabel-" + formatter.format( now );
  +            getLogger().warn( "name not set, assuming '" + m_name + "'" );
  +        }
  +    }
   }
  
  
  
  1.4       +13 -10    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Reopen.java
  
  Index: P4Reopen.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Reopen.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- P4Reopen.java	23 Dec 2001 06:31:59 -0000	1.3
  +++ P4Reopen.java	6 Jan 2002 02:30:43 -0000	1.4
  @@ -14,27 +14,30 @@
    *
    * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
    */
  -
  -public class P4Reopen extends P4Base
  +public class P4Reopen
  +    extends P4Base
   {
  +    private String m_toChange = "";
   
  -    private String toChange = "";
  -
  -    public void setToChange( String toChange )
  +    public void setToChange( final String toChange )
           throws TaskException
       {
           if( toChange == null && !toChange.equals( "" ) )
  +        {
               throw new TaskException( "P4Reopen: tochange cannot be null or empty" );
  +        }
   
  -        this.toChange = toChange;
  +        m_toChange = toChange;
       }
   
       public void execute()
           throws TaskException
       {
  -        if( P4View == null )
  -            if( P4View == null )
  -                throw new TaskException( "No view specified to reopen" );
  -        execP4Command( "-s reopen -c " + toChange + " " + P4View, new SimpleP4OutputHandler(
this ) );
  +        if( m_p4View == null )
  +        {
  +            throw new TaskException( "No view specified to reopen" );
  +        }
  +        final String message = "-s reopen -c " + m_toChange + " " + m_p4View;
  +        execP4Command( message, null );
       }
   }
  
  
  
  1.4       +18 -14    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java
  
  Index: P4Revert.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- P4Revert.java	23 Dec 2001 06:31:59 -0000	1.3
  +++ P4Revert.java	6 Jan 2002 02:30:43 -0000	1.4
  @@ -14,32 +14,31 @@
    *
    * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
    */
  -
  -public class P4Revert extends P4Base
  +public class P4Revert
  +    extends P4Base
   {
  +    private String m_revertChange;
  +    private boolean m_onlyUnchanged;
   
  -    private String revertChange = null;
  -    private boolean onlyUnchanged = false;
  -
  -    public void setChange( String revertChange )
  +    public void setChange( final String revertChange )
           throws TaskException
       {
           if( revertChange == null && !revertChange.equals( "" ) )
  +        {
               throw new TaskException( "P4Revert: change cannot be null or empty" );
  +        }
   
  -        this.revertChange = revertChange;
  -
  +        m_revertChange = revertChange;
       }
   
       public void setRevertOnlyUnchanged( boolean onlyUnchanged )
       {
  -        this.onlyUnchanged = onlyUnchanged;
  +        this.m_onlyUnchanged = onlyUnchanged;
       }
   
       public void execute()
           throws TaskException
       {
  -
           /*
            * Here we can either revert any unchanged files in a changelist
            * or
  @@ -49,12 +48,17 @@
            * The whole process also accepts a p4 filespec
            */
           String p4cmd = "-s revert";
  -        if( onlyUnchanged )
  +        if( m_onlyUnchanged )
  +        {
               p4cmd += " -a";
  +        }
   
  -        if( revertChange != null )
  -            p4cmd += " -c " + revertChange;
  +        if( m_revertChange != null )
  +        {
  +            p4cmd += " -c " + m_revertChange;
  +        }
   
  -        execP4Command( p4cmd + " " + P4View, new SimpleP4OutputHandler( this ) );
  +        final String command = p4cmd + " " + m_p4View;
  +        execP4Command( command, null );
       }
   }
  
  
  
  1.5       +16 -17    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java
  
  Index: P4Submit.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- P4Submit.java	23 Dec 2001 14:22:47 -0000	1.4
  +++ P4Submit.java	6 Jan 2002 02:30:43 -0000	1.5
  @@ -18,32 +18,32 @@
    *
    * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
    */
  -public class P4Submit extends P4Base
  +public class P4Submit
  +    extends P4Base
   {
  -
       //ToDo: If dealing with default cl need to parse out <enter description here>
  -    public String change;
  +    private String m_change;
  +
  +    public void setChange( final String change )
  +    {
  +        m_change = change;
  +    }
   
  -    public void setChange( String change )
  +    /**
  +     * Receive notification about the process writing
  +     * to standard output.
  +     */
  +    public void stdout( final String line )
       {
  -        this.change = change;
  +        getLogger().debug( line );
       }
   
       public void execute()
           throws TaskException
       {
  -        if( change != null )
  +        if( m_change != null )
           {
  -            execP4Command( "submit -c " + change,
  -                           new P4HandlerAdapter()
  -                           {
  -                               public void process( String line )
  -                               {
  -                                   getLogger().debug( line );
  -                               }
  -                           }
  -            );
  -
  +            execP4Command( "submit -c " + m_change, this );
           }
           else
           {
  @@ -52,5 +52,4 @@
               throw new TaskException( "No change specified (no support for default change
yet...." );
           }
       }
  -
   }
  
  
  
  1.5       +18 -15    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java
  
  Index: P4Sync.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- P4Sync.java	23 Dec 2001 14:22:47 -0000	1.4
  +++ P4Sync.java	6 Jan 2002 02:30:43 -0000	1.5
  @@ -84,44 +84,47 @@
    */
   public class P4Sync extends P4Base
   {
  -    private String syncCmd = "";
  +    private String m_syncCmd = "";
  +    private String m_label;
   
  -    String label;
  -
  -    public void setForce( String force )
  +    public void setForce( final String force )
           throws TaskException
       {
  -        if( force == null && !label.equals( "" ) )
  +        if( force == null && !m_label.equals( "" ) )
  +        {
               throw new TaskException( "P4Sync: If you want to force, set force to non-null
string!" );
  -        P4CmdOpts = "-f";
  +        }
  +        m_p4CmdOpts = "-f";
       }
   
       public void setLabel( String label )
           throws TaskException
       {
           if( label == null && !label.equals( "" ) )
  +        {
               throw new TaskException( "P4Sync: Labels cannot be Null or Empty" );
  +        }
   
  -        this.label = label;
  -
  +        m_label = label;
       }
   
       public void execute()
           throws TaskException
       {
  -
  -        if( P4View != null )
  +        if( m_p4View != null )
           {
  -            syncCmd = P4View;
  +            m_syncCmd = m_p4View;
           }
   
  -        if( label != null && !label.equals( "" ) )
  +        if( m_label != null && !m_label.equals( "" ) )
           {
  -            syncCmd = syncCmd + "@" + label;
  +            m_syncCmd = m_syncCmd + "@" + m_label;
           }
   
  -        getLogger().debug( "Execing sync " + P4CmdOpts + " " + syncCmd );
  +        final String message = "Execing sync " + m_p4CmdOpts + " " + m_syncCmd;
  +        getLogger().debug( message );
   
  -        execP4Command( "-s sync " + P4CmdOpts + " " + syncCmd, new SimpleP4OutputHandler(
this ) );
  +        final String command = "-s sync " + m_p4CmdOpts + " " + m_syncCmd;
  +        execP4Command( command, null );
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message