From 1f144f29556992e55c452f7f5e401f804effbcc7 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 10 Feb 2020 20:21:32 -0500 Subject: [PATCH] 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. --- .../tools/launchers/JvmOptionsParser.java | 22 +------------------ .../launchers/JvmOptionsParserTests.java | 9 -------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java index 936d4f51b8309..dcb14dd949472 100644 --- a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java +++ b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java @@ -35,7 +35,6 @@ 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; @@ -95,8 +94,7 @@ public static void main(final String[] args) throws InterruptedException, IOExce try { final List 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, @@ -340,22 +338,4 @@ static void parse( } } - /** - * 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 jvmOptions) { - final StringBuilder spaceDelimitedJvmOptionsBuilder = new StringBuilder(); - final Iterator it = jvmOptions.iterator(); - while (it.hasNext()) { - spaceDelimitedJvmOptionsBuilder.append(it.next()); - if (it.hasNext()) { - spaceDelimitedJvmOptionsBuilder.append(" "); - } - } - return spaceDelimitedJvmOptionsBuilder.toString(); - } - } diff --git a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmOptionsParserTests.java b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmOptionsParserTests.java index 57e63fde8b87f..953328b13c493 100644 --- a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmOptionsParserTests.java +++ b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmOptionsParserTests.java @@ -246,13 +246,4 @@ public void accept(final int lineNumber, final String line) { 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") - ); - } - }