package org.jenkinsci.plugins.p4.groovy; import hudson.FilePath.FileCallable; import hudson.model.TaskListener; 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 credential, TaskListener listener, String cmd, String[] args, Map<String, Object> spec) { super(credential, listener); this.cmd = cmd; this.args = Arrays.copyOf(args, args.length); this.spec = spec; } public P4GroovyTask(String credential, TaskListener listener, String cmd, String... args) { this(credential, listener, 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; } } @Override public void checkRoles(RoleChecker checker) throws SecurityException { checker.check((RoleSensitive) this, Roles.SLAVE); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 26097 | Paul Allen | Mark internal constructors protected. | ||
#4 | 26096 | Paul Allen |
Merge pull request #108 from joel-f-brown/master Credentials handling for Folders when using P4Groovy. Use run to determine the credentials in GetP4Task, then pass the P4BaseCredentials instead of the credentials ID. Now the P4Groovy getConnection() method uses the P4BaseCredentials instead of looking up the credentials from the active Jenkins instance. JENKINS-58745 JENKINS-57314 |
||
#3 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#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 |