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 java.util.logging.Logger; import org.jenkinsci.plugins.p4_client.client.ConnectionFactory; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.IStream; import com.perforce.p4java.core.IStreamSummary; import com.perforce.p4java.impl.mapbased.client.Client; import com.perforce.p4java.option.server.GetStreamsOptions; import com.perforce.p4java.server.IOptionsServer; public class StreamWorkspaceImpl extends Workspace { private final String streamName; private final String format; private static Logger logger = Logger.getLogger(StreamWorkspaceImpl.class .getName()); 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) { super(charset); this.streamName = streamName; this.format = format; } @Override public IClient setClient(IOptionsServer connection, String user) throws Exception { IClient iclient = connection.getClient(getName()); if (iclient == null) { logger.info("Creating stream 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); iclient.setStream(getStreamName()); return iclient; } @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(e.getMessage()); } } 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 | |
---|---|---|---|---|---|
#2 | 9554 | gronk | mege in Paul's changes | ||
#1 | 8783 | gronk | Populate //guest/gronk/p4-jenkins/.... | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/workspace/StreamWorkspaceImpl.java | |||||
#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. |