@@ -59,40 +59,41 @@ public static void main(final String[] args) throws InterruptedException, IOExce
59
59
}
60
60
final List <String > jvmOptions = new ArrayList <>();
61
61
final SortedMap <Integer , String > invalidLines = new TreeMap <>();
62
- try (InputStream is = Files .newInputStream (Paths .get (args [0 ]));
63
- Reader reader = new InputStreamReader (is , StandardCharsets .UTF_8 );
64
- BufferedReader br = new BufferedReader (reader )) {
65
- parse (
66
- JavaVersion .majorVersion (JavaVersion .CURRENT ),
67
- br ,
68
- new JvmOptionConsumer () {
69
- @ Override
70
- public void accept (final String jvmOption ) {
71
- jvmOptions .add (jvmOption );
72
- }
73
- },
74
- new InvalidLineConsumer () {
75
- @ Override
76
- public void accept (final int lineNumber , final String line ) {
77
- invalidLines .put (lineNumber , line );
78
- }
79
- });
62
+ try (
63
+ InputStream is = Files .newInputStream (Paths .get (args [0 ]));
64
+ Reader reader = new InputStreamReader (is , StandardCharsets .UTF_8 );
65
+ BufferedReader br = new BufferedReader (reader )
66
+ ) {
67
+ parse (JavaVersion .majorVersion (JavaVersion .CURRENT ), br , new JvmOptionConsumer () {
68
+ @ Override
69
+ public void accept (final String jvmOption ) {
70
+ jvmOptions .add (jvmOption );
71
+ }
72
+ }, new InvalidLineConsumer () {
73
+ @ Override
74
+ public void accept (final int lineNumber , final String line ) {
75
+ invalidLines .put (lineNumber , line );
76
+ }
77
+ });
80
78
}
81
79
82
80
if (invalidLines .isEmpty ()) {
83
81
// now append the JVM options from ES_JAVA_OPTS
84
82
final String environmentJvmOptions = System .getenv ("ES_JAVA_OPTS" );
85
83
if (environmentJvmOptions != null ) {
86
- jvmOptions .addAll (Arrays . stream ( environmentJvmOptions . split ( " \\ s+" ))
87
- . filter (s -> s .trim ().isEmpty () == false )
88
- . collect ( Collectors . toList ()) );
84
+ jvmOptions .addAll (
85
+ Arrays . stream ( environmentJvmOptions . split ( " \\ s+" )). filter (s -> s .trim ().isEmpty () == false ). collect ( Collectors . toList () )
86
+ );
89
87
}
90
- final List <String > substitutedJvmOptions =
91
- substitutePlaceholders (jvmOptions , Collections .singletonMap ("ES_TMPDIR" , System .getenv ("ES_TMPDIR" )));
88
+ final List <String > substitutedJvmOptions = substitutePlaceholders (
89
+ jvmOptions ,
90
+ Collections .singletonMap ("ES_TMPDIR" , System .getenv ("ES_TMPDIR" ))
91
+ );
92
92
final List <String > ergonomicJvmOptions = JvmErgonomics .choose (substitutedJvmOptions );
93
93
final List <String > systemJvmOptions = SystemJvmOptions .systemJvmOptions ();
94
- final List <String > finalJvmOptions =
95
- new ArrayList <>(systemJvmOptions .size () + substitutedJvmOptions .size () + ergonomicJvmOptions .size ());
94
+ final List <String > finalJvmOptions = new ArrayList <>(
95
+ systemJvmOptions .size () + substitutedJvmOptions .size () + ergonomicJvmOptions .size ()
96
+ );
96
97
finalJvmOptions .addAll (systemJvmOptions ); // add the system JVM options first so that they can be overridden
97
98
finalJvmOptions .addAll (substitutedJvmOptions );
98
99
finalJvmOptions .addAll (ergonomicJvmOptions );
@@ -101,43 +102,43 @@ public void accept(final int lineNumber, final String line) {
101
102
Launchers .exit (0 );
102
103
} else {
103
104
final String errorMessage = String .format (
104
- Locale .ROOT ,
105
- "encountered [%d] error%s parsing [%s]" ,
106
- invalidLines .size (),
107
- invalidLines .size () == 1 ? "" : "s" ,
108
- args [0 ]);
105
+ Locale .ROOT ,
106
+ "encountered [%d] error%s parsing [%s]" ,
107
+ invalidLines .size (),
108
+ invalidLines .size () == 1 ? "" : "s" ,
109
+ args [0 ]
110
+ );
109
111
Launchers .errPrintln (errorMessage );
110
112
int count = 0 ;
111
113
for (final Map .Entry <Integer , String > entry : invalidLines .entrySet ()) {
112
114
count ++;
113
115
final String message = String .format (
114
- Locale .ROOT ,
115
- "[%d]: encountered improperly formatted JVM option line [%s] on line number [%d]" ,
116
- count ,
117
- entry .getValue (),
118
- entry .getKey ());
116
+ Locale .ROOT ,
117
+ "[%d]: encountered improperly formatted JVM option line [%s] on line number [%d]" ,
118
+ count ,
119
+ entry .getValue (),
120
+ entry .getKey ()
121
+ );
119
122
Launchers .errPrintln (message );
120
123
}
121
124
Launchers .exit (1 );
122
125
}
123
126
}
124
127
125
128
static List <String > substitutePlaceholders (final List <String > jvmOptions , final Map <String , String > substitutions ) {
126
- final Map <String , String > placeholderSubstitutions =
127
- substitutions .entrySet ().stream ().collect (Collectors .toMap (e -> "${" + e .getKey () + "}" , Map .Entry ::getValue ));
128
- return jvmOptions .stream ()
129
- .map (
130
- jvmOption -> {
131
- String actualJvmOption = jvmOption ;
132
- int start = jvmOption .indexOf ("${" );
133
- if (start >= 0 && jvmOption .indexOf ('}' , start ) > 0 ) {
134
- for (final Map .Entry <String , String > placeholderSubstitution : placeholderSubstitutions .entrySet ()) {
135
- actualJvmOption = actualJvmOption .replace (placeholderSubstitution .getKey (), placeholderSubstitution .getValue ());
136
- }
137
- }
138
- return actualJvmOption ;
139
- })
140
- .collect (Collectors .toList ());
129
+ final Map <String , String > placeholderSubstitutions = substitutions .entrySet ()
130
+ .stream ()
131
+ .collect (Collectors .toMap (e -> "${" + e .getKey () + "}" , Map .Entry ::getValue ));
132
+ return jvmOptions .stream ().map (jvmOption -> {
133
+ String actualJvmOption = jvmOption ;
134
+ int start = jvmOption .indexOf ("${" );
135
+ if (start >= 0 && jvmOption .indexOf ('}' , start ) > 0 ) {
136
+ for (final Map .Entry <String , String > placeholderSubstitution : placeholderSubstitutions .entrySet ()) {
137
+ actualJvmOption = actualJvmOption .replace (placeholderSubstitution .getKey (), placeholderSubstitution .getValue ());
138
+ }
139
+ }
140
+ return actualJvmOption ;
141
+ }).collect (Collectors .toList ());
141
142
}
142
143
143
144
/**
@@ -223,10 +224,11 @@ interface InvalidLineConsumer {
223
224
* @throws IOException if an I/O exception occurs reading from the buffered reader
224
225
*/
225
226
static void parse (
226
- final int javaMajorVersion ,
227
- final BufferedReader br ,
228
- final JvmOptionConsumer jvmOptionConsumer ,
229
- final InvalidLineConsumer invalidLineConsumer ) throws IOException {
227
+ final int javaMajorVersion ,
228
+ final BufferedReader br ,
229
+ final JvmOptionConsumer jvmOptionConsumer ,
230
+ final InvalidLineConsumer invalidLineConsumer
231
+ ) throws IOException {
230
232
int lineNumber = 0 ;
231
233
while (true ) {
232
234
final String line = br .readLine ();
0 commit comments