forked from jenkinsci/p4-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise Errors from StreamingCallbacks.
- Loading branch information
Showing
5 changed files
with
87 additions
and
92 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/main/java/org/jenkinsci/plugins/p4/client/AbstractStreamingCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.jenkinsci.plugins.p4.client; | ||
|
||
import com.perforce.p4java.exception.P4JavaException; | ||
import com.perforce.p4java.impl.mapbased.server.Server; | ||
import com.perforce.p4java.server.IServer; | ||
import com.perforce.p4java.server.callback.IStreamingCallback; | ||
import hudson.model.TaskListener; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class AbstractStreamingCallback implements IStreamingCallback { | ||
|
||
private boolean done = false; | ||
private boolean fail = false; | ||
private P4JavaException exception = null; | ||
|
||
private final Server server; | ||
private final Validate validate; | ||
|
||
public AbstractStreamingCallback(IServer iserver, TaskListener listener) { | ||
this.server = (Server) iserver; | ||
this.validate = new Validate(listener); | ||
} | ||
|
||
@Override | ||
public boolean startResults(int key) throws P4JavaException { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean endResults(int key) throws P4JavaException { | ||
done = true; | ||
return true; | ||
} | ||
|
||
@Override | ||
public abstract boolean handleResult(Map<String, Object> map, int key) throws P4JavaException; | ||
|
||
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; | ||
} | ||
|
||
public Validate getValidate() { | ||
return validate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 8 additions & 31 deletions
39
src/main/java/org/jenkinsci/plugins/p4/client/ReconcileStreamingCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,33 @@ | ||
package org.jenkinsci.plugins.p4.client; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
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 hudson.model.TaskListener; | ||
|
||
public class ReconcileStreamingCallback implements IStreamingCallback { | ||
|
||
private boolean done = false; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
private final Server server; | ||
private final Validate validate; | ||
public class ReconcileStreamingCallback extends AbstractStreamingCallback { | ||
|
||
public ReconcileStreamingCallback(IServer iserver, TaskListener listener) { | ||
this.server = (Server) iserver; | ||
this.validate = new Validate(listener); | ||
} | ||
|
||
@Override | ||
public boolean startResults(int key) throws P4JavaException { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean endResults(int key) throws P4JavaException { | ||
done = true; | ||
return true; | ||
super(iserver, listener); | ||
} | ||
|
||
@Override | ||
public boolean handleResult(Map<String, Object> map, int key) throws P4JavaException { | ||
List<IFileSpec> specList = new ArrayList<IFileSpec>(); | ||
specList.add(server.handleFileReturn(map)); | ||
specList.add(ResultListBuilder.handleFileReturn(map, getServer())); | ||
|
||
try { | ||
validate.check(specList, "also opened by", "no file(s) to reconcile", "must sync/resolve", | ||
getValidate().check(specList, "also opened by", "no file(s) to reconcile", "must sync/resolve", | ||
"exclusive file already opened", "cannot submit from stream", "instead of", "empty, assuming text"); | ||
} catch (Exception e) { | ||
// re-throw exception as AbortException is only used if !quiet | ||
throw new P4JavaException(e); | ||
} | ||
return true; | ||
} | ||
|
||
public boolean isDone() { | ||
return done; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters