Skip to content

Commit

Permalink
Use client factory-method from the GitSCM-class
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Bø authored and ngiger committed Jan 22, 2015
1 parent 250a92c commit b736cd9
Showing 1 changed file with 1 addition and 30 deletions.
Expand Up @@ -8,12 +8,9 @@
import hudson.plugins.git.GitException;
import hudson.plugins.git.Revision;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.GitTool;
import hudson.scm.SCM;
import hudson.security.ACL;
import hudson.util.ListBoxModel;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -38,17 +35,12 @@
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;

public class GitParameterDefinition extends ParameterDefinition implements
Comparable<GitParameterDefinition> {
private static final long serialVersionUID = 9157832967140868122L;
Expand Down Expand Up @@ -258,17 +250,6 @@ public Map<String, String> generateContents(AbstractProject<?, ?> project,
this.errorMessage = "noWorkspace";
}

String defaultGitExe = File.separatorChar != '/' ? "git.exe" : "git";
hudson.plugins.git.GitTool.DescriptorImpl descriptor = (hudson.plugins.git.GitTool.DescriptorImpl) Hudson
.getInstance().getDescriptor(GitTool.class);
GitTool[] installations = descriptor.getInstallations();
for (GitTool gt : installations) {
if (gt.getGitExe() != null) {
defaultGitExe = gt.getGitExe();
break;
}
}

EnvVars environment = null;

try {
Expand All @@ -281,13 +262,7 @@ public Map<String, String> generateContents(AbstractProject<?, ?> project,
LOGGER.log(Level.INFO, "generateContents contenttype " + type
+ " RemoteConfig " + repository.getURIs());
for (URIish remoteURL : repository.getURIs()) {
GitClient newgit = new Git(TaskListener.NULL, environment)
.using(defaultGitExe).in(project.getSomeWorkspace())
.getClient();
List<StandardUsernameCredentials> credentials = CredentialsProvider
.lookupCredentials(StandardUsernameCredentials.class,
project, ACL.SYSTEM, URIRequirementBuilder
.fromUri(remoteURL.toString()).build());
GitClient newgit = git.createClient(TaskListener.NULL, environment, new Run(project) {}, project.getSomeWorkspace());
FilePath wsDir = null;
if (project.getSomeBuildWithWorkspace() != null) {
wsDir = project.getSomeBuildWithWorkspace().getWorkspace();
Expand All @@ -314,10 +289,6 @@ public Map<String, String> generateContents(AbstractProject<?, ?> project,
String errMsg = "!No workspace. Please build the project at least once";
return Collections.singletonMap(errMsg, errMsg);
}
for (StandardUsernameCredentials aCredential : credentials) {
newgit.setCredentials(aCredential);
LOGGER.log(Level.INFO, "getSomeBuildWithWorkspace setCredentials "+ aCredential.getDescription());
}

FetchCommand fetch = newgit.fetch_().from(remoteURL,
repository.getFetchRefSpecs());
Expand Down

0 comments on commit b736cd9

Please sign in to comment.