Browse Source

Started to move the perforce tasks towards the new Execute2 abstraction

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270591 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
0db510656a
32 changed files with 822 additions and 1066 deletions
  1. +12
    -6
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java
  2. +94
    -56
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java
  3. +90
    -77
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java
  4. +59
    -53
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
  5. +9
    -3
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java
  6. +9
    -3
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java
  7. +0
    -27
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java
  8. +0
    -91
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java
  9. +4
    -3
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java
  10. +69
    -89
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java
  11. +0
    -23
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4OutputHandler.java
  12. +13
    -10
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Reopen.java
  13. +18
    -14
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java
  14. +16
    -17
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java
  15. +18
    -15
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java
  16. +0
    -46
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java
  17. +12
    -6
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java
  18. +94
    -56
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java
  19. +90
    -77
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java
  20. +59
    -53
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
  21. +9
    -3
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java
  22. +9
    -3
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java
  23. +0
    -27
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java
  24. +0
    -91
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java
  25. +4
    -3
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java
  26. +69
    -89
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java
  27. +0
    -23
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4OutputHandler.java
  28. +13
    -10
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Reopen.java
  29. +18
    -14
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java
  30. +16
    -17
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java
  31. +18
    -15
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java
  32. +0
    -46
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java

+ 12
- 6
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java View File

@@ -111,12 +111,12 @@ public class P4Add extends P4Base
throws TaskException 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(); StringBuffer filelist = new StringBuffer();


@@ -152,10 +152,16 @@ public class P4Add extends P4Base


} }


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 );
} }
} }

+ 94
- 56
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java View File

@@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs.optional.perforce;


import java.io.IOException; import java.io.IOException;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.ExecOutputHandler;
import org.apache.oro.text.perl.Perl5Util; 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; import org.apache.tools.ant.types.Commandline;


/** /**
@@ -26,31 +27,32 @@ import org.apache.tools.ant.types.Commandline;
* @see P4Label * @see P4Label
* @see org.apache.tools.ant.taskdefs.Exec * @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? * Perl5 regexp in Java - cool eh?
*/ */
protected Perl5Util util = null;
protected Perl5Util util;


//P4 runtime directives //P4 runtime directives
/** /**
* Perforce Server Port (eg KM01:1666) * Perforce Server Port (eg KM01:1666)
*/ */
protected String P4Port = "";
protected String m_p4Port = "";
/** /**
* Perforce Client (eg myclientspec) * Perforce Client (eg myclientspec)
*/ */
protected String P4Client = "";
protected String m_p4Client = "";
/** /**
* Perforce User (eg fbloggs) * Perforce User (eg fbloggs)
*/ */
protected String P4User = "";
protected String m_p4User = "";
/** /**
* Perforce view for commands (eg //projects/foobar/main/source/... ) * Perforce view for commands (eg //projects/foobar/main/source/... )
*/ */
protected String P4View = "";
protected String m_p4View = "";


//P4 g-opts and cmd opts (rtfm) //P4 g-opts and cmd opts (rtfm)
/** /**
@@ -60,36 +62,38 @@ public abstract class P4Base extends org.apache.tools.ant.Task
/** /**
* Perforce command opts. Forms half of low level API * 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) * The OS shell to use (cmd.exe or /bin/sh)
*/ */
protected String shell; protected String shell;


private TaskException m_error;

public void setClient( String P4Client ) public void setClient( String P4Client )
{ {
this.P4Client = "-c" + P4Client;
this.m_p4Client = "-c" + P4Client;
} }


public void setCmdopts( String P4CmdOpts ) public void setCmdopts( String P4CmdOpts )
{ {
this.P4CmdOpts = P4CmdOpts;
this.m_p4CmdOpts = P4CmdOpts;
} }


//Setters called by Ant //Setters called by Ant
public void setPort( String P4Port ) public void setPort( String P4Port )
{ {
this.P4Port = "-p" + P4Port;
this.m_p4Port = "-p" + P4Port;
} }


public void setUser( String P4User ) public void setUser( String P4User )
{ {
this.P4User = "-u" + P4User;
this.m_p4User = "-u" + P4User;
} }


public void setView( String P4View ) public void setView( String P4View )
{ {
this.P4View = P4View;
this.m_p4View = P4View;
} }


private void prepare() private void prepare()
@@ -98,19 +102,19 @@ public abstract class P4Base extends org.apache.tools.ant.Task


//Get default P4 settings from environment - Mark would have done something cool with //Get default P4 settings from environment - Mark would have done something cool with
//introspection here.....:-) //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() public void execute()
@@ -123,36 +127,32 @@ public abstract class P4Base extends org.apache.tools.ant.Task


/** /**
* Execute P4 command assembled by subclasses. * 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 throws TaskException
{ {
try 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... //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 = ""; String cmdl = "";
for( int i = 0; i < cmdline.length; i++ ) for( int i = 0; i < cmdline.length; i++ )
{ {
@@ -160,12 +160,14 @@ public abstract class P4Base extends org.apache.tools.ant.Task
} }


getLogger().debug( "Execing " + cmdl ); getLogger().debug( "Execing " + cmdl );

if( handler == null ) 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 try
{ {
@@ -175,21 +177,57 @@ public abstract class P4Base extends org.apache.tools.ant.Task
{ {
throw new TaskException( "Error", e ); 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 ) catch( Exception e )
{ {
throw new TaskException( "Problem exec'ing P4 command: " + e.getMessage() ); 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 )
{
}
} }

+ 90
- 77
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java View File

@@ -8,7 +8,6 @@
package org.apache.tools.ant.taskdefs.optional.perforce; package org.apache.tools.ant.taskdefs.optional.perforce;


import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.Project;


/** /**
* P4Change - grab a new changelist from Perforce. P4Change creates a new * P4Change - grab a new changelist from Perforce. P4Change creates a new
@@ -19,97 +18,59 @@ import org.apache.tools.ant.Project;
* @see P4Edit * @see P4Edit
* @see P4Submit * @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. * 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 throws TaskException
{ {
final StringBuffer stringbuf = new StringBuffer();

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 stringbuf.toString();
m_changelist = true;
execP4Command( "change -o", null );
m_changelist = false;

return m_changelistData.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() public void execute()
throws TaskException 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 @@ public class P4Change extends P4Base
* @see < a href="http://jakarta.apache.org/oro/api/org/apache/oro/text/perl/Perl5Util.html#substitute(java.lang.String,%20java.lang.String)"> * @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> * Oro</a>
*/ */
protected String backslash( String value )
private String backslash( String value )
{ {
final StringBuffer buf = new StringBuffer( value.length() ); final StringBuffer buf = new StringBuffer( value.length() );
final int len = value.length(); final int len = value.length();
@@ -138,4 +99,56 @@ public class P4Change extends P4Base
return buf.toString(); 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 ) );
}
}
}

+ 59
- 53
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java View File

@@ -8,7 +8,6 @@
package org.apache.tools.ant.taskdefs.optional.perforce; package org.apache.tools.ant.taskdefs.optional.perforce;


import org.apache.myrmidon.api.TaskException; 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 * P4Counter - Obtain or set the value of a counter. P4Counter can be used to
@@ -20,48 +19,37 @@ import org.apache.tools.ant.Project;
* *
* @author <a href="mailto:kirk@radik.com">Kirk Wylie</a> * @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() public void execute()
throws TaskException 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 // NOTE kirk@radik.com 04-April-2001 -- If you put in the -s, you
// have to start running through regular expressions here. Much easier // have to start running through regular expressions here. Much easier
@@ -69,38 +57,56 @@ public class P4Counter extends P4Base
// and strip it later. // and strip it later.
command = "-s " + command; 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 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 );
}
} }

+ 9
- 3
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java View File

@@ -34,9 +34,15 @@ public class P4Delete extends P4Base
throws TaskException throws TaskException
{ {
if( change != null ) 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" ); 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 );
} }
} }

+ 9
- 3
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java View File

@@ -31,9 +31,15 @@ public class P4Edit extends P4Base
throws TaskException throws TaskException
{ {
if( change != null ) 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" ); 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 );
} }
} }

+ 0
- 27
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java View File

@@ -1,27 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler;

/**
* Interface for p4 job output stream handler. Classes implementing this
* interface can be called back by P4Base.execP4Command();
*
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
*/
public interface P4Handler extends ExecuteStreamHandler
{

public void process( String line )
throws TaskException;

public void setOutput( String line )
throws TaskException;
}

+ 0
- 91
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java View File

@@ -1,91 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import org.apache.myrmidon.api.TaskException;

public abstract class P4HandlerAdapter implements P4Handler
{

String p4input = "";//Input
InputStream es;//OUtput
InputStream is;

OutputStream os;

//set any data to be written to P4's stdin - messy, needs work
public void setOutput( String p4Input )
{
this.p4input = p4Input;
}

public void setProcessErrorStream( InputStream is )
throws IOException
{
this.es = is;
}//Error

public void setProcessInputStream( OutputStream os )
throws IOException
{
this.os = os;
}

public void setProcessOutputStream( InputStream is )
throws IOException
{
this.is = is;
}

public abstract void process( String line );

public void start()
throws TaskException
{

try
{
//First write any output to P4
if( p4input != null && p4input.length() > 0 && os != null )
{
os.write( p4input.getBytes() );
os.flush();
os.close();
}

//Now read any input and process

BufferedReader input = new BufferedReader(
new InputStreamReader(
new SequenceInputStream( is, es ) ) );

String line;
while( ( line = input.readLine() ) != null )
{
process( line );
}

input.close();

}
catch( Exception e )
{
throw new TaskException( "Error", e );
}
}

public void stop()
{
}
}

+ 4
- 3
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java View File

@@ -15,12 +15,13 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
*/ */
public class P4Have extends P4Base
public class P4Have
extends P4Base
{ {

public void execute() public void execute()
throws TaskException throws TaskException
{ {
execP4Command( "have " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler( this ) );
final String command = "have " + m_p4CmdOpts + " " + m_p4View;
execP4Command( command, null );
} }
} }

+ 69
- 89
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java View File

@@ -20,134 +20,114 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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 //We have to create a unlocked label first
String newLabel = String newLabel =
"Label: " + name + "\n" +
"Description: " + desc + "\n" +
"Label: " + m_name + "\n" +
"Description: " + m_description + "\n" +
"Options: unlocked\n" + "Options: unlocked\n" +
"View: " + P4View + "\n";

P4Handler handler =
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
}
};
"View: " + m_p4View + "\n";


handler.setOutput( newLabel );
//handler.setOutput( newLabel );
execP4Command( "label -i", null );
execP4Command( "labelsync -l " + m_name, null );


execP4Command( "label -i", handler );

execP4Command( "labelsync -l " + name,
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
}
} );

getLogger().info( "Created Label " + name + " (" + desc + ")" );
getLogger().info( "Created Label " + m_name + " (" + m_description + ")" );


//Now lock if required //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'" ); getLogger().info( "Modifying lock status to 'locked'" );


final StringBuffer labelSpec = new StringBuffer();

//Read back the label spec from perforce, //Read back the label spec from perforce,
//Replace Options //Replace Options
//Submit back to Perforce //Submit back to Perforce


handler =
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
m_labelSpec = new StringBuffer();
execP4Command( "label -o " + m_name, null );
final String labelSpec = m_labelSpec.toString();
getLogger().debug( labelSpec );


if( util.match( "/^Options:/", line ) )
{
line = "Options: " + lock;
}
//reset labelSpec to null so output is not written to it anymore
m_labelSpec = null;


labelSpec.append( line + "\n" );
}
};
getLogger().debug( "Now locking label..." );
//handler.setOutput( labelSpec );
execP4Command( "label -i", null );
}
}


execP4Command( "label -o " + name, handler );
getLogger().debug( labelSpec.toString() );
private void validate()
{
if( m_p4View == null || m_p4View.length() < 1 )
{
getLogger().warn( "View not set, assuming //depot/..." );
m_p4View = "//depot/...";
}


getLogger().debug( "Now locking label..." );
handler =
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
}
};

handler.setOutput( labelSpec.toString() );
execP4Command( "label -i", handler );
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 + "'" );
}
}
} }

+ 0
- 23
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4OutputHandler.java View File

@@ -1,23 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import org.apache.myrmidon.api.TaskException;

/**
* Interface for p4 job output stream handler. Classes implementing this
* interface can be called back by P4Base.execP4Command();
*
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
*/
public interface P4OutputHandler
{

public void process( String line )
throws TaskException;
}

+ 13
- 10
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Reopen.java View File

@@ -14,27 +14,30 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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 throws TaskException
{ {
if( toChange == null && !toChange.equals( "" ) ) if( toChange == null && !toChange.equals( "" ) )
{
throw new TaskException( "P4Reopen: tochange cannot be null or empty" ); throw new TaskException( "P4Reopen: tochange cannot be null or empty" );
}


this.toChange = toChange;
m_toChange = toChange;
} }


public void execute() public void execute()
throws TaskException 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 );
} }
} }

+ 18
- 14
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java View File

@@ -14,32 +14,31 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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 throws TaskException
{ {
if( revertChange == null && !revertChange.equals( "" ) ) if( revertChange == null && !revertChange.equals( "" ) )
{
throw new TaskException( "P4Revert: change cannot be null or empty" ); throw new TaskException( "P4Revert: change cannot be null or empty" );
}


this.revertChange = revertChange;

m_revertChange = revertChange;
} }


public void setRevertOnlyUnchanged( boolean onlyUnchanged ) public void setRevertOnlyUnchanged( boolean onlyUnchanged )
{ {
this.onlyUnchanged = onlyUnchanged;
this.m_onlyUnchanged = onlyUnchanged;
} }


public void execute() public void execute()
throws TaskException throws TaskException
{ {

/* /*
* Here we can either revert any unchanged files in a changelist * Here we can either revert any unchanged files in a changelist
* or * or
@@ -49,12 +48,17 @@ public class P4Revert extends P4Base
* The whole process also accepts a p4 filespec * The whole process also accepts a p4 filespec
*/ */
String p4cmd = "-s revert"; String p4cmd = "-s revert";
if( onlyUnchanged )
if( m_onlyUnchanged )
{
p4cmd += " -a"; 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 );
} }
} }

+ 16
- 17
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java View File

@@ -18,32 +18,32 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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> //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() public void execute()
throws TaskException 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 else
{ {
@@ -52,5 +52,4 @@ public class P4Submit extends P4Base
throw new TaskException( "No change specified (no support for default change yet...." ); throw new TaskException( "No change specified (no support for default change yet...." );
} }
} }

} }

+ 18
- 15
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java View File

@@ -84,44 +84,47 @@ import org.apache.myrmidon.api.TaskException;
*/ */
public class P4Sync extends P4Base 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 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!" ); 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 ) public void setLabel( String label )
throws TaskException throws TaskException
{ {
if( label == null && !label.equals( "" ) ) if( label == null && !label.equals( "" ) )
{
throw new TaskException( "P4Sync: Labels cannot be Null or Empty" ); throw new TaskException( "P4Sync: Labels cannot be Null or Empty" );
}


this.label = label;

m_label = label;
} }


public void execute() public void execute()
throws TaskException 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 );
} }
} }

+ 0
- 46
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java View File

@@ -1,46 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import org.apache.myrmidon.api.TaskException;

public class SimpleP4OutputHandler
extends P4HandlerAdapter
{
private P4Base parent;

public SimpleP4OutputHandler( P4Base parent )
{
this.parent = parent;
}

public void process( String line )
throws TaskException
{
if( parent.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( parent.util.match( "/error:/", line ) && !parent.util.match( "/up-to-date/", line ) )
{
throw new TaskException( line );
}

parent.getLogger().info( parent.util.substitute( "s/^.*: //", line ) );

}
}

+ 12
- 6
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java View File

@@ -111,12 +111,12 @@ public class P4Add extends P4Base
throws TaskException 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(); StringBuffer filelist = new StringBuffer();


@@ -152,10 +152,16 @@ public class P4Add extends P4Base


} }


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 );
} }
} }

+ 94
- 56
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java View File

@@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs.optional.perforce;


import java.io.IOException; import java.io.IOException;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.ExecOutputHandler;
import org.apache.oro.text.perl.Perl5Util; 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; import org.apache.tools.ant.types.Commandline;


/** /**
@@ -26,31 +27,32 @@ import org.apache.tools.ant.types.Commandline;
* @see P4Label * @see P4Label
* @see org.apache.tools.ant.taskdefs.Exec * @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? * Perl5 regexp in Java - cool eh?
*/ */
protected Perl5Util util = null;
protected Perl5Util util;


//P4 runtime directives //P4 runtime directives
/** /**
* Perforce Server Port (eg KM01:1666) * Perforce Server Port (eg KM01:1666)
*/ */
protected String P4Port = "";
protected String m_p4Port = "";
/** /**
* Perforce Client (eg myclientspec) * Perforce Client (eg myclientspec)
*/ */
protected String P4Client = "";
protected String m_p4Client = "";
/** /**
* Perforce User (eg fbloggs) * Perforce User (eg fbloggs)
*/ */
protected String P4User = "";
protected String m_p4User = "";
/** /**
* Perforce view for commands (eg //projects/foobar/main/source/... ) * Perforce view for commands (eg //projects/foobar/main/source/... )
*/ */
protected String P4View = "";
protected String m_p4View = "";


//P4 g-opts and cmd opts (rtfm) //P4 g-opts and cmd opts (rtfm)
/** /**
@@ -60,36 +62,38 @@ public abstract class P4Base extends org.apache.tools.ant.Task
/** /**
* Perforce command opts. Forms half of low level API * 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) * The OS shell to use (cmd.exe or /bin/sh)
*/ */
protected String shell; protected String shell;


private TaskException m_error;

public void setClient( String P4Client ) public void setClient( String P4Client )
{ {
this.P4Client = "-c" + P4Client;
this.m_p4Client = "-c" + P4Client;
} }


public void setCmdopts( String P4CmdOpts ) public void setCmdopts( String P4CmdOpts )
{ {
this.P4CmdOpts = P4CmdOpts;
this.m_p4CmdOpts = P4CmdOpts;
} }


//Setters called by Ant //Setters called by Ant
public void setPort( String P4Port ) public void setPort( String P4Port )
{ {
this.P4Port = "-p" + P4Port;
this.m_p4Port = "-p" + P4Port;
} }


public void setUser( String P4User ) public void setUser( String P4User )
{ {
this.P4User = "-u" + P4User;
this.m_p4User = "-u" + P4User;
} }


public void setView( String P4View ) public void setView( String P4View )
{ {
this.P4View = P4View;
this.m_p4View = P4View;
} }


private void prepare() private void prepare()
@@ -98,19 +102,19 @@ public abstract class P4Base extends org.apache.tools.ant.Task


//Get default P4 settings from environment - Mark would have done something cool with //Get default P4 settings from environment - Mark would have done something cool with
//introspection here.....:-) //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() public void execute()
@@ -123,36 +127,32 @@ public abstract class P4Base extends org.apache.tools.ant.Task


/** /**
* Execute P4 command assembled by subclasses. * 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 throws TaskException
{ {
try 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... //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 = ""; String cmdl = "";
for( int i = 0; i < cmdline.length; i++ ) for( int i = 0; i < cmdline.length; i++ )
{ {
@@ -160,12 +160,14 @@ public abstract class P4Base extends org.apache.tools.ant.Task
} }


getLogger().debug( "Execing " + cmdl ); getLogger().debug( "Execing " + cmdl );

if( handler == null ) 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 try
{ {
@@ -175,21 +177,57 @@ public abstract class P4Base extends org.apache.tools.ant.Task
{ {
throw new TaskException( "Error", e ); 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 ) catch( Exception e )
{ {
throw new TaskException( "Problem exec'ing P4 command: " + e.getMessage() ); 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 )
{
}
} }

+ 90
- 77
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java View File

@@ -8,7 +8,6 @@
package org.apache.tools.ant.taskdefs.optional.perforce; package org.apache.tools.ant.taskdefs.optional.perforce;


import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.Project;


/** /**
* P4Change - grab a new changelist from Perforce. P4Change creates a new * P4Change - grab a new changelist from Perforce. P4Change creates a new
@@ -19,97 +18,59 @@ import org.apache.tools.ant.Project;
* @see P4Edit * @see P4Edit
* @see P4Submit * @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. * 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 throws TaskException
{ {
final StringBuffer stringbuf = new StringBuffer();

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 stringbuf.toString();
m_changelist = true;
execP4Command( "change -o", null );
m_changelist = false;

return m_changelistData.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() public void execute()
throws TaskException 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 @@ public class P4Change extends P4Base
* @see < a href="http://jakarta.apache.org/oro/api/org/apache/oro/text/perl/Perl5Util.html#substitute(java.lang.String,%20java.lang.String)"> * @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> * Oro</a>
*/ */
protected String backslash( String value )
private String backslash( String value )
{ {
final StringBuffer buf = new StringBuffer( value.length() ); final StringBuffer buf = new StringBuffer( value.length() );
final int len = value.length(); final int len = value.length();
@@ -138,4 +99,56 @@ public class P4Change extends P4Base
return buf.toString(); 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 ) );
}
}
}

+ 59
- 53
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java View File

@@ -8,7 +8,6 @@
package org.apache.tools.ant.taskdefs.optional.perforce; package org.apache.tools.ant.taskdefs.optional.perforce;


import org.apache.myrmidon.api.TaskException; 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 * P4Counter - Obtain or set the value of a counter. P4Counter can be used to
@@ -20,48 +19,37 @@ import org.apache.tools.ant.Project;
* *
* @author <a href="mailto:kirk@radik.com">Kirk Wylie</a> * @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() public void execute()
throws TaskException 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 // NOTE kirk@radik.com 04-April-2001 -- If you put in the -s, you
// have to start running through regular expressions here. Much easier // have to start running through regular expressions here. Much easier
@@ -69,38 +57,56 @@ public class P4Counter extends P4Base
// and strip it later. // and strip it later.
command = "-s " + command; 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 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 );
}
} }

+ 9
- 3
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java View File

@@ -34,9 +34,15 @@ public class P4Delete extends P4Base
throws TaskException throws TaskException
{ {
if( change != null ) 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" ); 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 );
} }
} }

+ 9
- 3
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java View File

@@ -31,9 +31,15 @@ public class P4Edit extends P4Base
throws TaskException throws TaskException
{ {
if( change != null ) 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" ); 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 );
} }
} }

+ 0
- 27
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java View File

@@ -1,27 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler;

/**
* Interface for p4 job output stream handler. Classes implementing this
* interface can be called back by P4Base.execP4Command();
*
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
*/
public interface P4Handler extends ExecuteStreamHandler
{

public void process( String line )
throws TaskException;

public void setOutput( String line )
throws TaskException;
}

+ 0
- 91
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java View File

@@ -1,91 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import org.apache.myrmidon.api.TaskException;

public abstract class P4HandlerAdapter implements P4Handler
{

String p4input = "";//Input
InputStream es;//OUtput
InputStream is;

OutputStream os;

//set any data to be written to P4's stdin - messy, needs work
public void setOutput( String p4Input )
{
this.p4input = p4Input;
}

public void setProcessErrorStream( InputStream is )
throws IOException
{
this.es = is;
}//Error

public void setProcessInputStream( OutputStream os )
throws IOException
{
this.os = os;
}

public void setProcessOutputStream( InputStream is )
throws IOException
{
this.is = is;
}

public abstract void process( String line );

public void start()
throws TaskException
{

try
{
//First write any output to P4
if( p4input != null && p4input.length() > 0 && os != null )
{
os.write( p4input.getBytes() );
os.flush();
os.close();
}

//Now read any input and process

BufferedReader input = new BufferedReader(
new InputStreamReader(
new SequenceInputStream( is, es ) ) );

String line;
while( ( line = input.readLine() ) != null )
{
process( line );
}

input.close();

}
catch( Exception e )
{
throw new TaskException( "Error", e );
}
}

public void stop()
{
}
}

+ 4
- 3
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java View File

@@ -15,12 +15,13 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
*/ */
public class P4Have extends P4Base
public class P4Have
extends P4Base
{ {

public void execute() public void execute()
throws TaskException throws TaskException
{ {
execP4Command( "have " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler( this ) );
final String command = "have " + m_p4CmdOpts + " " + m_p4View;
execP4Command( command, null );
} }
} }

+ 69
- 89
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java View File

@@ -20,134 +20,114 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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 //We have to create a unlocked label first
String newLabel = String newLabel =
"Label: " + name + "\n" +
"Description: " + desc + "\n" +
"Label: " + m_name + "\n" +
"Description: " + m_description + "\n" +
"Options: unlocked\n" + "Options: unlocked\n" +
"View: " + P4View + "\n";

P4Handler handler =
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
}
};
"View: " + m_p4View + "\n";


handler.setOutput( newLabel );
//handler.setOutput( newLabel );
execP4Command( "label -i", null );
execP4Command( "labelsync -l " + m_name, null );


execP4Command( "label -i", handler );

execP4Command( "labelsync -l " + name,
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
}
} );

getLogger().info( "Created Label " + name + " (" + desc + ")" );
getLogger().info( "Created Label " + m_name + " (" + m_description + ")" );


//Now lock if required //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'" ); getLogger().info( "Modifying lock status to 'locked'" );


final StringBuffer labelSpec = new StringBuffer();

//Read back the label spec from perforce, //Read back the label spec from perforce,
//Replace Options //Replace Options
//Submit back to Perforce //Submit back to Perforce


handler =
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
m_labelSpec = new StringBuffer();
execP4Command( "label -o " + m_name, null );
final String labelSpec = m_labelSpec.toString();
getLogger().debug( labelSpec );


if( util.match( "/^Options:/", line ) )
{
line = "Options: " + lock;
}
//reset labelSpec to null so output is not written to it anymore
m_labelSpec = null;


labelSpec.append( line + "\n" );
}
};
getLogger().debug( "Now locking label..." );
//handler.setOutput( labelSpec );
execP4Command( "label -i", null );
}
}


execP4Command( "label -o " + name, handler );
getLogger().debug( labelSpec.toString() );
private void validate()
{
if( m_p4View == null || m_p4View.length() < 1 )
{
getLogger().warn( "View not set, assuming //depot/..." );
m_p4View = "//depot/...";
}


getLogger().debug( "Now locking label..." );
handler =
new P4HandlerAdapter()
{
public void process( String line )
{
getLogger().debug( line );
}
};

handler.setOutput( labelSpec.toString() );
execP4Command( "label -i", handler );
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 + "'" );
}
}
} }

+ 0
- 23
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4OutputHandler.java View File

@@ -1,23 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import org.apache.myrmidon.api.TaskException;

/**
* Interface for p4 job output stream handler. Classes implementing this
* interface can be called back by P4Base.execP4Command();
*
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
*/
public interface P4OutputHandler
{

public void process( String line )
throws TaskException;
}

+ 13
- 10
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Reopen.java View File

@@ -14,27 +14,30 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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 throws TaskException
{ {
if( toChange == null && !toChange.equals( "" ) ) if( toChange == null && !toChange.equals( "" ) )
{
throw new TaskException( "P4Reopen: tochange cannot be null or empty" ); throw new TaskException( "P4Reopen: tochange cannot be null or empty" );
}


this.toChange = toChange;
m_toChange = toChange;
} }


public void execute() public void execute()
throws TaskException 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 );
} }
} }

+ 18
- 14
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java View File

@@ -14,32 +14,31 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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 throws TaskException
{ {
if( revertChange == null && !revertChange.equals( "" ) ) if( revertChange == null && !revertChange.equals( "" ) )
{
throw new TaskException( "P4Revert: change cannot be null or empty" ); throw new TaskException( "P4Revert: change cannot be null or empty" );
}


this.revertChange = revertChange;

m_revertChange = revertChange;
} }


public void setRevertOnlyUnchanged( boolean onlyUnchanged ) public void setRevertOnlyUnchanged( boolean onlyUnchanged )
{ {
this.onlyUnchanged = onlyUnchanged;
this.m_onlyUnchanged = onlyUnchanged;
} }


public void execute() public void execute()
throws TaskException throws TaskException
{ {

/* /*
* Here we can either revert any unchanged files in a changelist * Here we can either revert any unchanged files in a changelist
* or * or
@@ -49,12 +48,17 @@ public class P4Revert extends P4Base
* The whole process also accepts a p4 filespec * The whole process also accepts a p4 filespec
*/ */
String p4cmd = "-s revert"; String p4cmd = "-s revert";
if( onlyUnchanged )
if( m_onlyUnchanged )
{
p4cmd += " -a"; 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 );
} }
} }

+ 16
- 17
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java View File

@@ -18,32 +18,32 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @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> //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() public void execute()
throws TaskException 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 else
{ {
@@ -52,5 +52,4 @@ public class P4Submit extends P4Base
throw new TaskException( "No change specified (no support for default change yet...." ); throw new TaskException( "No change specified (no support for default change yet...." );
} }
} }

} }

+ 18
- 15
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java View File

@@ -84,44 +84,47 @@ import org.apache.myrmidon.api.TaskException;
*/ */
public class P4Sync extends P4Base 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 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!" ); 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 ) public void setLabel( String label )
throws TaskException throws TaskException
{ {
if( label == null && !label.equals( "" ) ) if( label == null && !label.equals( "" ) )
{
throw new TaskException( "P4Sync: Labels cannot be Null or Empty" ); throw new TaskException( "P4Sync: Labels cannot be Null or Empty" );
}


this.label = label;

m_label = label;
} }


public void execute() public void execute()
throws TaskException 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 );
} }
} }

+ 0
- 46
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java View File

@@ -1,46 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;

import org.apache.myrmidon.api.TaskException;

public class SimpleP4OutputHandler
extends P4HandlerAdapter
{
private P4Base parent;

public SimpleP4OutputHandler( P4Base parent )
{
this.parent = parent;
}

public void process( String line )
throws TaskException
{
if( parent.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( parent.util.match( "/error:/", line ) && !parent.util.match( "/up-to-date/", line ) )
{
throw new TaskException( line );
}

parent.getLogger().info( parent.util.substitute( "s/^.*: //", line ) );

}
}

Loading…
Cancel
Save