Skip to content

Commit 81bcc7b

Browse files
Improve and standardize task run log messages
1 parent 940601e commit 81bcc7b

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public TaskResult execute(final TaskContext taskContext) throws TaskException
7474
state.taskContext = taskContext;
7575
state.buildLogger = taskContext.getBuildLogger();
7676

77-
log(state, "Starting Code Dx Task.");
77+
log(state, "Starting Code Dx scan task");
7878

7979
// Split up the work and into "states" for readability and order
8080
List<Function<ScanTaskState, Boolean>> stateMachine = new ArrayList<Function<ScanTaskState, Boolean>>();
@@ -90,10 +90,10 @@ public TaskResult execute(final TaskContext taskContext) throws TaskException
9090

9191
boolean success = runStateMachine(stateMachine, state);
9292
if (success) {
93-
log(state, "Code Dx Scan Task completed successfully!");
93+
log(state, "Code Dx scan task completed successfully!");
9494
return TaskResultBuilder.newBuilder(taskContext).success().build();
9595
} else {
96-
log(state, "Code Dx Scan Task failed to complete.");
96+
log(state, "Code Dx scan task failed to complete");
9797
return TaskResultBuilder.newBuilder(taskContext).failed().build();
9898
}
9999
}
@@ -114,7 +114,7 @@ private static Boolean runStateMachine(List<Function<ScanTaskState, Boolean>> st
114114
private static Boolean loadUserPreferences(ScanTaskState state) {
115115

116116
// Load task specific settings
117-
log(state, "Loading Task settings.");
117+
log(state, "Loading task settings");
118118
ConfigurationMap config = state.taskContext.getConfigurationMap();
119119
state.analysisName = config.get("analysisName");
120120
state.includePaths = config.get("includePaths");
@@ -136,13 +136,13 @@ private static Boolean loadUserPreferences(ScanTaskState state) {
136136
state.useDefaults = config.getAsBoolean("useDefaults");
137137
if (state.useDefaults) {
138138
// Load global settings
139-
log(state, "Loading Code Dx plug-in global settings.");
139+
log(state, "Loading Code Dx plug-in global settings");
140140
state.apiUrl = ServerConfigManager.getUrl();
141141
state.apiKey = ServerConfigManager.getApiKey();
142142
state.fingerprint = ServerConfigManager.getFingerprint();
143143

144144
if (state.apiUrl == null || state.apiKey == null || state.apiUrl.isEmpty() || state.apiKey.isEmpty()) {
145-
logError(state, "Code Dx url and api key are not properly configured. Please configure them on the plug-in settings page.");
145+
logError(state, "Code Dx URL and API key are not properly configured. Please configure them on the plug-in settings page.");
146146
return false;
147147
}
148148
} else {
@@ -151,25 +151,25 @@ private static Boolean loadUserPreferences(ScanTaskState state) {
151151
state.fingerprint = config.get("fingerprint");
152152

153153
if (state.apiUrl == null || state.apiUrl.isEmpty()) {
154-
logError(state, "Missing Code Dx url. Please configure it on the task configuration page.");
154+
logError(state, "Missing Code Dx URL. Please configure it on the task configuration page.");
155155
return false;
156156
} else {
157157
try {
158158
new URL(state.apiUrl);
159159
} catch (MalformedURLException e) {
160-
logError(state, "Malformed Code Dx url. Please correct it on the task configuration page.");
160+
logError(state, "Malformed Code Dx URL. Please correct it on the task configuration page.");
161161
return false;
162162
}
163163
}
164164

165165
if (state.apiKey == null || state.apiKey.isEmpty()) {
166-
logError(state, "Missing Code Dx api key. Please configure it on the task configuration page.");
166+
logError(state, "Missing Code Dx API key. Please configure it on the task configuration page.");
167167
return false;
168168
}
169169
}
170170

171171
if (state.analysisName == null || state.analysisName.isEmpty()) {
172-
logError(state, "Missing Code Dx Analysis Name. Please configure it on the task configuration page.");
172+
logError(state, "Missing Code Dx analysis name. Please configure it on the task configuration page.");
173173
return false;
174174
}
175175

@@ -178,13 +178,13 @@ private static Boolean loadUserPreferences(ScanTaskState state) {
178178
return false;
179179
}
180180

181-
log(state, "Code Dx url set to %s", state.apiUrl);
181+
log(state, "Code Dx URL set to %s", state.apiUrl);
182182

183183
return true;
184184
}
185185

186186
private static Boolean setupApiClient(ScanTaskState state) {
187-
log(state, "Setting up Code Dx Api Client.");
187+
log(state, "Setting up Code Dx API client");
188188

189189
if (state.useDefaults) {
190190
state.apiClient = ServerConfigManager.getConfiguredClient();
@@ -205,19 +205,19 @@ private static Boolean setupApiClient(ScanTaskState state) {
205205
}
206206

207207
private static Boolean collectFilesToUpload(ScanTaskState state) {
208-
log(state, "Archiving source files to upload to Code Dx.");
208+
log(state, "Archiving source files to upload to Code Dx");
209209

210210
state.filesToUpload = new ArrayList<>();
211211
try {
212212
state.filesToUpload.add(Archiver.archive(state.taskContext.getRootDirectory(), state.includePaths, state.excludePaths, "files_to_scan"));
213213
} catch (IOException e) {
214-
logError(state, "An error occurred when trying to archive source files.");
214+
logError(state, "An error occurred while trying to archive source files");
215215
return false;
216216
}
217217

218218
// Add tool output files
219219
if (state.toolOutputFiles != null && !state.toolOutputFiles.isEmpty()) {
220-
log(state, "Collecting tool output files.");
220+
log(state, "Collecting tool output files");
221221
for (String fileName : state.toolOutputFiles.split(",")) {
222222
fileName = fileName.trim();
223223
Path path = Paths.get(fileName);
@@ -238,7 +238,7 @@ private static Boolean collectFilesToUpload(ScanTaskState state) {
238238
}
239239

240240
private static Boolean uploadFiles(ScanTaskState state) {
241-
log(state, "Uploading files to Code Dx.");
241+
log(state, "Uploading files to Code Dx");
242242

243243
ProjectId project = new ProjectId();
244244
project.setProjectId(state.projectId);
@@ -256,7 +256,7 @@ private static Boolean uploadFiles(ScanTaskState state) {
256256
logApiException(state);
257257
return false;
258258
} catch (IOException e) {
259-
logError(state, "An error occurred when trying to archive source files.");
259+
logError(state, "An error occurred while trying to archive source files");
260260
return false;
261261
}
262262

@@ -316,7 +316,7 @@ private static Boolean getBuildStatsBeforeAnalysis(ScanTaskState state) {
316316
return true;
317317
}
318318

319-
log(state, "Querying Code Dx for pre-analysis statistics.");
319+
log(state, "Querying Code Dx for pre-analysis statistics");
320320

321321
CodeDxBuildStatistics stats = getBuildStats(state);
322322

@@ -330,7 +330,7 @@ private static Boolean getBuildStatsBeforeAnalysis(ScanTaskState state) {
330330
}
331331

332332
private static Boolean startAnalysis(ScanTaskState state) {
333-
log(state, "Querying Code Dx to start analysis.");
333+
log(state, "Querying Code Dx to start analysis");
334334

335335
try {
336336
Analysis analysis = state.analysisApi.runPreparedAnalysis(state.analysisPrepId);
@@ -342,7 +342,7 @@ private static Boolean startAnalysis(ScanTaskState state) {
342342

343343
state.analysisApi.setAnalysisName(state.projectId, analysisId, analysisName);
344344
} else {
345-
logError(state, "An unexpected issue arose regarding the analysis name. Please double check it in the task configuration page.");
345+
logError(state, "An unexpected issue arose regarding the analysis name. Please double check it on the task configuration page.");
346346
return false;
347347
}
348348
state.analysisJobId = analysis.getJobId();
@@ -396,7 +396,7 @@ private static Boolean waitForAnalysisToFinish(ScanTaskState state) {
396396

397397
JobStatus status = job.getStatus();
398398
if(status == null) {
399-
logError(state, "Job status is null for job %s.", state.analysisJobId);
399+
logError(state, "Job status is null for job %s", state.analysisJobId);
400400
return false;
401401
}
402402

@@ -409,7 +409,7 @@ private static Boolean waitForAnalysisToFinish(ScanTaskState state) {
409409
if (status == JobStatus.COMPLETED) {
410410
isAnalysisFinished = true;
411411
} else if(status == JobStatus.FAILED) {
412-
logError(state, "The Code Dx analysis has reported a failure.");
412+
logError(state, "The Code Dx analysis has reported a failure");
413413
return false;
414414
}
415415
}
@@ -418,7 +418,7 @@ private static Boolean waitForAnalysisToFinish(ScanTaskState state) {
418418
}
419419

420420
private static Boolean getBuildStatsAfterAnalysis(ScanTaskState state) {
421-
log(state, "Querying Code Dx for post-analysis statistics.");
421+
log(state, "Querying Code Dx for post-analysis statistics");
422422

423423
CodeDxBuildStatistics stats = getBuildStats(state);
424424

@@ -487,7 +487,7 @@ private static Boolean checkFailureSeverity(ScanTaskState state) {
487487
return true;
488488
}
489489

490-
log(state, "Checking%s findings against build failure threshold.", state.onlyConsiderNewFindings ? " new" : "");
490+
log(state, "Checking%s findings against build failure threshold", state.onlyConsiderNewFindings ? " new" : "");
491491

492492
for(int i = Severity.all.length - 1; i >= Severity.indexOf(state.failureSeverity); i--) {
493493
String severityName = Severity.all[i].name;

0 commit comments

Comments
 (0)