Skip to content
Permalink
Browse files

JENKINS-44627# Use git tests jar (#7)

Fixes issue where if user.name and user.email not set causes tests
to fail.
  • Loading branch information
vivek authored and i386 committed Jun 2, 2017
1 parent d5c36a1 commit 590c9d00a7cbad12e550af5eb42b39ecabbc8b8e
23 pom.xml
@@ -25,6 +25,8 @@
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
-->
<scm-api.version>2.1.1</scm-api.version>
<git.version>3.3.0</git.version>
</properties>

<name>Display URL for Blue Ocean</name>
@@ -80,10 +82,29 @@
<artifactId>workflow-multibranch</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>${scm-api.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>${git.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.4.2</version>
<classifier>tests</classifier>
<version>${git.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>${scm-api.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>

This file was deleted.

@@ -1,15 +1,14 @@
package org.jenkinsci.plugins.blueoceandisplayurl;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import hudson.model.FreeStyleProject;
import hudson.model.Project;
import jenkins.branch.BranchProperty;
import jenkins.branch.BranchSource;
import jenkins.branch.DefaultBranchPropertyStrategy;
import jenkins.plugins.git.GitSCMSource;
import jenkins.plugins.git.GitSampleRepoRule;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
@@ -34,10 +33,20 @@
*/
public class BlueOceanDisplayURLImplTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Rule
public GitSampleRepoRule gitSampleRepoRule = new GitSampleRepoRule();

DisplayURLProvider displayURL;

private GitUtil repo;

@Before
public void before() throws Exception {
repo.init();
gitSampleRepoRule.init();
this.repo = new GitUtil(gitSampleRepoRule);

}
Pattern pathPAttern = Pattern.compile("http://.+:[0-9]+(/.*)");
@@ -47,14 +56,6 @@ private String getPath(String url) throws URISyntaxException {
return m.group(1);
}

@Rule
public JenkinsRule j = new JenkinsRule();

@Rule
public GitSampleRepoRule repo = new GitSampleRepoRule();

DisplayURLProvider displayURL;

@Test
public void testProjectURL() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("abc");
@@ -86,7 +87,7 @@ public void testMultibranchUrls() throws Exception {
.addFile("Jenkinsfile")
.commit("Initial commit to feature/test-1");

MultiBranchTestBuilder mp = MultiBranchTestBuilder.createProjectInFolder(j, "folder", "test", repo);
MultiBranchTestBuilder mp = MultiBranchTestBuilder.createProjectInFolder(j, "folder", "test", gitSampleRepoRule);

WorkflowJob job = mp.scheduleAndFindBranchProject("feature%2Ftest-1");

This file was deleted.

@@ -24,48 +24,46 @@

package org.jenkinsci.plugins.blueoceandisplayurl;

import org.apache.commons.io.FileUtils;
import jenkins.plugins.git.GitSampleRepoRule;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class AbstractSampleDVCSRepoRule extends AbstractSampleRepoRule {

protected File sampleRepo;

@Override protected void before() throws Throwable {
super.before();
sampleRepo = tmp.newFolder();
/**
* Manages a sample Git repository.
*/
public final class GitUtil {
private final GitSampleRepoRule gitSampleRepoRule;
public GitUtil(GitSampleRepoRule gitSampleRepoRule) {
this.gitSampleRepoRule = gitSampleRepoRule;
}

public final void write(String rel, String text) throws IOException {
FileUtils.write(new File(sampleRepo, rel), text);
public void git(String... cmds) throws Exception {
gitSampleRepoRule.git(cmds);
}

@Override public final String toString() {
return sampleRepo.getAbsolutePath();
public GitUtil checkoutNewBranch(String branchName) throws Exception {
git("checkout", "-b", branchName);
return this;
}

public abstract void init() throws Exception;
public GitUtil writeFile(String fileName, String fileContents) throws IOException {
gitSampleRepoRule.write(fileName, fileContents);
return this;
}

protected final void run(String tool, String... cmds) throws Exception {
List<String> args = new ArrayList<String>();
args.add(tool);
args.addAll(Arrays.asList(cmds));
run(false, sampleRepo, args.toArray(new String[args.size()]));
public GitUtil writeJenkinsFile(BlueOceanDisplayURLImplTest.JenkinsFile file) throws IOException {
gitSampleRepoRule.write("Jenkinsfile", file.getFileContents());
return this;
}

public final String bareUrl() throws UnsupportedEncodingException {
return URLEncoder.encode(toString(), "UTF-8");
public GitUtil addFile(String fileName) throws Exception {
git("add", fileName);
return this;
}

public final String fileUrl() {
return sampleRepo.toURI().toString();
public GitUtil commit(String msg) throws Exception {
git("commit", "--all", "--message='"+msg+"'");
return this;
}

}

0 comments on commit 590c9d0

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