Skip to content

Commit b3ba0a8

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 b3ba0a8

1 file changed

Lines changed: 38 additions & 40 deletions

File tree

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

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -151,52 +151,50 @@ 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('/' + p.getUrl(), p.getFullDisplayName()));
171+
future.cancel(true);
172+
throw x; // rethrow so that the triggering project get flagged as cancelled
173+
}
174174

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

0 commit comments

Comments
 (0)