Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-11333] Allow users to disable automatic fingerprinting…
…, but add in explicit fingerprinting if desired.
  • Loading branch information
jglick committed May 21, 2014
1 parent 2320cc9 commit 33c52c8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hudson/maven/MavenModule.java
Expand Up @@ -477,7 +477,7 @@ public Resource getWorkspaceResource() {

@Override
public boolean isFingerprintConfigured() {
return true;
return getParent().isFingerprintConfigured();
}

@Override // to make this accessible to MavenModuleSet
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/hudson/maven/MavenModuleSet.java
Expand Up @@ -24,7 +24,6 @@
*/
package hudson.maven;

import static hudson.model.ItemGroupMixIn.loadChildren;
import hudson.CopyOnWrite;
import hudson.EnvVars;
import hudson.Extension;
Expand All @@ -46,6 +45,7 @@
import hudson.model.Executor;
import hudson.model.Item;
import hudson.model.ItemGroup;
import static hudson.model.ItemGroupMixIn.loadChildren;
import hudson.model.Job;
import hudson.model.Queue;
import hudson.model.Queue.Task;
Expand All @@ -62,17 +62,17 @@
import hudson.tasks.BuildWrappers;
import hudson.tasks.Builder;
import hudson.tasks.Fingerprinter;
import hudson.tasks.JavadocArchiver;
import hudson.tasks.Mailer;
import hudson.tasks.Maven;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.Publisher;
import hudson.tasks.JavadocArchiver;
import hudson.tasks.junit.JUnitResultArchiver;
import hudson.util.AlternativeUiTextProvider;
import hudson.util.CopyOnWriteMap;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import hudson.util.Function1;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -87,9 +87,7 @@
import java.util.Set;
import java.util.Stack;
import java.util.logging.Logger;

import javax.servlet.ServletException;

import jenkins.model.Jenkins;
import jenkins.mvn.FilePathSettingsProvider;
import jenkins.mvn.GlobalMavenConfig;
Expand All @@ -98,14 +96,10 @@
import jenkins.mvn.SettingsProvider;
import jenkins.mvn.SettingsProviderDescriptor;
import net.sf.json.JSONObject;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.maven.model.building.ModelBuildingRequest;

import hudson.tasks.Mailer;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.HttpResponse;
Expand Down Expand Up @@ -231,6 +225,11 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
* If true, do not archive artifacts to the master during site deploy.
*/
private boolean siteArchivingDisabled = false;

/**
* If true, do not fingerprint consumed and produced artifacts.
*/
private boolean fingerprintingDisabled = false;

/**
* parameter for pom parsing by default <code>false</code> to be faster
Expand Down Expand Up @@ -588,6 +587,10 @@ public boolean isSiteArchivingDisabled() {
return siteArchivingDisabled;
}

public boolean isFingerprintingDisabled() {
return fingerprintingDisabled;
}

public void setIncrementalBuild(boolean incrementalBuild) {
this.incrementalBuild = incrementalBuild;
}
Expand Down Expand Up @@ -652,7 +655,11 @@ public void setIsArchivingDisabled(boolean archivingDisabled) {
public void setIsSiteArchivingDisabled(boolean siteArchivingDisabled) {
this.siteArchivingDisabled = siteArchivingDisabled;
}


public void setIsFingerprintingDisabled(boolean fingerprintingDisabled) {
this.fingerprintingDisabled = fingerprintingDisabled;
}

public boolean isResolveDependencies()
{
return resolveDependencies;
Expand Down Expand Up @@ -773,7 +780,7 @@ protected String getName(MavenModule o) {

@Override
public boolean isFingerprintConfigured() {
return true;
return !isFingerprintingDisabled() || getPublishersList().get(Fingerprinter.class) != null;
}

public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
Expand Down Expand Up @@ -1181,6 +1188,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
incrementalBuild = req.hasParameter("maven.incrementalBuild");
archivingDisabled = req.hasParameter("maven.archivingDisabled");
siteArchivingDisabled = req.hasParameter("maven.siteArchivingDisabled");
fingerprintingDisabled = req.hasParameter("maven.fingerprintingDisabled");
resolveDependencies = req.hasParameter( "maven.resolveDependencies" );
processPlugins = req.hasParameter( "maven.processPlugins" );
mavenValidationLevel = NumberUtils.toInt(req.getParameter("maven.validationLevel"), -1);
Expand Down Expand Up @@ -1343,7 +1351,6 @@ public boolean isApplicable(Descriptor descriptor) {

@SuppressWarnings("unchecked")
private static final Set<Class> NOT_APPLICABLE_TYPES = new HashSet<Class>(Arrays.asList(
Fingerprinter.class, // this kicks in automatically
JavadocArchiver.class, // this kicks in automatically
Mailer.class, // for historical reasons, Maven uses MavenMailer
JUnitResultArchiver.class // done by SurefireArchiver
Expand Down
Expand Up @@ -156,7 +156,7 @@ public Void call(MavenBuild build) throws IOException, InterruptedException {
String target = assembly.getName();
listener.getLogger().println("[JENKINS] Archiving "+ assembly+" to "+target);
build.queueArchiving(target, assembly.getAbsolutePath());
// TODO: fingerprint
// TODO: fingerprint (if configured)
}
}

Expand Down
Expand Up @@ -227,7 +227,7 @@ public String getDisplayName() {
}

public MavenReporter newAutoInstance(MavenModule module) {
return new MavenFingerprinter();
return module.getParent().isFingerprintingDisabled() ? null : new MavenFingerprinter();
}
}

Expand Down
Expand Up @@ -94,6 +94,10 @@ THE SOFTWARE.
title="${%Disable automatic site documentation artifact archiving}"
help="/plugin/maven-plugin/siteArchivingDisabled.html"
checked="${it.isSiteArchivingDisabled()}" />
<f:optionalBlock name="maven.fingerprintingDisabled"
title="${%Disable automatic fingerprinting of consumed and produced artifacts}"
help="/plugin/maven-plugin/fingerprintingDisabled.html"
checked="${it.isFingerprintingDisabled()}" />
<f:optionalBlock name="maven.disableTriggerDownstreamProjects"
title="${%Disable triggering of downstream projects}"
help="/plugin/maven-plugin/downstreamDisabled.html"
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/fingerprintingDisabled.html
@@ -0,0 +1,5 @@
<div>
If checked, Jenkins will not automatically compute and the record the fingerprints of all artifacts consumed and produced by the Maven build.
(Recording fingerprints is useful for tracking dependencies among builds, and the origin of binaries, but in some projects it can add considerable overhead to Jenkins on both the master and slave.)
If you still wish to record <em>some</em> fingerprints, select <i>Record fingerprints of files to track usage</i> under <i>Post-build Actions</i>.
</div>
40 changes: 39 additions & 1 deletion src/test/java/hudson/maven/MavenModuleSetTest.java
@@ -1,9 +1,12 @@
package hudson.maven;

import hudson.maven.local_repo.PerJobLocalRepositoryLocator;
import hudson.maven.reporters.MavenFingerprinter;
import hudson.model.Item;
import hudson.tasks.Fingerprinter;
import java.util.TreeSet;
import org.jvnet.hudson.test.Bug;

import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;

/**
Expand All @@ -29,4 +32,39 @@ public void testGetItem() throws Exception {
assertNull(createMavenProject().getItem("invalid"));
}

public void testExplicitFingerprints() throws Exception {
configureMaven31();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
assertFalse(m.isArchivingDisabled());
assertFalse(m.isSiteArchivingDisabled());
assertFalse(m.isFingerprintingDisabled());
assertTrue(m.isFingerprintConfigured());
Fingerprinter.FingerprintAction fa = buildAndAssertSuccess(m).getAction(Fingerprinter.FingerprintAction.class); // determines root module as a side effect
assertNotNull(fa);
assertEquals("[junit:junit-3.8.1.jar, test:test:pom.xml]", new TreeSet<String>(fa.getFingerprints().keySet()).toString());
assertNotNull(jenkins.getDescriptorByType(MavenFingerprinter.DescriptorImpl.class).newAutoInstance(m.getRootModule()));
m.setIsArchivingDisabled(true);
m.setIsSiteArchivingDisabled(true);
m.setIsFingerprintingDisabled(true);
// Worth testing configRoundtrip since MMS uses old, deprecated, pre-auto-form-binding idioms to configure itself.
// (And the setter names do not even follow JavaBeans conventions.)
configRoundtrip(m);
assertTrue(m.isArchivingDisabled());
assertTrue(m.isSiteArchivingDisabled());
assertTrue(m.isFingerprintingDisabled());
assertFalse(m.isFingerprintConfigured());
assertNull(buildAndAssertSuccess(m).getAction(Fingerprinter.FingerprintAction.class));
assertNull(jenkins.getDescriptorByType(MavenFingerprinter.DescriptorImpl.class).newAutoInstance(m.getRootModule()));
m.getPublishersList().add(new Fingerprinter("pom.xml", false));
configRoundtrip(m);
assertTrue(m.isFingerprintingDisabled());
assertTrue(m.isFingerprintConfigured());
assertNotNull(m.getPublishersList().get(Fingerprinter.class));
fa = buildAndAssertSuccess(m).getAction(Fingerprinter.FingerprintAction.class);
assertNotNull(fa);
assertEquals("[pom.xml]", new TreeSet<String>(fa.getFingerprints().keySet()).toString());
assertNull(jenkins.getDescriptorByType(MavenFingerprinter.DescriptorImpl.class).newAutoInstance(m.getRootModule()));
}

}

0 comments on commit 33c52c8

Please sign in to comment.