Skip to content
Permalink
Browse files

Added options to GitSCMSource for setting GitTool, RepositoryBrowser,

and Additional Behaviours. This can be useful for some jobs for
multi-branch projects (such as literate plugin and multi-branch project
plugin).
  • Loading branch information
wadahiro committed Sep 2, 2015
1 parent b622397 commit cb3d137f4df37c4f9f0664492a547750ddd33336
@@ -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,12 @@ public AbstractGitSCMSource(String id) {

public abstract String getExcludes();

public abstract GitRepositoryBrowser getBrowser();

public abstract String getGitTool();

public abstract List<GitSCMExtension> getExtensions();

public String getRemoteName() {
return "origin";
}
@@ -286,11 +293,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() {
@@ -28,9 +28,16 @@
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;
@@ -76,20 +83,46 @@

private final boolean ignoreOnPushNotifications;

private final GitRepositoryBrowser browser;

private final String gitTool;

private final List<GitSCMExtension> extensions;

@DataBoundConstructor
public GitSCMSource(String id, String remote, String credentialsId, String includes, String excludes, boolean ignoreOnPushNotifications) {
public GitSCMSource(String id, String remote, String credentialsId, String includes, String excludes,
boolean ignoreOnPushNotifications, GitRepositoryBrowser browser, String gitTool,
List<GitSCMExtension> extensions) {
super(id);
this.remote = remote;
this.credentialsId = credentialsId;
this.includes = includes;
this.excludes = excludes;
this.ignoreOnPushNotifications = ignoreOnPushNotifications;
this.browser = browser;
this.gitTool = gitTool;
this.extensions = Util.fixNull(extensions);
}

public boolean isIgnoreOnPushNotifications() {
return ignoreOnPushNotifications;
}

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

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

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

@Override
public String getCredentialsId() {
return credentialsId;
@@ -140,7 +173,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="*"/>

0 comments on commit cb3d137

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