desruisseaux commented on code in PR #3395: URL: https://github.com/apache/maven-surefire/pull/3395#discussion_r3623823872
########## maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ModuleInfoPatchArgsFile.java: ########## @@ -0,0 +1,144 @@ +/* + * 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.maven.plugin.surefire; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableSet; + +/** + * The runtime handoff file {@code META-INF/maven/module-info-patch.args} written by + * maven-compiler-plugin 4.x from {@code module-info-patch.maven}. It contains the Java + * Modules options the compiler used for the test compilation (one option per line, value + * either on the same line separated by whitespace or on the following line). + * + * @since 3.6.0 + */ +public final class ModuleInfoPatchArgsFile { + public static final String RELATIVE_PATH = "META-INF/maven/module-info-patch.args"; + + private final File file; + private final List<String> lines; + private final Set<String> addedModules; + + private ModuleInfoPatchArgsFile(File file, List<String> lines, Set<String> addedModules) { + this.file = file; + this.lines = lines; + this.addedModules = addedModules; + } + + /** + * Loads the handoff file from the test output directory. + * + * @param testClassesDirectory the test output directory (e.g. target/test-classes) + * @return the parsed file, or null if it does not exist + * @throws IOException if the file exists but cannot be read + */ + public static ModuleInfoPatchArgsFile load(File testClassesDirectory) throws IOException { + if (testClassesDirectory == null || !testClassesDirectory.isDirectory()) { + return null; + } + return parse(new File(testClassesDirectory, RELATIVE_PATH)); + } + + /** + * Parses the given handoff file. + * + * @param file the module-info-patch.args file + * @return the parsed file, or null if it does not exist + * @throws IOException if the file exists but cannot be read + */ + public static ModuleInfoPatchArgsFile parse(File file) throws IOException { + if (file == null || !file.isFile()) { + return null; + } + + List<String> lines = new ArrayList<>(); + Set<String> addedModules = new LinkedHashSet<>(); + try (BufferedReader reader = Files.newBufferedReader(file.toPath())) { Review Comment: > `Files.newBufferedReader(file.toPath())` This is not true, the Javadoc explicitly said that it uses UTF-8 and it can be verified by looking at the source code. -- 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]
