36
36
import com .diffplug .spotless .FormatterFunc ;
37
37
import com .diffplug .spotless .FormatterStep ;
38
38
import com .diffplug .spotless .ProcessRunner ;
39
+ import com .diffplug .spotless .ThrowingEx ;
39
40
40
41
public final class IdeaStep {
41
42
@@ -120,15 +121,21 @@ private String pathToExe() {
120
121
121
122
@ Override
122
123
public String applyWithFile (String unix , File file ) throws Exception {
123
- List <String > params = getParams (file );
124
-
125
- try (ProcessRunner runner = new ProcessRunner ()) {
126
- var result = runner .exec (params );
127
-
128
- LOGGER .debug ("command finished with stdout: {}" ,
129
- result .assertExitZero (StandardCharsets .UTF_8 ));
130
-
131
- return Files .readString (file .toPath ());
124
+ // since we cannot directly work with the file, we need to write the unix string to a temporary file
125
+ File tempFile = File .createTempFile ("spotless" , file .getName ());
126
+ try {
127
+ Files .write (tempFile .toPath (), unix .getBytes (StandardCharsets .UTF_8 ));
128
+ List <String > params = getParams (tempFile );
129
+
130
+ try (ProcessRunner runner = new ProcessRunner ()) {
131
+ var result = runner .exec (params );
132
+ LOGGER .debug ("command finished with stdout: {}" ,
133
+ result .assertExitZero (StandardCharsets .UTF_8 ));
134
+
135
+ return Files .readString (tempFile .toPath (), StandardCharsets .UTF_8 );
136
+ }
137
+ } finally {
138
+ Files .delete (tempFile .toPath ());
132
139
}
133
140
}
134
141
@@ -143,7 +150,7 @@ private List<String> getParams(File file) {
143
150
builder .add ("-s" );
144
151
builder .add (codeStyleSettingsPath );
145
152
}
146
- builder .add (file . toString ( ));
153
+ builder .add (ThrowingEx . get ( file :: getCanonicalPath ));
147
154
return builder .build ().collect (Collectors .toList ());
148
155
}
149
156
}
0 commit comments