package org.jenkinsci.plugins.p4.workspace; import hudson.Extension; import hudson.model.AutoCompletionCandidates; import hudson.util.FormValidation; import java.util.List; import java.util.logging.Logger; import org.jenkinsci.plugins.p4.client.ConnectionFactory; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import com.perforce.p4java.client.IClient; import com.perforce.p4java.client.IClientSummary; import com.perforce.p4java.impl.mapbased.client.Client; import com.perforce.p4java.option.server.GetClientsOptions; import com.perforce.p4java.option.server.SwitchClientViewOptions; import com.perforce.p4java.server.IOptionsServer; public class TemplateWorkspaceImpl extends Workspace { private final String templateName; private final String format; private static Logger logger = Logger.getLogger(TemplateWorkspaceImpl.class .getName()); public String getTemplateName() { return templateName; } public String getFormat() { return format; } @Override public WorkspaceType getType() { return WorkspaceType.TEMPLATED; } @DataBoundConstructor public TemplateWorkspaceImpl(String charset, String templateName, String format) { super(charset); this.templateName = templateName; this.format = format; } @Override public IClient setClient(IOptionsServer connection, String user) throws Exception { String template = getTemplateName(); IClient iclient = connection.getClient(getName()); if (iclient == null) { logger.info("Creating template client: " + getName()); Client implClient = new Client(); implClient.setName(getName()); connection.createClient(implClient); iclient = connection.getClient(getName()); } // Set owner (not set during create) iclient.setOwnerName(user); // Root required to switch view; must reload values in iclient. iclient.setRoot(getRootPath()); SwitchClientViewOptions opts = new SwitchClientViewOptions(); opts.setForce(true); connection.switchClientView(template, getName(), opts); iclient = connection.getClient(getName()); return iclient; } @Extension public static final class DescriptorImpl extends WorkspaceDescriptor { public static final String defaultFormat = "jenkins-${node}-${project}"; @Override public String getDisplayName() { return "Template (view generated for each node)"; } /** * Provides auto-completion for workspace names. Stapler finds this * method via the naming convention. * * @param value * The text that the user entered. */ public AutoCompletionCandidates doAutoCompleteTemplateName( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); try { IOptionsServer iserver = ConnectionFactory.getConnection(); if (iserver != null && value.length() > 0) { List<IClientSummary> list; GetClientsOptions opts = new GetClientsOptions(); opts.setMaxResults(10); opts.setNameFilter(value + "*"); list = iserver.getClients(opts); for (IClientSummary l : list) { c.add(l.getName()); } } } catch (Exception e) { } return c; } public FormValidation doCheckTemplateName(@QueryParameter String value) { return checkClientName(value); } public FormValidation doCheckFormat(@QueryParameter final String value) { if (value == null || value.isEmpty()) return FormValidation .error("Workspace Name format is mandatory."); if (value.contains("${") && value.contains("}")) { return FormValidation.ok(); } return FormValidation.error("Workspace Name format error."); } } /** * Builds Workspace name from prefix, node and project. * * @return */ @Override public String getName() { return getFormattedName(format); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 9768 | Paul Allen | Missing client update on templare workspaces. | ||
#3 | 9750 | Paul Allen |
Add support for Environment variables. Includes cleanup of Perforce exception reporting for Connections and Workspaces. |
||
#2 | 9736 | Paul Allen |
Custom build args for Workspace names. Takes `${parameter}` and replaces it with the value if defined or uses the tag (`parameter` in this case). Includes substitution for a space ` ` with `_` as per P4 behaviour. |
||
#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/TemplateWorkspaceImpl.java | |||||
#13 | 9495 | Paul Allen |
Fix Polling issue; using the wrong client. Removed static classes and internal referenced to PerforceScm attributes, to avoid threading issues. |
||
#12 | 9040 | Paul Allen | Sets the workspace 'Owner' field when generating a workspace for Template/Stream modes. | ||
#11 | 8929 | Paul Allen |
Clean up doCheck Warnings on configuration page (TPI-80). - Added check exceptions to log as warnings. |
||
#10 | 8926 | Paul Allen |
Bug fix when unshelving files with the Template workspace option. p4-java was unable to switch the worksapce view (without the -f flag) if there were files open. - Improved logging (as this error was hidden) - Added test case for this condition. |
||
#9 | 8902 | Paul Allen |
Updated test cases: Pushed Workspace 'charset' to abstract Workspace class. Minor bugfixes in Workspace AutoCompletionCandidates method. |
||
#8 | 8899 | Paul Allen | Move Workspace setup/creation code to Implementation class. | ||
#7 | 8896 | Paul Allen | Moved common method 'doFillCharsetItems' into abstract class 'WorkspaceDescriptor'. | ||
#6 | 8771 | Paul Allen |
Perforce Server 12.1 min check for: Build configuration and password/ticket credentials. Includes: - Added logging for Perforce connections (fine) and set connection pool to 2. - Add 'none' to empty charset list (connection bug?) - Supress P4Java errors for syncing ubinary, xtext, unicode |
||
#5 | 8769 | Paul Allen | Update to charset option for workspaces to use a drop-down select with a default of 'none'. | ||
#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 | 8662 | Paul Allen | Added auto fill and checks for streams and templates. | ||
#1 | 8641 | Paul Allen | Added workspace helper (setClient) and template/stream types. |