package org.jenkinsci.plugins.p4.workspace; import hudson.Extension; import hudson.model.AutoCompletionCandidates; import hudson.util.FormValidation; import java.io.InputStream; import java.util.List; import java.util.logging.Logger; import org.apache.commons.io.IOUtils; import org.jenkinsci.plugins.p4.client.ConnectionFactory; import org.jenkinsci.plugins.p4.client.NavigateHelper; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.file.FileSpecBuilder; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.impl.mapbased.client.Client; import com.perforce.p4java.option.server.GetFileContentsOptions; import com.perforce.p4java.server.IOptionsServer; public class SpecWorkspaceImpl extends Workspace { private final String name; private final String specPath; private static Logger logger = Logger.getLogger(SpecWorkspaceImpl.class .getName()); @Override public String getName() { return name; } public String getSpecPath() { return specPath; } @Override public WorkspaceType getType() { return WorkspaceType.SPEC; } @DataBoundConstructor public SpecWorkspaceImpl(String charset, boolean pinHost, String name, String specPath) { super(charset, pinHost); this.name = name; this.specPath = specPath; } @Override public IClient setClient(IOptionsServer connection, String user) throws Exception { // expands Workspace name if formatters are used. String clientName = getFullName(); IClient iclient = connection.getClient(clientName); if (iclient == null) { logger.info("P4: Creating client from spec: " + clientName); Client implClient = new Client(connection); implClient.setName(clientName); connection.createClient(implClient); iclient = connection.getClient(clientName); } // Set owner (not set during create) iclient.setOwnerName(user); List<IFileSpec> file = FileSpecBuilder.makeFileSpecList(specPath); GetFileContentsOptions printOpts = new GetFileContentsOptions(); printOpts.setNoHeaderLine(true); InputStream ins = connection.getFileContents(file, printOpts); String spec = IOUtils.toString(ins, "UTF-8"); connection.execInputStringMapCmd("client", new String[] { "-i" }, spec); iclient.refresh(); return iclient; } @Extension public static final class DescriptorImpl extends WorkspaceDescriptor { @Override public String getDisplayName() { return "Spec File (load workspace spec from file in Perforce)"; } /** * Provides auto-completion for workspace names. Stapler finds this * method via the naming convention. * * @param value * The text that the user entered. */ public AutoCompletionCandidates doAutoCompleteName( @QueryParameter String value) { return autoCompleteName(value); } public FormValidation doCheckName(@QueryParameter String value) { return checkClientName(value); } /** * Provides auto-completion for workspace names. Stapler finds this * method via the naming convention. * * @param value * The text that the user entered. */ public AutoCompletionCandidates doAutoCompleteSpecPath( @QueryParameter String value) { return NavigateHelper.getPath(value); } public FormValidation doCheckSpecPath(@QueryParameter String value) { try { IOptionsServer p4 = ConnectionFactory.getConnection(); List<IFileSpec> file = FileSpecBuilder.makeFileSpecList(value); GetFileContentsOptions printOpts = new GetFileContentsOptions(); InputStream ins = p4.getFileContents(file, printOpts); if (ins != null) { return FormValidation.ok(); } return FormValidation.error("Unknown file: " + value); } catch (Exception e) { return FormValidation.error(e.getMessage()); } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 11628 | Paul Allen | Branching using p4-jenkins-R1.1 | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/workspace/SpecWorkspaceImpl.java | |||||
#5 | 11472 | Paul Allen |
Pin the Workspace to the build host. Added a check box under the Workspace configuration to allow Jenkins to Pin the workspace, by setting the Host field. The hostname is resolved from the Computer object or InetAddress. |
||
#4 | 10854 | Paul Allen |
Clone Workspace Object Seems Jenkins makes re-entrant calls to the PerforceScm Object and caused the Workspace Object to get trampled. JENKINS-25547 |
||
#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/SpecWorkspaceImpl.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/SpecWorkspaceImpl.java | |||||
#1 | 9133 | Paul Allen |
Added Workspace mode for versioned Client Specs. Client Spec can be specified by depot path and used to configure workspace for build. - Includes fix for removing header when using p4 print. |