|
8 | 8 | import hudson.FilePath; |
9 | 9 | import hudson.model.BuildableItem; |
10 | 10 | import hudson.model.Item; |
| 11 | +import hudson.model.Run; |
11 | 12 | import hudson.model.TaskListener; |
12 | 13 | import hudson.util.ComboBoxModel; |
13 | 14 | import hudson.util.FormValidation; |
|
43 | 44 | import org.jenkinsci.plugins.pipeline.maven.Messages; |
44 | 45 | import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils; |
45 | 46 | import org.jenkinsci.plugins.variant.OptionalExtension; |
| 47 | +import org.jenkinsci.plugins.workflow.graph.FlowNode; |
46 | 48 | import org.jenkinsci.plugins.workflow.steps.StepContext; |
47 | 49 | import org.jenkinsci.plugins.workflow.steps.StepExecution; |
48 | 50 | import org.kohsuke.stapler.AncestorInPath; |
@@ -210,13 +212,13 @@ public void process(@NonNull StepContext context, @NonNull Element mavenSpyLogsE |
210 | 212 | return; |
211 | 213 | } |
212 | 214 |
|
213 | | - perform(List.of(new MavenConsole()), context, listener, "Maven console", step -> {}); |
214 | | - perform(List.of(new Java(), new JavaDoc()), context, listener, "Java and JavaDoc", step -> { |
| 215 | + perform(List.of(maven(context)), context, listener, "Maven console", step -> {}); |
| 216 | + perform(java(context), context, listener, "Java and JavaDoc", step -> { |
215 | 217 | if (javaIgnorePatterns != null && !javaIgnorePatterns.isEmpty()) { |
216 | 218 | step.setFilters(List.of(new ExcludeFile(javaIgnorePatterns))); |
217 | 219 | } |
218 | 220 | }); |
219 | | - perform(List.of(taskScanner()), context, listener, "Open tasks", step -> {}); |
| 221 | + perform(List.of(taskScanner(context)), context, listener, "Open tasks", step -> {}); |
220 | 222 | // TODO: PMD |
221 | 223 | /* |
222 | 224 | Map pmdArguments = [tool: pmdParser(pattern: '* * /target/* * /pmd.xml'), |
@@ -245,8 +247,8 @@ public void process(@NonNull StepContext context, @NonNull Element mavenSpyLogsE |
245 | 247 | if (spotbugsEvents.isEmpty()) { |
246 | 248 | if (LOGGER.isLoggable(Level.FINE)) { |
247 | 249 | listener.getLogger() |
248 | | - .println("[withMaven] warningsPublisher - No " + SPOTBUGS_GROUP_ID + ":" + SPOTBUGS_ID + ":" + SPOTBUGS_GOAL |
249 | | - + " execution found"); |
| 250 | + .println("[withMaven] warningsPublisher - No " + SPOTBUGS_GROUP_ID + ":" + SPOTBUGS_ID + ":" |
| 251 | + + SPOTBUGS_GOAL + " execution found"); |
250 | 252 | } |
251 | 253 | } else { |
252 | 254 | processBugs(spotbugsEvents, "spotbugs", "spotbugsXml.xml", context, listener); |
@@ -287,7 +289,8 @@ private void processBugs( |
287 | 289 | } |
288 | 290 |
|
289 | 291 | String resultFile = xmlOutputDirectory + File.separator + reportFilename; |
290 | | - tools.add(spotBugs(mavenArtifact, pluginInvocation, XmlUtils.getPathInWorkspace(resultFile, workspace))); |
| 292 | + tools.add(spotBugs( |
| 293 | + context, mavenArtifact, pluginInvocation, XmlUtils.getPathInWorkspace(resultFile, workspace))); |
291 | 294 | } |
292 | 295 |
|
293 | 296 | perform(tools, context, listener, kind, step -> { |
@@ -342,25 +345,59 @@ private void perform( |
342 | 345 | } |
343 | 346 | } |
344 | 347 |
|
345 | | - private OpenTasks taskScanner() { |
346 | | - OpenTasks scanner = new OpenTasks(); |
347 | | - scanner.setIncludePattern(tasksIncludePattern); |
348 | | - scanner.setExcludePattern(tasksExcludePattern); |
349 | | - scanner.setHighTags(highPriorityTaskIdentifiers); |
350 | | - scanner.setNormalTags(normalPriorityTaskIdentifiers); |
351 | | - return scanner; |
| 348 | + private MavenConsole maven(StepContext context) throws IOException, InterruptedException { |
| 349 | + MavenConsole tool = new MavenConsole(); |
| 350 | + String name = computeName(tool, context); |
| 351 | + tool.setId(toId(name)); |
| 352 | + tool.setName(name); |
| 353 | + return tool; |
| 354 | + } |
| 355 | + |
| 356 | + private List<Tool> java(StepContext context) throws IOException, InterruptedException { |
| 357 | + Java java = new Java(); |
| 358 | + String name = computeName(java, context); |
| 359 | + java.setId(toId(name)); |
| 360 | + java.setName(name); |
| 361 | + JavaDoc javadoc = new JavaDoc(); |
| 362 | + name = computeName(javadoc, context); |
| 363 | + javadoc.setId(toId(name)); |
| 364 | + javadoc.setName(name); |
| 365 | + return List.of(java, javadoc); |
| 366 | + } |
| 367 | + |
| 368 | + private OpenTasks taskScanner(StepContext context) throws IOException, InterruptedException { |
| 369 | + OpenTasks tool = new OpenTasks(); |
| 370 | + String name = computeName(tool, context); |
| 371 | + tool.setId(toId(name)); |
| 372 | + tool.setName(name); |
| 373 | + tool.setIncludePattern(tasksIncludePattern); |
| 374 | + tool.setExcludePattern(tasksExcludePattern); |
| 375 | + tool.setHighTags(highPriorityTaskIdentifiers); |
| 376 | + tool.setNormalTags(normalPriorityTaskIdentifiers); |
| 377 | + return tool; |
352 | 378 | } |
353 | 379 |
|
354 | 380 | private SpotBugs spotBugs( |
| 381 | + StepContext context, |
355 | 382 | MavenArtifact mavenArtifact, |
356 | 383 | MavenSpyLogProcessor.PluginInvocation pluginInvocation, |
357 | | - String spotBugsReportFile) { |
358 | | - SpotBugs spotBugs = new SpotBugs(); |
359 | | - String name = spotBugs.getDescriptor().getName() + " " + mavenArtifact.getId() + " " + pluginInvocation.getId(); |
360 | | - spotBugs.setId(name.replaceAll("[^\\p{Alnum}-_.]", "_")); |
361 | | - spotBugs.setName(name); |
362 | | - spotBugs.setPattern(spotBugsReportFile); |
363 | | - return spotBugs; |
| 384 | + String spotBugsReportFile) |
| 385 | + throws IOException, InterruptedException { |
| 386 | + SpotBugs tool = new SpotBugs(); |
| 387 | + String name = computeName(tool, context) + " " + mavenArtifact.getId() + " " + pluginInvocation.getId(); |
| 388 | + tool.setId(toId(name)); |
| 389 | + tool.setName(name); |
| 390 | + tool.setPattern(spotBugsReportFile); |
| 391 | + return tool; |
| 392 | + } |
| 393 | + |
| 394 | + private String computeName(Tool tool, StepContext context) throws IOException, InterruptedException { |
| 395 | + return tool.getDescriptor().getName() + " " + context.get(Run.class).toString() + " " |
| 396 | + + context.get(FlowNode.class).getId(); |
| 397 | + } |
| 398 | + |
| 399 | + private String toId(String name) { |
| 400 | + return name.replaceAll("[^\\p{Alnum}-_.]", "_"); |
364 | 401 | } |
365 | 402 |
|
366 | 403 | @Symbol("warningsPublisher") |
|
0 commit comments