-
Notifications
You must be signed in to change notification settings - Fork 582
Run test-scope dependencies as named modules with module-info-patch.args (#3090) #3395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ascheman
wants to merge
10
commits into
apache:master
Choose a base branch
from
aschemaven:bugfix/3090-test-deps-on-module-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
09f0e5b
Use forked JVM mode for Maven 4 in ITs
ascheman 2fc6f9d
Support Maven 4 module source hierarchy (#3345)
ascheman 7b78650
Clarify patch-args handling, sort module dirs
ascheman 8dd1792
Read module-info-patch.args as UTF-8
ascheman 9c51a44
Polish patch-args handling after review
ascheman f9d59d5
Support multiple modules per POM (#3393)
ascheman bef0da5
Address review: dedupe module scan, use Path API
ascheman d6a1bff
Move handoff modules to module path (#3090)
ascheman d5a46b6
Split newStartupConfigWithModularPath by cases
ascheman 4ea4f28
Add Surefire3090TestDepsOnModulePathIT
ascheman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
570 changes: 546 additions & 24 deletions
570
...-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
Large diffs are not rendered by default.
Oops, something went wrong.
144 changes: 144 additions & 0 deletions
144
...refire-common/src/main/java/org/apache/maven/plugin/surefire/ModuleInfoPatchArgsFile.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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())) { | ||
| String line; | ||
| while ((line = reader.readLine()) != null) { | ||
| line = line.trim(); | ||
| if (line.isEmpty() || line.startsWith("#")) { | ||
| continue; | ||
| } | ||
| lines.add(line); | ||
| } | ||
| } | ||
| for (int i = 0; i < lines.size(); i++) { | ||
| String line = lines.get(i); | ||
| String value = optionValue(line, "--add-modules", lines, i); | ||
| if (value != null) { | ||
| for (String module : value.split(",")) { | ||
| String name = module.trim(); | ||
| if (!name.isEmpty()) { | ||
| addedModules.add(name); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return new ModuleInfoPatchArgsFile(file, unmodifiableList(lines), unmodifiableSet(addedModules)); | ||
| } | ||
|
|
||
| /** | ||
| * The value of the given option at index {@code i}, supporting both the same-line form | ||
| * ({@code --add-modules a,b}) and the two-line argfile form (value on the next line). | ||
| * | ||
| * @return the option value, or null if the line is not the given option | ||
| */ | ||
| private static String optionValue(String line, String option, List<String> lines, int i) { | ||
| if (line.equals(option)) { | ||
| return i + 1 < lines.size() ? lines.get(i + 1) : null; | ||
| } | ||
| if (line.startsWith(option) && Character.isWhitespace(line.charAt(option.length()))) { | ||
| return line.substring(option.length()).trim(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public File getFile() { | ||
| return file; | ||
| } | ||
|
|
||
| /** | ||
| * @return all non-empty, non-comment lines of the file, in order | ||
| */ | ||
| public List<String> getLines() { | ||
| return lines; | ||
| } | ||
|
|
||
| /** | ||
| * Module names listed by the file's {@code --add-modules} directives — with | ||
| * {@code module-info-patch.maven}'s {@code add-modules TEST-MODULE-PATH} these are the | ||
| * test-scope dependencies that belong on the module path. | ||
| * | ||
| * @return the module names, in file order | ||
| */ | ||
| public Set<String> getAddedModules() { | ||
| return addedModules; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace the first
NLby a space for consistency with the options added above. The goal is to make the file not only machine readable, but also human readable. I think that it is a little bit easier to understand when we have one option (including its value) per line.