EricJoy2048 commented on code in PR #3771: URL: https://github.com/apache/incubator-seatunnel/pull/3771#discussion_r1099970491
########## seatunnel-core/seatunnel-starter/src/main/java/org/apache/seatunnel/core/starter/seatunnel/jvm/JavaVersion.java: ########## @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.core.starter.seatunnel.jvm; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class JavaVersion { + + public static final List<Integer> CURRENT = parse(System.getProperty("java.specification.version")); + + static List<Integer> parse(final String value) { + if (!value.matches("^0*[0-9]+(\\.[0-9]+)*$")) { + throw new IllegalArgumentException(value); Review Comment: Use a custom Exception is better. ########## seatunnel-core/seatunnel-starter/src/main/java/org/apache/seatunnel/core/starter/seatunnel/jvm/JvmOptionsParser.java: ########## @@ -0,0 +1,275 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.core.starter.seatunnel.jvm; + +import lombok.SneakyThrows; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Parses JVM options from a file and prints a single line with all JVM options to standard output. + */ +@SuppressWarnings("checkstyle:InnerTypeLast") +final class JvmOptionsParser { + + /** + * The main entry point. The exit code is 0 if the JVM options were successfully parsed, otherwise the exit code is 1. If an improperly + * formatted line is discovered, the line is output to standard error. + */ + public static void main(final String[] args) { + if (args.length != 1) { + throw new IllegalArgumentException("expected one argument specifying path to jvm.options but was " + Arrays.toString(args)); + } + readJvmOptionsFiles(args[0]); + } + + @SneakyThrows + @SuppressWarnings("checkstyle:RegexpSingleline") + public static void readJvmOptionsFiles(String configPath){ + final List<String> jvmOptions = new ArrayList<>(); + final SortedMap<Integer, String> invalidLines = new TreeMap<>(); + try (InputStream is = Files.newInputStream(Paths.get(configPath)); + Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8); + BufferedReader br = new BufferedReader(reader)) { + parse( + JavaVersion.majorVersion(JavaVersion.CURRENT), + br, + new JvmOptionConsumer() { Review Comment: `jvmOption -> jvmOptions.add(jvmOption)` is better. ########## seatunnel-core/seatunnel-starter/src/main/java/org/apache/seatunnel/core/starter/seatunnel/jvm/JvmOptionsParser.java: ########## @@ -0,0 +1,275 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.core.starter.seatunnel.jvm; + +import lombok.SneakyThrows; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Parses JVM options from a file and prints a single line with all JVM options to standard output. + */ +@SuppressWarnings("checkstyle:InnerTypeLast") +final class JvmOptionsParser { + + /** + * The main entry point. The exit code is 0 if the JVM options were successfully parsed, otherwise the exit code is 1. If an improperly + * formatted line is discovered, the line is output to standard error. + */ + public static void main(final String[] args) { + if (args.length != 1) { + throw new IllegalArgumentException("expected one argument specifying path to jvm.options but was " + Arrays.toString(args)); + } + readJvmOptionsFiles(args[0]); + } + + @SneakyThrows + @SuppressWarnings("checkstyle:RegexpSingleline") + public static void readJvmOptionsFiles(String configPath){ + final List<String> jvmOptions = new ArrayList<>(); + final SortedMap<Integer, String> invalidLines = new TreeMap<>(); + try (InputStream is = Files.newInputStream(Paths.get(configPath)); + Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8); + BufferedReader br = new BufferedReader(reader)) { + parse( + JavaVersion.majorVersion(JavaVersion.CURRENT), + br, + new JvmOptionConsumer() { + @Override + public void accept(final String jvmOption) { + jvmOptions.add(jvmOption); + } + }, + new InvalidLineConsumer() { Review Comment: `(lineNumber, line) -> invalidLines.put(lineNumber, line)` is bettter. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
