diff --git a/src/main/java/hudson/tasks/junit/History.java b/src/main/java/hudson/tasks/junit/History.java index b9da9b36c..0879b8332 100644 --- a/src/main/java/hudson/tasks/junit/History.java +++ b/src/main/java/hudson/tasks/junit/History.java @@ -26,6 +26,9 @@ import edu.hm.hafner.echarts.ChartModelConfiguration; import edu.hm.hafner.echarts.JacksonFacade; import edu.hm.hafner.echarts.LinesChartModel; +import hudson.model.Job; +import hudson.model.Run; +import jenkins.model.Jenkins; import hudson.tasks.test.TestObject; import hudson.tasks.test.TestObjectIterable; import hudson.tasks.test.TestResultDurationChart; @@ -34,6 +37,8 @@ import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.bind.JavaScriptMethod; +import java.util.List; +import java.util.ArrayList; /** * History of {@link hudson.tasks.test.TestObject} over time. @@ -49,6 +54,19 @@ public History(TestObject testObject) { this.testObject = testObject; } + public List getList(int start, int end) { + List list = new ArrayList(); + end = Math.min(end, testObject.getRun().getParent().getBuilds().size()); + for (Run b: testObject.getRun().getParent().getBuilds().subList(start, end)) { + if (b.isBuilding()) continue; + TestResult o = testObject.getResultInRun(b); + if (o != null) { + list.add(o); + } + } + return list; + } + @SuppressWarnings("unused") // Called by jelly view public TestObject getTestObject() { return testObject; @@ -56,6 +74,9 @@ public TestObject getTestObject() { @SuppressWarnings("unused") // Called by jelly view public boolean historyAvailable() { + Job job = testObject.getRun().getParent(); + JobTestResultDisplayProperty settings = job.getProperty(JobTestResultDisplayProperty.class); + if (settings != null && settings.getDisableHistoricalResults()) return false if (testObject instanceof hudson.tasks.junit.TestResult) { TestResultImpl pluggableStorage = ((hudson.tasks.junit.TestResult) testObject).getPluggableStorage(); if (pluggableStorage != null) { diff --git a/src/main/java/hudson/tasks/junit/JobTestResultDisplayProperty.java b/src/main/java/hudson/tasks/junit/JobTestResultDisplayProperty.java new file mode 100644 index 000000000..c4794a5a2 --- /dev/null +++ b/src/main/java/hudson/tasks/junit/JobTestResultDisplayProperty.java @@ -0,0 +1,66 @@ +/* + * The MIT License + * + * Copyright 2016 SAP SE + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package hudson.tasks.junit; + +import hudson.Extension; +import hudson.model.Job; +import hudson.model.JobProperty; +import hudson.model.JobPropertyDescriptor; +import net.sf.json.JSONObject; +import org.kohsuke.stapler.StaplerRequest; + +/** + * + */ +public class JobTestResultDisplayProperty extends JobProperty> { + private final boolean disableHistoricalResults; + + public JobTestResultDisplayProperty(Boolean disableHistoricalResults) { + if ( disableHistoricalResults != null ) { + this.disableHistoricalResults = disableHistoricalResults; + } + else { + this.disableHistoricalResults = false; + } + } + + public boolean getDisableHistoricalResults() { + return disableHistoricalResults; + } + + @Extension + public static class DescriptorImpl extends JobPropertyDescriptor { + + @Override + public String getDisplayName() { + return ""; + } + + @Override + public JobTestResultDisplayProperty newInstance(StaplerRequest req, JSONObject formData) { + if (formData.isNullObject()) return null; + return new JobTestResultDisplayProperty(formData.getBoolean("junitsettings-disableHistoricalResults")); + } + } +} diff --git a/src/main/java/hudson/tasks/junit/TestResultAction.java b/src/main/java/hudson/tasks/junit/TestResultAction.java index ca1e13d75..a172616af 100644 --- a/src/main/java/hudson/tasks/junit/TestResultAction.java +++ b/src/main/java/hudson/tasks/junit/TestResultAction.java @@ -224,6 +224,17 @@ public List getSkippedTests() { } + @Override + public boolean shouldCalculatePreviousResults() { + JobTestResultDisplayProperty settings = run.getParent().getProperty(JobTestResultDisplayProperty.class); + if ( settings != null ) { + return !settings.getDisableHistoricalResults(); + } + else { + return super.shouldCalculatePreviousResults(); + } + } + /** * Loads a {@link TestResult} from disk. */ diff --git a/src/main/java/hudson/tasks/test/AbstractTestResultAction.java b/src/main/java/hudson/tasks/test/AbstractTestResultAction.java index 8046b011d..f22d91227 100644 --- a/src/main/java/hudson/tasks/test/AbstractTestResultAction.java +++ b/src/main/java/hudson/tasks/test/AbstractTestResultAction.java @@ -189,6 +189,15 @@ public double getHealthScaleFactor() { return 1.0; } + /** + * Allows a particular job to disable scanning previous result history. + * + * @return if calculation of previous results should be done + */ + public boolean shouldCalculatePreviousResults() { + return true; + } + /** * Exposes this object to the remote API. */ diff --git a/src/main/java/hudson/tasks/test/TestResult.java b/src/main/java/hudson/tasks/test/TestResult.java index 317f0b745..e8375cfa2 100644 --- a/src/main/java/hudson/tasks/test/TestResult.java +++ b/src/main/java/hudson/tasks/test/TestResult.java @@ -137,6 +137,11 @@ public TestResult getPreviousResult() { if (b == null) { return null; } + + // abort if the job is configured to not do this + AbstractTestResultAction tra = b.getAction(getParentAction().getClass()); + if ( tra != null && !tra.shouldCalculatePreviousResults()) return null; + while(true) { b = b.getPreviousBuild(); if(b==null) diff --git a/src/main/java/hudson/tasks/test/TestResultProjectAction.java b/src/main/java/hudson/tasks/test/TestResultProjectAction.java index 0d1f2736a..afc516876 100644 --- a/src/main/java/hudson/tasks/test/TestResultProjectAction.java +++ b/src/main/java/hudson/tasks/test/TestResultProjectAction.java @@ -156,7 +156,7 @@ private TestResultActionIterable createBuildHistory(Run lastCompletedBuild @Deprecated public void doTrend( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { AbstractTestResultAction a = getLastTestResultAction(); - if(a!=null) + if(a!=null && a.shouldCalculatePreviousResults()) a.doGraph(req,rsp); else rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); diff --git a/src/main/resources/hudson/tasks/junit/JobTestResultDisplayProperty/config.jelly b/src/main/resources/hudson/tasks/junit/JobTestResultDisplayProperty/config.jelly new file mode 100644 index 000000000..53648bb18 --- /dev/null +++ b/src/main/resources/hudson/tasks/junit/JobTestResultDisplayProperty/config.jelly @@ -0,0 +1,33 @@ + + + + + diff --git a/src/main/resources/hudson/tasks/junit/JobTestResultDisplayProperty/help-disableHistoricalResults.html b/src/main/resources/hudson/tasks/junit/JobTestResultDisplayProperty/help-disableHistoricalResults.html new file mode 100644 index 000000000..4b2726ffa --- /dev/null +++ b/src/main/resources/hudson/tasks/junit/JobTestResultDisplayProperty/help-disableHistoricalResults.html @@ -0,0 +1,28 @@ + +
+If enabled, historical test results will not be computed and maintained for this job. +
+The test results graph will not be displayed, and the number of builds for which a test has been failing will not be computed. +
diff --git a/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly b/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly index 2847b649c..2ea26a07d 100644 --- a/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly +++ b/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly @@ -25,5 +25,31 @@ THE SOFTWARE. - + + + +
+ + + + + +
+ ${%Test Result Trend} +
+
+ [Test result trend chart] +
+ +
+