forked from jenkinsci/gerrit-trigger-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildMemory.java
895 lines (836 loc) · 29.4 KB
/
BuildMemory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
/*
* The MIT License
*
* Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
* Copyright 2012 Sony Mobile Communications AB. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.model;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.model.BuildMemory.MemoryImprint.Entry;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritCause;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.TriggerContext;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import jenkins.model.Jenkins;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;
import static com.sonyericsson.hudson.plugins.gerrit.trigger.utils.Logic.shouldSkip;
/**
* Keeps track of what builds have been triggered and if all builds are done for specific events.
*
* @author Robert Sandell <robert.sandell@sonyericsson.com>
*/
public class BuildMemory {
/**
* Compares GerritTriggeredEvents using the Object.hashCode() method. This ensures that every event received from
* Gerrit is kept track of individually.
*
* @author James E. Blair <jeblair@hp.com>
*/
static class GerritTriggeredEventComparator implements Comparator<GerritTriggeredEvent> {
@Override
public int compare(GerritTriggeredEvent o1, GerritTriggeredEvent o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 != null && o2 == null) {
return 1;
}
if (o1 == null && o2 != null) {
return -1;
}
return Integer.valueOf(o1.hashCode()).compareTo(o2.hashCode());
}
}
private TreeMap<GerritTriggeredEvent, MemoryImprint> memory =
new TreeMap<GerritTriggeredEvent, MemoryImprint>(
new GerritTriggeredEventComparator());
private static final Logger logger = LoggerFactory.getLogger(BuildMemory.class);
/**
* Gets the memory of a specific event.
*
* @param event the event.
* @return the memory.
*/
public synchronized MemoryImprint getMemoryImprint(GerritTriggeredEvent event) {
return memory.get(event);
}
/**
* Tells if all triggered builds have started for a specific memory imprint.
*
* @param event the event.
* @return true if it is so.
*/
public synchronized boolean isAllBuildsCompleted(GerritTriggeredEvent event) {
MemoryImprint pb = memory.get(event);
if (pb != null) {
return pb.isAllBuildsCompleted();
} else {
return false;
}
}
/**
* Gets the statistics of started builds for a specific memory imprint.
*
* @param event the event.
* @return the statistics.
*/
public synchronized BuildsStartedStats getBuildsStartedStats(GerritTriggeredEvent event) {
MemoryImprint pb = memory.get(event);
if (pb != null) {
return pb.getBuildsStartedStats();
} else {
return null;
}
}
/**
* Returns the status report for the given MemoryImprint.
*
* @param event the event.
* @return the status as it is now.
*
* @see MemoryImprint#getStatusReport()
*/
public synchronized String getStatusReport(GerritTriggeredEvent event) {
MemoryImprint pb = memory.get(event);
if (pb != null) {
return pb.getStatusReport();
} else {
return null;
}
}
/**
* Tells if all triggered builds have started for a specific memory imprint.
*
* @param event the event.
* @return true if it is so.
*/
public synchronized boolean isAllBuildsStarted(GerritTriggeredEvent event) {
MemoryImprint pb = memory.get(event);
if (pb != null) {
return pb.isAllBuildsSet();
} else {
return false;
}
}
/**
* Sets the memory that a build is completed for an event.
*
* @param event the event
* @param build the build.
*/
public synchronized void completed(GerritTriggeredEvent event, Run build) {
MemoryImprint pb = memory.get(event);
if (pb == null) {
//Shoudn't happen but just in case, keep the memory.
pb = new MemoryImprint(event);
memory.put(event, pb);
}
pb.set(build.getParent(), build, true);
}
/**
* Sets the memory that a build has started for an event.
*
* @param event the event.
* @param build the build.
*/
public synchronized void started(GerritTriggeredEvent event, Run build) {
MemoryImprint pb = memory.get(event);
if (pb == null) {
//A build should not start for a job that hasn't been registered. Keep the memory anyway.
pb = new MemoryImprint(event);
logger.warn("Build started without being registered first.");
memory.put(event, pb);
}
pb.set(build.getParent(), build);
}
/**
* Adds a new memory about a build that has been/will be triggered.
*
* @param event the event that triggered it.
* @param project the project that was triggered.
*/
public synchronized void triggered(GerritTriggeredEvent event, Job project) {
MemoryImprint pb = memory.get(event);
if (pb == null) {
pb = new MemoryImprint(event);
memory.put(event, pb);
}
pb.set(project);
}
/**
* Adds a new memory about a build that has been retriggered. If there is an active memory about the provided event,
* then the project is reset with no build info. Otherwise the memory is recreated from the list of other builds and
* their result.
*
* @param event the event to be retriggered.
* @param project the project that has been retriggered.
* @param otherBuilds the list of other builds that was in the "old" memory.
*/
public synchronized void retriggered(
GerritTriggeredEvent event,
Job project,
List<Run> otherBuilds) {
MemoryImprint pb = memory.get(event);
if (pb == null) {
pb = new MemoryImprint(event);
memory.put(event, pb);
if (otherBuilds != null) {
//It is a new memory so it wasn't building, let's populate with old build info
for (Run build : otherBuilds) {
pb.set(build.getParent(), build, !build.isBuilding());
}
}
}
pb.reset(project);
}
/**
* Removes the memory for the event.
*
* @param event the event.
*/
public synchronized void forget(GerritTriggeredEvent event) {
memory.remove(event);
}
/**
* Updates the {@link TriggerContext} for the event. The cause and build is the "focal point" for the update, but
* all memory entities will be updated, but only the current context will be {@link
* TriggerContext#setThisBuild(hudson.model.Run)}updated.
*
* @param cause the cause.
* @param r the build the cause is in.
*/
public synchronized void updateTriggerContext(GerritCause cause, Run r) {
MemoryImprint imprint = getMemoryImprint(cause.getEvent());
TriggerContext context = cause.getContext();
context.setThisBuild(r);
for (MemoryImprint.Entry entry : imprint.getEntries()) {
Run build = entry.getBuild();
if (build != null && !build.equals(r)) {
context.addOtherBuild(build);
updateTriggerContext(entry, imprint);
} else {
Job project = entry.getProject();
if (build == null && project != null && !project.equals(r.getParent())) {
context.addOtherProject(project);
}
}
}
if (!r.hasntStartedYet() && !r.isBuilding()) {
try {
r.save();
} catch (IOException ex) {
logger.error("Could not save build state for build " + r, ex);
}
}
}
/**
* Updates the {@link TriggerContext} for the provided entry.
*
* @param entryToUpdate the entry to update.
* @param imprint the information for the update.
*/
private synchronized void updateTriggerContext(@Nonnull Entry entryToUpdate, @Nonnull MemoryImprint imprint) {
Run build = entryToUpdate.getBuild();
if (build != null) {
GerritCause cause = (GerritCause)build.getCause(GerritCause.class);
if (cause != null) {
TriggerContext context = cause.getContext();
for (MemoryImprint.Entry ent : imprint.getEntries()) {
Run entBuild = ent.getBuild();
if (entBuild != null && !entBuild.equals(build)) {
context.addOtherBuild(entBuild);
} else {
Job entProject = ent.getProject();
if (entBuild == null && entProject != null && !entProject.equals(entryToUpdate.getProject())) {
context.addOtherProject(entProject);
}
}
}
if (!build.hasntStartedYet() && !build.isBuilding()) {
try {
build.save();
} catch (IOException ex) {
logger.error("Could not save state for build " + build, ex);
}
}
}
}
}
/**
* Checks in memory if the project has been triggered for the event.
*
* @param event the event.
* @param project the project.
* @return true if so.
*/
public synchronized boolean isTriggered(@Nonnull GerritTriggeredEvent event, @Nonnull Job project) {
MemoryImprint pb = memory.get(event);
if (pb == null) {
return false;
} else {
for (Entry entry : pb.getEntries()) {
if (project.equals(entry.getProject())) {
return true;
}
}
return false;
}
}
/**
* Checks in memory if the project is building the event.
*
* @param event the event.
* @param project the project.
* @return true if so.
*/
public synchronized boolean isBuilding(GerritTriggeredEvent event, Job project) {
MemoryImprint pb = memory.get(event);
if (pb == null) {
return false;
} else {
for (Entry entry : pb.getEntries()) {
if (entry.isProject(project)) {
if (entry.getBuild() != null) {
return !entry.isBuildCompleted();
} else {
return true;
}
}
}
return false;
}
}
/**
* Checks if the provided event exists in this memory.
*
* @param event the event to look for.
* @return true if so.
*/
public synchronized boolean isBuilding(GerritTriggeredEvent event) {
MemoryImprint pb = memory.get(event);
return pb != null;
}
/**
* Returns all started builds in memory for the event.
*
* @param event the event.
* @return the list of builds, or null if there is no memory.
*/
public synchronized List<Run> getBuilds(GerritTriggeredEvent event) {
MemoryImprint pb = memory.get(event);
if (pb != null) {
List<Run> list = new LinkedList<Run>();
for (Entry entry : pb.getEntries()) {
if (entry.getBuild() != null) {
list.add(entry.getBuild());
}
}
return list;
} else {
return null;
}
}
/**
* Records the failure message for the given build.
*
* @param event the event.
* @param r the build that caused the failure.
* @param failureMessage the failure message
*/
public void setEntryFailureMessage(GerritTriggeredEvent event, Run r, String failureMessage) {
MemoryImprint pb = getMemoryImprint(event);
if (pb != null) {
Entry entry = pb.getEntry(r.getParent());
if (entry != null) {
logger.info("Recording unsuccessful message for {}: {}", event, failureMessage);
entry.setUnsuccessfulMessage(failureMessage);
}
}
}
/**
* A holder for all builds triggered by one event.
*/
public static class MemoryImprint {
private GerritTriggeredEvent event;
private List<Entry> list = new ArrayList<Entry>();
/**
* Constructor.
*
* @param event the event.
*/
public MemoryImprint(GerritTriggeredEvent event) {
this.event = event;
}
/**
* Constructor.
*
* @param event the event.
* @param project the first project.
*/
public MemoryImprint(GerritTriggeredEvent event, Job project) {
this.event = event;
set(project);
}
/**
* The event.
*
* @return the event.
*/
public GerritTriggeredEvent getEvent() {
return event;
}
/**
* A list of Project-Build tuple entries.
*
* @return the memory entries.
*/
public synchronized Entry[] getEntries() {
return list.toArray(new Entry[list.size()]);
}
/**
* Sets the build to a project or adds the project to the list.
*
* @param project the project.
* @param build the build.
*/
protected synchronized void set(Job project, Run build) {
Entry entry = getEntry(project);
if (entry == null) {
entry = new Entry(project, build);
list.add(entry);
} else {
entry.setBuild(build);
}
}
/**
* Adds the project to the list.
*
* @param project the project.
*/
protected synchronized void set(Job project) {
Entry entry = getEntry(project);
if (entry == null) {
entry = new Entry(project);
list.add(entry);
}
}
/**
* Resets the build info for the project. If the project doesn't exist it would be as if calling {@link
* #set(hudson.model.Job)}.
*
* @param project the project to reset.
*/
protected synchronized void reset(Job project) {
Entry entry = getEntry(project);
if (entry == null) {
entry = new Entry(project);
list.add(entry);
} else {
entry.setBuild(null);
entry.setBuildCompleted(false);
}
}
/**
* Sets all the values of an entry and adds it if the project has not been added before.
*
* @param project the project
* @param build the build
* @param buildCompleted if the build is finished.
*/
private synchronized void set(Job project, Run build, boolean buildCompleted) {
Entry entry = getEntry(project);
if (entry == null) {
entry = new Entry(project, build);
entry.setBuildCompleted(buildCompleted);
list.add(entry);
} else {
if (entry.getBuild() == null) {
entry.setBuild(build);
}
entry.setBuildCompleted(buildCompleted);
}
}
/**
* Tells if all builds have a value (not null).
*
* @return true if it is so.
*/
public synchronized boolean isAllBuildsSet() {
for (Entry entry : list) {
if (entry.getBuild() == null) {
return false;
}
}
return true;
}
/**
* Tells if all builds have Completed.
*
* @return true if it is so.
*/
public synchronized boolean isAllBuildsCompleted() {
for (Entry entry : list) {
if (!entry.isBuildCompleted()) {
return false;
}
}
return true;
}
/**
* Returns a string describing the projects and builds status in this memory. Good for logging.
*
* @return a report.
*/
public synchronized String getStatusReport() {
StringBuilder str = new StringBuilder("");
for (Entry entry : list) {
if (entry == null) {
continue;
}
Job project = entry.getProject();
if (project != null) {
str.append(" Project/Build: [").append(project.getName()).append("]");
str.append(": [#");
Run build = entry.getBuild();
if (build != null) {
str.append(build.getNumber());
str.append(": ").append(build.getResult());
} else {
str.append("XX: NULL");
}
str.append("] Completed: ").append(entry.isBuildCompleted());
} else {
str.append(" Project/Build: MISSING PROJECT!");
}
str.append("\n");
}
return str.toString();
}
/**
* Searches the internal list for an entry with the specified project.
*
* @param project the project.
* @return the entry or null if nothing is found.
*/
private Entry getEntry(@Nonnull Job project) {
for (Entry entry : list) {
if (entry != null && project.equals(entry.getProject())) {
return entry;
}
}
return null;
}
/**
* Gets the statistics about builds started.
*
* @return the stats.
*/
public synchronized BuildsStartedStats getBuildsStartedStats() {
int started = 0;
for (Entry entry : list) {
if (entry.getBuild() != null) {
started++;
}
}
return new BuildsStartedStats(event, list.size(), started);
}
/**
* If all entry's results are configured to be skipped.
*
* @return true if so.
* @see #wereAllBuildsSuccessful()
*/
public synchronized boolean areAllBuildResultsSkipped() {
for (Entry entry : list) {
if (entry == null) {
continue;
}
Run build = entry.getBuild();
if (build == null) {
return false;
} else if (!entry.isBuildCompleted()) {
return false;
}
Result buildResult = build.getResult();
GerritTrigger trigger = GerritTrigger.getTrigger(entry.getProject());
if (!shouldSkip(trigger.getSkipVote(), buildResult)) {
return false;
}
}
return true;
}
/**
* Tells if all builds in the memory were successful.
*
* @return true if it is so, false if not all builds have started or not completed or have any different result
* than {@link Result#SUCCESS}.
*/
public synchronized boolean wereAllBuildsSuccessful() {
if (areAllBuildResultsSkipped()) {
for (Entry entry : list) {
if (entry == null) {
continue;
}
Run build = entry.getBuild();
if (build == null) {
return false;
} else if (!entry.isBuildCompleted()) {
return false;
}
Result buildResult = build.getResult();
if (buildResult != Result.SUCCESS) {
return false;
}
}
} else {
for (Entry entry : list) {
if (entry == null) {
continue;
}
Run build = entry.getBuild();
if (build == null) {
return false;
} else if (!entry.isBuildCompleted()) {
return false;
}
Result buildResult = build.getResult();
if (buildResult != Result.SUCCESS) {
GerritTrigger trigger = GerritTrigger.getTrigger(entry.getProject());
if (!shouldSkip(trigger.getSkipVote(), buildResult)) {
return false;
}
}
}
}
return true;
}
/**
* Returns if any started and completed build has the result {@link Result#FAILURE}.
*
* @return true if it is so.
*/
public synchronized boolean wereAnyBuildsFailed() {
for (Entry entry : list) {
if (entry == null) {
continue;
}
Run build = entry.getBuild();
if (build != null && entry.isBuildCompleted()
&& build.getResult() == Result.FAILURE) {
return true;
}
}
return false;
}
/**
* Returns if any started and completed build has the result {@link Result#UNSTABLE}.
*
* @return true if it is so.
*/
public synchronized boolean wereAnyBuildsUnstable() {
for (Entry entry : list) {
if (entry == null) {
continue;
}
Run build = entry.getBuild();
if (build != null && entry.isBuildCompleted()
&& build.getResult() == Result.UNSTABLE) {
return true;
}
}
return false;
}
/**
* Tells if all builds in the memory were not built.
*
* @return true if it is so, false if not all builds have started or not completed or have any different result
* than {@link Result#NOT_BUILT}.
*/
public synchronized boolean wereAllBuildsNotBuilt() {
for (Entry entry : list) {
if (entry == null) {
continue;
}
Run build = entry.getBuild();
if (build == null) {
return false;
} else if (!entry.isBuildCompleted()) {
return false;
}
Result buildResult = build.getResult();
if (buildResult != Result.NOT_BUILT) {
return false;
}
}
return true;
}
//CS IGNORE FinalClass FOR NEXT 5 LINES. REASON: Testability.
/**
* A project-build entry in the list of a MemoryImprint.
*/
public static class Entry {
private String project;
private String build;
private boolean buildCompleted;
private String unsuccessfulMessage;
/**
* Constructor.
*
* @param project the project
* @param build the build.
*/
private Entry(Job project, Run build) {
this.project = project.getFullName();
this.build = build.getId();
buildCompleted = false;
}
/**
* Constructor.
*
* @param project the project.
*/
private Entry(Job project) {
this.project = project.getFullName();
buildCompleted = false;
}
/**
* The Project.
*
* @return the project.
*/
@CheckForNull
@WithBridgeMethods(AbstractProject.class)
public Job getProject() {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins != null) {
return jenkins.getItemByFullName(project, Job.class);
} else {
return null;
}
}
/**
* The build of a project.
*
* @return the build.
*/
@CheckForNull
@WithBridgeMethods(AbstractBuild.class)
public Run getBuild() {
Job p = getProject();
if (p != null && build != null) {
return p.getBuild(build);
} else {
return null;
}
}
/**
* The build of a project.
*
* @param build the build.
*/
private void setBuild(Run build) {
if (build != null) {
this.build = build.getId();
} else {
this.build = null;
}
}
/**
* Sets the unsuccessful message for an entry.
*
* @param unsuccessfulMessage the message.
*/
private void setUnsuccessfulMessage(String unsuccessfulMessage) {
this.unsuccessfulMessage = unsuccessfulMessage;
}
/**
* Gets the unsuccessful message for an entry.
*
* @return the message.
*/
public String getUnsuccessfulMessage() {
return this.unsuccessfulMessage;
}
/**
* If the build is completed.
*
* @return true if the build is completed.
*/
public boolean isBuildCompleted() {
return buildCompleted;
}
/**
* If the build is completed.
*
* @param buildCompleted true if the build is completed.
*/
private void setBuildCompleted(boolean buildCompleted) {
this.buildCompleted = buildCompleted;
}
@Override
public String toString() {
String s = "";
Run theBuild = getBuild();
if (theBuild != null) {
s = theBuild.toString();
} else {
Job theProject = getProject();
if (theProject != null) {
s = theProject.getName();
}
}
if (isBuildCompleted()) {
s += " (completed)";
}
return s;
}
/**
* If the provided project is the same as this entry is referencing.
* It does so by checking the fullName for equality.
*
* @param other the other project to check
* @return true if so.
* @see #getProject()
*/
public boolean isProject(Job other) {
if (this.project != null && other != null) {
return this.project.equals(other.getFullName());
} else {
return this.project == null && other == null;
}
}
}
}
}