package org.jenkinsci.plugins.p4.groovy; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.server.IOptionsServer; import hudson.FilePath; import hudson.model.TaskListener; import jenkins.model.Jenkins; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.workspace.Workspace; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; public class P4Groovy implements Serializable { private static final long serialVersionUID = 1L; private final String credential; private final Workspace workspace; private final FilePath buildWorkspace; private transient TaskListener listener = null; public P4Groovy(String credential, TaskListener listener, Workspace workspace, FilePath buildWorkspace) { this.credential = credential; this.workspace = workspace; this.listener = listener; this.buildWorkspace = buildWorkspace; } public String getClientName() { return workspace.getFullName(); } public String getUserName() throws P4JavaException { IOptionsServer p4 = getConnection(); String user = p4.getUserName(); p4.disconnect(); return user; } @Deprecated public Map<String, Object>[] runString(String cmd, String args) throws P4JavaException, InterruptedException, IOException { List<String> argList = new ArrayList<String>(); for (String arg : args.split(",")) { arg = arg.trim(); argList.add(arg); } String[] array = argList.toArray(new String[0]); return run(cmd, array); } public Map<String, Object>[] run(String cmd, String... args) throws P4JavaException, InterruptedException, IOException { P4GroovyTask task = new P4GroovyTask(cmd, args); task.setListener(listener); task.setCredential(credential); task.setWorkspace(workspace); return buildWorkspace.act(task); } public Map<String, Object>[] run(String cmd, List<String> args) throws P4JavaException, InterruptedException, IOException { String[] array = args.toArray(new String[0]); return run(cmd, array); } public Map<String, Object>[] save(String type, Map<String, Object> spec) throws P4JavaException, InterruptedException, IOException { String[] array = {"-i"}; P4GroovyTask task = new P4GroovyTask(type, array, spec); task.setListener(listener); task.setCredential(credential); task.setWorkspace(workspace); return buildWorkspace.act(task); } public Map<String, Object> fetch(String type, String id) throws P4JavaException, InterruptedException, IOException { String[] array = {"-o", id}; Map<String, Object>[] maps = run(type, array); if (maps.length == 0) return null; maps[0].remove("specFormatted"); return maps[0]; } private IOptionsServer getConnection() { String client = workspace.getFullName(); String charset = workspace.getCharset(); ClientHelper p4 = new ClientHelper(Jenkins.getActiveInstance(), credential, listener, client, charset); try { p4.setClient(workspace); } catch (Exception e) { p4.log("Unable to set Client!"); } return p4.getConnection(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 22127 | Paul Allen | Merge down 1.6.2 release and P4Groovy fixes. | ||
#3 | 22022 | Paul Allen |
Merge down. FindBug fix for transient TaskListener |
||
#2 | 21998 | Paul Allen |
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. |
||
#1 | 21940 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/groovy/P4Groovy.java | |||||
#6 | 21821 | Paul Allen |
Merge pull request #40 from s-sutherland/slaveexec P4Groovy execution to run on the slave |
||
#5 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#4 | 21449 | Paul Allen |
Rename and Deprecated the old P4Groovy run method. Force use of variable arg/Array method over a single String. Add support for List<String> PR #35 JENKINS-40454 |
||
#3 | 21447 | Paul Allen |
P4Groovy can take variable args or one string for run. A string for simple commands (that don't use a comma): def changes = p4.run("changes", "//...@${A}, -s, submitted") Or more complex commands use variable args: def changes = p4.run("changes", "//...@${A},${B}", "-s submitted", "-m4") Uses the same rules as P4Python/P4Perl/P4Ruby by keep arg groups together ("-flag <arg>"). JENKINS-40454 |
||
#2 | 20783 | Paul Allen | Tidy up and mark as BETA | ||
#1 | 20308 | Paul Allen |
P4Groovy (experimental) Get a P4 object in groovy. Supporting basic functions: ’run’ (to run perforce commands), ‘fetch’ and ‘save’ (to access Perforce specs). |