Skip to content
Permalink
Browse files

Merge pull request #350 from wadahiro/add-options-to-gitscmsource

Add ability to configure git tool, repository browser, and additional behaviours for literate/multi-branch projects.

Passed interactive testing with a freestyle multi-branch job (confirmed the "Additional Behaviours" are now available in a freestyle multi-branch job when it uses git).

Passed automated testing on multiple platforms.
  • Loading branch information
MarkEWaite committed Jun 25, 2016
2 parents 686430b + fda4f12 commit 38a3b04b4a60e6368a1752ee22048091ea69e108
@@ -42,6 +42,7 @@
import hudson.plugins.git.Revision;
import hudson.plugins.git.SubmoduleConfig;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.browser.GitRepositoryBrowser;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.BuildChooserSetting;
import hudson.plugins.git.util.Build;
@@ -110,6 +111,18 @@ public AbstractGitSCMSource(String id) {

public abstract String getExcludes();

public abstract GitRepositoryBrowser getBrowser();

public abstract void setBrowser(GitRepositoryBrowser browser);

public abstract String getGitTool();

public abstract void setGitTool(String gitTool);

public abstract List<GitSCMExtension> getExtensions();

public abstract void setExtensions(List<GitSCMExtension> extensions);

public String getRemoteName() {
return "origin";
}
@@ -289,11 +302,13 @@ protected StandardUsernameCredentials getCredentials() {
public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) {
BuildChooser buildChooser = revision instanceof SCMRevisionImpl ? new SpecificRevisionBuildChooser(
(SCMRevisionImpl) revision) : new DefaultBuildChooser();
List<GitSCMExtension> extensions = getExtensions();
return new GitSCM(
getRemoteConfigs(),
Collections.singletonList(new BranchSpec(head.getName())),
false, Collections.<SubmoduleConfig>emptyList(),
null, null, Collections.<GitSCMExtension>singletonList(new BuildChooserSetting(buildChooser)));
getBrowser(), getGitTool(),
extensions.isEmpty() ? Collections.<GitSCMExtension>singletonList(new BuildChooserSetting(buildChooser)) : extensions);
}

protected List<UserRemoteConfig> getRemoteConfigs() {
@@ -27,24 +27,36 @@
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;

import hudson.Extension;
import hudson.Util;
import hudson.model.Item;
import hudson.model.Descriptor;
import hudson.model.ParameterValue;
import hudson.plugins.git.GitStatus;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.browser.GitRepositoryBrowser;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.scm.RepositoryBrowser;
import hudson.security.ACL;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;

import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;

import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceDescriptor;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.SCMSourceOwners;

import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -76,6 +88,12 @@

private final boolean ignoreOnPushNotifications;

private GitRepositoryBrowser browser;

private String gitTool;

private List<GitSCMExtension> extensions;

@DataBoundConstructor
public GitSCMSource(String id, String remote, String credentialsId, String includes, String excludes, boolean ignoreOnPushNotifications) {
super(id);
@@ -90,6 +108,42 @@ public boolean isIgnoreOnPushNotifications() {
return ignoreOnPushNotifications;
}

@Override
public GitRepositoryBrowser getBrowser() {
return browser;
}

@Override
@DataBoundSetter
public void setBrowser(GitRepositoryBrowser browser) {
this.browser = browser;
}

@Override
public String getGitTool() {
return gitTool;
}

@Override
@DataBoundSetter
public void setGitTool(String gitTool) {
this.gitTool = gitTool;
}

@Override
public List<GitSCMExtension> getExtensions() {
if (extensions == null) {
extensions = new ArrayList<GitSCMExtension>();
}
return extensions;
}

@Override
@DataBoundSetter
public void setExtensions(List<GitSCMExtension> extensions) {
this.extensions = Util.fixNull(extensions);
}

@Override
public String getCredentialsId() {
return credentialsId;
@@ -140,7 +194,25 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner cont
return result;
}

public GitSCM.DescriptorImpl getSCMDescriptor() {
return (GitSCM.DescriptorImpl)Jenkins.getInstance().getDescriptor(GitSCM.class);
}

public List<GitSCMExtensionDescriptor> getExtensionDescriptors() {
return getSCMDescriptor().getExtensionDescriptors();
}

public List<Descriptor<RepositoryBrowser<?>>> getBrowserDescriptors() {
return getSCMDescriptor().getBrowserDescriptors();
}

public boolean showGitToolOptions() {
return getSCMDescriptor().showGitToolOptions();
}

public ListBoxModel doFillGitToolItems() {
return getSCMDescriptor().doFillGitToolItems();
}
}

@Extension
@@ -33,6 +33,20 @@
<f:entry title="${%Ignore on push notifications}" field="ignoreOnPushNotifications">
<f:checkbox/>
</f:entry>

<j:set var="scm" value="${instance}" />

<j:if test="${descriptor.showGitToolOptions()}">
<f:entry title="${%Git executable}" field="gitTool">
<f:select />
</f:entry>
</j:if>
<t:listScmBrowsers name="git.browser" />
<f:entry title="${%Additional Behaviours}">
<f:hetero-list name="extensions" items="${instance.extensions}" descriptors="${descriptor.getExtensionDescriptors()}"
hasHeader="true" />
</f:entry>

<f:advanced>
<f:entry title="${%Include branches}" field="includes">
<f:textbox default="*"/>
@@ -8,6 +8,7 @@
import hudson.plugins.git.GitChangeSet;
import hudson.plugins.git.GitChangeSet.Path;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.scm.RepositoryBrowser;

import java.io.IOException;
@@ -165,6 +166,27 @@ public String getExcludes() {
}
return result;
}
@Override
public GitRepositoryBrowser getBrowser() {
return null;
}
@Override
public void setBrowser(GitRepositoryBrowser browser) {
}
@Override
public String getGitTool() {
return null;
}
@Override
public void setGitTool(String gitTool) {
}
@Override
public List<GitSCMExtension> getExtensions() {
return new ArrayList<GitSCMExtension>();
}
@Override
public void setExtensions(List<GitSCMExtension> extensions) {
}
}

private GitChangeSet createChangeSet(String rawchangelogpath) throws IOException, SAXException {
@@ -4,6 +4,9 @@
import hudson.plugins.git.BranchSpec;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.browser.GitRepositoryBrowser;
import hudson.plugins.git.extensions.GitSCMExtension;

import java.util.ArrayList;
import java.util.List;
import jenkins.scm.api.SCMHead;
@@ -140,6 +143,33 @@ public String getExcludes() {
public List<RefSpec> getRefSpecs() {
return expectedRefSpecs;
}

@Override
public GitRepositoryBrowser getBrowser() {
return null;
}

@Override
public void setBrowser(GitRepositoryBrowser browser) {
}

@Override
public String getGitTool() {
return null;
}

@Override
public void setGitTool(String gitTool) {
}

@Override
public List<GitSCMExtension> getExtensions() {
return new ArrayList<GitSCMExtension>();
}

@Override
public void setExtensions(List<GitSCMExtension> extensions) {
}
}

private class SCMRevisionImpl extends SCMRevision {

0 comments on commit 38a3b04

Please sign in to comment.
You can’t perform that action at this time.