From 58c8f2b573bf7b4e41c9e65bd15048180c1fdbbd Mon Sep 17 00:00:00 2001 From: Kezhi Xiong Date: Tue, 23 Feb 2021 14:49:43 +0800 Subject: [PATCH 1/2] Fix trivial pmc warnings --- .../AbstractStatusChecksProperties.java | 2 +- .../checks/status/FlowExecutionAnalyzer.java | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java b/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java index 33ff92b7..429bbb3b 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java +++ b/src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java @@ -45,7 +45,7 @@ public abstract class AbstractStatusChecksProperties implements ExtensionPoint { * A jenkins job. * @return false to treat a unstable build as failure. */ - public boolean isUnstableBuildNeutral(Job job) { + public boolean isUnstableBuildNeutral(final Job job) { return false; } } diff --git a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java index 629ae8d2..0278df07 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java +++ b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java @@ -29,9 +29,7 @@ import java.util.stream.Collectors; class FlowExecutionAnalyzer { - private static final Logger LOGGER = Logger.getLogger(FlowExecutionAnalyzer.class.getName()); - private static final String TRUNCATED_MESSAGE = "\n\nOutput truncated."; private final Run run; @@ -63,7 +61,8 @@ private static Optional getParallelName(final FlowNode node) { .map(ThreadNameAction::getThreadName); } - private Pair processStageOrBranchRow(final FlowGraphTable.Row row, final String stageOrBranchName) { + private Pair processStageOrBranchRow(final FlowGraphTable.Row row, + final String stageOrBranchName) { final StringBuilder nodeTextBuilder = new StringBuilder(); while (!indentationStack.isEmpty() && row.getTreeDepth() < indentationStack.peek()) { indentationStack.pop(); @@ -86,7 +85,8 @@ else if (row.getDurationMillis() > 0) { return Pair.of(nodeTextBuilder.toString(), ""); } - private Pair processErrorOrWarningRow(final FlowGraphTable.Row row, final ErrorAction errorAction, final WarningAction warningAction) { + private Pair processErrorOrWarningRow(final FlowGraphTable.Row row, final ErrorAction errorAction, + final WarningAction warningAction) { FlowNode flowNode = row.getNode(); StringBuilder nodeSummaryBuilder = new StringBuilder(); @@ -104,7 +104,8 @@ private Pair processErrorOrWarningRow(final FlowGraphTable.Row r nodeSummaryBuilder.append(String.format("### `%s`%n", String.join(" / ", location))); - nodeSummaryBuilder.append(String.format("%s in `%s` step", errorAction == null ? "Warning" : "Error", flowNode.getDisplayFunctionName())); + nodeSummaryBuilder.append(String.format("%s in `%s` step", errorAction == null ? "Warning" : "Error", + flowNode.getDisplayFunctionName())); String arguments = ArgumentsAction.getStepArgumentsAsString(flowNode); if (arguments == null) { nodeSummaryBuilder.append(".\n"); @@ -133,7 +134,6 @@ private Pair processErrorOrWarningRow(final FlowGraphTable.Row r } ChecksOutput extractOutput() { - FlowGraphTable table = new FlowGraphTable(execution); table.build(); @@ -172,8 +172,9 @@ ChecksOutput extractOutput() { .build(); } - private String getPotentialTitle(FlowNode flowNode, ErrorAction errorAction) { - final String whereBuildFailed = String.format("%s in '%s' step", errorAction == null ? "warning" : "error", flowNode.getDisplayFunctionName()); + private String getPotentialTitle(final FlowNode flowNode, final ErrorAction errorAction) { + final String whereBuildFailed = String.format("%s in '%s' step", errorAction == null ? "warning" : "error", + flowNode.getDisplayFunctionName()); List enclosingStagesAndParallels = getEnclosingStagesAndParallels(flowNode); List enclosingBlockNames = getEnclosingBlockNames(enclosingStagesAndParallels); @@ -181,7 +182,7 @@ private String getPotentialTitle(FlowNode flowNode, ErrorAction errorAction) { return StringUtils.join(new ReverseListIterator(enclosingBlockNames), "/") + ": " + whereBuildFailed; } - private static boolean isStageNode(@NonNull FlowNode node) { + private static boolean isStageNode(@NonNull final FlowNode node) { if (node instanceof StepNode) { StepDescriptor d = ((StepNode) node).getDescriptor(); return d != null && d.getFunctionName().equals("stage"); @@ -197,13 +198,12 @@ private static boolean isStageNode(@NonNull FlowNode node) { * @return A nonnull, possibly empty list of stage/parallel branch start nodes, innermost first. */ @NonNull - private static List getEnclosingStagesAndParallels(FlowNode node) { + private static List getEnclosingStagesAndParallels(final FlowNode node) { List enclosingBlocks = new ArrayList<>(); for (FlowNode enclosing : node.getEnclosingBlocks()) { - if (enclosing != null && enclosing.getAction(LabelAction.class) != null) { - if (isStageNode(enclosing) || enclosing.getAction(ThreadNameAction.class) != null) { + if (enclosing != null && enclosing.getAction(LabelAction.class) != null + && (isStageNode(enclosing) || enclosing.getAction(ThreadNameAction.class) != null)) { enclosingBlocks.add(enclosing); - } } } @@ -211,7 +211,7 @@ private static List getEnclosingStagesAndParallels(FlowNode node) { } @NonNull - private static List getEnclosingBlockNames(@NonNull List nodes) { + private static List getEnclosingBlockNames(@NonNull final List nodes) { List names = new ArrayList<>(); for (FlowNode n : nodes) { ThreadNameAction threadNameAction = n.getPersistentAction(ThreadNameAction.class); @@ -246,12 +246,13 @@ private static String getLog(final FlowNode flowNode) { return outputString.replaceAll("\u001B\\[[;\\d]*m", ""); } catch (IOException e) { - LOGGER.log(Level.WARNING, String.format("Failed to extract logs for step '%s'", flowNode.getDisplayName()).replaceAll("[\r\n]", ""), e); + LOGGER.log(Level.WARNING, String.format("Failed to extract logs for step '%s'", + flowNode.getDisplayName()).replaceAll("[\r\n]", ""), e); return null; } } - private String extractOutputTitle(String title) { + private String extractOutputTitle(final String title) { Result result = run.getResult(); if (result == null) { return "In progress"; From b20c9f55e381780bf6bd02b602b9e94d6c6c3285 Mon Sep 17 00:00:00 2001 From: Kezhi Xiong Date: Tue, 23 Feb 2021 15:08:21 +0800 Subject: [PATCH 2/2] Fix new checkstyle warning --- .../io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java index 0278df07..0ac7f589 100644 --- a/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java +++ b/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java @@ -203,7 +203,7 @@ private static List getEnclosingStagesAndParallels(final FlowNode node for (FlowNode enclosing : node.getEnclosingBlocks()) { if (enclosing != null && enclosing.getAction(LabelAction.class) != null && (isStageNode(enclosing) || enclosing.getAction(ThreadNameAction.class) != null)) { - enclosingBlocks.add(enclosing); + enclosingBlocks.add(enclosing); } }