4848
4949public final class IdeaStep {
5050
51+ private static final Logger LOGGER = LoggerFactory .getLogger (IdeaStep .class );
52+
5153 public static final String NAME = "IDEA" ;
5254
5355 public static final String IDEA_EXECUTABLE_DEFAULT = "idea" ;
5456
55- private static final Logger LOGGER = LoggerFactory .getLogger (IdeaStep .class );
5657 public static final String IDEA_CONFIG_PATH_PROPERTY = "idea.config.path" ;
5758 public static final String IDEA_SYSTEM_PATH_PROPERTY = "idea.system.path" ;
59+ @ Nonnull
60+ private final IdeaStepBuilder builder ;
5861
59- private IdeaStep () {}
62+ private IdeaStep (@ Nonnull IdeaStepBuilder builder ) {
63+ this .builder = builder ;
64+ }
6065
61- public static IdeaStepBuilder create (@ Nonnull File buildDir ) {
66+ public static IdeaStepBuilder newBuilder (@ Nonnull File buildDir ) {
6267 return new IdeaStepBuilder (Objects .requireNonNull (buildDir ));
6368 }
6469
65- private static FormatterStep create (@ Nonnull IdeaStepBuilder builder ) {
66- Objects .requireNonNull (builder );
67- return FormatterStep .createLazy (NAME ,
68- () -> createState (builder ), State ::toFunc );
70+ private static FormatterStep create (IdeaStepBuilder builder ) {
71+ return new IdeaStep (builder ).createFormatterStep ();
6972 }
7073
71- private static State createState (@ Nonnull IdeaStepBuilder builder ) {
74+ private FormatterStep createFormatterStep () {
75+ return FormatterStep .createLazy (NAME , this ::createState , State ::toFunc );
76+ }
77+
78+ private State createState () {
7279 return new State (Objects .requireNonNull (builder ));
7380 }
7481
@@ -114,6 +121,17 @@ public IdeaStepBuilder setIdeaProperties(@Nonnull Map<String, String> ideaProper
114121 public FormatterStep build () {
115122 return create (this );
116123 }
124+
125+ @ Override
126+ public String toString () {
127+ return String .format (
128+ "IdeaStepBuilder[useDefaults=%s, binaryPath=%s, codeStyleSettingsPath=%s, ideaProperties=%s, buildDir=%s]" ,
129+ this .useDefaults ,
130+ this .binaryPath ,
131+ this .codeStyleSettingsPath ,
132+ this .ideaProperties ,
133+ this .buildDir );
134+ }
117135 }
118136
119137 private static class State implements Serializable {
@@ -128,6 +146,7 @@ private static class State implements Serializable {
128146 private final TreeMap <String , String > ideaProperties ;
129147
130148 private State (@ Nonnull IdeaStepBuilder builder ) {
149+ LOGGER .debug ("Creating {} state with configuration {}" , NAME , builder );
131150 this .uniqueBuildFolder = new File (builder .buildDir , UUID .randomUUID ().toString ());
132151 this .withDefaults = builder .useDefaults ;
133152 this .codeStyleSettingsPath = builder .codeStyleSettingsPath ;
@@ -203,7 +222,9 @@ private String format(IdeaStepFormatterCleanupResources ideaStepFormatterCleanup
203222 List <String > params = getParams (tempFile );
204223
205224 Map <String , String > env = createEnv ();
225+ LOGGER .info ("Launching IDEA formatter for orig file {} with params: {} and env: {}" , file , params , env );
206226 var result = ideaStepFormatterCleanupResources .runner .exec (null , env , null , params );
227+ LOGGER .debug ("command finished with exit code: {}" , result .exitCode ());
207228 LOGGER .debug ("command finished with stdout: {}" ,
208229 result .assertExitZero (StandardCharsets .UTF_8 ));
209230 return Files .readString (tempFile .toPath (), StandardCharsets .UTF_8 );
@@ -236,6 +257,7 @@ private File createIdeaPropertiesFile() {
236257 properties .put (IDEA_CONFIG_PATH_PROPERTY , ThrowingEx .get (configPath .toFile ()::getCanonicalPath ));
237258 properties .put (IDEA_SYSTEM_PATH_PROPERTY , ThrowingEx .get (systemPath .toFile ()::getCanonicalPath ));
238259
260+ LOGGER .debug ("Creating IDEA properties file at {} with content: {}" , ideaProps , properties );
239261 try (FileOutputStream out = new FileOutputStream (ideaProps .toFile ())) {
240262 properties .store (out , "Generated by spotless" );
241263 } catch (IOException e ) {
0 commit comments