11/*
2- * Copyright 2016-2025 DiffPlug
2+ * Copyright 2016-2026 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -37,29 +37,21 @@ class IdeHookTest extends GradleIntegrationHarness {
3737 private String error ;
3838 private File dirty ;
3939 private File clean ;
40+ private File clean2 ;
4041 private File diverge ;
4142 private File outofbounds ;
4243
4344 @ BeforeEach
4445 void before () throws IOException {
45- setFile ("build.gradle" ).toLines (
46- "plugins {" ,
47- " id 'com.diffplug.spotless'" ,
48- "}" ,
49- "spotless {" ,
50- " format 'misc', {" ,
51- " target 'DIRTY.md', 'CLEAN.md'" ,
52- " addStep com.diffplug.spotless.TestingOnly.lowercase()" ,
53- " }" ,
54- " format 'diverge', {" ,
55- " target 'DIVERGE.md'" ,
56- " addStep com.diffplug.spotless.TestingOnly.diverge()" ,
57- " }" ,
58- "}" );
46+ var miscTargets = "'DIRTY.md', 'CLEAN.md', 'CLEAN2.md'" ;
47+ var divergeTargets = "'DIVERGE.md'" ;
48+ initPluginConfig (miscTargets , divergeTargets );
5949 dirty = new File (rootFolder (), "DIRTY.md" );
6050 Files .write ("ABC" .getBytes (StandardCharsets .UTF_8 ), dirty );
6151 clean = new File (rootFolder (), "CLEAN.md" );
6252 Files .write ("abc" .getBytes (StandardCharsets .UTF_8 ), clean );
53+ clean2 = new File (rootFolder (), "CLEAN2.md" );
54+ Files .write ("def" .getBytes (StandardCharsets .UTF_8 ), clean2 );
6355 diverge = new File (rootFolder (), "DIVERGE.md" );
6456 Files .write ("ABC" .getBytes (StandardCharsets .UTF_8 ), diverge );
6557 outofbounds = new File (rootFolder (), "OUTOFBOUNDS.md" );
@@ -85,6 +77,23 @@ private void runWith(boolean configurationCache, String... arguments) throws IOE
8577 this .error = error .toString ();
8678 }
8779
80+ private void initPluginConfig (String miscTargets , String divergeTargets ) throws IOException {
81+ setFile ("build.gradle" ).toLines (
82+ "plugins {" ,
83+ " id 'com.diffplug.spotless'" ,
84+ "}" ,
85+ "spotless {" ,
86+ " format 'misc', {" ,
87+ " target " + miscTargets ,
88+ " addStep com.diffplug.spotless.TestingOnly.lowercase()" ,
89+ " }" ,
90+ " format 'diverge', {" ,
91+ " target " + divergeTargets ,
92+ " addStep com.diffplug.spotless.TestingOnly.diverge()" ,
93+ " }" ,
94+ "}" );
95+ }
96+
8897 protected GradleRunner gradleRunner (boolean configurationCache ) throws IOException {
8998 if (configurationCache ) {
9099 setFile ("gradle.properties" ).toContent ("org.gradle.unsafe.configuration-cache=true" );
@@ -139,6 +148,91 @@ void outofbounds(boolean configurationCache) throws IOException {
139148 void notAbsolute (boolean configurationCache ) throws IOException {
140149 runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=build.gradle" , "-PspotlessIdeHookUseStdOut" );
141150 Assertions .assertThat (output ).isEmpty ();
142- Assertions .assertThat (error ).contains ("Argument passed to spotlessIdeHook must be an absolute path" );
151+ Assertions .assertThat (error ).contains ("Argument passed to spotlessIdeHook must be one or multiple absolute paths" );
152+ }
153+
154+ @ ParameterizedTest
155+ @ MethodSource ("configurationCacheProvider" )
156+ void multipleFilesBothDirty (boolean configurationCache ) throws IOException {
157+ String paths = dirty .getAbsolutePath () + "," + diverge .getAbsolutePath ();
158+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths );
159+ Assertions .assertThat (output ).isEmpty ();
160+ Assertions .assertThat (error ).contains ("IS DIRTY" );
161+ Assertions .assertThat (error ).contains ("DID NOT CONVERGE" );
162+ }
163+
164+ @ ParameterizedTest
165+ @ MethodSource ("configurationCacheProvider" )
166+ void multipleFilesBothClean (boolean configurationCache ) throws IOException {
167+ String paths = clean .getAbsolutePath () + "," + clean2 .getAbsolutePath ();
168+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths );
169+ Assertions .assertThat (output ).isEmpty ();
170+ Assertions .assertThat (error ).contains ("IS CLEAN" );
171+ }
172+
173+ @ ParameterizedTest
174+ @ MethodSource ("configurationCacheProvider" )
175+ void multipleFilesMixed (boolean configurationCache ) throws IOException {
176+ String paths = clean .getAbsolutePath () + "," + dirty .getAbsolutePath ();
177+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths );
178+ Assertions .assertThat (output ).isEmpty ();
179+ Assertions .assertThat (error ).contains ("IS CLEAN" );
180+ Assertions .assertThat (error ).contains ("IS DIRTY" );
181+ }
182+
183+ @ ParameterizedTest
184+ @ MethodSource ("configurationCacheProvider" )
185+ void multipleFilesWithSpaces (boolean configurationCache ) throws IOException {
186+ String paths = clean .getAbsolutePath () + " , " + dirty .getAbsolutePath ();
187+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths );
188+ Assertions .assertThat (output ).isEmpty ();
189+ Assertions .assertThat (error ).contains ("IS CLEAN" );
190+ Assertions .assertThat (error ).contains ("IS DIRTY" );
191+ }
192+
193+ @ ParameterizedTest
194+ @ MethodSource ("configurationCacheProvider" )
195+ void multipleFilesWithOutOfBounds (boolean configurationCache ) throws IOException {
196+ String paths = dirty .getAbsolutePath () + "," + outofbounds .getAbsolutePath ();
197+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths );
198+ Assertions .assertThat (output ).isEmpty ();
199+ Assertions .assertThat (error ).contains ("IS DIRTY" );
200+ }
201+
202+ @ ParameterizedTest
203+ @ MethodSource ("configurationCacheProvider" )
204+ void multipleFilesStdOutThrowsException (boolean configurationCache ) throws IOException {
205+ String paths = dirty .getAbsolutePath () + "," + clean .getAbsolutePath ();
206+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths , "-PspotlessIdeHookUseStdOut" );
207+ Assertions .assertThat (output ).isEmpty ();
208+ Assertions .assertThat (error ).contains ("Using spotlessIdeHookUseStdIn or spotlessIdeHookUseStdOut with multiple files is not supported" );
209+ }
210+
211+ @ ParameterizedTest
212+ @ MethodSource ("configurationCacheProvider" )
213+ void multipleFilesStdInThrowsException (boolean configurationCache ) throws IOException {
214+ String paths = dirty .getAbsolutePath () + "," + clean .getAbsolutePath ();
215+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths , "-PspotlessIdeHookUseStdIn" );
216+ Assertions .assertThat (output ).isEmpty ();
217+ Assertions .assertThat (error ).contains ("Using spotlessIdeHookUseStdIn or spotlessIdeHookUseStdOut with multiple files is not supported" );
218+ }
219+
220+ @ ParameterizedTest
221+ @ MethodSource ("configurationCacheProvider" )
222+ void multipleFilesLargeScale (boolean configurationCache ) throws IOException {
223+ int fileCount = 500 ;
224+ StringBuilder paths = new StringBuilder ();
225+ for (int i = 0 ; i < fileCount ; i ++) {
226+ File f = new File (rootFolder (), "file_" + i + ".md" );
227+ Files .write (("Some content " + i ).getBytes (StandardCharsets .UTF_8 ), f );
228+ if (i > 0 ) {
229+ paths .append ("," );
230+ }
231+ paths .append (f .getAbsolutePath ());
232+ }
233+ initPluginConfig ("'file_*.md'" , "'DIVERGE.md'" );
234+ runWith (configurationCache , "spotlessApply" , "--quiet" , "-PspotlessIdeHook=" + paths );
235+ Assertions .assertThat (output ).isEmpty ();
236+ Assertions .assertThat (error ).contains ("IS DIRTY" );
143237 }
144238}
0 commit comments