Skip to content

Commit aa92dfe

Browse files
committed
Move condition up to save a level of indentation
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. ^^^
1 parent ff0efe5 commit aa92dfe

1 file changed

Lines changed: 41 additions & 40 deletions

File tree

src/main/java/hudson/plugins/parameterizedtrigger/TriggerBuilder.java

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -151,52 +151,53 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
151151
}
152152
for (QueueTaskFuture<AbstractBuild> future : futures.get(p)) {
153153
try {
154-
if (future != null) {
154+
if (future == null) {
155155
listener.getLogger()
156-
.println("Waiting for the completion of "
157-
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
158-
Run startedRun;
159-
try {
160-
startedRun = future.waitForStart();
161-
} catch (InterruptedException x) {
162-
listener.getLogger()
163-
.println("Build aborting: cancelling queued project "
164-
+ HyperlinkNote.encodeTo(
165-
'/' + p.getUrl(), p.getFullDisplayName()));
166-
future.cancel(true);
167-
throw x; // rethrow so that the triggering project get flagged as cancelled
168-
}
156+
.println("Skipping " + ModelHyperlinkNote.encodeTo(p)
157+
+ ". The project was not triggered for some reason.");
158+
continue;
159+
}
169160

161+
listener.getLogger()
162+
.println("Waiting for the completion of "
163+
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
164+
Run startedRun;
165+
try {
166+
startedRun = future.waitForStart();
167+
} catch (InterruptedException x) {
170168
listener.getLogger()
171-
.println(HyperlinkNote.encodeTo(
172-
'/' + startedRun.getUrl(), startedRun.getFullDisplayName())
173-
+ " started.");
169+
.println("Build aborting: cancelling queued project "
170+
+ HyperlinkNote.encodeTo(
171+
'/' + p.getUrl(), p.getFullDisplayName()));
172+
future.cancel(true);
173+
throw x; // rethrow so that the triggering project get flagged as cancelled
174+
}
174175

175-
Run completedRun = future.get();
176-
listener.getLogger()
177-
.println(HyperlinkNote.encodeTo(
178-
'/' + completedRun.getUrl(),
179-
completedRun.getFullDisplayName())
180-
+ " completed. Result was " + completedRun.getResult());
181-
BuildInfoExporterAction.addBuildInfoExporterAction(
182-
build,
183-
completedRun.getParent().getFullName(),
184-
completedRun.getNumber(),
185-
completedRun.getResult());
186-
187-
if (buildStepResult
188-
&& config.getBlock().mapBuildStepResult(completedRun.getResult())) {
189-
Result r = config.getBlock().mapBuildResult(completedRun.getResult());
190-
if (r != null) { // The blocking job is not a success
191-
build.setResult(r);
192-
}
193-
} else {
194-
buildStepResult = false;
176+
listener.getLogger()
177+
.println(HyperlinkNote.encodeTo(
178+
'/' + startedRun.getUrl(), startedRun.getFullDisplayName())
179+
+ " started.");
180+
181+
Run completedRun = future.get();
182+
listener.getLogger()
183+
.println(HyperlinkNote.encodeTo(
184+
'/' + completedRun.getUrl(),
185+
completedRun.getFullDisplayName())
186+
+ " completed. Result was " + completedRun.getResult());
187+
BuildInfoExporterAction.addBuildInfoExporterAction(
188+
build,
189+
completedRun.getParent().getFullName(),
190+
completedRun.getNumber(),
191+
completedRun.getResult());
192+
193+
if (buildStepResult
194+
&& config.getBlock().mapBuildStepResult(completedRun.getResult())) {
195+
Result r = config.getBlock().mapBuildResult(completedRun.getResult());
196+
if (r != null) { // The blocking job is not a success
197+
build.setResult(r);
195198
}
196199
} else {
197-
listener.getLogger()
198-
.println("Skipping " + ModelHyperlinkNote.encodeTo(p)
199-
+ ". The project was not triggered by some reason.");
200+
buildStepResult = false;
200201
}
201202
} catch (CancellationException x) {
202203
throw new AbortException(p.getFullDisplayName() + " aborted.");

0 commit comments

Comments
 (0)