26
26
import java .util .stream .Collectors ;
27
27
import java .util .stream .Stream ;
28
28
29
+ import javax .annotation .CheckForNull ;
29
30
import javax .annotation .Nullable ;
30
31
31
32
import org .slf4j .Logger ;
@@ -56,15 +57,15 @@ public static FormatterStep create(boolean withDefaults,
56
57
}
57
58
58
59
public static FormatterStep create (boolean withDefaults ,
59
- @ Nullable String binaryPath , @ Nullable String configPath ) {
60
+ @ Nullable String binaryPath , @ Nullable String codeStyleSettingsPath ) {
60
61
return FormatterStep .createLazy ("IDEA" ,
61
- () -> createState (withDefaults , binaryPath , configPath ),
62
+ () -> createState (withDefaults , binaryPath , codeStyleSettingsPath ),
62
63
state -> state );
63
64
}
64
65
65
66
private static State createState (boolean withDefaults ,
66
- @ Nullable String binaryPath , @ Nullable String configPath ) {
67
- return new State (withDefaults , binaryPath , configPath );
67
+ @ Nullable String binaryPath , @ Nullable String codeStyleSettingsPath ) {
68
+ return new State (withDefaults , binaryPath , codeStyleSettingsPath );
68
69
}
69
70
70
71
private static class State
@@ -75,24 +76,25 @@ private static class State
75
76
76
77
private String binaryPath ;
77
78
@ Nullable
78
- private String configPath ;
79
+ private String codeStyleSettingsPath ;
79
80
private boolean withDefaults ;
80
81
81
82
private State (boolean withDefaults , @ Nullable String binaryPath ,
82
- @ Nullable String configPath ) {
83
+ @ Nullable String codeStyleSettingsPath ) {
83
84
this .withDefaults = withDefaults ;
84
- this .configPath = configPath ;
85
+ this .codeStyleSettingsPath = codeStyleSettingsPath ;
85
86
this .binaryPath = Objects .requireNonNullElse (binaryPath , DEFAULT_IDEA );
86
87
resolveFullBinaryPathAndCheckVersion ();
87
88
}
88
89
89
90
private void resolveFullBinaryPathAndCheckVersion () {
90
91
var exe = ForeignExe
91
92
.nameAndVersion (this .binaryPath , "IntelliJ IDEA" )
93
+ .pathToExe (pathToExe ())
92
94
.versionRegex (Pattern .compile ("(IntelliJ IDEA) .*" ))
93
95
.fixCantFind (
94
96
"IDEA executable cannot be found on your machine, "
95
- + "please install it and put idea binary to PATH; or report the problem" )
97
+ + "please install it and put idea binary to PATH, provide a valid path to the executable or report the problem" )
96
98
.fixWrongVersion ("Provided binary is not IDEA, "
97
99
+ "please check it and fix the problem; or report the problem" );
98
100
try {
@@ -105,6 +107,17 @@ private void resolveFullBinaryPathAndCheckVersion() {
105
107
}
106
108
}
107
109
110
+ @ CheckForNull
111
+ private String pathToExe () {
112
+ if (binaryPath == null ) {
113
+ throw new IllegalStateException ("binaryPath is not set" );
114
+ }
115
+ if (new File (binaryPath ).exists ()) {
116
+ return binaryPath ;
117
+ }
118
+ return null ; // search in PATH
119
+ }
120
+
108
121
@ Override
109
122
public String applyWithFile (String unix , File file ) throws Exception {
110
123
List <String > params = getParams (file );
@@ -126,9 +139,9 @@ private List<String> getParams(File file) {
126
139
if (withDefaults ) {
127
140
builder .add ("-allowDefaults" );
128
141
}
129
- if (configPath != null ) {
142
+ if (codeStyleSettingsPath != null ) {
130
143
builder .add ("-s" );
131
- builder .add (configPath );
144
+ builder .add (codeStyleSettingsPath );
132
145
}
133
146
builder .add (file .toString ());
134
147
return builder .build ().collect (Collectors .toList ());
0 commit comments