Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trivial pmd warnings #86

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +61,8 @@ private static Optional<String> getParallelName(final FlowNode node) {
.map(ThreadNameAction::getThreadName);
}

private Pair<String, String> processStageOrBranchRow(final FlowGraphTable.Row row, final String stageOrBranchName) {
private Pair<String, String> processStageOrBranchRow(final FlowGraphTable.Row row,
final String stageOrBranchName) {
final StringBuilder nodeTextBuilder = new StringBuilder();
while (!indentationStack.isEmpty() && row.getTreeDepth() < indentationStack.peek()) {
indentationStack.pop();
Expand All @@ -86,7 +85,8 @@ else if (row.getDurationMillis() > 0) {
return Pair.of(nodeTextBuilder.toString(), "");
}

private Pair<String, String> processErrorOrWarningRow(final FlowGraphTable.Row row, final ErrorAction errorAction, final WarningAction warningAction) {
private Pair<String, String> processErrorOrWarningRow(final FlowGraphTable.Row row, final ErrorAction errorAction,
final WarningAction warningAction) {
FlowNode flowNode = row.getNode();

StringBuilder nodeSummaryBuilder = new StringBuilder();
Expand All @@ -104,7 +104,8 @@ private Pair<String, String> 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");
Expand Down Expand Up @@ -133,7 +134,6 @@ private Pair<String, String> processErrorOrWarningRow(final FlowGraphTable.Row r
}

ChecksOutput extractOutput() {

FlowGraphTable table = new FlowGraphTable(execution);
table.build();

Expand Down Expand Up @@ -172,16 +172,17 @@ 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<FlowNode> enclosingStagesAndParallels = getEnclosingStagesAndParallels(flowNode);
List<String> enclosingBlockNames = getEnclosingBlockNames(enclosingStagesAndParallels);

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");
Expand All @@ -197,21 +198,20 @@ 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<FlowNode> getEnclosingStagesAndParallels(FlowNode node) {
private static List<FlowNode> getEnclosingStagesAndParallels(final FlowNode node) {
List<FlowNode> enclosingBlocks = new ArrayList<>();
for (FlowNode enclosing : node.getEnclosingBlocks()) {
if (enclosing != null && enclosing.getAction(LabelAction.class) != null) {
if (isStageNode(enclosing) || enclosing.getAction(ThreadNameAction.class) != null) {
enclosingBlocks.add(enclosing);
}
if (enclosing != null && enclosing.getAction(LabelAction.class) != null
&& (isStageNode(enclosing) || enclosing.getAction(ThreadNameAction.class) != null)) {
enclosingBlocks.add(enclosing);
}
}

return enclosingBlocks;
}

@NonNull
private static List<String> getEnclosingBlockNames(@NonNull List<FlowNode> nodes) {
private static List<String> getEnclosingBlockNames(@NonNull final List<FlowNode> nodes) {
List<String> names = new ArrayList<>();
for (FlowNode n : nodes) {
ThreadNameAction threadNameAction = n.getPersistentAction(ThreadNameAction.class);
Expand Down Expand Up @@ -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";
Expand Down