package org.jenkinsci.plugins.p4.groovy; import hudson.FilePath.FileCallable; import hudson.remoting.VirtualChannel; import jenkins.security.Roles; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.tasks.AbstractTask; import org.jenkinsci.remoting.RoleChecker; import org.jenkinsci.remoting.RoleSensitive; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.Arrays; import java.util.Map; import java.util.logging.Logger; public class P4GroovyTask extends AbstractTask implements FileCallable<Map<String, Object>[]>, Serializable { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(P4GroovyTask.class.getName()); private final String cmd; private final String[] args; private final Map<String, Object> spec; public P4GroovyTask(String cmd, String[] args, Map<String, Object> spec) { this.cmd = cmd; this.args = Arrays.copyOf(args, args.length); this.spec = spec; } public P4GroovyTask(String cmd, String... args) { this(cmd, args, null); } @Override public Map<String, Object>[] invoke(File workspace, VirtualChannel channel) throws IOException { return (Map<String, Object>[]) tryTask(); } @Override public Object task(ClientHelper p4) throws Exception { try { if (!checkConnection(p4)) { return null; } return p4.getConnection().execMapCmd(cmd, args, spec); } catch (Exception e) { StringBuilder sb = new StringBuilder(); sb.append("P4: Unable to execute p4 groovy task: "); sb.append(cmd == null ? "[null]" : cmd).append(" "); sb.append(args == null ? "[null]" : Arrays.toString(args)).append(": "); sb.append(e.toString()); String err = sb.toString(); logger.severe(err); p4.log(err); throw e; } finally { p4.disconnect(); } } @Override public void checkRoles(RoleChecker checker) throws SecurityException { checker.check((RoleSensitive) this, Roles.SLAVE); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 23691 | Paul Allen | Cleanup P4Task: Remove disconnect and use Closeable. | ||
#2 | 23686 | Paul Allen | Cleanup P4Task: Move setters into constructor. | ||
#1 | 23685 | Paul Allen | Copy main -> dev | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/groovy/P4GroovyTask.java | |||||
#2 | 22019 | Paul Allen |
Fix TaskListener serialisation issue. TaskListener field must be transient as part of the program state, but is marked `Serializable` for the Task as it is sent over the Remoting Channel. Update p4 groovy to extend Step and not AbstractStepImpl. |
||
#1 | 21821 | Paul Allen |
Merge pull request #40 from s-sutherland/slaveexec P4Groovy execution to run on the slave |