package org.jenkinsci.plugins.p4.workspace; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.file.FileSpecBuilder; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.option.server.GetFileContentsOptions; import com.perforce.p4java.server.IOptionsServer; import hudson.Extension; import hudson.model.AutoCompletionCandidates; import hudson.util.FormValidation; 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 java.io.InputStream; import java.io.Serializable; import java.util.List; import java.util.logging.Logger; public class SpecWorkspaceImpl extends Workspace implements Serializable { private static final long serialVersionUID = 1L; 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(); // fetch spec String specPathFull = getExpand().format(getSpecPath(), false); List<IFileSpec> file = FileSpecBuilder.makeFileSpecList(specPathFull); GetFileContentsOptions printOpts = new GetFileContentsOptions(); printOpts.setNoHeaderLine(true); InputStream ins = connection.getFileContents(file, printOpts); // parse spec String spec = IOUtils.toString(ins, "UTF-8"); spec = getExpand().format(spec, false); connection.execInputStringMapCmd("client", new String[]{"-i"}, spec); // get client IClient iclient = connection.getClient(clientName); iclient.setName(clientName); iclient.setOwnerName(user); // save and return IClient 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. * @return suggestion */ 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. * @return suggestion */ 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 | 21940 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/workspace/SpecWorkspaceImpl.java | |||||
#11 | 21562 | Paul Allen |
Expand variables for Spec Workspace definitions. Add test to verify variable expansion for name and view. |
||
#10 | 20950 | Paul Allen | Add variable expansion to SpecFile based workspaces. | ||
#9 | 20308 | Paul Allen |
P4Groovy (experimental) Get a P4 object in groovy. Supporting basic functions: ’run’ (to run perforce commands), ‘fetch’ and ‘save’ (to access Perforce specs). |
||
#8 | 20179 | Paul Allen | Javadoc fixes for java 8 builds. | ||
#7 | 16628 | Paul Allen |
Set the Client Owner field on update as well as creation. (support for p4maven) |
||
#6 | 16625 | Paul Allen | Set the Workspace Owner at creation (not on update). | ||
#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. |