Skip to content

Commit 7b61cd0

Browse files
authored
Merge pull request #216 from jenkinsci/trend-chart
[JENKINS-46095] Provide option to hide all trend charts
2 parents 8e57bf0 + 6ef4407 commit 7b61cd0

25 files changed

Lines changed: 211 additions & 123 deletions

src/main/java/io/jenkins/plugins/analysis/core/model/JobAction.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.jenkins.plugins.analysis.core.charts.SeverityTrendChart;
1919
import io.jenkins.plugins.analysis.core.charts.ToolsTrendChart;
2020
import io.jenkins.plugins.analysis.core.util.JacksonFacade;
21+
import io.jenkins.plugins.analysis.core.util.TrendChartType;
2122

2223
/**
2324
* A job action displays a link on the side panel of a job. This action also is responsible to render the historical
@@ -29,6 +30,7 @@ public class JobAction implements Action {
2930
private final Job<?, ?> owner;
3031
private final StaticAnalysisLabelProvider labelProvider;
3132
private final int numberOfTools;
33+
private final TrendChartType trendChartType;
3234

3335
/**
3436
* Creates a new instance of {@link JobAction}.
@@ -55,9 +57,27 @@ public JobAction(final Job<?, ?> owner, final StaticAnalysisLabelProvider labelP
5557
* the number of tools that have results to show
5658
*/
5759
public JobAction(final Job<?, ?> owner, final StaticAnalysisLabelProvider labelProvider, final int numberOfTools) {
60+
this(owner, labelProvider, numberOfTools, TrendChartType.TOOLS_ONLY);
61+
}
62+
63+
/**
64+
* Creates a new instance of {@link JobAction}.
65+
*
66+
* @param owner
67+
* the job that owns this action
68+
* @param labelProvider
69+
* the label provider
70+
* @param numberOfTools
71+
* the number of tools that have results to show
72+
* @param trendChartType
73+
* determines if the trend chart will be shown
74+
*/
75+
public JobAction(final Job<?, ?> owner, final StaticAnalysisLabelProvider labelProvider, final int numberOfTools,
76+
final TrendChartType trendChartType) {
5877
this.owner = owner;
5978
this.labelProvider = labelProvider;
6079
this.numberOfTools = numberOfTools;
80+
this.trendChartType = trendChartType;
6181
}
6282

6383
/**
@@ -182,7 +202,7 @@ private LinesChartModel createChartModel() {
182202
*/
183203
@SuppressWarnings("unused") // Called by jelly view
184204
public boolean isTrendVisible() {
185-
return createBuildHistory().hasMultipleResults();
205+
return trendChartType != TrendChartType.NONE && createBuildHistory().hasMultipleResults();
186206
}
187207

188208
@Override

src/main/java/io/jenkins/plugins/analysis/core/model/ResultAction.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import io.jenkins.plugins.analysis.core.util.HealthDescriptor;
2424
import io.jenkins.plugins.analysis.core.util.QualityGateEvaluator;
25+
import io.jenkins.plugins.analysis.core.util.TrendChartType;
2526

2627
/**
2728
* Controls the live cycle of the results in a job. This action persists the results of a build and displays them on the
@@ -42,6 +43,7 @@ public class ResultAction implements HealthReportingAction, LastBuildAction, Run
4243
private final String id;
4344
private final String name;
4445
private final String charset;
46+
private TrendChartType trendChartType;
4547

4648
/**
4749
* Creates a new instance of {@link ResultAction}.
@@ -61,12 +63,48 @@ public class ResultAction implements HealthReportingAction, LastBuildAction, Run
6163
*/
6264
public ResultAction(final Run<?, ?> owner, final AnalysisResult result, final HealthDescriptor healthDescriptor,
6365
final String id, final String name, final Charset charset) {
66+
this(owner, result, healthDescriptor, id, name, charset, TrendChartType.AGGREGATION_TOOLS);
67+
}
68+
69+
/**
70+
* Creates a new instance of {@link ResultAction}.
71+
*
72+
* @param owner
73+
* the associated build/run that created the static analysis result
74+
* @param result
75+
* the result of the static analysis run
76+
* @param healthDescriptor
77+
* the health descriptor of the static analysis run
78+
* @param id
79+
* the ID of the results
80+
* @param name
81+
* the optional name of the results
82+
* @param charset
83+
* the charset to use to display source files
84+
* @param trendChartType
85+
* determines if the trend chart will be shown
86+
*/
87+
public ResultAction(final Run<?, ?> owner, final AnalysisResult result, final HealthDescriptor healthDescriptor,
88+
final String id, final String name, final Charset charset, final TrendChartType trendChartType) {
6489
this.owner = owner;
6590
this.result = result;
6691
this.healthDescriptor = healthDescriptor;
6792
this.id = id;
6893
this.name = name;
6994
this.charset = charset.name();
95+
this.trendChartType = trendChartType;
96+
}
97+
98+
/**
99+
* Called after de-serialization to retain backward compatibility.
100+
*
101+
* @return this
102+
*/
103+
protected Object readResolve() {
104+
if (trendChartType == null) {
105+
trendChartType = TrendChartType.TOOLS_ONLY;
106+
}
107+
return this;
70108
}
71109

72110
/**
@@ -136,8 +174,8 @@ public String getRelativeUrl() {
136174
}
137175

138176
/**
139-
* Gets the absolute path to the build from the owner.
140-
* This is needed for testing due to {@link Run#getAbsoluteUrl()} being final and therefore not mockable.
177+
* Gets the absolute path to the build from the owner. This is needed for testing due to {@link
178+
* Run#getAbsoluteUrl()} being final and therefore not mockable.
141179
*
142180
* @return the absolute url to the job
143181
*/
@@ -155,7 +193,9 @@ public HealthReport getBuildHealth() {
155193

156194
@Override
157195
public Collection<? extends Action> getProjectActions() {
158-
return Collections.singleton(new JobAction(owner.getParent(), getLabelProvider(), result.getSizePerOrigin().size()));
196+
return Collections.singleton(
197+
new JobAction(owner.getParent(), getLabelProvider(), result.getSizePerOrigin().size(),
198+
trendChartType));
159199
}
160200

161201
public AnalysisResult getResult() {

src/main/java/io/jenkins/plugins/analysis/core/steps/AnalysisStepDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public FormValidation doCheckUnhealthy(@QueryParameter final int healthy, @Query
113113
*
114114
* @return a model with all aggregation trend chart positions
115115
*/
116-
public ListBoxModel doFillAggregationTrendItems() {
117-
return model.getAllAggregationTrendChartPositions();
116+
public ListBoxModel doFillTrendChartTypeItems() {
117+
return model.getAllTrendChartTypes();
118118
}
119119
}

src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesPublisher.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import io.jenkins.plugins.analysis.core.model.ResetReferenceAction;
2323
import io.jenkins.plugins.analysis.core.model.ResultAction;
2424
import io.jenkins.plugins.analysis.core.model.ResultSelector;
25-
import io.jenkins.plugins.analysis.core.util.AggregationTrendChartDisplay;
2625
import io.jenkins.plugins.analysis.core.util.HealthDescriptor;
2726
import io.jenkins.plugins.analysis.core.util.JenkinsFacade;
2827
import io.jenkins.plugins.analysis.core.util.LogHandler;
2928
import io.jenkins.plugins.analysis.core.util.QualityGateEvaluator;
3029
import io.jenkins.plugins.analysis.core.util.QualityGateStatus;
3130
import io.jenkins.plugins.analysis.core.util.StageResultHandler;
31+
import io.jenkins.plugins.analysis.core.util.TrendChartType;
3232
import io.jenkins.plugins.forensics.blame.Blames;
3333
import io.jenkins.plugins.forensics.miner.RepositoryStatistics;
3434

@@ -87,19 +87,19 @@ private String getId() {
8787
* @return the created result action
8888
*/
8989
ResultAction attachAction() {
90-
return attachAction(AggregationTrendChartDisplay.TOP);
90+
return attachAction(TrendChartType.AGGREGATION_TOOLS);
9191
}
9292

9393
/**
9494
* Creates a new {@link AnalysisResult} and attaches the result in a {@link ResultAction} that is registered with
9595
* the current run.
9696
*
97-
* @param chartType
97+
* @param trendChartType
9898
* the chart to show
9999
*
100100
* @return the created result action
101101
*/
102-
ResultAction attachAction(final AggregationTrendChartDisplay chartType) {
102+
ResultAction attachAction(final TrendChartType trendChartType) {
103103
logger.log("Attaching ResultAction with ID '%s' to run '%s'.", getId(), run);
104104

105105
ResultSelector selector = ensureThatIdIsUnique();
@@ -114,16 +114,17 @@ ResultAction attachAction(final AggregationTrendChartDisplay chartType) {
114114
"Some errors have been logged during recording of issues");
115115
}
116116

117-
if (chartType == AggregationTrendChartDisplay.TOP) {
117+
if (trendChartType == TrendChartType.AGGREGATION_TOOLS) {
118118
AggregationAction action = run.getAction(AggregationAction.class);
119119
if (action == null) {
120120
run.addAction(new AggregationAction());
121121
}
122122
}
123-
ResultAction action = new ResultAction(run, result, healthDescriptor, getId(), name, sourceCodeEncoding);
123+
ResultAction action = new ResultAction(run, result, healthDescriptor, getId(), name, sourceCodeEncoding,
124+
trendChartType);
124125
run.addAction(action);
125126

126-
if (chartType == AggregationTrendChartDisplay.BOTTOM) {
127+
if (trendChartType == TrendChartType.TOOLS_AGGREGATION) {
127128
run.addOrReplaceAction(new AggregationAction());
128129
}
129130
return action;

src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesRecorder.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import io.jenkins.plugins.analysis.core.model.Tool;
4747
import io.jenkins.plugins.analysis.core.steps.IssuesScanner.BlameMode;
4848
import io.jenkins.plugins.analysis.core.steps.IssuesScanner.ForensicsMode;
49-
import io.jenkins.plugins.analysis.core.util.AggregationTrendChartDisplay;
5049
import io.jenkins.plugins.analysis.core.util.HealthDescriptor;
5150
import io.jenkins.plugins.analysis.core.util.LogHandler;
5251
import io.jenkins.plugins.analysis.core.util.ModelValidation;
@@ -56,6 +55,7 @@
5655
import io.jenkins.plugins.analysis.core.util.QualityGateEvaluator;
5756
import io.jenkins.plugins.analysis.core.util.RunResultHandler;
5857
import io.jenkins.plugins.analysis.core.util.StageResultHandler;
58+
import io.jenkins.plugins.analysis.core.util.TrendChartType;
5959

6060
/**
6161
* Freestyle or Maven job {@link Recorder} that scans report files or the console log for issues. Stores the created
@@ -106,7 +106,7 @@ public class IssuesRecorder extends Recorder {
106106

107107
private List<QualityGate> qualityGates = new ArrayList<>();
108108

109-
private AggregationTrendChartDisplay aggregationTrend = AggregationTrendChartDisplay.TOP;
109+
private TrendChartType trendChartType = TrendChartType.AGGREGATION_TOOLS;
110110

111111
/**
112112
* Creates a new instance of {@link IssuesRecorder}.
@@ -124,8 +124,8 @@ public IssuesRecorder() {
124124
* @return this
125125
*/
126126
protected Object readResolve() {
127-
if (aggregationTrend == null) {
128-
aggregationTrend = AggregationTrendChartDisplay.TOP;
127+
if (trendChartType == null) {
128+
trendChartType = TrendChartType.AGGREGATION_TOOLS;
129129
}
130130
if (analysisTools == null) {
131131
analysisTools = new ArrayList<>();
@@ -471,18 +471,18 @@ public String getMinimumSeverity() {
471471
}
472472

473473
/**
474-
* Sets the type of the aggregation trend chart that should be shown on the job page.
474+
* Sets the type of the trend chart that should be shown on the job page.
475475
*
476-
* @param aggregationTrend
476+
* @param trendChartType
477477
* the type of the trend chart to use
478478
*/
479479
@DataBoundSetter
480-
public void setAggregationTrend(final AggregationTrendChartDisplay aggregationTrend) {
481-
this.aggregationTrend = aggregationTrend;
480+
public void setTrendChartType(final TrendChartType trendChartType) {
481+
this.trendChartType = trendChartType;
482482
}
483483

484-
public AggregationTrendChartDisplay getAggregationTrend() {
485-
return aggregationTrend;
484+
public TrendChartType getTrendChartType() {
485+
return trendChartType;
486486
}
487487

488488
/**
@@ -638,7 +638,7 @@ void publishResult(final Run<?, ?> run, final TaskListener listener, final Strin
638638
new HealthDescriptor(healthy, unhealthy, minimumSeverity), qualityGate,
639639
reportName, referenceJobName, ignoreQualityGate, ignoreFailedBuilds, getSourceCodeCharset(),
640640
new LogHandler(listener, loggerName, report.getReport()), statusHandler, failOnError);
641-
publisher.attachAction(aggregationTrend);
641+
publisher.attachAction(trendChartType);
642642
}
643643

644644
/**
@@ -1188,8 +1188,8 @@ public FormValidation doCheckUnhealthy(@QueryParameter final int healthy, @Query
11881188
*
11891189
* @return a model with all aggregation trend chart positions
11901190
*/
1191-
public ListBoxModel doFillAggregationTrendItems() {
1192-
return model.getAllAggregationTrendChartPositions();
1191+
public ListBoxModel doFillTrendChartTypeItems() {
1192+
return model.getAllTrendChartTypes();
11931193
}
11941194
}
11951195
}

src/main/java/io/jenkins/plugins/analysis/core/steps/PublishIssuesStep.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import io.jenkins.plugins.analysis.core.model.LabelProviderFactory;
2929
import io.jenkins.plugins.analysis.core.model.ResultAction;
3030
import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider;
31-
import io.jenkins.plugins.analysis.core.util.AggregationTrendChartDisplay;
3231
import io.jenkins.plugins.analysis.core.util.HealthDescriptor;
3332
import io.jenkins.plugins.analysis.core.util.LogHandler;
3433
import io.jenkins.plugins.analysis.core.util.PipelineResultHandler;
@@ -37,6 +36,7 @@
3736
import io.jenkins.plugins.analysis.core.util.QualityGate.QualityGateType;
3837
import io.jenkins.plugins.analysis.core.util.QualityGateEvaluator;
3938
import io.jenkins.plugins.analysis.core.util.StageResultHandler;
39+
import io.jenkins.plugins.analysis.core.util.TrendChartType;
4040

4141
/**
4242
* Publish issues created by a static analysis build. The recorded issues are stored as a {@link ResultAction} in the
@@ -63,7 +63,7 @@ public class PublishIssuesStep extends Step implements Serializable {
6363

6464
private List<QualityGate> qualityGates = new ArrayList<>();
6565

66-
private AggregationTrendChartDisplay aggregationTrend = AggregationTrendChartDisplay.TOP;
66+
private TrendChartType trendChartType = TrendChartType.AGGREGATION_TOOLS;
6767

6868
private String id = StringUtils.EMPTY;
6969
private String name = StringUtils.EMPTY;
@@ -271,18 +271,18 @@ public void setMinimumSeverity(final String minimumSeverity) {
271271
}
272272

273273
/**
274-
* Sets the type of the aggregation trend chart that should be shown on the job page.
274+
* Sets the type of the trend chart that should be shown on the job page.
275275
*
276-
* @param aggregationTrend
276+
* @param trendChartType
277277
* the type of the trend chart to use
278278
*/
279279
@DataBoundSetter
280-
public void setAggregationTrend(final AggregationTrendChartDisplay aggregationTrend) {
281-
this.aggregationTrend = aggregationTrend;
280+
public void setTrendChartType(final TrendChartType trendChartType) {
281+
this.trendChartType = trendChartType;
282282
}
283283

284-
public AggregationTrendChartDisplay getAggregationTrend() {
285-
return aggregationTrend;
284+
public TrendChartType getTrendChartType() {
285+
return trendChartType;
286286
}
287287

288288
/**
@@ -791,7 +791,7 @@ protected ResultAction run() throws IOException, InterruptedException, IllegalSt
791791
step.getMinimumSeverityAsSeverity()), qualityGate,
792792
StringUtils.defaultString(step.getName()), step.getReferenceJobName(), step.getIgnoreQualityGate(), step.getIgnoreFailedBuilds(),
793793
getCharset(step.getSourceCodeEncoding()), getLogger(report), statusHandler, step.getFailOnError());
794-
return publisher.attachAction(step.getAggregationTrend());
794+
return publisher.attachAction(step.getTrendChartType());
795795
}
796796

797797
private LogHandler getLogger(final AnnotatedReport report) throws InterruptedException {

0 commit comments

Comments
 (0)