Remove unnecessary method in JvmOptionsParser (#52173)

Back when the distribution launchers were compiled to target JDK 7, we
did not have access to the String#join method to space-delimit JVM
options. Since the launchers now target the same minimum JDK as
Elasticsearch itself, we now have access to this method and can replace
the use of spaceDelimitJvmOptions with String#join. This commit does
that.
This commit is contained in:
Jason Tedor 2020-02-10 20:21:32 -05:00
parent 350288ddf8
commit 91d0996e08
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
2 changed files with 1 additions and 30 deletions

View File

@ -35,7 +35,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -94,8 +93,7 @@ final class JvmOptionsParser {
try {
final List<String> jvmOptions = parser.jvmOptions(Paths.get(args[0]), System.getenv("ES_JAVA_OPTS"), substitutions);
final String spaceDelimitedJvmOptions = spaceDelimitJvmOptions(jvmOptions);
Launchers.outPrintln(spaceDelimitedJvmOptions);
Launchers.outPrintln(String.join(" ", jvmOptions));
} catch (final JvmOptionsFileParserException e) {
final String errorMessage = String.format(
Locale.ROOT,
@ -339,22 +337,4 @@ final class JvmOptionsParser {
}
}
/**
* Delimits the specified JVM options by spaces.
*
* @param jvmOptions the JVM options
* @return a single-line string containing the specified JVM options in the order they appear delimited by spaces
*/
static String spaceDelimitJvmOptions(final List<String> jvmOptions) {
final StringBuilder spaceDelimitedJvmOptionsBuilder = new StringBuilder();
final Iterator<String> it = jvmOptions.iterator();
while (it.hasNext()) {
spaceDelimitedJvmOptionsBuilder.append(it.next());
if (it.hasNext()) {
spaceDelimitedJvmOptionsBuilder.append(" ");
}
}
return spaceDelimitedJvmOptionsBuilder.toString();
}
}

View File

@ -246,13 +246,4 @@ public class JvmOptionsParserTests extends LaunchersTestCase {
assertThat(seenInvalidLines, equalTo(invalidLines));
}
public void testSpaceDelimitedJvmOptions() {
assertThat(JvmOptionsParser.spaceDelimitJvmOptions(Collections.singletonList("-Xms1g")), equalTo("-Xms1g"));
assertThat(JvmOptionsParser.spaceDelimitJvmOptions(Arrays.asList("-Xms1g", "-Xmx1g")), equalTo("-Xms1g -Xmx1g"));
assertThat(
JvmOptionsParser.spaceDelimitJvmOptions(Arrays.asList("-Xms1g", "-Xmx1g", "-XX:+UseG1GC")),
equalTo("-Xms1g -Xmx1g -XX:+UseG1GC")
);
}
}