package org.jenkinsci.plugins.p4_client.workspace; import hudson.Extension; import hudson.model.AutoCompletionCandidates; import hudson.util.FormValidation; import java.util.ArrayList; import java.util.List; import org.jenkinsci.plugins.p4_client.client.CharsetTypes; import org.jenkinsci.plugins.p4_client.client.ConnectionFactory; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import com.perforce.p4java.core.IStream; import com.perforce.p4java.core.IStreamSummary; import com.perforce.p4java.option.server.GetStreamsOptions; import com.perforce.p4java.server.IOptionsServer; public class StreamWorkspaceImpl extends Workspace { private final String charset; private final String streamName; private final String format; public String getCharset() { return charset; } public String getStreamName() { return streamName; } public String getFormat() { return format; } @Override public WorkspaceType getType() { return WorkspaceType.STREAM; } @DataBoundConstructor public StreamWorkspaceImpl(String charset, String streamName, String format) { this.charset = charset; this.streamName = streamName; this.format = format; } @Extension public static final class DescriptorImpl extends WorkspaceDescriptor { public static final String defaultFormat = "jenkins-${node}-${project}"; @Override public String getDisplayName() { return "Streams (view generated by Perforce 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 doAutoCompleteStreamName( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); try { IOptionsServer iserver = ConnectionFactory.getConnection(); if (iserver != null && value.length() > 1) { List<String> streamPaths = new ArrayList<String>(); streamPaths.add(value + "..."); GetStreamsOptions opts = new GetStreamsOptions(); opts.setMaxResults(10); List<IStreamSummary> list = iserver.getStreams(streamPaths, opts); for (IStreamSummary l : list) { c.add(l.getStream()); } } } catch (Exception e) { } return c; } public FormValidation doCheckStreamName(@QueryParameter String value) { try { IOptionsServer p4 = ConnectionFactory.getConnection(); IStream stream = p4.getStream(value); if (stream != null) { return FormValidation.ok(); } return FormValidation.error("Unknown Stream: " + value); } catch (Exception e) { return FormValidation.error("Perforce connection error."); } } public FormValidation doCheckFormat(@QueryParameter final String value) { if (value == null || value.isEmpty()) return FormValidation .error("Workspace Name format is mandatory."); for (String l : ClientTags.getTags()) { if (value.contains("${" + l + "}")) { return FormValidation.ok(); } } return FormValidation.error("Workspace Name format error."); } /** * Magic Stapler method; provides auto-completion for Charset types. * * @param value * The text that the user entered. */ public AutoCompletionCandidates doAutoCompleteCharset( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); for (String set : CharsetTypes.getCharsetsSince(20133)) { if (set.startsWith(value)) { c.add(set); } } return c; } } /** * Builds Workspace name from prefix, node and project. * * @return */ @Override public String getName() { return ClientTags.getFormattedName(format); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#14 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
#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 | 9038 | Paul Allen |
Improved error messages for Form Validate field checks. Uses Perforce Server messages (TPI-80) |
||
#10 | 8929 | Paul Allen |
Clean up doCheck Warnings on configuration page (TPI-80). - Added check exceptions to log as warnings. |
||
#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. |