提交 fe3f951e 编写于 作者: C Christoph Kutzinski

Merge pull request #184 from kutzi/maven-fingerprinter

Minor optimization for MavenFingerprinter + unit test for fingerprinter
......@@ -126,23 +126,25 @@ public class MavenFingerprinter extends MavenReporter {
/**
* Records the fingerprint of the given {@link Artifact}.
*
* <p>
* This method contains the logic to avoid doubly recording the fingerprint
* of the same file.
*/
private void record(Artifact a, Map<String,String> record) throws IOException, InterruptedException {
File f = a.getFile();
if(files==null)
throw new InternalError();
record(a.getGroupId(), f, record);
}
/**
* Records the fingerprint of the given file.
*
* <p>
* This method contains the logic to avoid doubly recording the fingerprint
* of the same file.
*/
private void record(String groupId, File f, Map<String, String> record) throws IOException, InterruptedException {
if(f==null || !f.exists() || f.isDirectory() || !files.add(f))
if(f==null || files.contains(f) || !f.isFile())
return;
// new file
files.add(f);
String digest = new FilePath(f).digest();
record.put(groupId+':'+f.getName(),digest);
}
......
package hudson.maven;
import org.junit.Assert;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
......@@ -7,12 +8,14 @@ import org.jvnet.hudson.test.ExtractResourceWithChangesSCM;
import org.jvnet.hudson.test.ExtractChangeLogSet;
import hudson.Launcher;
import hudson.maven.reporters.MavenArtifact;
import hudson.maven.reporters.MavenArtifactRecord;
import hudson.maven.reporters.MavenFingerprinter;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.scm.NullSCM;
import hudson.model.Run.Artifact;
import hudson.tasks.Fingerprinter.FingerprintAction;
import hudson.tasks.Maven.MavenInstallation;
import java.io.IOException;
......@@ -38,6 +41,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.getReporters().add(new MavenFingerprinter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod.zip"),
getClass().getResource("maven-multimod-changes.zip")));
......@@ -71,6 +75,40 @@ public class MavenMultiModuleTest extends HudsonTestCase {
}
assertTrue("duration of moduleset build should be greater-equal than sum of the module builds",
pBuild.getDuration() >= summedModuleDuration);
assertFingerprintWereRecorded(pBuild);
}
private void assertFingerprintWereRecorded(MavenModuleSetBuild modulesetBuild) {
boolean mustHaveFingerprints = false;
for (MavenBuild moduleBuild : modulesetBuild.getModuleLastBuilds().values()) {
if (moduleBuild.getResult() != Result.NOT_BUILT && moduleBuild.getResult() != Result.ABORTED) {
assertFingerprintWereRecorded(moduleBuild);
mustHaveFingerprints = true;
}
}
if (mustHaveFingerprints) {
FingerprintAction action = modulesetBuild.getAction(FingerprintAction.class);
Assert.assertNotNull(action);
Assert.assertFalse(action.getFingerprints().isEmpty());
}
}
private void assertFingerprintWereRecorded(MavenBuild moduleBuild) {
FingerprintAction action = moduleBuild.getAction(FingerprintAction.class);
Assert.assertNotNull(action);
Assert.assertFalse(action.getFingerprints().isEmpty());
MavenArtifactRecord artifactRecord = moduleBuild.getAction(MavenArtifactRecord.class);
Assert.assertNotNull(artifactRecord);
String fingerprintName = artifactRecord.mainArtifact.groupId + ":" + artifactRecord.mainArtifact.fileName;
Assert.assertTrue("Expected fingerprint " + fingerprintName + " in module build " + moduleBuild,
action.getFingerprints().containsKey(fingerprintName));
// we should assert more - i.e. that all dependencies are fingerprinted, too,
// but it's complicated to find out the dependencies of the build
}
@Bug(5357)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册