Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-17606] Reuse existing fingerprint action if present.
Prevents multiple FingerprintActions.

(cherry picked from commit be7a97e)

Conflicts:
	changelog.html
	core/src/main/java/hudson/tasks/Fingerprinter.java
	test/src/test/java/hudson/tasks/FingerprinterTest.java
  • Loading branch information
Stefan Wolf authored and olivergondza committed Feb 26, 2014
1 parent f768fb7 commit 1c847cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
7 changes: 6 additions & 1 deletion core/src/main/java/hudson/tasks/Fingerprinter.java
Expand Up @@ -133,7 +133,12 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
record(build, listener, record, expandedArtifacts);
}

build.getActions().add(new FingerprintAction(build,record));
FingerprintAction fingerprintAction = build.getAction(FingerprintAction.class);
if (fingerprintAction != null) {
fingerprintAction.add(record);
} else {
build.addAction(new FingerprintAction(build,record));
}

if (enableFingerprintsInDependencyGraph) {
Jenkins.getInstance().rebuildDependencyGraphAsync();
Expand Down
35 changes: 28 additions & 7 deletions test/src/test/java/hudson/tasks/FingerprinterTest.java
Expand Up @@ -24,18 +24,15 @@

package hudson.tasks;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import hudson.Launcher;
import hudson.Util;
import hudson.XmlFile;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixProject;
import hudson.model.AbstractProject;
import hudson.model.Fingerprint;
import hudson.model.FingerprintCleanupThread;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.model.*;
import hudson.util.RunList;
import java.io.File;

Expand All @@ -44,10 +41,14 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.*;

import hudson.util.StreamTaskListener;

import org.junit.Assume;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -109,6 +110,26 @@ public static void setUp() throws Exception {
assertTrue(downstreamProjects.contains(downstream));
}

private static class FingerprintAddingBuilder extends Builder {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.addAction(new Fingerprinter.FingerprintAction(build, ImmutableMap.of(singleFiles2[0], "fakefingerprint")));
return true;
}
}

@Test public void presentFingerprintActionIsReused() throws Exception {
FreeStyleProject project = createFreeStyleProjectWithFingerprints(singleContents, singleFiles);
project.getBuildersList().add(new FingerprintAddingBuilder());

FreeStyleBuild build = j.buildAndAssertSuccess(project);

assertThat(build.getActions(Fingerprinter.FingerprintAction.class), hasSize(1));

Fingerprinter.FingerprintAction action = build.getAction(Fingerprinter.FingerprintAction.class);
assertEquals(action.getRecords().keySet(), ImmutableSet.of(singleFiles2[0], singleFiles[0]));
}

@Test public void multipleUpstreamDependencies() throws Exception {
FreeStyleProject upstream = createFreeStyleProjectWithFingerprints(singleContents, singleFiles);
FreeStyleProject upstream2 = createFreeStyleProjectWithFingerprints(singleContents2, singleFiles2);
Expand Down

0 comments on commit 1c847cc

Please sign in to comment.