git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270591 13f79535-47bb-0310-9956-ffa450edef68master
@@ -111,12 +111,12 @@ public class P4Add extends P4Base | |||
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 @@ 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 ); | |||
} | |||
} |
@@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs.optional.perforce; | |||
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 @@ import org.apache.tools.ant.types.Commandline; | |||
* @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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
/** | |||
* 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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
//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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
/** | |||
* 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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
} | |||
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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
{ | |||
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 ) | |||
{ | |||
} | |||
} |
@@ -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 @@ import org.apache.tools.ant.Project; | |||
* @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(); | |||
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() | |||
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)"> | |||
* 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 @@ public class P4Change extends P4Base | |||
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 ) ); | |||
} | |||
} | |||
} |
@@ -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 @@ import org.apache.tools.ant.Project; | |||
* | |||
* @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 @@ public class P4Counter extends P4Base | |||
// 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 ); | |||
} | |||
} |
@@ -34,9 +34,15 @@ public class P4Delete extends P4Base | |||
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 ); | |||
} | |||
} |
@@ -31,9 +31,15 @@ public class P4Edit extends P4Base | |||
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,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; | |||
} |
@@ -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() | |||
{ | |||
} | |||
} |
@@ -15,12 +15,13 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 ); | |||
} | |||
} |
@@ -20,134 +20,114 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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"; | |||
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 | |||
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 ); | |||
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 + "'" ); | |||
} | |||
} | |||
} |
@@ -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; | |||
} |
@@ -14,27 +14,30 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 ); | |||
} | |||
} |
@@ -14,32 +14,31 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 @@ public class P4Revert extends P4Base | |||
* 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 ); | |||
} | |||
} |
@@ -18,32 +18,32 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 @@ public class P4Submit extends P4Base | |||
throw new TaskException( "No change specified (no support for default change yet...." ); | |||
} | |||
} | |||
} |
@@ -84,44 +84,47 @@ import org.apache.myrmidon.api.TaskException; | |||
*/ | |||
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 ); | |||
} | |||
} |
@@ -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 ) ); | |||
} | |||
} |
@@ -111,12 +111,12 @@ public class P4Add extends P4Base | |||
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 @@ 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 ); | |||
} | |||
} |
@@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs.optional.perforce; | |||
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 @@ import org.apache.tools.ant.types.Commandline; | |||
* @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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
/** | |||
* 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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
//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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
/** | |||
* 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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
} | |||
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 @@ public abstract class P4Base extends org.apache.tools.ant.Task | |||
{ | |||
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 ) | |||
{ | |||
} | |||
} |
@@ -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 @@ import org.apache.tools.ant.Project; | |||
* @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(); | |||
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() | |||
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)"> | |||
* 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 @@ public class P4Change extends P4Base | |||
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 ) ); | |||
} | |||
} | |||
} |
@@ -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 @@ import org.apache.tools.ant.Project; | |||
* | |||
* @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 @@ public class P4Counter extends P4Base | |||
// 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 ); | |||
} | |||
} |
@@ -34,9 +34,15 @@ public class P4Delete extends P4Base | |||
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 ); | |||
} | |||
} |
@@ -31,9 +31,15 @@ public class P4Edit extends P4Base | |||
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,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; | |||
} |
@@ -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() | |||
{ | |||
} | |||
} |
@@ -15,12 +15,13 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 ); | |||
} | |||
} |
@@ -20,134 +20,114 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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"; | |||
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 | |||
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 ); | |||
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 + "'" ); | |||
} | |||
} | |||
} |
@@ -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; | |||
} |
@@ -14,27 +14,30 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 ); | |||
} | |||
} |
@@ -14,32 +14,31 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 @@ public class P4Revert extends P4Base | |||
* 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 ); | |||
} | |||
} |
@@ -18,32 +18,32 @@ import org.apache.myrmidon.api.TaskException; | |||
* | |||
* @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 @@ public class P4Submit extends P4Base | |||
throw new TaskException( "No change specified (no support for default change yet...." ); | |||
} | |||
} | |||
} |
@@ -84,44 +84,47 @@ import org.apache.myrmidon.api.TaskException; | |||
*/ | |||
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 ); | |||
} | |||
} |
@@ -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 ) ); | |||
} | |||
} |