package org.jenkinsci.plugins.p4.scm; import com.perforce.p4java.core.file.IFileSpec; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.TaskListener; import org.jenkinsci.Symbol; import org.jenkinsci.plugins.p4.browsers.P4Browser; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.jenkinsci.plugins.p4.client.ViewMapHelper; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; public class BranchesScmSource extends AbstractP4ScmSource { private P4Browser browser; private String filter = DescriptorImpl.defaultFilter; private String mappings = DescriptorImpl.defaultPath; @DataBoundConstructor public BranchesScmSource(String credential, String includes, String charset, String format) { super(credential); setIncludes(includes); setCharset(charset); setFormat(format); } @DataBoundSetter public void setBrowser(P4Browser browser) { this.browser = browser; } @DataBoundSetter public void setFilter(String filter) { this.filter = filter; } public String getFilter() { return filter; } public String getMappings() { // support 1.8.1 configurations that did not have any mappings if(mappings == null) { mappings = DescriptorImpl.defaultPath; } return mappings; } @DataBoundSetter public void setMappings(String mappings) { this.mappings = mappings; } @Override public P4Browser getBrowser() { return browser; } @Override public List<P4Head> getTags(@NonNull TaskListener listener) throws Exception { return new ArrayList<>(); } @Override public List<P4Head> getHeads(@NonNull TaskListener listener) throws Exception { List<String> paths = getIncludePaths(); List<P4Head> list = new ArrayList<>(); try (ConnectionHelper p4 = new ConnectionHelper(getOwner(), getCredential(), listener)) { String actualFilter = getFilter(); if (getFilter() == null || filter.trim().equals("")) { actualFilter = ".*"; } Pattern filterPattern = Pattern.compile(actualFilter); List<IFileSpec> specs = p4.getDirs(paths); for (IFileSpec s : specs) { String branch = s.getOriginalPathString(); // check the branch is not empty if (branch == null || branch.isEmpty()) { continue; } // check the filters if (!filterPattern.matcher(branch).matches()) { continue; } // get filename and check for null String file = branch.substring(branch.lastIndexOf("/") + 1); if (file == null || file.isEmpty()) { continue; } P4Path p4Path = new P4Path(branch); P4Head head = new P4Head(file, p4Path); list.add(head); } } return list; } @Override public Workspace getWorkspace(P4Path path) { if (path == null) { throw new IllegalArgumentException("missing branch path"); } List<String> views = new ArrayList<>(); for (String mapping : getViewMappings()) { StringBuffer sb = new StringBuffer(); sb.append(path.getPath()); sb.append("/"); sb.append(mapping); views.add(sb.toString()); } String client = getFormat(); String jenkinsPath = path.getPath() + "/" + getScriptPathOrDefault("Jenkinsfile"); String jenkinsView = ViewMapHelper.getClientView(jenkinsPath , client); String mappingsView = ViewMapHelper.getClientView(views, client); String view = jenkinsView + "\n" + mappingsView; WorkspaceSpec spec = new WorkspaceSpec(view, null); return new ManualWorkspaceImpl(getCharset(), false, client, spec); } private List<String> getViewMappings() { return toLines(getMappings()); } @Extension @Symbol("multiBranch") public static final class DescriptorImpl extends P4ScmSourceDescriptor { public static final String defaultPath = "..."; public static final String defaultFilter = ".*"; @Override public String getDisplayName() { return "Helix Branches"; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 24478 | Paul Allen |
Merging using p4-jenkins_main>dev @24454 |
||
#4 | 24477 | Paul Allen |
Merging using p4-jenkins_main>dev @24439 |
||
#3 | 24420 | Paul Allen |
Merging using p4-jenkins_main>dev @24233 |
||
#2 | 23691 | Paul Allen | Cleanup P4Task: Remove disconnect and use Closeable. | ||
#1 | 23685 | Paul Allen | Copy main -> dev | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/scm/BranchesScmSource.java | |||||
#15 | 23373 | Paul Allen |
Lightweight checkout support. Implementation for scm-api classes SCMFile and SCMFileSystem, allowing Jenkins to navigate Perforce within the scope of a workspace view. Lightweight checkout uses a tempoary Perforce workspace to naviagete and fetch the files. The client name and client view mapping will be modified from a template name e.g. jenkins-${NODE_NAME}-${JOB_NAME} to the tempoary name jenkinsTemp-UUID. Alternativly if a user as used ${P4_CLIENT} in the client mapping this will remain unchanged and will be get expanded during the job run. JENKINS-45999 JENKINS-46269 |
||
#14 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#13 | 23261 | Paul Allen | Backwards compatibility for new Mappings field in MultiBranch. | ||
#12 | 23217 | Paul Allen |
Add the ability to provide a view spec to Helix Branches SCM Pr/61. Review Pr/64 |
||
#11 | 23028 | Paul Allen |
MultiBranch docs and tidy up. Move getScriptPathOrDefault and getWorkspace from Helix Branches to AbstractP4ScmSource. |
||
#10 | 23024 | Paul Allen |
Merge pull request #59 from fbyrne/JENKINS-45657 [Jenkins-45657] Recreation of pull request |
||
#9 | 23017 | Paul Allen |
MultiBranch configuration cleanup. Remove BETA, hide standard options in Advanced group and added isGraphCompatible check in Populate Descriptor. |
||
#8 | 22875 | Paul Allen | Refactor P4Path and Swarm API | ||
#7 | 22866 | Paul Allen |
Merge pull request #55 from jenkinsci/hth Global Pipeline Library support. JENKINS-46121 JENKINS-46550 |
||
#6 | 22684 | Paul Allen | Added @Symbol to Extension classes for Pipeline Syntax. | ||
#5 | 22678 | Paul Allen |
MultiBranch support for Helix4Git (GitHub PR model). Update MultiBranch product names to Helix. |
||
#4 | 22396 | Paul Allen |
MultiBranch support for Perforce Swarm Reviews. A work in progress - adds Swarm API support to find branches and reviews from a Swarm project. #review-22354 |
||
#3 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#2 | 21779 | Paul Allen |
Help for MultiBranch include field and update BETA label. JENKINS-32616 |
||
#1 | 21758 | Paul Allen |
Merge pull request #38 from jenkinsci/dev scm-api 2.0.2 updates |