package org.jenkinsci.plugins.p4.workspace; import hudson.DescriptorExtensionList; import hudson.ExtensionPoint; import hudson.model.Describable; import hudson.model.Hudson; import hudson.slaves.NodeProperty; import hudson.slaves.EnvironmentVariablesNodeProperty; import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; import jenkins.model.Jenkins; import org.jenkinsci.plugins.p4.review.ReviewProp; import com.perforce.p4java.client.IClient; import com.perforce.p4java.server.IOptionsServer; public abstract class Workspace implements Cloneable, ExtensionPoint, Describable<Workspace> { private static Logger logger = Logger.getLogger(Workspace.class.getName()); private String charset; private String rootPath; private String hostname; private Map<String, String> formatTags; public Workspace(String charset) { this.charset = charset; } public abstract WorkspaceType getType(); /** * Returns the client workspace name as defined in the configuration. This * may include ${tag} that have not been expanded. * * @return */ public abstract String getName(); public String getCharset() { return charset; } /** * Setup/Create a Perforce workspace for this mode. * * @param connection * @param user * @return Perforce client * @throws Exception */ public abstract IClient setClient(IOptionsServer connection, String user) throws Exception; public WorkspaceDescriptor getDescriptor() { return (WorkspaceDescriptor) Hudson.getInstance().getDescriptor( getClass()); } public static DescriptorExtensionList<Workspace, WorkspaceDescriptor> all() { return Hudson.getInstance() .<Workspace, WorkspaceDescriptor> getDescriptorList( Workspace.class); } public String getRootPath() { return rootPath; } public void setHostName(String hostname) { this.hostname = hostname; } public String getHostName() { return hostname; } public void setRootPath(String rootPath) { this.rootPath = rootPath; } public String expand(String format, boolean wildcard) { if (formatTags != null) { for (String tag : formatTags.keySet()) { String value = formatTags.get(tag); if (value != null) { format = format.replace("${" + tag + "}", value); } } } // cleanup undefined tags if (wildcard) { format = format.replaceAll("\\$\\{.+?\\}", "*"); } format = format.replace("${", ""); format = format.replace("}", ""); return format; } public void set(String tag, String value) { formatTags.put(tag, value); } public String get(String tag) { if (formatTags == null) { return null; } return formatTags.get(tag); } public void load(Map<String, String> map) { for (String key : map.keySet()) { String value = map.get(key); if (ReviewProp.isProp(key)) { // Known Perforce Review property; prefix with namespace key = ReviewProp.NAMESPACE + key; } set(key, value); } } /** * Returns the fully expanded client workspace name. * * @return */ public String getFullName() { // expands Workspace name if formatters are used. String clientName = expand(getName(), false); // replace restricted characters with "-" as per the old plugin clientName = clientName.replaceAll(" ", "_"); clientName = clientName.replaceAll(",", "-"); clientName = clientName.replaceAll("=", "-"); clientName = clientName.replaceAll("/", "-"); return clientName; } public void clear() { formatTags = new HashMap<String, String>(); Jenkins jenkins = Jenkins.getInstance(); for (NodeProperty<?> node : jenkins.getGlobalNodeProperties()) { if (node instanceof EnvironmentVariablesNodeProperty) { EnvironmentVariablesNodeProperty env = (EnvironmentVariablesNodeProperty) node; formatTags.putAll((env).getEnvVars()); } } } public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { return null; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 11053 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/workspace/Workspace.java | |||||
#6 | 10906 | Paul Allen |
Matrix Polling and Parent control - Polling for Matrix builds calculates changes based on children. - Parent build disabled when using "Matrix options for Perforce" in the Matrix Configuration (can be enabled by checking the “Build parent” box). - Parent Build now substitutes ${var} with ‘*’ for the workspace view. e.g. //depot/${os}/… //ws/${os}/… becomes… //depot/*/… //ws/*/… instead of… //depot/os/… //ws/os/… |
||
#5 | 10755 | Paul Allen |
Separate name space for 'label' parameter. Perforce Review endpoint added `label`, `change`, `status`, `pass`, and `fail` parameter into the environment, which is a shared name space. This clashed with the default `label` matrix name and causing users issues. The change prefixes the review parameters with `p4.` on addition to the environment. |
||
#4 | 9803 | Paul Allen | Merging using p4-jenkins | ||
#3 | 9769 | Paul Allen | Copying using p4-jenkins | ||
#2 | 9738 | Paul Allen | Merging using p4-jenkins | ||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4/workspace/Workspace.java | |||||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/workspace/Workspace.java | |||||
#7 | 9495 | Paul Allen |
Fix Polling issue; using the wrong client. Removed static classes and internal referenced to PerforceScm attributes, to avoid threading issues. |
||
#6 | 8902 | Paul Allen |
Updated test cases: Pushed Workspace 'charset' to abstract Workspace class. Minor bugfixes in Workspace AutoCompletionCandidates method. |
||
#5 | 8899 | Paul Allen | Move Workspace setup/creation code to Implementation class. | ||
#4 | 8738 | Paul Allen |
Workspace Name Formatter. For Template and Stream workspaces it allows the substitution of the following tags: ${node} The name given to the slave Jenkins node. ${hostname} The hostname for the slave Jenkins node. ${project} The name of the Jenkins build Job. ${hash} Unique hash code of the Jenkins node. |
||
#3 | 8663 | Paul Allen | Rollout of charset for all Workspace modes. | ||
#2 | 8641 | Paul Allen | Added workspace helper (setClient) and template/stream types. | ||
#1 | 8640 | Paul Allen |
Added Workspace and Singleton descriptor. Removed old connection code. |