package org.jenkinsci.plugins.p4.workflow; import hudson.model.Item; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.browsers.P4WebBrowser; import org.jenkinsci.plugins.p4.credentials.P4CredentialsImpl; import org.jenkinsci.plugins.p4.populate.AutoCleanImpl; import org.jenkinsci.plugins.p4.populate.Populate; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.StreamWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.TemplateWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.jenkinsci.plugins.p4.workspace.WorkspaceDescriptor; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.jenkinsci.plugins.workflow.steps.scm.SCMStep; import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; import hudson.Extension; import hudson.model.AutoCompletionCandidates; import hudson.scm.SCM; import hudson.util.FormValidation; import hudson.util.ListBoxModel; public class P4Step extends SCMStep { private static final long serialVersionUID = 1L; private final String credential; private String stream = ""; private String depotPath = ""; private String template = ""; private String charset = ""; private String format = DescriptorImpl.defaultFormat; private Populate populate; private Workspace workspace; @DataBoundConstructor public P4Step(String credential) { this.credential = credential; } public String getStream() { return stream; } @DataBoundSetter public void setStream(String stream) { this.stream = stream; } public String getDepotPath() { return depotPath; } @DataBoundSetter public void setDepotPath(String path) { this.depotPath = path; } public String getTemplate() { return template; } @DataBoundSetter public void setTemplate(String template) { this.template = template; } public String getCharset() { return charset; } @DataBoundSetter public void setWorkspace(Workspace workspace) { this.workspace = workspace; } public Workspace getWorkspace() { return workspace; } @DataBoundSetter public void setCharset(String charset) { this.charset = charset; } public String getFormat() { return format; } @DataBoundSetter public void setFormat(String format) { this.format = format; } public String getCredential() { return credential; } @DataBoundSetter public void setPopulate(Populate populate) { this.populate = populate; } public Populate getPopulate() { return populate; } @Override protected SCM createSCM() { P4WebBrowser browser = null; if ( workspace == null) { if (notNull(stream)) workspace = new StreamWorkspaceImpl(charset, false, stream, format); else if (notNull(template)) workspace = new TemplateWorkspaceImpl(charset, false, template, format); else if (notNull(depotPath)) { String view = depotPath + "/..." + " " + "//" + format + "/..."; WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, null, "local", view); workspace = new ManualWorkspaceImpl(charset, false, format, spec); } } // use basic populate options if no class provided if(populate == null) { populate = new AutoCleanImpl(true, true, false, false, null, null); } PerforceScm scm = new PerforceScm(credential, workspace, null, populate, browser); return scm; } static boolean notNull(String value) { return (value != null && !value.isEmpty()); } @Extension(optional = true) public static final class DescriptorImpl extends SCMStepDescriptor { public static final String defaultFormat = "jenkins-${NODE_NAME}-${JOB_NAME}"; public DescriptorImpl() { // Fail now if dependency plugin not loaded. Descriptor.<init> will // actually fail anyway, but this is just to be sure. PerforceScm.class.hashCode(); } /** * Credentials list, a Jelly config method for a build job. * * @return A list of Perforce credential items to populate the jelly * Select list. */ public ListBoxModel doFillCredentialItems(@AncestorInPath Item project, @QueryParameter String credential) { return P4CredentialsImpl.doFillCredentialItems(project, credential); } public FormValidation doCheckCredential(@AncestorInPath Item project, @QueryParameter String value) { return P4CredentialsImpl.doCheckCredential(project, value); } public AutoCompletionCandidates doAutoCompleteStream(@QueryParameter String value) { return WorkspaceDescriptor.doAutoCompleteStreamName(value); } public AutoCompletionCandidates doAutoCompleteTemplate(@QueryParameter String value) { return WorkspaceDescriptor.doAutoCompleteTemplateName(value); } // check there is only one source private static boolean hasMultiple(String stream, String template, String path) { if (P4Step.notNull(stream)) { if (P4Step.notNull(template) || P4Step.notNull(path)) { return true; } } if (P4Step.notNull(template)) { if (P4Step.notNull(stream) || P4Step.notNull(path)) { return true; } } if (P4Step.notNull(path)) { if (P4Step.notNull(template) || P4Step.notNull(stream)) { return true; } } return false; } public FormValidation doCheckStream(@QueryParameter String value, @QueryParameter String template, @QueryParameter String path) { if (P4Step.notNull(value)) { if (hasMultiple(value, template, path)) { return FormValidation.error("Specify only one source."); } return WorkspaceDescriptor.doCheckStreamName(value); } return FormValidation.ok(); } public FormValidation doCheckTemplate(@QueryParameter String value, @QueryParameter String stream, @QueryParameter String path) { if (P4Step.notNull(value)) { if (hasMultiple(stream, value, path)) { return FormValidation.error("Specify only one source."); } return WorkspaceDescriptor.checkClientName(value); } return FormValidation.ok(); } public FormValidation doCheckPath(@QueryParameter String value, @QueryParameter String stream, @QueryParameter String template) { if (P4Step.notNull(value)) { if (hasMultiple(stream, template, value)) { return FormValidation.error("Specify only one source."); } return FormValidation.ok(); } return FormValidation.ok(); } public ListBoxModel doFillCharsetItems() { return WorkspaceDescriptor.doFillCharsetItems(); } @Override public String getFunctionName() { return "p4sync"; } @Override public String getDisplayName() { return "P4 Sync"; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#13 | 29868 | Sandeep Kumar |
Merge pull request #196 from jenkinsci/StreamAtChange Add stream at change in StreamWorkspace and P4Sync |
||
#12 | 24401 | Paul Allen | Fix 'p4sync' auto complete and validate checks. | ||
#11 | 23155 | Paul Allen |
Remove Workspace cloning for better concurrent builds. Remove Workspace cloning and encourage users to make use of EXECUTOR_NUMBER in the Jenkins job name. JENKINS-41432 |
||
#10 | 22856 | Paul Allen |
Remove guessBrowser() and lookup browser when used. guessBrowser() gets called a lot and each lookup opens a Perforce connection. JENKINS-46810 |
||
#9 | 22684 | Paul Allen | Added @Symbol to Extension classes for Pipeline Syntax. | ||
#8 | 22400 | Paul Allen |
(tpeths) Enabling Graph support in p4sync DSL. #review-22378 |
||
#7 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#6 | 22040 | Paul Allen |
Merge pull request #41 from lizlam/master Strip the trailing slash in the depot path so that p4sync step doesn't fail. |
||
#5 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#4 | 21189 | Paul Allen |
Merge pull request #34 from DrakkenWulf/cleanChange Custom workspace support. |
||
#3 | 19357 | Paul Allen |
Populate class support for DSL p4sync. JENKINS-34318 |
||
#2 | 19324 | Paul Allen |
Added Parallel Sync. An Advanced Populate option. Must specify the PATH to the ‘p4’ executable as parallel sync is not supported by p4java. JENKINS-29228 |
||
#1 | 15394 | Paul Allen |
Workflow-DSL functionality. Tested workflow DSL against 1.596.1 older functionality tested against 1.580.1 @sven_erik_knop |
||
//guest/sven_erik_knop/p4jenkins/src/main/java/org/jenkinsci/plugins/p4/workflow/P4Step.java | |||||
#7 | 15216 | Sven Erik Knop | Simple implementation of depot path for DSL | ||
#6 | 14133 | Sven Erik Knop | Added p4tag to the DSL part | ||
#5 | 14070 | Sven Erik Knop | Improved fill and check options | ||
#4 | 14052 | Sven Erik Knop | Fixed verification of source for P4: stream, template or path | ||
#3 | 14014 | Sven Erik Knop |
Single P4 Step works, but needs validation of fields for snippet generator |
||
#2 | 12959 | Sven Erik Knop |
Refactored p4 to p4_stream Connection selector works, stream autocomplete works workspace default name still missing |
||
#1 | 12958 | Sven Erik Knop |
DSL for P4 works in principle (hard coded workspace for now) Misses automatic loading of aggregator |