package org.jenkinsci.plugins.p4.scm; import com.perforce.p4java.core.IRepo; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.graph.IGraphRef; import com.perforce.p4java.option.server.GraphShowRefOptions; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.DescriptorExtensionList; import hudson.Extension; import hudson.model.Descriptor; import hudson.model.TaskListener; import jenkins.model.Jenkins; import jenkins.scm.api.SCMHeadCategory; import jenkins.scm.impl.ChangeRequestSCMHeadCategory; import jenkins.scm.impl.UncategorizedSCMHeadCategory; import jenkins.util.NonLocalizable; import org.jenkinsci.Symbol; import org.jenkinsci.plugins.p4.browsers.P4Browser; import org.jenkinsci.plugins.p4.changes.P4Ref; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.jenkinsci.plugins.p4.client.ViewMapHelper; import org.jenkinsci.plugins.p4.populate.Populate; import org.jenkinsci.plugins.p4.populate.PopulateDescriptor; 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; public class GraphScmSource extends AbstractP4ScmSource { private P4Browser browser; @DataBoundConstructor public GraphScmSource(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; } @Override public P4Browser getBrowser() { return browser; } @Override public List<P4SCMHead> getTags(@NonNull TaskListener listener) throws Exception { List<P4SCMHead> list = new ArrayList<>(); List<String> includes = getIncludePaths(); try (ConnectionHelper p4 = new ConnectionHelper(getOwner(), credential, listener)) { for (String inc : includes) { List<IRepo> repos = p4.listRepos(inc); list.addAll(getRefsFromRepos(repos, p4)); } } return list; } @Override public List<P4SCMHead> getHeads(@NonNull TaskListener listener) throws Exception { List<P4SCMHead> list = new ArrayList<>(); List<String> includes = getIncludePaths(); try (ConnectionHelper p4 = new ConnectionHelper(getOwner(), credential, listener)) { for (String inc : includes) { List<IRepo> repos = p4.listRepos(inc); list.addAll(getBranchesFromRepos(repos, p4)); } } return list; } private List<P4SCMHead> getBranchesFromRepos(List<IRepo> repos, ConnectionHelper p4) throws Exception { List<P4SCMHead> list = new ArrayList<>(); for (IRepo repo : repos) { String repoName = getRepoName(repo); List<IGraphRef> refs = getRefs(p4, repoName, "branch"); for (IGraphRef ref : refs) { String branchName = ref.getName(); P4Path p4Path = new P4Path(repoName); p4Path.setRevision(branchName); String name = p4Path.getName(); P4SCMHead head = new P4SCMHead(name, p4Path); list.add(head); } } return list; } private List<P4GraphRequestSCMHead> getRefsFromRepos(List<IRepo> repos, ConnectionHelper p4) throws Exception { List<P4GraphRequestSCMHead> list = new ArrayList<>(); for (IRepo repo : repos) { String repoName = getRepoName(repo); List<IGraphRef> refs = getRefs(p4, repoName, "ref"); for (IGraphRef ref : refs) { String branchName = ref.getName(); // only process 'merge' if (!branchName.endsWith("/merge")) { continue; } P4Path p4Path = new P4Path(repoName); p4Path.setRevision(branchName); String name = p4Path.getName(); P4SCMHead target = new P4SCMHead(name, p4Path); P4GraphRequestSCMHead tag = new P4GraphRequestSCMHead(name, repoName, branchName, p4Path, target); list.add(tag); } } return list; } private String getRepoName(IRepo repo) { String repoName = repo.getName(); if (repoName.endsWith(".git")) { repoName = repoName.substring(0, repoName.lastIndexOf(".git")); } return repoName; } private List<IGraphRef> getRefs(ConnectionHelper p4, String repoName, String type) throws P4JavaException { GraphShowRefOptions opts = new GraphShowRefOptions(); opts.setType(type); opts.setRepo(repoName); List<IGraphRef> refs = p4.getConnection().getGraphShowRefs(opts); return refs; } @Override public P4SCMRevision getRevision(P4SCMHead head, TaskListener listener) throws Exception { try (ConnectionHelper p4 = new ConnectionHelper(getOwner(), credential, listener)) { P4Ref ref = p4.getGraphHead(head.getPath().getPath()); P4SCMRevision revision = new P4SCMRevision(head, ref); return revision; } } @Override public Workspace getWorkspace(P4Path path) { if (path == null) { throw new IllegalArgumentException("missing path"); } StringBuffer depotView = new StringBuffer(); depotView.append(path.getPath()); depotView.append("/..."); String client = getFormat(); String view = ViewMapHelper.getClientView(depotView.toString(), client, false); WorkspaceSpec spec = new WorkspaceSpec(view, null); return new ManualWorkspaceImpl(getCharset(), false, client, spec); } @Extension @Symbol("multiGraph") public static final class DescriptorImpl extends P4SCMSourceDescriptor { @Override public String getDisplayName() { return "Helix4Git"; } @NonNull @Override protected SCMHeadCategory[] createCategories() { return new SCMHeadCategory[]{ new UncategorizedSCMHeadCategory(new NonLocalizable("Branches")), new ChangeRequestSCMHeadCategory(new NonLocalizable("Reviews")) }; } public List getGraphPopulateDescriptors() { Jenkins j = Jenkins.getInstance(); DescriptorExtensionList<Populate, Descriptor<Populate>> list = j.getDescriptorList(Populate.class); for (Descriptor<Populate> d : list) { if (!(d instanceof PopulateDescriptor)) { list.remove(d); } else { PopulateDescriptor p = (PopulateDescriptor) d; if (!p.isGraphCompatible()) { list.remove(p); } } } return list; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#21 | 26673 | Paul Allen |
Code cleanup - remove calls to Deprecated methods - Deprecated classes like AbstractStepImpl, AbstractStepDescriptorImpl and AbstractSynchronousStepExecution for P4TaggingStep |
||
#20 | 26602 | Paul Allen |
Reuse temp client connections for the multi-branch scan. TempClientHelper is set in retrieve and updated for different heads. |
||
#19 | 25564 | Paul Allen |
Merge branch 'local_map' MultiBranch support for 'HelixBranches' local and remote Mappings. Allows MultiBranches to map Depot paths external to the MultiBranch projects root. For example, a MultiBranch project with the following Jenkinsfiles: ProjA >> main //depot/projA/main/Jenkinsfile //depot/projA/main/src/... ProjA>> dev //depot/projA/dev/Jenkinsfile //depot/projA/dev/src/... An 'Includes' path for Branch Sources set to: //depot/projA/... Jenkins will now create two branches 'main' and 'dev'. The default Mapping is '...' so the 'src/...' and any other files under the branch root will appear in the project's workspace. To import an extenal location we can add another line to the mapping: ... //depot/external/stuff/... Now both branches 'main' and 'dev' will have a folder 'depot/external/stuff' with the mapped files. We can also use the `BRANCH_NAME` environment variable in the remote path uses the branch name. ... //depot/external/${BRANCH_NAME}/... and in 'main' you will now see the remote files in ' depot/external/main' along with the local project files mapped with '...' |
||
#18 | 25006 | Paul Allen |
Support for remote Jenkinsfiles in a MultiBranch project. Jenkinsfile are idenitified by the Include branches path (e.g. //depot/Remote/...), but you must add a Mapping in the BranchSource->Advanced->View Mappings to locate the projects source and use a special ${BRANCH_NAME} in the path. e.g. //depot/ProjectA/${BRANCH_NAME}/... JENKINS-53936 |
||
#17 | 24767 | Paul Allen |
Global Library support for multiple instances. Enforce a depot syntax path ending of "/..." Remove 'beta' from Global Library configuration. Generate a unique workspace to sync multiple Libraries. JENKINS-53922 |
||
#16 | 24662 | Paul Allen |
Undo *SCMSource rename to original *ScmSource. Reslove configuration loading issue due to 1.9.0 bad release. |
||
#15 | 24504 | Paul Allen |
Tree walter for BranchSCMSource Events. On a change-submit event use the change number and grab a submitted file. Walk up the path looking for a Jenkinsfile, then derive 'Project' path, 'Branch' name and 'Path' for the SCMHead/Revision. This assumes that the Jenkinsfile is in the route of your projects. Alternatively use the Swarm Event and pass your own 'Project', 'Branch' and 'Path'. |
||
#14 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#13 | 24488 | Paul Allen |
Min version Jenkins 2.60.3 Upgrade dependencies and move to Java 8. |
||
#12 | 24454 | Paul Allen |
Exclude and Include mapping support. Refactored P4Path usage and added P4SwarmPath. JENKINS-49804 |
||
#11 | 23328 | Paul Allen | Use client less connection for MultiBranch Graph. | ||
#10 | 23324 | Paul Allen | Use short lived temporary client when scanning MultiBranch. | ||
#9 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#8 | 23017 | Paul Allen |
MultiBranch configuration cleanup. Remove BETA, hide standard options in Advanced group and added isGraphCompatible check in Populate Descriptor. |
||
#7 | 22875 | Paul Allen | Refactor P4Path and Swarm API | ||
#6 | 22866 | Paul Allen |
Merge pull request #55 from jenkinsci/hth Global Pipeline Library support. JENKINS-46121 JENKINS-46550 |
||
#5 | 22863 | Paul Allen | Store change in P4Revision as P4Ref. | ||
#4 | 22684 | Paul Allen | Added @Symbol to Extension classes for Pipeline Syntax. | ||
#3 | 22678 | Paul Allen |
MultiBranch support for Helix4Git (GitHub PR model). Update MultiBranch product names to Helix. |
||
#2 | 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 |
||
#1 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/scm/GraphSCMSource.java | |||||
#1 | 24504 | Paul Allen |
Tree walter for BranchSCMSource Events. On a change-submit event use the change number and grab a submitted file. Walk up the path looking for a Jenkinsfile, then derive 'Project' path, 'Branch' name and 'Path' for the SCMHead/Revision. This assumes that the Jenkinsfile is in the route of your projects. Alternatively use the Swarm Event and pass your own 'Project', 'Branch' and 'Path'. |
||
# | Change | User | Description | Committed | |
#14 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#13 | 24488 | Paul Allen |
Min version Jenkins 2.60.3 Upgrade dependencies and move to Java 8. |
||
#12 | 24454 | Paul Allen |
Exclude and Include mapping support. Refactored P4Path usage and added P4SwarmPath. JENKINS-49804 |
||
#11 | 23328 | Paul Allen | Use client less connection for MultiBranch Graph. | ||
#10 | 23324 | Paul Allen | Use short lived temporary client when scanning MultiBranch. | ||
#9 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#8 | 23017 | Paul Allen |
MultiBranch configuration cleanup. Remove BETA, hide standard options in Advanced group and added isGraphCompatible check in Populate Descriptor. |
||
#7 | 22875 | Paul Allen | Refactor P4Path and Swarm API | ||
#6 | 22866 | Paul Allen |
Merge pull request #55 from jenkinsci/hth Global Pipeline Library support. JENKINS-46121 JENKINS-46550 |
||
#5 | 22863 | Paul Allen | Store change in P4Revision as P4Ref. | ||
#4 | 22684 | Paul Allen | Added @Symbol to Extension classes for Pipeline Syntax. | ||
#3 | 22678 | Paul Allen |
MultiBranch support for Helix4Git (GitHub PR model). Update MultiBranch product names to Helix. |
||
#2 | 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 |
||
#1 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
//guest/paul_allen/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/scm/GraphScmSource.java | |||||
#1 | 22049 | Paul Allen | Basic MultiBranch support for Graph. |