This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
BuildResult.java
1626 lines (1466 loc) · 51.1 KB
/
BuildResult.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
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package hudson.plugins.analysis.core; // NOPMD
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import com.google.common.collect.Sets;
import com.thoughtworks.xstream.XStream;
import jenkins.model.Jenkins;
import hudson.XmlFile;
import hudson.model.AbstractBuild;
import hudson.model.Api;
import hudson.model.Hudson;
import hudson.model.ModelObject;
import hudson.model.Result;
import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.util.HtmlPrinter;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.analysis.util.model.AnnotationContainer;
import hudson.plugins.analysis.util.model.AnnotationProvider;
import hudson.plugins.analysis.util.model.AnnotationStream;
import hudson.plugins.analysis.util.model.AnnotationsLabelProvider;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.JavaProject;
import hudson.plugins.analysis.util.model.MavenModule;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.analysis.views.DetailFactory;
/**
* A base class for build results that is capable of storing a reference to the
* current build. Provides support for persisting the results of the build and
* loading and saving of annotations (all, new, and fixed) and delta
* computation.
*
* @author Ulli Hafner
*/
//CHECKSTYLE:COUPLING-OFF
@ExportedBean
@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveClassLength"})
public abstract class BuildResult implements ModelObject, Serializable, AnnotationProvider {
private static final long serialVersionUID = 1110545450292087475L;
private static final Logger LOGGER = Logger.getLogger(BuildResult.class.getName());
private static final String UNSTABLE = "yellow.png";
private static final String FAILED = "red.png";
private static final String SUCCESS = "blue.png";
private transient Object projectLock = new Object();
/**
* Returns the number of days for the specified number of milliseconds.
*
* @param ms
* milliseconds
* @return the number of days
*/
public static long getDays(final long ms) {
return Math.max(1, ms / DateUtils.MILLIS_PER_DAY);
}
/** Current build as owner of this action. */
private AbstractBuild<?, ?> owner;
/** All parsed modules. */
private Set<String> modules;
/** The total number of parsed modules (regardless if there are annotations). */
private int numberOfModules;
/** The default encoding to be used when reading and parsing files. */
private String defaultEncoding;
/** The project containing the annotations. */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("Se")
private transient WeakReference<JavaProject> project;
/** All new warnings in the current build. */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("Se")
private transient WeakReference<Collection<FileAnnotation>> newWarningsReference;
/** All fixed warnings in the current build. */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("Se")
private transient WeakReference<Collection<FileAnnotation>> fixedWarningsReference;
/** The build history for the results of this plug-in. */
private transient BuildHistory history;
/** The number of warnings in this build. */
private int numberOfWarnings;
/** The number of new warnings in this build. */
private int numberOfNewWarnings;
/** The number of fixed warnings in this build. */
private int numberOfFixedWarnings;
/** Difference between this and the previous build. */
private int delta;
/** Difference between this and the previous build (Priority low). */
private int lowDelta;
/** Difference between this and the previous build (Priority normal). */
private int normalDelta;
/** Difference between this and the previous build (Priority high). */
private int highDelta;
/** The number of low priority warnings in this build. */
private int lowWarnings;
/** The number of normal priority warnings in this build. */
private int normalWarnings;
/** The number of high priority warnings in this build. */
private int highWarnings;
/** Determines since which build we have zero warnings. */
private int zeroWarningsSinceBuild;
/** Determines since which time we have zero warnings. */
private long zeroWarningsSinceDate;
/** Determines the zero warnings high score. */
private long zeroWarningsHighScore;
/** Determines if the old zero high score has been broken. */
private boolean isZeroWarningsHighscore;
/** Determines the number of msec still to go before a new high score is reached. */
private long highScoreGap;
/** Error messages. */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("Se")
private List<String> errors;
/**
* The build result of the associated plug-in. This result is an additional
* state that denotes if this plug-in has changed the overall build result.
*
* @since 1.4
*/
private Result pluginResult = Result.SUCCESS;
/**
* Determines since which build the result is successful.
*
* @since 1.4
*/
private int successfulSinceBuild;
/**
* Determines since which time the result is successful.
*
* @since 1.4
*/
private long successfulSinceDate;
/**
* Determines the succesful build result high score.
*
* @since 1.4
*/
private long successfulHighscore;
/**
* Determines if the old successful build result high score has been broken.
*
* @since 1.4
*/
private boolean isSuccessfulHighscore;
/**
* Determines the number of msec still to go before a new high score is
* reached.
*
* @since 1.4
*/
private long successfulHighScoreGap;
/**
* Determines if this result has touched the successful state.
*
* @since 1.4
*/
private boolean isSuccessfulStateTouched;
private transient boolean useDeltaValues;
private transient Thresholds thresholds = new Thresholds();
/**
* Reference build number. If not defined then 0 or -1 could be used.
*
* @since 1.20
*/
private int referenceBuild;
/**
* Describes the reason for the build result evaluation.
*
* @since 1.38
*/
private String reason;
/**
* Creates a new instance of {@link BuildResult}. Note that the warnings are
* not serialized anymore automatically. You need to call
* {@link #serializeAnnotations(Collection)} manually in your constructor to
* persist them.
*
* @param build
* the current build as owner of this action
* @param history
* build history
* @param result
* the parsed result with all annotations
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @since 1.39
*/
protected BuildResult(final AbstractBuild<?, ?> build, final BuildHistory history,
final ParserResult result, final String defaultEncoding) {
initialize(history, build, defaultEncoding, result);
}
/**
* Creates a new history based on the specified build.
*
* @param build
* the build to start with
* @return the history
*/
protected BuildHistory createHistory(final AbstractBuild<?, ?> build) {
return new BuildHistory(build, getResultActionType(), false);
}
/**
* Determines whether only stable builds should be used as reference builds
* or not.
*
* @return <code>true</code> if only stable builds should be used
*/
public boolean useOnlyStableBuildsAsReference() {
return history.useOnlyStableBuildsAsReference();
}
/**
* Determines whether to always use the previous build as the reference.
*
* @return <code>true</code> if the previous build should always be used.
*/
public boolean usePreviousBuildAsStable() {
return history.usePreviousBuildAsStable();
}
/**
* Initializes this new instance of {@link BuildResult}.
*
* @param build
* the current build as owner of this action
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param result
* the parsed result with all annotations
* @param history
* the history of build results of the associated plug-in
*/
@SuppressWarnings("hiding")
private void initialize(final BuildHistory history, final AbstractBuild<?, ?> build, final String defaultEncoding, // NOCHECKSTYLE
final ParserResult result) {
this.history = history;
owner = build;
this.defaultEncoding = defaultEncoding;
modules = new HashSet<String>(result.getModules());
numberOfModules = modules.size();
errors = new ArrayList<String>(result.getErrorMessages());
numberOfWarnings = result.getNumberOfAnnotations();
AnnotationContainer referenceResult = history.getReferenceAnnotations();
delta = result.getNumberOfAnnotations() - referenceResult.getNumberOfAnnotations();
lowDelta = computeDelta(result, referenceResult, Priority.LOW);
normalDelta = computeDelta(result, referenceResult, Priority.NORMAL);
highDelta = computeDelta(result, referenceResult, Priority.HIGH);
Set<FileAnnotation> allWarnings = result.getAnnotations();
// FIXME: why is there a flag to enable computation of new warnings?
Set<FileAnnotation> newWarnings = AnnotationDifferencer.getNewAnnotations(allWarnings, referenceResult.getAnnotations());
numberOfNewWarnings = newWarnings.size();
newWarningsReference = new WeakReference<Collection<FileAnnotation>>(newWarnings);
Set<FileAnnotation> fixedWarnings = AnnotationDifferencer.getFixedAnnotations(allWarnings, referenceResult.getAnnotations());
numberOfFixedWarnings = fixedWarnings.size();
fixedWarningsReference = new WeakReference<Collection<FileAnnotation>>(fixedWarnings);
highWarnings = result.getNumberOfAnnotations(Priority.HIGH);
normalWarnings = result.getNumberOfAnnotations(Priority.NORMAL);
lowWarnings = result.getNumberOfAnnotations(Priority.LOW);
JavaProject container = new JavaProject();
container.addAnnotations(result.getAnnotations());
for (FileAnnotation newWarning : newWarnings) {
newWarning.setBuild(build.getNumber());
}
// FIXME: for the old warnings we need to find the introducing build by using the context hash code
project = new WeakReference<JavaProject>(container);
computeZeroWarningsHighScore(build, result);
defineReferenceBuild(history);
}
/**
* Returns the build history.
*
* @return the history
*/
public BuildHistory getHistory() {
return history;
}
@edu.umd.cs.findbugs.annotations.SuppressWarnings("NP")
private void defineReferenceBuild(final BuildHistory buildHistory) {
if (buildHistory.hasReferenceBuild()) {
referenceBuild = buildHistory.getReferenceBuild().getNumber();
}
else {
referenceBuild = -1;
}
}
/**
* Returns whether there is a reference build available.
*
* @return <code>true</code> if there is such a build, <code>false</code>
* otherwise
*/
private boolean hasReferenceBuild() {
return referenceBuild > 0 && getReferenceBuild() != null;
}
/**
* Returns the reference build.
* @return the reference build.
*/
@Exported
public AbstractBuild<?, ?> getReferenceBuild() {
return owner.getProject().getBuildByNumber(referenceBuild);
}
private int computeDelta(final ParserResult result, final AnnotationContainer referenceResult, final Priority priority) {
return result.getNumberOfAnnotations(priority) - referenceResult.getNumberOfAnnotations(priority);
}
/**
* Computes the zero warnings high score based on the current build and the
* previous build (with results of the associated plug-in).
*
* @param build
* the current build
* @param currentResult
* the current result
*/
private void computeZeroWarningsHighScore(final AbstractBuild<?, ?> build, final ParserResult currentResult) {
if (history.hasPreviousResult()) {
BuildResult previous = history.getPreviousResult();
if (currentResult.hasNoAnnotations()) {
if (previous.hasNoAnnotations()) {
zeroWarningsSinceBuild = previous.getZeroWarningsSinceBuild();
zeroWarningsSinceDate = previous.getZeroWarningsSinceDate();
}
else {
zeroWarningsSinceBuild = build.getNumber();
zeroWarningsSinceDate = build.getTimestamp().getTimeInMillis();
}
zeroWarningsHighScore = Math.max(previous.getZeroWarningsHighScore(), build.getTimestamp().getTimeInMillis() - zeroWarningsSinceDate);
if (previous.getZeroWarningsHighScore() == 0) {
isZeroWarningsHighscore = true;
}
else {
isZeroWarningsHighscore = zeroWarningsHighScore != previous.getZeroWarningsHighScore();
}
if (!isZeroWarningsHighscore) {
highScoreGap = previous.getZeroWarningsHighScore() - (build.getTimestamp().getTimeInMillis() - zeroWarningsSinceDate);
}
}
else {
zeroWarningsHighScore = previous.getZeroWarningsHighScore();
}
}
else {
if (currentResult.hasNoAnnotations()) {
zeroWarningsSinceBuild = build.getNumber();
zeroWarningsSinceDate = build.getTimestamp().getTimeInMillis();
isZeroWarningsHighscore = true;
zeroWarningsHighScore = 0;
}
}
}
/**
* Returns whether a module with an error is part of this project.
*
* @return <code>true</code> if at least one module has an error.
*/
public boolean hasError() {
return !errors.isEmpty();
}
/**
* Returns the error messages associated with this build.
*
* @return the error messages
*/
public List<String> getErrors() {
return errors;
}
/**
* Initializes members that were not present in previous versions of the
* associated plug-in.
*
* @return the created object
*/
@SuppressWarnings("PMD")
protected Object readResolve() {
projectLock = new Object();
if (pluginResult == null) {
pluginResult = Result.SUCCESS;
resetSuccessfulState();
}
if (projectLock == null) {
projectLock = new Object();
}
if (history == null) {
history = createHistory(owner);
}
if (modules == null) {
modules = new HashSet<String>();
}
if (errors == null) {
errors = new ArrayList<String>();
}
try {
if (low != null) {
lowWarnings = Integer.valueOf(low);
}
if (normal != null) {
normalWarnings = Integer.valueOf(normal);
}
if (high != null) {
highWarnings = Integer.valueOf(high);
}
}
catch (NumberFormatException exception) {
// ignore, and start with zero
}
return this;
}
/**
* Returns the modules of this build result.
*
* @return the modules
*/
@Exported
public Collection<String> getModules() {
return modules;
}
/**
* Returns the number of modules in this project.
*
* @return the number of modules
*/
public int getNumberOfModules() {
return numberOfModules;
}
/**
* Returns the defined default encoding.
*
* @return the default encoding
*/
public String getDefaultEncoding() {
return defaultEncoding;
}
/**
* Returns the thresholds used to compute the build health.
*
* @return the thresholds
*/
public Thresholds getThresholds() {
return (Thresholds)ObjectUtils.defaultIfNull(thresholds, new Thresholds());
}
/**
* Returns the whether delta values should be used to compute the new
* warnings.
*
* @return <code>true</code> if the absolute annotations delta should be
* used, <code>false</code> if the actual annotations set difference
* should be used to evaluate the build stability.
*/
public boolean canUseDeltaValues() {
return useDeltaValues;
}
/**
* Returns the serialization file for all warnings.
*
* @return the serialization file.
*/
public final XmlFile getDataFile() {
return new XmlFile(getXStream(), new File(getOwner().getRootDir(), getSerializationFileName()));
}
/**
* Returns the serialization file for the fixed warnings.
*
* @return the serialization file.
*/
private XmlFile getFixedDataFile() {
return new XmlFile(getXStream(), new File(getOwner().getRootDir(),
getSerializationFileName().replace(".xml", "-fixed.xml")));
}
/**
* Returns the {@link XStream} to use.
*
* @return the annotation stream to use
*/
private XStream getXStream() {
AnnotationStream xstream = new AnnotationStream();
configure(xstream);
return xstream;
}
/**
* Configures the {@link XStream}. This default implementation is empty.
*
* @param xstream the stream to configure
*/
protected void configure(final XStream xstream) {
// empty default
}
/**
* Returns the name of the file to store the serialized annotations.
*
* @return the name of the file to store the serialized annotations
*/
protected abstract String getSerializationFileName();
/**
* Returns whether this result belongs to the last build.
*
* @return <code>true</code> if this result belongs to the last build
*/
public boolean isCurrent() {
return getOwner().getProject().getLastBuild().number == getOwner().number;
}
/**
* Returns the build as owner of this action.
*
* @return the owner
*/
public AbstractBuild<?, ?> getOwner() {
return owner;
}
@Override
public boolean hasAnnotations(final Priority priority) {
return getContainer().hasAnnotations(priority);
}
@Override
public boolean hasAnnotations(final String priority) {
return getContainer().hasAnnotations(priority);
}
@Override
public boolean hasAnnotations() {
return numberOfWarnings != 0;
}
@Override
public boolean hasNoAnnotations() {
return numberOfWarnings == 0;
}
@Override
public boolean hasNoAnnotations(final Priority priority) {
return getContainer().hasAnnotations(priority);
}
@Override
public boolean hasNoAnnotations(final String priority) {
return getContainer().hasAnnotations(priority);
}
@Override
@Exported(name = "warnings")
public Set<FileAnnotation> getAnnotations() {
return getContainer().getAnnotations();
}
@Override
public FileAnnotation getAnnotation(final long key) {
return getContainer().getAnnotation(key);
}
@Override
public FileAnnotation getAnnotation(final String key) {
return getContainer().getAnnotation(key);
}
/**
* Sets the number of high warnings to the specified value.
*
* @param highWarnings the value to set
*/
protected void setHighWarnings(final int highWarnings) {
this.highWarnings = highWarnings;
}
/**
* Sets the number of normal warnings to the specified value.
*
* @param normalWarnings the value to set
*/
protected void setNormalWarnings(final int normalWarnings) {
this.normalWarnings = normalWarnings;
}
/**
* Sets the number of low warnings to the specified value.
*
* @param lowWarnings the value to set
*/
protected void setLowWarnings(final int lowWarnings) {
this.lowWarnings = lowWarnings;
}
/**
* Sets the number of warnings to the specified value.
*
* @param warnings the value to set
*/
protected void setWarnings(final int warnings) {
numberOfWarnings = warnings;
}
@Override
public Set<FileAnnotation> getAnnotations(final Priority priority) {
return getContainer().getAnnotations(priority);
}
/**
* Serializes the annotations of the specified project and writes them to
* the file specified by method {@link #getDataFile()}.
*
* @param annotations
* the annotations to store
*/
protected void serializeAnnotations(final Collection<FileAnnotation> annotations) {
try {
getDataFile().write(annotations.toArray(new FileAnnotation[annotations.size()]));
Set<FileAnnotation> allAnnotations = new HashSet<FileAnnotation>();
allAnnotations.addAll(annotations);
Collection<FileAnnotation> fixedWarnings = history.getFixedWarnings(allAnnotations);
getFixedDataFile().write(fixedWarnings.toArray(new FileAnnotation[fixedWarnings.size()]));
}
catch (IOException exception) {
LOGGER.log(Level.SEVERE, "Failed to serialize the annotations of the build.", exception);
}
}
/**
* Returns the build since we have zero warnings.
*
* @return the build since we have zero warnings
*/
@Exported
public int getZeroWarningsSinceBuild() {
return zeroWarningsSinceBuild;
}
/**
* Returns the time since we have zero warnings.
*
* @return the time since we have zero warnings
*/
@Exported
public long getZeroWarningsSinceDate() {
return zeroWarningsSinceDate;
}
/**
* Returns the maximum period with zero warnings in a build.
*
* @return the time since we have zero warnings
*/
@Exported
public long getZeroWarningsHighScore() {
return zeroWarningsHighScore;
}
/**
* Returns if the current result reached the old zero warnings highscore.
*
* @return <code>true</code>, if the current result reached the old zero warnings highscore.
*/
@Exported
public boolean isNewZeroWarningsHighScore() {
return isZeroWarningsHighscore;
}
/**
* Returns the number of msec still to go before a new highscore is reached.
*
* @return the number of msec still to go before a new highscore is reached.
*/
public long getHighScoreGap() {
return highScoreGap;
}
/**
* Returns the build since we are successful.
*
* @return the build since we are successful
*/
@Exported
public int getSuccessfulSinceBuild() {
return successfulSinceBuild;
}
/**
* Returns the time since we are successful.
*
* @return the time since we are successful
*/
@Exported
public long getSuccessfulSinceDate() {
return successfulSinceDate;
}
/**
* Returns the maximum period of successful builds.
*
* @return the maximum period of successful builds
*/
@Exported
public long getSuccessfulHighScore() {
return successfulHighscore;
}
/**
* Returns if the current result reached the old successful highscore.
*
* @return <code>true</code>, if the current result reached the old successful highscore.
*/
@Exported
public boolean isNewSuccessfulHighScore() {
return isSuccessfulHighscore;
}
/**
* Returns the number of msec still to go before a new highscore is reached.
*
* @return the number of msec still to go before a new highscore is reached.
*/
public long getSuccessfulHighScoreGap() {
return successfulHighScoreGap;
}
/**
* Gets the number of warnings.
*
* @return the number of warnings
*/
@Exported
public int getNumberOfWarnings() {
return numberOfWarnings;
}
/**
* Gets the number of warnings.
*
* @return the number of warnings
*/
@Override
public int getNumberOfAnnotations() {
return getNumberOfWarnings();
}
/**
* Returns the total number of warnings of the specified priority for
* this object.
*
* @param priority
* the priority
* @return total number of annotations of the specified priority for this
* object
*/
@Override
public int getNumberOfAnnotations(final Priority priority) {
if (priority == Priority.HIGH) {
return highWarnings;
}
else if (priority == Priority.NORMAL) {
return normalWarnings;
}
else {
return lowWarnings;
}
}
/**
* Gets the number of fixed warnings.
*
* @return the number of fixed warnings
*/
@Exported
public int getNumberOfFixedWarnings() {
return numberOfFixedWarnings;
}
/**
* Gets the number of new warnings.
*
* @return the number of new warnings
*/
@Exported
public int getNumberOfNewWarnings() {
return numberOfNewWarnings;
}
/**
* Returns the delta.
*
* @return the delta
*/
public int getDelta() {
return delta;
}
/**
* Returns the high delta.
*
* @return the delta
*/
public int getHighDelta() {
return highDelta;
}
/**
* Returns the normal delta.
*
* @return the delta
*/
public int getNormalDelta() {
return normalDelta;
}
/**
* Returns the low delta.
*
* @return the delta
*/
public int getLowDelta() {
return lowDelta;
}
/**
* Returns the delta between two builds.
*
* @return the delta
*/
@Exported
public int getWarningsDelta() {
return delta;
}
/**
* Returns the number of warnings with high priority.
*
* @return the number of warnings with high priority
*/
@Exported
public int getNumberOfHighPriorityWarnings() {
return highWarnings;
}
/**
* Returns the number of warnings with normal priority.
*
* @return the number of warnings with normal priority
*/
@Exported
public int getNumberOfNormalPriorityWarnings() {
return normalWarnings;
}
/**
* Returns the number of warnings with low priority.
*
* @return the number of warnings with low priority
*/
@Exported
public int getNumberOfLowPriorityWarnings() {
return lowWarnings;
}
/**
* Returns the associated project of this result.
*
* @return the associated project of this result.
*/
public JavaProject getProject() {
synchronized (projectLock) {
if (project == null) {
return loadResult();
}
JavaProject result = project.get();
if (result == null) {
return loadResult();
}
return result;
}
}
/**
* Loads the results and wraps them in a weak reference that might get
* removed by the garbage collector.
*
* @return the loaded result
*/
private JavaProject loadResult() {
JavaProject result;
try {
JavaProject newProject = new JavaProject();
FileAnnotation[] annotations = (FileAnnotation[])getDataFile().read();
newProject.addAnnotations(annotations);
attachLabelProvider(newProject);
LOGGER.log(Level.FINE, "Loaded data file " + getDataFile() + " for build " + getOwner().getNumber());
result = newProject;
}
catch (IOException exception) {
LOGGER.log(Level.WARNING, "Failed to load " + getDataFile(), exception);
result = new JavaProject();
}
project = new WeakReference<JavaProject>(result);
return result;
}
/**
* Returns the default label provider that is used to visualize the build result (i.e., the tab labels).
*
* @return the default label probider
* @since 1.69
*/
protected void attachLabelProvider(final AnnotationContainer container) {
container.setLabelProvider(new AnnotationsLabelProvider(container.getPackageCategoryTitle()));
}
/**
* Returns the new warnings of this build.
*
* @return the new warnings of this build
*/
@Exported
public Collection<FileAnnotation> getNewWarnings() {
if (newWarningsReference == null) {
return loadNewWarnings();
}
Collection<FileAnnotation> result = newWarningsReference.get();
if (result == null) {
return loadNewWarnings();
}
return result;
}
/**
* Filters all warnings by the current build number and wraps them in a weak reference that might get
* removed by the garbage collector.
*
* @return the new warnings
*/
private Collection<FileAnnotation> loadNewWarnings() {
Set<FileAnnotation> newWarnings = new HashSet<FileAnnotation>();
for (FileAnnotation warning : getProject().getAnnotations()) {
if (warning.getBuild() == getOwner().getNumber()) {
newWarnings.add(warning);
}