Browse Source

Code layout only.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270644 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
244252d7c9
14 changed files with 219 additions and 196 deletions
  1. +61
    -46
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java
  2. +47
    -45
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java
  3. +9
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
  4. +5
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java
  5. +6
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java
  6. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java
  7. +18
    -16
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java
  8. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java
  9. +30
    -31
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java
  10. +4
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Reopen.java
  11. +7
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java
  12. +7
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java
  13. +17
    -17
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java
  14. +5
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java

+ 61
- 46
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java View File

@@ -59,11 +59,12 @@
package org.apache.tools.ant.taskdefs.optional.perforce; package org.apache.tools.ant.taskdefs.optional.perforce;


import java.io.IOException; import java.io.IOException;

import org.apache.oro.text.perl.Perl5Util;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.oro.text.perl.Perl5Util;




/** Base class for Perforce (P4) ANT tasks. See individual task for example usage. /** Base class for Perforce (P4) ANT tasks. See individual task for example usage.
@@ -86,58 +87,72 @@ public abstract class P4Base extends org.apache.tools.ant.Task {


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


//P4 g-opts and cmd opts (rtfm) //P4 g-opts and cmd opts (rtfm)
/** Perforce 'global' opts. /** Perforce 'global' opts.
* Forms half of low level API */
protected String P4Opts = "";
* Forms half of low level API */
protected String P4Opts = "";
/** Perforce command opts. /** Perforce command opts.
* Forms half of low level API */
protected String P4CmdOpts = "";
* Forms half of low level API */
protected String P4CmdOpts = "";


//Setters called by Ant //Setters called by Ant
public void setPort(String P4Port) { this.P4Port = "-p"+P4Port; }
public void setClient(String P4Client) { this.P4Client = "-c"+P4Client; }
public void setUser(String P4User) { this.P4User = "-u"+P4User; }
public void setView(String P4View) { this.P4View = P4View; }
public void setCmdopts(String P4CmdOpts) { this.P4CmdOpts = P4CmdOpts; }
public void setPort(String P4Port) {
this.P4Port = "-p" + P4Port;
}

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

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

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

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


public void init() { public void init() {


util = new Perl5Util(); util = new Perl5Util();


//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.....:-)
String tmpprop;
if((tmpprop = project.getProperty("p4.port")) != null) {
setPort(tmpprop);
//introspection here.....:-)
String tmpprop;
if ((tmpprop = project.getProperty("p4.port")) != null) {
setPort(tmpprop);
}
if ((tmpprop = project.getProperty("p4.client")) != null) {
setClient(tmpprop);
} }
if((tmpprop = project.getProperty("p4.client")) != null) {
setClient(tmpprop);
if ((tmpprop = project.getProperty("p4.user")) != null) {
setUser(tmpprop);
} }
if((tmpprop = project.getProperty("p4.user")) != null) {
setUser(tmpprop);
}
} }


protected void execP4Command(String command) throws BuildException { protected void execP4Command(String command) throws BuildException {
execP4Command(command, null); execP4Command(command, null);
} }
/** Execute P4 command assembled by subclasses. /** Execute P4 command assembled by subclasses.
@param command The command to run
@param p4input Input to be fed to command on stdin
@param handler A P4Handler to process any input and output
*/
@param command The command to run
@param p4input Input to be fed to command on stdin
@param handler A P4Handler to process any input and output
*/
protected void execP4Command(String command, P4Handler handler) throws BuildException { protected void execP4Command(String command, P4Handler handler) throws BuildException {
try{
try {


Commandline commandline = new Commandline(); Commandline commandline = new Commandline();
commandline.setExecutable("p4"); commandline.setExecutable("p4");
@@ -155,38 +170,38 @@ public abstract class P4Base extends org.apache.tools.ant.Task {
commandline.createArgument().setLine(command); commandline.createArgument().setLine(command);




String[] cmdline = commandline.getCommandline() ;
String[] cmdline = commandline.getCommandline();
String cmdl = ""; String cmdl = "";
for (int i=0 ; i < cmdline.length ; i++) {
for (int i = 0; i < cmdline.length; i++) {
cmdl += cmdline[i] + " "; cmdl += cmdline[i] + " ";
} }
log("Execing "+cmdl, Project.MSG_VERBOSE);


if(handler == null ) {
handler = new SimpleP4OutputHandler(this);
log("Execing " + cmdl, Project.MSG_VERBOSE);

if (handler == null) {
handler = new SimpleP4OutputHandler(this);
} }


Execute exe = new Execute(handler, null); Execute exe = new Execute(handler, null);


exe.setAntRun(project); exe.setAntRun(project);
exe.setCommandline(commandline.getCommandline()); exe.setCommandline(commandline.getCommandline());


try{
exe.execute();
}catch(IOException e) {
try {
exe.execute();
} catch (IOException e) {
throw new BuildException(e); throw new BuildException(e);
} finally { } finally {
try{
try {
handler.stop(); handler.stop();
}catch(Exception e) {}
} catch (Exception e) {
}
} }


}catch(Exception e) {
throw new BuildException("Problem exec'ing P4 command: "+e.getMessage());
}

} catch (Exception e) {
throw new BuildException("Problem exec'ing P4 command: " + e.getMessage());
}
} }
} }

+ 47
- 45
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java View File

@@ -79,27 +79,28 @@ public class P4Change extends P4Base {


public void execute() throws BuildException { public void execute() throws BuildException {


if(emptyChangeList == null) {
emptyChangeList = getEmptyChangeList();
if (emptyChangeList == null) {
emptyChangeList = getEmptyChangeList();
} }
final Project myProj = project; final Project myProj = project;


P4Handler handler = new P4HandlerAdapter() { 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);
log("Change Number is "+changenumber, Project.MSG_INFO);
myProj.setProperty("p4.change", ""+changenumber);

} else if(util.match("/error/", line)) {
throw new BuildException("Perforce Error, check client settings and/or server");
}
}};
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);
log("Change Number is " + changenumber, Project.MSG_INFO);
myProj.setProperty("p4.change", "" + changenumber);

} else if (util.match("/error/", line)) {
throw new BuildException("Perforce Error, check client settings and/or server");
}

}
};


handler.setOutput(emptyChangeList); handler.setOutput(emptyChangeList);


@@ -109,32 +110,33 @@ public class P4Change extends P4Base {


public String getEmptyChangeList() throws BuildException { public String getEmptyChangeList() throws BuildException {
final StringBuffer stringbuf = new StringBuffer(); final StringBuffer stringbuf = new StringBuffer();
execP4Command("change -o", new P4HandlerAdapter() { execP4Command("change -o", new P4HandlerAdapter() {
public void process(String line) {
if(!util.match("/^#/",line)){
if(util.match("/error/", line)) {
log("Client Error", Project.MSG_VERBOSE);
throw new BuildException("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");
public void process(String line) {
if (!util.match("/^#/", line)) {
if (util.match("/error/", line)) {

log("Client Error", Project.MSG_VERBOSE);
throw new BuildException("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(); return stringbuf.toString();
} }


@@ -146,12 +148,12 @@ public class P4Change extends P4Base {
* @return the backslashed string * @return the backslashed 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> * @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>
*/ */
public static final String backslash(String value){
public static final 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();
for (int i = 0; i < len; i++){
for (int i = 0; i < len; i++) {
char c = value.charAt(i); char c = value.charAt(i);
if (c == '/'){
if (c == '/') {
buf.append('\\'); buf.append('\\');
} }
buf.append(c); buf.append(c);
@@ -160,7 +162,7 @@ public class P4Change extends P4Base {
} }


/* Set Description Variable. */ /* Set Description Variable. */
public void setDescription(String desc){
public void setDescription(String desc) {
this.description = desc; this.description = desc;
} }




+ 9
- 9
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java View File

@@ -66,13 +66,13 @@ import org.apache.tools.ant.Project;
* to the output stream for the project (by setting the "name" * to the output stream for the project (by setting the "name"
* attribute only), to set a property based on the value of * attribute only), to set a property based on the value of
* a counter (by setting the "property" attribute) or to set the counter * a counter (by setting the "property" attribute) or to set the counter
* on the perforce server (by setting the "value" attribute).
* on the perforce server (by setting the "value" attribute).
* *
* Example Usage:<br> * Example Usage:<br>
* &lt;p4counter name="${p4.counter}" property=${p4.change}"/&gt; * &lt;p4counter name="${p4.counter}" property=${p4.change}"/&gt;
* @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 counter = null;
public String property = null; public String property = null;
@@ -96,35 +96,35 @@ public class P4Counter extends P4Base {


public void execute() throws BuildException { public void execute() throws BuildException {


if((counter == null) || counter.length() == 0) {
if ((counter == null) || counter.length() == 0) {
throw new BuildException("No counter specified to retrieve"); throw new BuildException("No counter specified to retrieve");
} }


if(shouldSetValue && shouldSetProperty) {
if (shouldSetValue && shouldSetProperty) {
throw new BuildException("Cannot both set the value of the property and retrieve the value of the property."); throw new BuildException("Cannot both set the value of the property and retrieve the value of the property.");
} }


String command = "counter " + P4CmdOpts + " " + counter; String command = "counter " + P4CmdOpts + " " + counter;
if(!shouldSetProperty) {
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
// to just not include the scripting information than to try to add it // to just not include the scripting information than to try to add it
// and strip it later. // and strip it later.
command = "-s " + command; command = "-s " + command;
} }
if(shouldSetValue) {
if (shouldSetValue) {
command += " " + value; command += " " + value;
} }


if(shouldSetProperty) {
if (shouldSetProperty) {
final Project myProj = project; final Project myProj = project;


P4Handler handler = new P4HandlerAdapter() { P4Handler handler = new P4HandlerAdapter() {
public void process(String line) { public void process(String line) {
log("P4Counter retrieved line \""+ line + "\"", Project.MSG_VERBOSE);
log("P4Counter retrieved line \"" + line + "\"", Project.MSG_VERBOSE);
try { try {
value = Integer.parseInt(line); value = Integer.parseInt(line);
myProj.setProperty(property, ""+value);
myProj.setProperty(property, "" + value);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
throw new BuildException("Perforce error. Could not retrieve counter value."); throw new BuildException("Perforce error. Could not retrieve counter value.");
} }


+ 5
- 5
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Delete.java View File

@@ -76,12 +76,12 @@ public class P4Delete extends P4Base {
} }


public void execute() throws BuildException { public void execute() throws BuildException {
if(change != null ) {
P4CmdOpts = "-c "+change;
if (change != null) {
P4CmdOpts = "-c " + change;
} }
if(P4View == null) {
throw new BuildException("No view specified to delete");
if (P4View == null) {
throw new BuildException("No view specified to delete");
} }
execP4Command("-s delete "+P4CmdOpts+" "+P4View, new SimpleP4OutputHandler(this));
execP4Command("-s delete " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this));
} }
} }

+ 6
- 6
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java View File

@@ -69,7 +69,7 @@ import org.apache.tools.ant.BuildException;
* ToDo: Should call reopen if file is already open in one of our changelists perhaps? * ToDo: Should call reopen if file is already open in one of our changelists perhaps?
*/ */


public class P4Edit extends P4Base {
public class P4Edit extends P4Base {


public String change = null; public String change = null;


@@ -78,12 +78,12 @@ import org.apache.tools.ant.BuildException;
} }


public void execute() throws BuildException { public void execute() throws BuildException {
if(change != null ) {
P4CmdOpts = "-c "+change;
if (change != null) {
P4CmdOpts = "-c " + change;
} }
if(P4View == null) {
throw new BuildException("No view specified to edit");
if (P4View == null) {
throw new BuildException("No view specified to edit");
} }
execP4Command("-s edit "+P4CmdOpts+" "+P4View, new SimpleP4OutputHandler(this));
execP4Command("-s edit " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this));
} }
} }

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

@@ -65,5 +65,6 @@ import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
public interface P4Handler extends ExecuteStreamHandler { public interface P4Handler extends ExecuteStreamHandler {


public void process(String line) throws BuildException; public void process(String line) throws BuildException;

public void setOutput(String line) throws BuildException; public void setOutput(String line) throws BuildException;
} }

+ 18
- 16
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java View File

@@ -54,12 +54,13 @@


package org.apache.tools.ant.taskdefs.optional.perforce; package org.apache.tools.ant.taskdefs.optional.perforce;


import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.SequenceInputStream; import java.io.SequenceInputStream;

import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;


public abstract class P4HandlerAdapter implements P4Handler { public abstract class P4HandlerAdapter implements P4Handler {
@@ -77,29 +78,29 @@ public abstract class P4HandlerAdapter implements P4Handler {


public void start() throws BuildException { public void start() throws BuildException {


try{
//First write any output to P4
if(p4input != null && p4input.length() >0 && os != null) {
os.write(p4input.getBytes());
os.flush();
os.close();
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
//Now read any input and process


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


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


input.close(); input.close();




}catch(Exception e) {
} catch (Exception e) {
throw new BuildException(e); throw new BuildException(e);
} }
} }
@@ -120,5 +121,6 @@ public abstract class P4HandlerAdapter implements P4Handler {
this.is = is; this.is = is;
} }


public void stop(){}
public void stop() {
}
} }

+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java View File

@@ -62,7 +62,7 @@ import org.apache.tools.ant.BuildException;




/** P4Have - lists files currently on client. /** P4Have - lists files currently on client.
*
*
* P4Have simply dumps the current file version info into * P4Have simply dumps the current file version info into
* the Ant log (or stdout). * the Ant log (or stdout).
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A>
@@ -70,6 +70,6 @@ import org.apache.tools.ant.BuildException;
public class P4Have extends P4Base { public class P4Have extends P4Base {


public void execute() throws BuildException { public void execute() throws BuildException {
execP4Command("have "+P4CmdOpts+" "+P4View, new SimpleP4OutputHandler(this));
execP4Command("have " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this));
} }
} }

+ 30
- 31
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java View File

@@ -58,12 +58,12 @@


package org.apache.tools.ant.taskdefs.optional.perforce; package org.apache.tools.ant.taskdefs.optional.perforce;


import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;


import java.util.Date;
import java.text.SimpleDateFormat;



/** P4Label - create a Perforce Label. /** P4Label - create a Perforce Label.
* *
@@ -93,41 +93,41 @@ public class P4Label extends P4Base {
this.desc = desc; this.desc = desc;
} }


public void setLock(String lock) {
public void setLock(String lock) {
this.lock = lock; this.lock = lock;
}
}


public void execute() throws BuildException { public void execute() throws BuildException {
log("P4Label exec:",Project.MSG_INFO);
log("P4Label exec:", Project.MSG_INFO);


if(P4View == null || P4View.length() < 1) {
if (P4View == null || P4View.length() < 1) {
log("View not set, assuming //depot/...", Project.MSG_WARN); log("View not set, assuming //depot/...", Project.MSG_WARN);
P4View = "//depot/..."; P4View = "//depot/...";
} }


if(desc == null || desc.length() < 1) {
if (desc == null || desc.length() < 1) {
log("Label Description not set, assuming 'AntLabel'", Project.MSG_WARN); log("Label Description not set, assuming 'AntLabel'", Project.MSG_WARN);
desc = "AntLabel"; desc = "AntLabel";
} }


if(lock != null && !lock.equalsIgnoreCase("locked")) {
log("lock attribute invalid - ignoring",Project.MSG_WARN);
if (lock != null && !lock.equalsIgnoreCase("locked")) {
log("lock attribute invalid - ignoring", Project.MSG_WARN);
} }


if(name == null || name.length() < 1) {
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd-hh:mm");
if (name == null || name.length() < 1) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd-hh:mm");
Date now = new Date(); Date now = new Date();
name = "AntLabel-"+formatter.format(now);
log("name not set, assuming '"+name+"'", Project.MSG_WARN);
name = "AntLabel-" + formatter.format(now);
log("name not set, assuming '" + name + "'", Project.MSG_WARN);
} }




//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"+
"Options: unlocked\n"+
"View: "+P4View+"\n";
"Label: " + name + "\n" +
"Description: " + desc + "\n" +
"Options: unlocked\n" +
"View: " + P4View + "\n";


P4Handler handler = new P4HandlerAdapter() { P4Handler handler = new P4HandlerAdapter() {
public void process(String line) { public void process(String line) {
@@ -139,19 +139,19 @@ public class P4Label extends P4Base {


execP4Command("label -i", handler); execP4Command("label -i", handler);


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




log("Created Label "+name+" ("+desc+")", Project.MSG_INFO);
log("Created Label " + name + " (" + desc + ")", Project.MSG_INFO);


//Now lock if required //Now lock if required
if (lock != null && lock.equalsIgnoreCase("locked")) {
if (lock != null && lock.equalsIgnoreCase("locked")) {


log("Modifying lock status to 'locked'",Project.MSG_INFO);
log("Modifying lock status to 'locked'", Project.MSG_INFO);


final StringBuffer labelSpec = new StringBuffer(); final StringBuffer labelSpec = new StringBuffer();


@@ -159,24 +159,23 @@ public class P4Label extends P4Base {
//Replace Options //Replace Options
//Submit back to Perforce //Submit back to Perforce


handler = new P4HandlerAdapter() {
public void process(String line) {
handler = new P4HandlerAdapter() {
public void process(String line) {
log(line, Project.MSG_VERBOSE); log(line, Project.MSG_VERBOSE);


if(util.match("/^Options:/",line)) {
line = "Options: "+lock;
if (util.match("/^Options:/", line)) {
line = "Options: " + lock;
} }


labelSpec.append(line+"\n");
labelSpec.append(line + "\n");
} }
}; };




execP4Command("label -o " + name, handler);
log(labelSpec.toString(), Project.MSG_DEBUG);


execP4Command("label -o "+name, handler);
log(labelSpec.toString(),Project.MSG_DEBUG);

log("Now locking label...",Project.MSG_VERBOSE);
log("Now locking label...", Project.MSG_VERBOSE);
handler = new P4HandlerAdapter() { handler = new P4HandlerAdapter() {
public void process(String line) { public void process(String line) {
log(line, Project.MSG_VERBOSE); log(line, Project.MSG_VERBOSE);


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

@@ -64,12 +64,13 @@ import org.apache.tools.ant.BuildException;
* *
* @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 toChange = ""; private String toChange = "";


public void setToChange(String toChange) throws BuildException { public void setToChange(String toChange) throws BuildException {
if(toChange == null && !toChange.equals("")) {
if (toChange == null && !toChange.equals("")) {
throw new BuildException("P4Reopen: tochange cannot be null or empty"); throw new BuildException("P4Reopen: tochange cannot be null or empty");
} }


@@ -77,9 +78,9 @@ public class P4Reopen extends P4Base {
} }


public void execute() throws BuildException { public void execute() throws BuildException {
if(P4View == null) {
if (P4View == null) {
throw new BuildException("No view specified to reopen"); throw new BuildException("No view specified to reopen");
} }
execP4Command("-s reopen -c "+toChange+" "+P4View, new SimpleP4OutputHandler(this));
execP4Command("-s reopen -c " + toChange + " " + P4View, new SimpleP4OutputHandler(this));
} }
} }

+ 7
- 6
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Revert.java View File

@@ -64,13 +64,14 @@ import org.apache.tools.ant.BuildException;
* *
* @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 revertChange = null; private String revertChange = null;
private boolean onlyUnchanged = false; private boolean onlyUnchanged = false;


public void setChange(String revertChange) throws BuildException { public void setChange(String revertChange) throws BuildException {
if(revertChange == null && !revertChange.equals("")) {
if (revertChange == null && !revertChange.equals("")) {
throw new BuildException("P4Revert: change cannot be null or empty"); throw new BuildException("P4Revert: change cannot be null or empty");
} }


@@ -78,7 +79,7 @@ public class P4Revert extends P4Base {


} }


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


@@ -92,14 +93,14 @@ 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) {
p4cmd+=" -a";
if (onlyUnchanged) {
p4cmd += " -a";
} }


if (revertChange != null) { if (revertChange != null) {
p4cmd += " -c "+revertChange;
p4cmd += " -c " + revertChange;
} }


execP4Command(p4cmd+" "+P4View, new SimpleP4OutputHandler(this));
execP4Command(p4cmd + " " + P4View, new SimpleP4OutputHandler(this));
} }
} }

+ 7
- 6
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java View File

@@ -81,14 +81,15 @@ public class P4Submit extends P4Base {
public void setChange(String change) { public void setChange(String change) {
this.change = change; this.change = change;
} }

public void execute() throws BuildException { public void execute() throws BuildException {
if(change != null) {
execP4Command("submit -c "+change,
new P4HandlerAdapter() {
public void process(String line) {
log(line, Project.MSG_VERBOSE);
if (change != null) {
execP4Command("submit -c " + change,
new P4HandlerAdapter() {
public void process(String line) {
log(line, Project.MSG_VERBOSE);
}
} }
}
); );


} else { } else {


+ 17
- 17
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java View File

@@ -62,7 +62,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;


/** P4Sync - synchronise client space to a perforce depot view. /** P4Sync - synchronise client space to a perforce depot view.
* The API allows additional functionality of the "p4 sync" command
* The API allows additional functionality of the "p4 sync" command
* (such as "p4 sync -f //...#have" or other exotic invocations).</P> * (such as "p4 sync -f //...#have" or other exotic invocations).</P>
* *
* <b>Example Usage:</b> * <b>Example Usage:</b>
@@ -83,9 +83,9 @@ public class P4Sync extends P4Base {
String label; String label;
private String syncCmd = ""; private String syncCmd = "";


public void setLabel(String label) throws BuildException {
if(label == null && !label.equals("")) {
throw new BuildException("P4Sync: Labels cannot be Null or Empty");
public void setLabel(String label) throws BuildException {
if (label == null && !label.equals("")) {
throw new BuildException("P4Sync: Labels cannot be Null or Empty");
} }


this.label = label; this.label = label;
@@ -94,27 +94,27 @@ public class P4Sync extends P4Base {




public void setForce(String force) throws BuildException { public void setForce(String force) throws BuildException {
if(force == null && !label.equals("")) {
throw new BuildException("P4Sync: If you want to force, set force to non-null string!");
if (force == null && !label.equals("")) {
throw new BuildException("P4Sync: If you want to force, set force to non-null string!");
} }
P4CmdOpts = "-f";
}
P4CmdOpts = "-f";
}
public void execute() throws BuildException { public void execute() throws BuildException {




if (P4View != null) { if (P4View != null) {
syncCmd = P4View;
syncCmd = P4View;
}


if (label != null && !label.equals("")) {
syncCmd = syncCmd + "@" + label;
} }


if(label != null && !label.equals("")) {
syncCmd = syncCmd + "@" + label;
}


log("Execing sync "+P4CmdOpts+" "+syncCmd, Project.MSG_VERBOSE);
log("Execing sync " + P4CmdOpts + " " + syncCmd, Project.MSG_VERBOSE);


execP4Command("-s sync "+P4CmdOpts+" "+syncCmd, new SimpleP4OutputHandler(this));
execP4Command("-s sync " + P4CmdOpts + " " + syncCmd, new SimpleP4OutputHandler(this));
} }
} }

+ 5
- 4
src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java View File

@@ -64,13 +64,14 @@ import org.apache.tools.ant.Project;
public class SimpleP4OutputHandler extends P4HandlerAdapter { public class SimpleP4OutputHandler extends P4HandlerAdapter {


P4Base parent; P4Base parent;

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


public void process(String line) throws BuildException { public void process(String line) throws BuildException {
if(parent.util.match("/^exit/",line)) {
return;
if (parent.util.match("/^exit/", line)) {
return;
} }


//Throw exception on errors (except up-to-date) //Throw exception on errors (except up-to-date)
@@ -83,12 +84,12 @@ public class SimpleP4OutputHandler extends P4HandlerAdapter {
//which is already open for edit..... //which is already open for edit.....
//Just look for error: - catches most things.... //Just look for error: - catches most things....


if(parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line)) {
if (parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line)) {
throw new BuildException(line); throw new BuildException(line);


} }


parent.log(parent.util.substitute("s/^.*: //",line), Project.MSG_INFO);
parent.log(parent.util.substitute("s/^.*: //", line), Project.MSG_INFO);


} }
} }

Loading…
Cancel
Save