Skip to content

Commit

Permalink
Remove unnecessary method in JvmOptionsParser (#52173)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor authored Feb 11, 2020
1 parent 9fb5c81 commit 1f144f2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,8 +94,7 @@ public static void main(final String[] args) throws InterruptedException, IOExce

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,
Expand Down Expand Up @@ -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<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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}

}

0 comments on commit 1f144f2

Please sign in to comment.