package test; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.impl.mapbased.server.Server; import com.perforce.p4java.impl.mapbased.server.cmd.ResultListBuilder; import com.perforce.p4java.server.IServer; import com.perforce.p4java.server.callback.IStreamingCallback; import java.io.PrintStream; import java.util.ArrayList; import java.util.List; import java.util.Map; public class SyncStreamingCallback implements IStreamingCallback { private boolean done = false; private boolean fail = false; private P4JavaException exception = null; private final Server server; private final Validate validate; public SyncStreamingCallback(IServer iserver) { this.server = (Server)iserver; this.validate = new Validate(); } private PrintStream out = System.out; public void setOutput(PrintStream pw) { if (pw != null) { this.out = pw; } } private void println(String msg) { if (out != null) { out.println(msg); } } @Override public boolean startResults(int key) throws P4JavaException { //out.println("Start " + key); return true; } @Override public boolean endResults(int key) throws P4JavaException { // out.println("End " + key); done = true; return true; } public boolean isDone() { return done; } public boolean isFail() { return fail; } public void setFail() { fail = true; } public P4JavaException getException() { return exception; } public void setException(P4JavaException exception) { this.exception = exception; } public Server getServer() { return server; } private long resultCount = 0; public long getResultCount() { return resultCount; } @Override public boolean handleResult(Map<String, Object> map, int key) throws P4JavaException { List<IFileSpec> specList = new ArrayList<>(); specList.add(ResultListBuilder.handleFileReturn(map, getServer())); if (ConnectFactory.LOGGING) { println("----"); for (Map.Entry entry : map.entrySet()) { println(" Key = " + entry.getKey() + ", Value = " + entry.toString()); } } try { getValidate().check(specList, "file(s) up-to-date.", "file does not exist", "no file(s) as of that date", "no such file(s)", "Unexpected argument syntax - @"); IFileSpec fspec = specList.get(0); if (fspec.getStatusMessage() != null && fspec.getStatusMessage().length() > 0) { println("Status: " + fspec.getStatusMessage()); } else { resultCount++; println(fspec.getDepotPath() + " - " + fspec.getAction() + " as " + fspec.getClientPathString()); } } catch (Exception e) { P4JavaException except = new P4JavaException(e); // re-throw exception as AbortException is only used if !quiet throw except; } return true; } public Validate getValidate() { return validate; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 26536 | Joel Brown | Add additional logging | ||
#1 | 26533 | Joel Brown |
Add Streaming Sync test. This will use a streaming sync call similar to what P4 Plugin for Jenkins uses. |