1
1
/*
2
- * Copyright 2016-2023 DiffPlug
2
+ * Copyright 2016-2024 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import org .apache .maven .plugin .MojoExecutionException ;
25
25
import org .apache .maven .plugins .annotations .LifecyclePhase ;
26
26
import org .apache .maven .plugins .annotations .Mojo ;
27
+ import org .apache .maven .plugins .annotations .Parameter ;
27
28
import org .sonatype .plexus .build .incremental .BuildContext ;
28
29
29
30
import com .diffplug .spotless .Formatter ;
38
39
@ Mojo (name = AbstractSpotlessMojo .GOAL_CHECK , defaultPhase = LifecyclePhase .VERIFY , threadSafe = true )
39
40
public class SpotlessCheckMojo extends AbstractSpotlessMojo {
40
41
42
+ private static final String INCREMENTAL_MESSAGE_PREFIX = "Spotless Violation: " ;
43
+
44
+ public enum MessageSeverity {
45
+ WARNING (BuildContext .SEVERITY_WARNING ), ERROR (BuildContext .SEVERITY_ERROR );
46
+
47
+ private final int severity ;
48
+
49
+ MessageSeverity (int severity ) {
50
+ this .severity = severity ;
51
+ }
52
+
53
+ public int getSeverity () {
54
+ return severity ;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * The severity used to emit messages during incremental builds.
60
+ * Either {@code WARNING} or {@code ERROR}.
61
+ * @see AbstractSpotlessMojo#enableForIncrementalBuild
62
+ */
63
+ @ Parameter (defaultValue = "WARNING" )
64
+ private MessageSeverity incrementalBuildMessageSeverity ;
65
+
41
66
@ Override
42
67
protected void process (Iterable <File > files , Formatter formatter , UpToDateChecker upToDateChecker ) throws MojoExecutionException {
43
68
ImpactedFilesTracker counter = new ImpactedFilesTracker ();
@@ -51,14 +76,14 @@ protected void process(Iterable<File> files, Formatter formatter, UpToDateChecke
51
76
}
52
77
continue ;
53
78
}
54
-
79
+ buildContext . removeMessages ( file );
55
80
try {
56
81
PaddedCell .DirtyState dirtyState = PaddedCell .calculateDirtyState (formatter , file );
57
82
if (!dirtyState .isClean () && !dirtyState .didNotConverge ()) {
58
83
problemFiles .add (file );
59
84
if (buildContext .isIncremental ()) {
60
85
Map .Entry <Integer , String > diffEntry = DiffMessageFormatter .diff (formatter , file );
61
- buildContext .addMessage (file , diffEntry .getKey () + 1 , 0 , diffEntry .getValue (), BuildContext . SEVERITY_ERROR , null );
86
+ buildContext .addMessage (file , diffEntry .getKey () + 1 , 0 , INCREMENTAL_MESSAGE_PREFIX + diffEntry .getValue (), incrementalBuildMessageSeverity . getSeverity () , null );
62
87
}
63
88
counter .cleaned ();
64
89
} else {
0 commit comments