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.Arrays; 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 Exception { 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(credential, listener, cmd, args); 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 { return save(type, spec, new ArrayList()); } public Map<String, Object>[] save(String type, Map<String, Object> spec, List<String> list) throws P4JavaException, InterruptedException, IOException { // add '-i' to user provided args list if (!list.contains("-i")) { list.add("-i"); } String[] args = list.toArray(new String[0]); P4GroovyTask task = new P4GroovyTask(credential, listener, type, args, spec); task.setWorkspace(workspace); return buildWorkspace.act(task); } public Map<String, Object>[] save(String type, Map<String, Object> spec, String... args) throws P4JavaException, InterruptedException, IOException { ArrayList<String> list = new ArrayList<>(Arrays.asList(args)); return save(type, spec, list); } 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() throws IOException { ClientHelper p4 = new ClientHelper(Jenkins.getActiveInstance(), credential, listener, workspace); return p4.getConnection(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#17 | 28024 | Paul Allen | findbugs SE_TRANSIENT_FIELD_NOT_RESTORED | ||
#16 | 28023 | Paul Allen |
Backout: Serialise TaskListener for remote slave. Serialisation of TaskListener causes tests to fail (may be due to old Workflow dependency). |
||
#15 | 28020 | Paul Allen |
Serialise TaskListener for remote slave. The log output (along with 'tick') is now streamed from a remote slave, however this does not prevent the InterruptedException. JENKINS-58161 |
||
#14 | 26097 | Paul Allen | Mark internal constructors protected. | ||
#13 | 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 |
||
#12 | 24944 | Paul Allen |
Merge pull request #86 from p4charu/jenkinsci-master JENKINS-51632 and minor code cleanup |
||
#11 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#10 | 24433 | Paul Allen |
Extra arguments support for P4Groovy save function. JENKINS-52782 |
||
#9 | 22091 | Paul Allen |
Fix Job form issue in P4Groovy. A custom job spec would return an extra field 'specFormatted' normally hidden by the C++ API, but exposed in P4Java's execMap results. P4Groovy needs to remove the field before returning the map to the user. Minor updates to the P4Groovy doc. |
||
#8 | 22020 | Paul Allen | FindBug fix for transient TaskListener | ||
#7 | 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. |
||
#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). |