Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move condition up to save a level of indentation
Browse files Browse the repository at this point in the history
Instead of:

  if (condition != null) {
    // indented large block code
  } else {
    log.info("Skipped");
  }

Inverse the condition check to move the logging code at the top and add
an explicit continue. This saves a level of indentation on the code
block:

  if (condition == null) {
    log.info("Skipped");
    continue;
  }
  // large block code

Also adjust the logging message while at it:

                              vv
- The project was not trigger by some reason.
+ The project was not trigger for some reason.
                              ^^^
hashar committed Nov 14, 2024
1 parent 5ac1e7c commit 3bd62c1
Showing 1 changed file with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -151,52 +151,50 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}
for (QueueTaskFuture<AbstractBuild> future : futures.get(p)) {
try {
if (future != null) {
if (future == null) {
listener.getLogger()
.println("Waiting for the completion of "
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
Run startedRun;
try {
startedRun = future.waitForStart();
} catch (InterruptedException x) {
listener.getLogger()
.println("Build aborting: cancelling queued project "
+ HyperlinkNote.encodeTo(
'/' + p.getUrl(), p.getFullDisplayName()));
future.cancel(true);
throw x; // rethrow so that the triggering project get flagged as cancelled
}
.println("Skipping " + ModelHyperlinkNote.encodeTo(p)
+ ". The project was not triggered for some reason.");
continue;
}

listener.getLogger()
.println("Waiting for the completion of "
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
Run startedRun;
try {
startedRun = future.waitForStart();
} catch (InterruptedException x) {
listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + startedRun.getUrl(), startedRun.getFullDisplayName())
+ " started.");
.println("Build aborting: cancelling queued project "
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
future.cancel(true);
throw x; // rethrow so that the triggering project get flagged as cancelled
}

Run completedRun = future.get();
listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + completedRun.getUrl(),
completedRun.getFullDisplayName())
+ " completed. Result was " + completedRun.getResult());
BuildInfoExporterAction.addBuildInfoExporterAction(
build,
completedRun.getParent().getFullName(),
completedRun.getNumber(),
completedRun.getResult());

if (buildStepResult
&& config.getBlock().mapBuildStepResult(completedRun.getResult())) {
Result r = config.getBlock().mapBuildResult(completedRun.getResult());
if (r != null) { // The blocking job is not a success
build.setResult(r);
}
} else {
buildStepResult = false;
listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + startedRun.getUrl(), startedRun.getFullDisplayName())
+ " started.");

Run completedRun = future.get();
listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + completedRun.getUrl(), completedRun.getFullDisplayName())
+ " completed. Result was " + completedRun.getResult());
BuildInfoExporterAction.addBuildInfoExporterAction(
build,
completedRun.getParent().getFullName(),
completedRun.getNumber(),
completedRun.getResult());

if (buildStepResult && config.getBlock().mapBuildStepResult(completedRun.getResult())) {
Result r = config.getBlock().mapBuildResult(completedRun.getResult());
if (r != null) { // The blocking job is not a success
build.setResult(r);
}
} else {
listener.getLogger()
.println("Skipping " + ModelHyperlinkNote.encodeTo(p)
+ ". The project was not triggered by some reason.");
buildStepResult = false;
}
} catch (CancellationException x) {
throw new AbortException(p.getFullDisplayName() + " aborted.");

0 comments on commit 3bd62c1

Please sign in to comment.