Skip to content

Commit d8e288a

Browse files
Removed unused report archive code. Remove constants class.
1 parent ea9a7fa commit d8e288a

5 files changed

Lines changed: 22 additions & 262 deletions

File tree

src/main/java/com/codedx/bambooplugin/CodeDxScanTask.java

Lines changed: 22 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import com.atlassian.util.concurrent.NotNull;
1111
import com.codedx.bambooplugin.utils.Archiver;
1212
import com.codedx.bambooplugin.utils.CodeDxBuildStatistics;
13-
import com.codedx.bambooplugin.utils.CodeDxConstants;
14-
import com.codedx.bambooplugin.utils.CodeDxReportWriter;
1513
import com.codedx.client.ApiClient;
1614
import com.codedx.client.ApiException;
1715
import com.codedx.client.api.*;
@@ -45,7 +43,6 @@ private static class ScanTaskState {
4543
String includePaths;
4644
String excludePaths;
4745
String toolOutputFiles;
48-
String reportArchiveName;
4946
boolean waitForResults;
5047
String failureSeverity;
5148
boolean onlyConsiderNewFindings;
@@ -60,8 +57,7 @@ private static class ScanTaskState {
6057
List<File> filesToUpload;
6158
String analysisPrepId;
6259
String analysisJobId;
63-
CodeDxBuildStatistics statsBeforeAnalysis;
64-
CodeDxBuildStatistics statsAfterAnalysis;
60+
CodeDxBuildStatistics buildStatistics;
6561
List<GroupedCount> groupedCounts;
6662
}
6763

@@ -81,7 +77,6 @@ public TaskResult execute(final TaskContext taskContext) throws TaskException
8177

8278
stateMachine.add(CodeDxScanTask::loadUserPreferences);
8379
stateMachine.add(CodeDxScanTask::setupApiClient);
84-
stateMachine.add(CodeDxScanTask::getBuildStatsBeforeAnalysis);
8580
stateMachine.add(CodeDxScanTask::collectFilesToUpload);
8681
stateMachine.add(CodeDxScanTask::uploadFiles);
8782
stateMachine.add(CodeDxScanTask::waitForCodeDxToBeReadyForAnalysis);
@@ -126,7 +121,6 @@ private static Boolean loadUserPreferences(ScanTaskState state) {
126121
return false;
127122
}
128123
state.toolOutputFiles = config.get("toolOutputFiles");
129-
state.reportArchiveName = config.get("reportArchiveName");
130124
state.waitForResults = config.getAsBoolean("waitForResults");
131125
state.failureSeverity = config.get("selectedFailureSeverity");
132126
// Don't wait if the failure severity is "None". Is this what we want?
@@ -309,26 +303,6 @@ private static Boolean waitForCodeDxToBeReadyForAnalysis(ScanTaskState state) {
309303
return true;
310304
}
311305

312-
private static Boolean getBuildStatsBeforeAnalysis(ScanTaskState state) {
313-
314-
if(!state.waitForResults || state.reportArchiveName == null || state.reportArchiveName.isEmpty()) {
315-
// We only need the pre-analysis stats if we are writing the report later
316-
return true;
317-
}
318-
319-
log(state, "Querying Code Dx for pre-analysis statistics");
320-
321-
CodeDxBuildStatistics stats = getBuildStats(state);
322-
323-
if (stats == null) {
324-
return false; // Error already logged in helper method
325-
}
326-
327-
state.statsBeforeAnalysis = stats;
328-
329-
return true;
330-
}
331-
332306
private static Boolean startAnalysis(ScanTaskState state) {
333307
log(state, "Querying Code Dx to start analysis");
334308

@@ -364,9 +338,8 @@ private static Boolean handleAnalysisResults(ScanTaskState state) {
364338
List<Function<ScanTaskState, Boolean>> stateMachine = new ArrayList<Function<ScanTaskState, Boolean>>();
365339

366340
stateMachine.add(CodeDxScanTask::waitForAnalysisToFinish);
367-
stateMachine.add(CodeDxScanTask::getBuildStatsAfterAnalysis);
341+
stateMachine.add(CodeDxScanTask::getBuildStatistics);
368342
stateMachine.add(CodeDxScanTask::getGroupedCounts);
369-
stateMachine.add(CodeDxScanTask::writeReportArchive);
370343
stateMachine.add(CodeDxScanTask::checkFailureSeverity);
371344

372345
return runStateMachine(stateMachine, state);
@@ -417,16 +390,30 @@ private static Boolean waitForAnalysisToFinish(ScanTaskState state) {
417390
return true;
418391
}
419392

420-
private static Boolean getBuildStatsAfterAnalysis(ScanTaskState state) {
393+
private static Boolean getBuildStatistics(ScanTaskState state) {
421394
log(state, "Querying Code Dx for post-analysis statistics");
422395

423-
CodeDxBuildStatistics stats = getBuildStats(state);
396+
Filter filter = new Filter();
397+
filter.put("~status", "gone");
424398

425-
if (stats == null) {
426-
return false; // Error already logged in helper method
399+
GroupedCountsRequest bySeverity = new GroupedCountsRequest();
400+
bySeverity.setFilter(filter);
401+
bySeverity.setCountBy("severity");
402+
403+
GroupedCountsRequest byStatus = new GroupedCountsRequest();
404+
byStatus.setFilter(filter);
405+
byStatus.setCountBy("status");
406+
407+
CodeDxBuildStatistics stats = null;
408+
try {
409+
List<GroupedCount> severityGroupedCounts = state.findingDataApi.getFindingsGroupCount(state.projectId, bySeverity);
410+
List<GroupedCount> statusGroupedCounts = state.findingDataApi.getFindingsGroupCount(state.projectId, byStatus);
411+
stats = new CodeDxBuildStatistics(severityGroupedCounts, statusGroupedCounts);
412+
} catch (ApiException e) {
413+
logApiException(state, e);
427414
}
428415

429-
state.statsAfterAnalysis = stats;
416+
state.buildStatistics = stats;
430417

431418
return true;
432419
}
@@ -450,33 +437,8 @@ private static Boolean getGroupedCounts(ScanTaskState state) {
450437
return false;
451438
}
452439
} else {
453-
state.groupedCounts = state.statsAfterAnalysis.getGroupedSeverityCounts();
454-
}
455-
456-
return true;
457-
}
458-
459-
private static Boolean writeReportArchive(ScanTaskState state) {
460-
461-
// TODO: Remove if not needed after implementing Build Results / Tables
462-
/*
463-
// If user provides an archive name, create a zip containing an simple html file
464-
if(state.reportArchiveName != null && !state.reportArchiveName.isEmpty()) {
465-
log(state, "Creating archived report file. Name: %s", state.reportArchiveName);
466-
467-
CodeDxReportWriter reportWriter = new CodeDxReportWriter(state.reportArchiveName,
468-
state.statsBeforeAnalysis,
469-
state.statsAfterAnalysis,
470-
state.apiUrl,
471-
state.projectId);
472-
try {
473-
reportWriter.writeReport(state.taskContext.getRootDirectory());
474-
} catch (IOException e) {
475-
logError(state, "An error occurred when trying to create the report archive file.");
476-
return false;
477-
}
440+
state.groupedCounts = state.buildStatistics.getGroupedSeverityCounts();
478441
}
479-
*/
480442

481443
return true;
482444
}
@@ -501,32 +463,6 @@ private static Boolean checkFailureSeverity(ScanTaskState state) {
501463
return true;
502464
}
503465

504-
// Helper methods
505-
506-
private static CodeDxBuildStatistics getBuildStats(ScanTaskState state) {
507-
Filter filter = new Filter();
508-
filter.put("~status", "gone");
509-
510-
GroupedCountsRequest bySeverity = new GroupedCountsRequest();
511-
bySeverity.setFilter(filter);
512-
bySeverity.setCountBy("severity");
513-
514-
GroupedCountsRequest byStatus = new GroupedCountsRequest();
515-
byStatus.setFilter(filter);
516-
byStatus.setCountBy("status");
517-
518-
CodeDxBuildStatistics stats = null;
519-
try {
520-
List<GroupedCount> severityGroupedCounts = state.findingDataApi.getFindingsGroupCount(state.projectId, bySeverity);
521-
List<GroupedCount> statusGroupedCounts = state.findingDataApi.getFindingsGroupCount(state.projectId, byStatus);
522-
stats = new CodeDxBuildStatistics(severityGroupedCounts, statusGroupedCounts);
523-
} catch (ApiException e) {
524-
logApiException(state, e);
525-
}
526-
527-
return stats;
528-
}
529-
530466
private static void log(ScanTaskState state, String format, Object... args) {
531467
state.buildLogger.addBuildLogEntry(String.format(format, args));
532468
}

src/main/java/com/codedx/bambooplugin/CodeDxScanTaskConfigurator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public Map<String, String> generateTaskConfigMap(final ActionParametersMap param
7575
config.put("includePaths", params.getString("includePaths"));
7676
config.put("excludePaths", params.getString("excludePaths"));
7777
config.put("toolOutputFiles", params.getString("toolOutputFiles"));
78-
config.put("reportArchiveName", params.getString("reportArchiveName"));
7978
config.put("waitForResults", params.getString("waitForResults"));
8079
config.put("selectedFailureSeverity", params.getString("selectedFailureSeverity"));
8180
config.put("onlyConsiderNewFindings", params.getString("onlyConsiderNewFindings"));
@@ -212,7 +211,6 @@ public void populateContextForCreate(final Map<String, Object> context) {
212211
context.put("includePaths", "**");
213212
context.put("excludePaths", "");
214213
context.put("toolOutputFiles", "");
215-
context.put("reportArchiveName", "");
216214
context.put("waitForResults", false);
217215
context.put("severities", severities);
218216
context.put("selectedFailureSeverity", severities[0]);
@@ -250,7 +248,6 @@ public void populateContextForEdit(Map<String, Object> context, TaskDefinition t
250248
context.put("includePaths", config.get("includePaths"));
251249
context.put("excludePaths", config.get("excludePaths"));
252250
context.put("toolOutputFiles", config.get("toolOutputFiles"));
253-
context.put("reportArchiveName", config.get("reportArchiveName"));
254251
context.put("waitForResults", config.get("waitForResults"));
255252
context.put("selectedFailureSeverity", config.get("selectedFailureSeverity"));
256253
context.put("onlyConsiderNewFindings", config.get("onlyConsiderNewFindings"));

src/main/java/com/codedx/bambooplugin/utils/CodeDxConstants.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/com/codedx/bambooplugin/utils/CodeDxReportWriter.java

Lines changed: 0 additions & 137 deletions
This file was deleted.

src/main/resources/configureCodeDxTask.ftl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,6 @@
258258
<span>Only findings with the 'New' status will be considered when determining if the build is a failure.</span>
259259
</div>
260260

261-
<!--Report Archive Name-->
262-
<!-- TODO: Remove section if not needed after implementing Build Results / Tables -->
263-
<div class="setting-section" style="display:none;">
264-
<div class="setting-textfield">
265-
[@ww.textfield label="Report Archive Name" name="reportArchiveName"/]
266-
</div>
267-
<span id="help-button-report-name" class="setting-help-textfield" onclick="toggleHelp(this)">
268-
<i class="fas fa-question-circle"></i>
269-
</span>
270-
</div>
271-
<div id="help-content-report-name" class="setting-content">
272-
<span>Please provide a unique name for the report archive file.</span>
273-
<span>If the name is not unique, the report may be overwritten by other Code Dx build steps.</span>
274-
</div>
275-
276261
</div>
277262

278263
<!-- Workaround for bug(?) in bamboo to pass variables from server. After failing to save a configuration, variables get passed down inside of a size 1 array. This causes normal escape syntax to fail. -->

0 commit comments

Comments
 (0)