Skip to content

Commit a1903b8

Browse files
fix: refine execution ID handling in error messages for SpotlessCheckMojo
- Updated the logic to check for execution IDs, ensuring that messages correctly suggest commands based on the presence of default execution IDs. - Added a new test case to validate behavior when no explicit execution ID is provided, confirming that the output message is simplified accordingly.
1 parent aa0d8ba commit a1903b8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ protected void process(String name, Iterable<File> files, Formatter formatter, U
111111

112112
if (!problemFiles.isEmpty()) {
113113
final String runToFixMessage;
114-
if (executionId != null && !executionId.isEmpty() && !executionId.equals("default-cli")) {
114+
if (executionId != null && !executionId.isEmpty()
115+
&& !executionId.equals("default")
116+
&& !executionId.startsWith("default-")) {
115117
runToFixMessage = "Run 'mvn spotless:apply@" + executionId + "' to fix these violations.";
116118
} else {
117119
runToFixMessage = "Run 'mvn spotless:apply' to fix these violations.";

plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ void testSpotlessCheckBindingToVerifyPhase() throws Exception {
6868
testSpotlessCheck(UNFORMATTED_FILE, "verify", "check");
6969
}
7070

71+
@Test
72+
void testSpotlessCheckWithSimplifiedConfiguration() throws Exception {
73+
// Use configuration with default execution ID
74+
writePom(
75+
new String[]{
76+
"<execution>",
77+
" <!-- No ID specified = default ID -->",
78+
" <phase>verify</phase>",
79+
" <goals>",
80+
" <goal>check</goal>",
81+
" </goals>",
82+
"</execution>"},
83+
new String[]{
84+
"<java>",
85+
" <licenseHeader>",
86+
" <file>${basedir}/license.txt</file>",
87+
" </licenseHeader>",
88+
"</java>"},
89+
null,
90+
null);
91+
92+
// Without explicit execution ID, we should get a simple message without @id
93+
testSpotlessCheck(UNFORMATTED_FILE, "verify", true, "");
94+
}
95+
7196
private void testSpotlessCheck(String fileName, String command, boolean expectError) throws Exception {
7297
testSpotlessCheck(fileName, command, expectError, "");
7398
}

0 commit comments

Comments
 (0)