Skip to content

Commit

Permalink
Fix JENKINS-20098
Browse files Browse the repository at this point in the history
Also bumping core dependency to 1.480
it would be strange to keep to 1.424
since git-client requires 1.480.
  • Loading branch information
rsandell committed Oct 17, 2013
1 parent f1ca14d commit 4ff1718
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
9 changes: 8 additions & 1 deletion gerrithudsontrigger/pom.xml
Expand Up @@ -9,7 +9,7 @@

<groupId>com.sonyericsson.hudson.plugins.gerrit</groupId>
<artifactId>gerrit-trigger</artifactId>
<version>2.10.2-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Gerrit Trigger</name>
<description>Integrates with Gerrit code review.</description>
Expand Down Expand Up @@ -66,6 +66,13 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>1.2.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-client</artifactId>
<version>1.4.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sonyericsson.hudson.plugins.rebuild</groupId>
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.RepositoryCallback;
import org.kohsuke.stapler.DataBoundConstructor;
import org.eclipse.jgit.lib.ObjectId;

Expand Down Expand Up @@ -109,7 +110,7 @@ public Collection<Revision> getCandidateRevisions(boolean isPollCall, String sin

@Override
public Build prevBuildForChangelog(String singleBranch, BuildData data, GitClient git,
BuildChooserContext context) {
BuildChooserContext context) throws InterruptedException, IOException {
ObjectId sha1 = git.revParse("FETCH_HEAD");

// Now we cheat and add the parent as the last build on the branch, so we can
Expand Down Expand Up @@ -138,28 +139,36 @@ public Build prevBuildForChangelog(String singleBranch, BuildData data, GitClien
* @param git GitClient API object
* @return object id of Revision's parent, or of Revision itself if there is no parent
* @throws GitException In case of error in git call
* @throws InterruptedException if the repository handling gets interrupted
* @throws IOException in case of communication errors.
*/
private ObjectId getFirstParent(ObjectId id, GitClient git) throws GitException {
RevWalk walk = null;
ObjectId result = null;
try {
Repository repository = git.getRepository();
walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(id);
if (commit.getParentCount() > 0) {
result = commit.getParent(0);
} else {
// If this is the first commit in the git, there is no parent.
result = id;
}
} catch (Exception e) {
throw new GitException("Failed to find parent id. ", e);
} finally {
if (walk != null) {
walk.release();
private ObjectId getFirstParent(final ObjectId id, GitClient git)
throws GitException, IOException, InterruptedException {
return git.withRepository(new RepositoryCallback<ObjectId>() {
@Override
public ObjectId invoke(Repository repository, VirtualChannel virtualChannel)
throws IOException, InterruptedException {
RevWalk walk = null;
ObjectId result = null;
try {
walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(id);
if (commit.getParentCount() > 0) {
result = commit.getParent(0);
} else {
// If this is the first commit in the git, there is no parent.
result = id;
}
} catch (Exception e) {
throw new GitException("Failed to find parent id. ", e);
} finally {
if (walk != null) {
walk.release();
}
}
return result;
}
}
return result;
});
}

/**
Expand Down
Expand Up @@ -191,6 +191,7 @@ public void testMakeRefSpec4() {
public void testScheduleWithAverageBuildScheduleDelay() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
PowerMockito.mockStatic(PluginImpl.class);
PluginImpl plugin = PowerMockito.mock(PluginImpl.class);
IGerritHudsonTriggerConfig config = Setup.createConfig();
Expand Down Expand Up @@ -253,6 +254,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
@Test
public void testInitializeTriggerOnEvents() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullName()).thenReturn("MockedProject");
GerritTrigger trigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
true, true, false, "", "", "", "", "", null, null, null, false, "");
trigger = spy(trigger);
Expand All @@ -275,6 +277,7 @@ public void testInitializeTriggerOnEvents() {
public void testScheduleWithNegativeBuildScheduleDelay() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
PowerMockito.mockStatic(PluginImpl.class);
PluginImpl plugin = PowerMockito.mock(PluginImpl.class);
IGerritHudsonTriggerConfig config = Setup.createConfig();
Expand Down Expand Up @@ -310,6 +313,7 @@ public void testScheduleWithNegativeBuildScheduleDelay() {
public void testScheduleWithMaximumBuildScheduleDelay() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
PowerMockito.mockStatic(PluginImpl.class);
PluginImpl plugin = PowerMockito.mock(PluginImpl.class);
IGerritHudsonTriggerConfig config = Setup.createConfig();
Expand Down Expand Up @@ -346,6 +350,7 @@ public void testScheduleWithDefaultParameters() {

AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
ParametersDefinitionProperty parameters = mock(ParametersDefinitionProperty.class);
List<ParameterDefinition> list = new LinkedList<ParameterDefinition>();
list.add(new StringParameterDefinition("MOCK_PARAM", "mock_value"));
Expand Down Expand Up @@ -393,6 +398,7 @@ public void testScheduleWithDefaultParameters() {
public void testScheduleWithNoDefaultParameters() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
ParametersDefinitionProperty parameters = mock(ParametersDefinitionProperty.class);
when(parameters.getParameterDefinitions()).thenReturn(Collections.EMPTY_LIST);
when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(parameters);
Expand Down Expand Up @@ -439,6 +445,7 @@ public void testScheduleWithNoDefaultParameters() {
public void testScheduleWithOwnerAndUploader() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
ParametersDefinitionProperty parameters = mock(ParametersDefinitionProperty.class);
when(parameters.getParameterDefinitions()).thenReturn(Collections.EMPTY_LIST);
when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(parameters);
Expand Down Expand Up @@ -488,6 +495,7 @@ public void testScheduleWithOwnerAndUploader() {
public void testScheduleWithOwnerAndOneUploaderNull() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
ParametersDefinitionProperty parameters = mock(ParametersDefinitionProperty.class);
when(parameters.getParameterDefinitions()).thenReturn(Collections.EMPTY_LIST);
when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(parameters);
Expand Down Expand Up @@ -537,6 +545,7 @@ public void testScheduleWithOwnerAndOneUploaderNull() {
public void testScheduleWithOwnerAndOtherUploaderNull() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
ParametersDefinitionProperty parameters = mock(ParametersDefinitionProperty.class);
when(parameters.getParameterDefinitions()).thenReturn(Collections.EMPTY_LIST);
when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(parameters);
Expand Down Expand Up @@ -586,6 +595,7 @@ public void testScheduleWithOwnerAndOtherUploaderNull() {
public void testScheduleWithOwnerAndBothUploadersNull() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
ParametersDefinitionProperty parameters = mock(ParametersDefinitionProperty.class);
when(parameters.getParameterDefinitions()).thenReturn(Collections.EMPTY_LIST);
when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(parameters);
Expand Down Expand Up @@ -634,6 +644,7 @@ public void testScheduleWithOwnerAndBothUploadersNull() {
public void testScheduleWithOwnerAndPartOfUploadersNull() {
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullDisplayName()).thenReturn("MockedProject");
when(project.getFullName()).thenReturn("MockedProject");
ParametersDefinitionProperty parameters = mock(ParametersDefinitionProperty.class);
when(parameters.getParameterDefinitions()).thenReturn(Collections.EMPTY_LIST);
when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(parameters);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.424</version>
<version>1.480</version>
<!--<relativePath>../pom.xml</relativePath>-->
</parent>

Expand Down

0 comments on commit 4ff1718

Please sign in to comment.