From 0b7235c0942d5758692318919d5d34d6971f79d2 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Fri, 3 Jan 2025 09:42:52 +0100 Subject: [PATCH 01/11] Clarify that packaging is never inherited --- compat/maven-model-builder/src/site/apt/index.apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/maven-model-builder/src/site/apt/index.apt b/compat/maven-model-builder/src/site/apt/index.apt index 38faeff9b319..ca1ff8c6cb9b 100644 --- a/compat/maven-model-builder/src/site/apt/index.apt +++ b/compat/maven-model-builder/src/site/apt/index.apt @@ -132,7 +132,7 @@ Maven Model Builder ({{{./xref/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.html}source}}). By default, every model field is inherited as-is from parent, with a few exceptions that are intentionally not inherited: - <<>>, <<>>, <<>> (injected in phase 1) and <<>>. + <<>>, <<>>, <<>>, <<>> (injected in phase 1) and <<>>. Notice that the 5 URLs from the model (<<>>, <<>>, <<>>, <<>> and <<>>) have a special inheritance handling: From 0176ffb825175f8a0ce124b1de287e527dab50e0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Mon, 6 Jan 2025 11:32:18 +0100 Subject: [PATCH 02/11] [MNG-8487] Completely isolate UTs (#2021) UTs were using real user home, and in case user had user-wide extensions.xml, it resulted in failure. Goal: make sure all UTs are properly protected and isolated from user env, by providing "fake" user home (to not have user-wide extensions in real user home affect test outcome). --- https://issues.apache.org/jira/browse/MNG-8487 --- .../maven/cling/invoker/mvn/MavenInvokerTest.java | 9 ++++++--- .../invoker/mvn/MavenInvokerTestSupport.java | 3 ++- .../mvn/resident/ResidentMavenInvokerTest.java | 9 ++++++--- .../org/apache/maven/api/cli/ExecutorRequest.java | 15 +++++++++++++-- .../maven/cling/executor/internal/HelperImpl.java | 15 ++++++++++++--- .../maven/cling/executor/impl/HelperImplTest.java | 14 ++++++++++++++ .../main/java/org/apache/maven/it/Verifier.java | 1 + 7 files changed, 54 insertions(+), 12 deletions(-) diff --git a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java index 54d6fb147b79..bae4f7015f51 100644 --- a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java +++ b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTest.java @@ -52,15 +52,18 @@ protected Parser createParser() { } @Test - void defaultFs(@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path tempDir) throws Exception { - invoke(tempDir, Arrays.asList("clean", "verify")); + void defaultFs( + @TempDir(cleanup = CleanupMode.ON_SUCCESS) Path cwd, + @TempDir(cleanup = CleanupMode.ON_SUCCESS) Path userHome) + throws Exception { + invoke(cwd, userHome, Arrays.asList("clean", "verify")); } @Disabled("Until we move off fully from File") @Test void jimFs() throws Exception { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { - invoke(fs.getPath("/"), Arrays.asList("clean", "verify")); + invoke(fs.getPath("/cwd"), fs.getPath("/home"), Arrays.asList("clean", "verify")); } } } diff --git a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTestSupport.java b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTestSupport.java index 4f3f46d4a0b5..89b33df73fe8 100644 --- a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTestSupport.java +++ b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerTestSupport.java @@ -80,7 +80,7 @@ public static void main(String... args) { } """; - protected void invoke(Path cwd, Collection goals) throws Exception { + protected void invoke(Path cwd, Path userHome, Collection goals) throws Exception { // works only in recent Maven4 Assumptions.assumeTrue( Files.isRegularFile(Paths.get(System.getProperty("maven.home")) @@ -104,6 +104,7 @@ protected void invoke(Path cwd, Collection goals) throws Exception { new ProtoLogger(), new JLineMessageBuilderFactory()) .cwd(cwd) + .userHome(userHome) .build())); String log = Files.readString(logFile); System.out.println(log); diff --git a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvokerTest.java b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvokerTest.java index 004b234de676..a9d017c96cec 100644 --- a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvokerTest.java +++ b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvokerTest.java @@ -55,15 +55,18 @@ protected Parser createParser() { } @Test - void defaultFs(@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path tempDir) throws Exception { - invoke(tempDir, Arrays.asList("clean", "verify")); + void defaultFs( + @TempDir(cleanup = CleanupMode.ON_SUCCESS) Path cwd, + @TempDir(cleanup = CleanupMode.ON_SUCCESS) Path userHome) + throws Exception { + invoke(cwd, userHome, Arrays.asList("clean", "verify")); } @Disabled("Until we move off fully from File") @Test void jimFs() throws Exception { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { - invoke(fs.getPath("/"), Arrays.asList("clean", "verify")); + invoke(fs.getPath("/cwd"), fs.getPath("/home"), Arrays.asList("clean", "verify")); } } } diff --git a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java index d13fa7ee51de..494cb06e1bd1 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java @@ -163,7 +163,9 @@ static Builder mavenBuilder(@Nullable Path installationDirectory) { MVN, null, getCanonicalPath(Paths.get(System.getProperty("user.dir"))), - installationDirectory != null ? getCanonicalPath(installationDirectory) : discoverMavenHome(), + installationDirectory != null + ? getCanonicalPath(installationDirectory) + : discoverInstallationDirectory(), getCanonicalPath(Paths.get(System.getProperty("user.home"))), null, null, @@ -430,7 +432,7 @@ public String toString() { } @Nonnull - static Path discoverMavenHome() { + static Path discoverInstallationDirectory() { String mavenHome = System.getProperty("maven.home"); if (mavenHome == null) { throw new ExecutorException("requires maven.home Java System Property set"); @@ -438,6 +440,15 @@ static Path discoverMavenHome() { return getCanonicalPath(Paths.get(mavenHome)); } + @Nonnull + static Path discoverUserHomeDirectory() { + String userHome = System.getProperty("user.home"); + if (userHome == null) { + throw new ExecutorException("requires user.home Java System Property set"); + } + return getCanonicalPath(Paths.get(userHome)); + } + @Nonnull static Path getCanonicalPath(Path path) { requireNonNull(path, "path"); diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java index e33af152bc1f..4304f6d87195 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java @@ -39,16 +39,25 @@ public class HelperImpl implements ExecutorHelper { private final Mode defaultMode; private final Path installationDirectory; + private final Path userHomeDirectory; private final ExecutorTool executorTool; private final HashMap executors; private final ConcurrentHashMap cache; - public HelperImpl(Mode defaultMode, @Nullable Path installationDirectory, Executor embedded, Executor forked) { + public HelperImpl( + Mode defaultMode, + @Nullable Path installationDirectory, + @Nullable Path userHomeDirectory, + Executor embedded, + Executor forked) { this.defaultMode = requireNonNull(defaultMode); this.installationDirectory = installationDirectory != null ? ExecutorRequest.getCanonicalPath(installationDirectory) - : ExecutorRequest.discoverMavenHome(); + : ExecutorRequest.discoverInstallationDirectory(); + this.userHomeDirectory = userHomeDirectory != null + ? ExecutorRequest.getCanonicalPath(userHomeDirectory) + : ExecutorRequest.discoverUserHomeDirectory(); this.executorTool = new ToolboxTool(this); this.executors = new HashMap<>(); @@ -64,7 +73,7 @@ public Mode getDefaultMode() { @Override public ExecutorRequest.Builder executorRequest() { - return ExecutorRequest.mavenBuilder(installationDirectory); + return ExecutorRequest.mavenBuilder(installationDirectory).userHomeDirectory(userHomeDirectory); } @Override diff --git a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java index 452ab530f8fc..3e21b631bd83 100644 --- a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java +++ b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java @@ -28,6 +28,7 @@ import org.apache.maven.cling.executor.embedded.EmbeddedMavenExecutor; import org.apache.maven.cling.executor.forked.ForkedMavenExecutor; import org.apache.maven.cling.executor.internal.HelperImpl; +import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -40,12 +41,16 @@ public class HelperImplTest { private static final EmbeddedMavenExecutor EMBEDDED_MAVEN_EXECUTOR = new EmbeddedMavenExecutor(); private static final ForkedMavenExecutor FORKED_MAVEN_EXECUTOR = new ForkedMavenExecutor(); + @TempDir + private Path userHome; + @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) void dump3(ExecutorHelper.Mode mode) throws Exception { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); Map dump = helper.dump(helper.executorRequest()); @@ -58,6 +63,7 @@ void dump4(ExecutorHelper.Mode mode) throws Exception { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); Map dump = helper.dump(helper.executorRequest()); @@ -70,6 +76,7 @@ void version3(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); assertEquals(System.getProperty("maven3version"), helper.mavenVersion()); @@ -81,6 +88,7 @@ void version4(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); assertEquals(System.getProperty("maven4version"), helper.mavenVersion()); @@ -92,6 +100,7 @@ void localRepository3(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String localRepository = helper.localRepository(helper.executorRequest()); @@ -105,6 +114,7 @@ void localRepository4(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String localRepository = helper.localRepository(helper.executorRequest()); @@ -118,6 +128,7 @@ void artifactPath3(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.artifactPath(helper.executorRequest(), "aopalliance:aopalliance:1.0", "central"); @@ -133,6 +144,7 @@ void artifactPath4(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.artifactPath(helper.executorRequest(), "aopalliance:aopalliance:1.0", "central"); @@ -148,6 +160,7 @@ void metadataPath3(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.metadataPath(helper.executorRequest(), "aopalliance", "someremote"); @@ -160,6 +173,7 @@ void metadataPath4(ExecutorHelper.Mode mode) { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), + userHome, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.metadataPath(helper.executorRequest(), "aopalliance", "someremote"); diff --git a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java index 4624035ce338..b51180030ed6 100644 --- a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java +++ b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java @@ -140,6 +140,7 @@ public Verifier(String basedir, List defaultCliArguments) throws Verific this.executorHelper = new HelperImpl( VERIFIER_FORK_MODE, Paths.get(System.getProperty("maven.home")), + this.userHomeDirectory, EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); this.defaultCliArguments = From 0ac67e00f7770ec6787d00083ad8f477fe9679d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:14:22 +0100 Subject: [PATCH 03/11] [MNG-8497] Bump ch.qos.logback:logback-classic from 1.5.15 to 1.5.16 (#2028) Bumps [ch.qos.logback:logback-classic](https://github.com/qos-ch/logback) from 1.5.15 to 1.5.16. - [Commits](https://github.com/qos-ch/logback/compare/v_1.5.15...v_1.5.16) --- updated-dependencies: - dependency-name: ch.qos.logback:logback-classic dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- https://issues.apache.org/jira/browse/MNG-8497 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 88e0806554cc..86fb831dcf76 100644 --- a/pom.xml +++ b/pom.xml @@ -156,7 +156,7 @@ under the License. 3.28.0 5.11.4 1.3 - 1.5.15 + 1.5.16 5.14.2 1.3 1.27 From e78a3cdaa68ce6952818998ab262fd61839c2ff1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:15:24 +0100 Subject: [PATCH 04/11] [MNG-8498] Bump org.assertj:assertj-core from 3.27.0 to 3.27.2 (#2027) Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.27.0 to 3.27.2. - [Release notes](https://github.com/assertj/assertj/releases) - [Commits](https://github.com/assertj/assertj/compare/assertj-build-3.27.0...assertj-build-3.27.2) --- updated-dependencies: - dependency-name: org.assertj:assertj-core dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- https://issues.apache.org/jira/browse/MNG-8498 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 86fb831dcf76..35145b0b8e87 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ under the License. ref/4-LATEST 2024-12-13T23:22:29Z - 3.27.0 + 3.27.2 9.7.1 1.15.11 2.8.0 From 900839135d2ca05fa75a61600b2299b4405c5d0a Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Tue, 7 Jan 2025 05:19:29 -0500 Subject: [PATCH 05/11] [MNG-8479] Use 'ejb' not 'ejb3' as type in ReactorReader artifact resolution for compile phase (#2016) Use 'ejb' not 'ejb3' as type in ReactorReader artifact resolution for compile phase Signed-off-by: Scott Kurz --- https://issues.apache.org/jira/browse/MNG-8479 --- .../src/main/java/org/apache/maven/ReactorReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java index fcabbf4d72ff..31052b97a8f6 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -70,7 +70,7 @@ class ReactorReader implements MavenWorkspaceReader { public static final String PROJECT_LOCAL_REPO = "project-local-repo"; private static final Collection COMPILE_PHASE_TYPES = new HashSet<>( - Arrays.asList("jar", "ejb-client", "war", "rar", "ejb3", "par", "sar", "wsr", "har", "app-client")); + Arrays.asList("jar", "ejb-client", "war", "rar", "ejb", "par", "sar", "wsr", "har", "app-client")); private static final Logger LOGGER = LoggerFactory.getLogger(ReactorReader.class); From 43e25b5e89ee3017b56ed8c3580c8c3a5777787f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:42:35 +0100 Subject: [PATCH 06/11] [MNG-8499] Bump mockitoVersion from 5.14.2 to 5.15.2 (#2017) Bumps `mockitoVersion` from 5.14.2 to 5.15.2. Updates `org.mockito:mockito-bom` from 5.14.2 to 5.15.2 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.14.2...v5.15.2) Updates `org.mockito:mockito-junit-jupiter` from 5.14.2 to 5.15.2 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.14.2...v5.15.2) --- updated-dependencies: - dependency-name: org.mockito:mockito-bom dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.mockito:mockito-junit-jupiter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- https://issues.apache.org/jira/browse/MNG-8499 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 35145b0b8e87..c1806ff2989e 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,7 @@ under the License. 5.11.4 1.3 1.5.16 - 5.14.2 + 5.15.2 1.3 1.27 1.4.0 From a2ee8f8bc2206749b084e19b7a8f52e7bea9dcea Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Tue, 7 Jan 2025 12:34:28 +0100 Subject: [PATCH 07/11] Fix for HelperImplTest The UT runs for 60 sec that is unacceptable. This fix returns its runtime to 10+ sec. --- .../org/apache/maven/cling/executor/impl/HelperImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java index 3e21b631bd83..aa209350870f 100644 --- a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java +++ b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java @@ -42,7 +42,7 @@ public class HelperImplTest { private static final ForkedMavenExecutor FORKED_MAVEN_EXECUTOR = new ForkedMavenExecutor(); @TempDir - private Path userHome; + private static Path userHome; @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) From b99eac724643feebab1b52e80f6f313e9aef5bf2 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Tue, 7 Jan 2025 12:02:00 +0000 Subject: [PATCH 08/11] Copy edits in comments, API doc, and messages (#2020) * Copy edits --- .../java/org/apache/maven/api/Dependency.java | 2 +- .../maven/api/DependencyCoordinates.java | 10 +++---- .../org/apache/maven/api/JavaPathType.java | 24 ++++++++--------- .../java/org/apache/maven/api/PathType.java | 4 +-- .../main/java/org/apache/maven/api/Type.java | 26 +++++++++---------- .../services/DependencyResolverResult.java | 8 +++--- .../apache/maven/project/MavenProject.java | 10 +++---- .../impl/DefaultDependencyResolverResult.java | 16 ++++++------ .../impl/PathModularizationCache.java | 2 +- 9 files changed, 51 insertions(+), 51 deletions(-) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java index 50fbb6035327..4aff60b3271e 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java @@ -38,7 +38,7 @@ public interface Dependency extends Artifact { /** * {@return the type of the dependency} * A dependency can be a JAR file, - * a modular-JAR if it is intended to be placed on the module-path, + * a modular-JAR if it is intended to be placed on the module path, * a JAR containing test classes, etc. * * @see DependencyCoordinates#getType() diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java index a7330bcbb7e8..ada2f8ed0cfd 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java @@ -27,8 +27,8 @@ /** * {@code ArtifactCoordinates} completed with information about how the artifact will be used. - * This information include the dependency type (main classes, test classes, etc.), - * a scope (compile-time, run-time etc.), an obligation (whether the dependency + * This information includes the dependency type (main classes, test classes, etc.), + * a scope (compile, runtime etc.), an obligation (whether the dependency * is optional or mandatory), and possible exclusions for transitive dependencies. * The {@linkplain #getVersionConstraint() version} and the {@linkplain #getOptional() obligation} * may not be defined precisely. @@ -41,7 +41,7 @@ public interface DependencyCoordinates extends ArtifactCoordinates { /** * {@return the type of the dependency} * A dependency can be a JAR file, - * a modular-JAR if it is intended to be placed on the module-path, + * a modular-JAR if it is intended to be placed on the module path, * a JAR containing test classes, etc. */ @Nonnull @@ -49,13 +49,13 @@ public interface DependencyCoordinates extends ArtifactCoordinates { /** * {@return the time at which the dependency will be used} - * If may be, for example, at compile time only, at run time or at test time. + * It may be, for example, at compile time only, at run time or at test time. */ @Nonnull DependencyScope getScope(); /** - * Returns whether the dependency is optional, mandatory or of unspecified obligation. + * Returns whether the dependency is optional, mandatory, or of unspecified obligation. * * @return the obligation, or {@code null} if unspecified */ diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java b/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java index 43b4ad1f6262..fc13eac477d9 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java @@ -33,7 +33,7 @@ /** * The option of a Java command-line tool where to place the paths to some dependencies. - * A {@code PathType} can identify the class-path, the module-path, the patches for a specific module, + * A {@code PathType} can identify the class path, the module path, the patches for a specific module, * or another kind of path. * *

One path type is handled in a special way: unlike other options, @@ -41,8 +41,8 @@ * This type is created by calls to {@link #patchModule(String)} and a new instance must be created for * every module to patch.

* - *

Path types are often exclusive. For example, a dependency should not be both on the Java class-path - * and on the Java module-path.

+ *

Path types are often exclusive. For example, a dependency should not be both on the Java class path + * and on the Java module path.

* *

Relationship with Java compiler standard location

* This enumeration is closely related to the {@link JavaFileManager.Location} enumerations. @@ -63,16 +63,16 @@ public enum JavaPathType implements PathType { * The Java tools location is {@link StandardLocation#CLASS_PATH}. * *

Context-sensitive interpretation

- * A dependency with this path type will not necessarily be placed on the class-path. + * A dependency with this path type will not necessarily be placed on the class path. * There are two circumstances where the dependency may nevertheless be placed somewhere else: * *
    *
  • If {@link #MODULES} path type is also set, then the dependency can be placed either on the - * class-path or on the module-path, but only one of those. The choice is up to the plugin, + * class path or on the module path, but only one of those. The choice is up to the plugin, * possibly using heuristic rules (Maven 3 behavior).
  • - *
  • If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module-path, + *
  • If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module path, * then the test dependency will be placed on the Java {@code --patch-module} option instead of the - * class-path.
  • + * class path. *
*/ CLASSES(StandardLocation.CLASS_PATH, "--class-path"), @@ -83,16 +83,16 @@ public enum JavaPathType implements PathType { * The Java tools location is {@link StandardLocation#MODULE_PATH}. * *

Context-sensitive interpretation

- * A dependency with this flag will not necessarily be placed on the module-path. + * A dependency with this flag will not necessarily be placed on the module path. * There are two circumstances where the dependency may nevertheless be placed somewhere else: * *
    *
  • If {@link #CLASSES} path type is also set, then the dependency should be placed on the - * module-path, but is also compatible with placement on the class-path. Compatibility can + * module path, but is also compatible with placement on the class path. Compatibility can * be achieved, for example, by repeating in the {@code META-INF/services/} directory the services * that are declared in the {@code module-info.class} file. In that case, the path type can be chosen * by the plugin.
  • - *
  • If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module-path, + *
  • If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module path, * then the test dependency will be placed on the Java {@code --patch-module} option instead of the * {@code --module-path} option.
  • *
@@ -151,8 +151,8 @@ public enum JavaPathType implements PathType { * one specific module. Used for compilation and execution among others. * *

Context-sensitive interpretation

- * This path type makes sense only when a main module is added on the module-path by another dependency. - * In no main module is found, the patch dependency may be added on the class-path or module-path + * This path type makes sense only when a main module is added on the module path by another dependency. + * In no main module is found, the patch dependency may be added on the class path or module path * depending on whether {@link #CLASSES} or {@link #MODULES} is present. * * @param moduleName name of the module on which to apply the path diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java b/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java index 368d14443cba..5c2e302dca83 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java @@ -26,10 +26,10 @@ /** * The option of a command-line tool where to place the paths to some dependencies. - * A {@code PathType} can identify the Java class-path, the Java module-path, + * A {@code PathType} can identify the Java class-path, the Java module path, * or another kind of path for another programming language for example. * Path types are often exclusive. For example, a dependency should not be - * both on the Java class-path and on the Java module-path. + * both on the Java class path and on the Java module path. * * @see org.apache.maven.api.services.DependencyResolverResult#getDispatchedPaths() * diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java index 4d3cb13ea07b..fa3106fa57ae 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java @@ -32,7 +32,7 @@ *

* It provides information about the file type (or extension) of the associated artifact, * its default classifier, and how the artifact will be used in the build when creating - * class-paths or module-paths. + * class paths or module paths. *

* For example, the type {@code java-source} has a {@code jar} extension and a * {@code sources} classifier. The artifact and its dependencies should be added @@ -54,47 +54,47 @@ public interface Type extends ExtensibleEnum { String BOM = "bom"; /** - * Artifact type name for a JAR file that can be placed either on the class-path or on the module-path. + * Artifact type name for a JAR file that can be placed either on the class path or on the module path. * The path (classes or modules) is chosen by the plugin, possibly using heuristic rules. * This is the behavior of Maven 3. */ String JAR = "jar"; /** - * Artifact type name for a fat-JAR file that can be only on the class-path. + * Artifact type name for a fat-JAR file that can be only on the class path. * The fat-JAR is a self-contained JAR and its transitive dependencies will not be resolved, if any. * This type is new in Maven 4. */ String FATJAR = "fatjar"; /** - * Artifact type name for a JAR file to unconditionally place on the class-path. + * Artifact type name for a JAR file to unconditionally place on the class path. * If the JAR is modular, its module information are ignored. * This type is new in Maven 4. */ String CLASSPATH_JAR = "classpath-jar"; /** - * Artifact type name for a JAR file to unconditionally place on the module-path. + * Artifact type name for a JAR file to unconditionally place on the module path. * If the JAR is not modular, then it is loaded by Java as an unnamed module. * This type is new in Maven 4. */ String MODULAR_JAR = "modular-jar"; /** - * Artifact type name for a JAR file that can be placed either on the annotation processor class-path - * or module-path. The path (classes or modules) is chosen by the plugin, possibly using heuristic rules. + * Artifact type name for a JAR file that can be placed either on the annotation processor class path + * or module path. The path (classes or modules) is chosen by the plugin, possibly using heuristic rules. */ String PROCESSOR = "processor"; /** - * Artifact type name for a JAR file to unconditionally place on the annotation processor class-path. + * Artifact type name for a JAR file to unconditionally place on the annotation processor class path. * If the JAR is modular, its module information are ignored. */ String CLASSPATH_PROCESSOR = "classpath-processor"; /** - * Artifact type name for a JAR file to unconditionally place on the annotation processor module-path. + * Artifact type name for a JAR file to unconditionally place on the annotation processor module path. * If the JAR is not modular, then it is loaded by Java as an unnamed module. */ String MODULAR_PROCESSOR = "modular-processor"; @@ -115,9 +115,9 @@ public interface Type extends ExtensibleEnum { String MAVEN_PLUGIN = "maven-plugin"; /** - * Artifact type name for a JAR file containing test classes. If the main artifact is placed on the class-path - * ({@value #JAR} or {@value #CLASSPATH_JAR} types), then the test artifact will also be placed on the class-path. - * Otherwise, if the main artifact is placed on the module-path ({@value #JAR} or {@value #MODULAR_JAR} types), + * Artifact type name for a JAR file containing test classes. If the main artifact is placed on the class path + * ({@value #JAR} or {@value #CLASSPATH_JAR} types), then the test artifact will also be placed on the class path. + * Otherwise, if the main artifact is placed on the module path ({@value #JAR} or {@value #MODULAR_JAR} types), * then the test artifact will be added using {@code --patch-module} option. */ String TEST_JAR = "test-jar"; @@ -173,7 +173,7 @@ public interface Type extends ExtensibleEnum { * and no heuristic rule will be involved. * *

It is nevertheless common to specify two or more types of path. For example, - * a Java library may be compatible with either the class-path or the module-path, + * a Java library may be compatible with either the class path or the module path, * and the user may have provided no instruction about which type to use. In such * case, the plugin may apply rules for choosing a path. See for example * {@link JavaPathType#CLASSES} and {@link JavaPathType#MODULES}.

diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java index e2ab1c2a9e4e..7b7f92046928 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java @@ -69,8 +69,8 @@ public interface DependencyResolverResult { /** * Returns the file paths of all dependencies, regardless on which tool option those paths should be placed. - * The returned list may contain a mix of Java class-path, Java module-path, and other types of path elements. - * This collection has the same content than {@code getDependencies.values()} except that it does not contain + * The returned list may contain a mix of Java class path, Java module path, and other types of path elements. + * This collection has the same content as {@code getDependencies.values()} except that it does not contain * null elements. * * @return the paths of all dependencies @@ -136,8 +136,8 @@ public interface DependencyResolverResult { Optional getModuleDescriptor(@Nonnull Path dependency) throws IOException; /** - * If the module-path contains at least one filename-based auto-module, prepares a warning message. - * The module path is the collection of dependencies associated to {@link JavaPathType#MODULES}. + * If the module path contains at least one filename-based auto-module, prepares a warning message. + * The module path is the collection of dependencies associated with {@link JavaPathType#MODULES}. * It is caller's responsibility to send the message to a logger. * * @return warning message if at least one filename-based auto-module was found diff --git a/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index e155609de55e..f278f04afb2f 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -340,12 +340,12 @@ private static boolean isTestPathElement(final String scope) { } /** - * Returns a filtered list of classpath elements. This method is invoked when the caller - * requested that all dependencies are placed on the classpath, with no module-path element. + * Returns a filtered list of class path elements. This method is invoked when the caller + * requested that all dependencies are placed on the class path, with no module path element. * - * @param scopeFilter a filter returning {@code true} for the artifact scopes to accept. - * @param includeTestDir whether to include the test directory in the classpath elements. - * @return paths of all artifacts placed on the classpath. + * @param scopeFilter a filter returning {@code true} for the artifact scopes to accept + * @param includeTestDir whether to include the test directory in the classpath elements + * @return paths of all artifacts placed on the classpath * @throws DependencyResolutionRequiredException if an artifact file is used, but has not been resolved */ private List getClasspathElements(final Predicate scopeFilter, final boolean includeTestDir) diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java index be6a8cbb3a48..de33340a69b2 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java @@ -124,9 +124,9 @@ private void addPathElement(PathType type, Path path) { /** * Adds main and test output directories to the result. This method adds the main output directory - * to the module-path if it contains a {@code module-info.class}, or to the class-path otherwise. + * to the module path if it contains a {@code module-info.class}, or to the class path otherwise. * For the test output directory, the rules are more complex and are governed by the fact that - * Java does not accept the placement of two modules of the same name on the module-path. + * Java does not accept the placement of two modules of the same name on the module path. * So the modular test output directory usually needs to be placed in a {@code --path-module} option. * *
    @@ -134,21 +134,21 @@ private void addPathElement(PathType type, Path path) { *
      *
    • If a test module name is identical to a main module name, * place the test directory in a {@code --patch-module} option.
    • - *
    • Otherwise, place the test directory on the module-path. However, this case + *
    • Otherwise, place the test directory on the module path. However, this case * (a module existing only in test output, not in main output) should be uncommon.
    • *
    * *
  • Otherwise (test output contains no module information), then: *
      - *
    • If the main output is on the module-path, place the test output + *
    • If the main output is on the module path, place the test output * on a {@code --patch-module} option.
    • - *
    • Otherwise (main output on the class-path), place the test output on the class-path too.
    • + *
    • Otherwise (main output on the class path), place the test output on the class path too.
    • *
    *
  • *
* * This method must be invoked before {@link #addDependency(Node, Dependency, Predicate, Path)} - * if output directories are desired on the class-path or module-path. + * if output directories are desired on the class path or module path. * This method can be invoked at most once. * * @param main the main output directory, or {@code null} if none @@ -235,7 +235,7 @@ void addDependency(Node node, Dependency dep, Predicate filter, Path p } paths.add(path); /* - * Dispatch the dependency to class-path, module-path, patch-module path, etc. + * Dispatch the dependency to class path, module path, patch-module path, etc. * according the dependency properties. We need to process patch-module first, * because this type depends on whether a module of the same name has already * been added on the module-type. @@ -255,7 +255,7 @@ void addDependency(Node node, Dependency dep, Predicate filter, Path p if (!containsModule(moduleName)) { /* * Not patching an existing module. This case should be unusual. If it nevertheless - * happens, add on class-path or module-path if allowed, or keep patching otherwise. + * happens, add to class path or module path if allowed, or keep patching otherwise. * The latter case (keep patching) is okay if the main module will be defined later. */ type = cache.selectPathType(pathTypes, filter, path).orElse(type); diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java index 9b5e3aca61f3..650d9358df14 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java @@ -181,7 +181,7 @@ Optional warningForFilenameBasedAutomodules(Collection modulePaths String lineSeparator = System.lineSeparator(); var joiner = new StringJoiner( lineSeparator + " - ", - "Filename-based automodules detected on the module-path: " + lineSeparator + " - ", + "Filename-based automodules detected on the module path: " + lineSeparator + " - ", lineSeparator + "Please don't publish this project to a public artifact repository."); automodulesDetected.forEach(joiner::add); return Optional.of(joiner.toString()); From 99452bb86846684e1ad636023268bd4f9b17dfac Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 8 Jan 2025 15:51:49 +0000 Subject: [PATCH 09/11] Fix comparisons against null in PathSource.equals (#2026) * Fix comparisons against null --- .../apache/maven/api/services/PathSource.java | 4 +++ .../maven/api/services/PathSourceTest.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 api/maven-api-core/src/test/java/org/apache/maven/api/services/PathSourceTest.java diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java index e7b39ac1bef5..4029179f3fd4 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java @@ -72,6 +72,10 @@ public ModelSource resolve(ModelLocator locator, String relative) { @Override public boolean equals(Object o) { + if (o == null) { + return false; + } + return this == o || o.getClass() == getClass() && Objects.equals(path, ((PathSource) o).path); } diff --git a/api/maven-api-core/src/test/java/org/apache/maven/api/services/PathSourceTest.java b/api/maven-api-core/src/test/java/org/apache/maven/api/services/PathSourceTest.java new file mode 100644 index 000000000000..19a5efe79a6f --- /dev/null +++ b/api/maven-api-core/src/test/java/org/apache/maven/api/services/PathSourceTest.java @@ -0,0 +1,34 @@ +/* + * 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.api.services; + +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +class PathSourceTest { + + @Test + void testEquals() { + PathSource source = new PathSource(Paths.get("/tmp")); + assertFalse(source.equals(null)); + } +} From 209cd7fbe4d81218cc6b8ba2c72845afc19a5cbd Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 8 Jan 2025 17:01:07 +0100 Subject: [PATCH 10/11] [MNG-8502] Embedded executor should obey MAVEN_ARGS env variable (#2032) Salvaged from the "split repo for ITs" experiment. The experiment failed but this improvement is good to have, as makes the embedded executor behave more closely like forked executor. Embedded so far did not obey MAVEN_ARGS env variable while forked did. --- https://issues.apache.org/jira/browse/MNG-8502 --- .../embedded/EmbeddedMavenExecutor.java | 23 ++++++++++++++---- .../cling/executor/impl/HelperImplTest.java | 24 +++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java index e713a73a43ad..76928b124717 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java @@ -31,6 +31,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -108,6 +109,7 @@ public int hashCode() { } protected final boolean cacheContexts; + protected final boolean useMavenArgsEnv; protected final AtomicBoolean closed; protected final PrintStream originalStdout; protected final PrintStream originalStderr; @@ -116,11 +118,12 @@ public int hashCode() { protected final ConcurrentHashMap contexts; public EmbeddedMavenExecutor() { - this(true); + this(true, true); } - public EmbeddedMavenExecutor(boolean cacheContexts) { + public EmbeddedMavenExecutor(boolean cacheContexts, boolean useMavenArgsEnv) { this.cacheContexts = cacheContexts; + this.useMavenArgsEnv = useMavenArgsEnv; this.closed = new AtomicBoolean(false); this.originalStdout = System.out; this.originalStderr = System.err; @@ -223,6 +226,14 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) { "Installation directory does not point to Maven installation: " + mavenHome); } + ArrayList mavenArgs = new ArrayList<>(); + String mavenArgsEnv = System.getenv("MAVEN_ARGS"); + if (useMavenArgsEnv && mavenArgsEnv != null && !mavenArgsEnv.isEmpty()) { + Arrays.stream(mavenArgsEnv.split(" ")) + .filter(s -> !s.trim().isEmpty()) + .forEach(s -> mavenArgs.add(0, s)); + } + Properties properties = prepareProperties(executorRequest); System.setProperties(properties); @@ -264,8 +275,10 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) { exec = r -> { System.setProperties(prepareProperties(r)); try { + ArrayList args = new ArrayList<>(mavenArgs); + args.addAll(r.arguments()); return (int) doMain.invoke(mavenCli, new Object[] { - r.arguments().toArray(new String[0]), r.cwd().toString(), null, null + args.toArray(new String[0]), r.cwd().toString(), null, null }); } catch (Exception e) { throw new ExecutorException("Failed to execute", e); @@ -285,7 +298,9 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) { || r.stderrConsumer().isPresent()) { ansiConsoleInstalled.set(null, 1); } - return (int) mainMethod.invoke(null, r.arguments().toArray(new String[0]), classWorld); + ArrayList args = new ArrayList<>(mavenArgs); + args.addAll(r.arguments()); + return (int) mainMethod.invoke(null, args.toArray(new String[0]), classWorld); } finally { if (r.stdoutConsumer().isPresent() || r.stderrConsumer().isPresent()) { diff --git a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java index aa209350870f..d0ddf73f413e 100644 --- a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java +++ b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/HelperImplTest.java @@ -132,10 +132,11 @@ void artifactPath3(ExecutorHelper.Mode mode) { EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.artifactPath(helper.executorRequest(), "aopalliance:aopalliance:1.0", "central"); - assertEquals( - "aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator - + "aopalliance-1.0.jar", - path); + // split repository: assert "ends with" as split may introduce prefixes + assertTrue( + path.endsWith("aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator + + "aopalliance-1.0.jar"), + "path=" + path); } @ParameterizedTest @@ -148,10 +149,11 @@ void artifactPath4(ExecutorHelper.Mode mode) { EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.artifactPath(helper.executorRequest(), "aopalliance:aopalliance:1.0", "central"); - assertEquals( - "aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator - + "aopalliance-1.0.jar", - path); + // split repository: assert "ends with" as split may introduce prefixes + assertTrue( + path.endsWith("aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator + + "aopalliance-1.0.jar"), + "path=" + path); } @ParameterizedTest @@ -164,7 +166,8 @@ void metadataPath3(ExecutorHelper.Mode mode) { EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.metadataPath(helper.executorRequest(), "aopalliance", "someremote"); - assertEquals("aopalliance" + File.separator + "maven-metadata-someremote.xml", path); + // split repository: assert "ends with" as split may introduce prefixes + assertTrue(path.endsWith("aopalliance" + File.separator + "maven-metadata-someremote.xml"), "path=" + path); } @ParameterizedTest @@ -177,6 +180,7 @@ void metadataPath4(ExecutorHelper.Mode mode) { EMBEDDED_MAVEN_EXECUTOR, FORKED_MAVEN_EXECUTOR); String path = helper.metadataPath(helper.executorRequest(), "aopalliance", "someremote"); - assertEquals("aopalliance" + File.separator + "maven-metadata-someremote.xml", path); + // split repository: assert "ends with" as split may introduce prefixes + assertTrue(path.endsWith("aopalliance" + File.separator + "maven-metadata-someremote.xml"), "path=" + path); } } From 7546361a0d71193ad41886f7e4c6542fc2ef1d23 Mon Sep 17 00:00:00 2001 From: Jermaine Hua Date: Thu, 9 Jan 2025 01:20:28 +0800 Subject: [PATCH 11/11] [MNG-8475] In the loop scenario, StringBuilder is used instead of concatenation (#2014) Signed-off-by: crazyhzm --- https://issues.apache.org/jira/browse/MNG-8475 --- .../project/AbstractMavenProjectTestCase.java | 6 +++--- .../DefaultArtifactDescriptorReader.java | 12 +++++------ .../aether/ReverseTreeRepositoryListener.java | 18 ++++++++-------- .../internal/MojoDescriptorCreator.java | 21 ++++++++----------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index fffdbb85c655..4893eb69d974 100644 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -135,12 +135,12 @@ protected MavenProject getProjectWithDependencies(File pom) throws Exception { } catch (Exception e) { Throwable cause = e.getCause(); if (cause instanceof ModelBuildingException) { - String message = "In: " + pom + "\n\n"; + StringBuilder message = new StringBuilder("In: " + pom + "\n\n"); for (ModelProblem problem : ((ModelBuildingException) cause).getProblems()) { - message += problem + "\n"; + message.append(problem).append("\n"); } System.out.println(message); - fail(message); + fail(message.toString()); } throw e; diff --git a/compat/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java b/compat/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java index bbc55d4d263e..2ba1695fe0fc 100644 --- a/compat/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java +++ b/compat/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java @@ -240,19 +240,19 @@ private Model loadPom( if (logger.isDebugEnabled()) { String problem = (problems.size() == 1) ? "problem" : "problems"; String problemPredicate = problem + ((problems.size() == 1) ? " was" : " were"); - String message = String.format( + StringBuilder message = new StringBuilder(String.format( "%s %s encountered while building the effective model for %s during %s\n", problems.size(), problemPredicate, request.getArtifact(), - RequestTraceHelper.interpretTrace(true, request.getTrace())); - message += StringUtils.capitalizeFirstLetter(problem); + RequestTraceHelper.interpretTrace(true, request.getTrace()))); + message.append(StringUtils.capitalizeFirstLetter(problem)); for (ModelProblem modelProblem : problems) { - message += String.format( + message.append(String.format( "\n* %s @ %s", - modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null)); + modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null))); } - logger.warn(message); + logger.warn(message.toString()); } else { logger.warn( "{} {} encountered while building the effective model for {} during {} (use -X to see details)", diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/aether/ReverseTreeRepositoryListener.java b/impl/maven-core/src/main/java/org/apache/maven/internal/aether/ReverseTreeRepositoryListener.java index 14f7378703fc..4bb367ade8b0 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/internal/aether/ReverseTreeRepositoryListener.java +++ b/impl/maven-core/src/main/java/org/apache/maven/internal/aether/ReverseTreeRepositoryListener.java @@ -98,7 +98,7 @@ public void artifactResolved(RepositoryEvent event) { String ext = missing ? ".miss" : ".dep"; Path trackingFile = null; - String indent = ""; + StringBuilder indent = new StringBuilder(); ArrayList trackingData = new ArrayList<>(); if (collectStepTrace == null && plugin != null) { @@ -110,16 +110,16 @@ public void artifactResolved(RepositoryEvent event) { } if (event.getArtifact() != null) { - trackingData.add(indent + event.getArtifact()); - indent += " "; + trackingData.add(indent.toString() + event.getArtifact()); + indent.append(" "); } trackingData.add(indent + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion()); - indent += " "; + indent.append(" "); InputLocation location = plugin.getLocation(""); if (location != null && location.getSource() != null) { trackingData.add(indent + location.getSource().getModelId() + " (implicit)"); - indent += " "; + indent.append(" "); } } else if (collectStepTrace != null) { if (collectStepTrace.getPath().get(0).getArtifact() == null) { @@ -138,15 +138,15 @@ public void artifactResolved(RepositoryEvent event) { if (isInScope(resolvedArtifact, nodeArtifact) || "pom".equals(resolvedArtifact.getExtension())) { Dependency node = collectStepTrace.getNode(); trackingData.add(resolvedArtifact.toString()); - indent += " "; - trackingData.add(indent + node + " (" + collectStepTrace.getContext() + ")"); + indent.append(" "); + trackingData.add(indent.toString() + node + " (" + collectStepTrace.getContext() + ")"); ListIterator iter = collectStepTrace .getPath() .listIterator(collectStepTrace.getPath().size()); while (iter.hasPrevious()) { DependencyNode curr = iter.previous(); - indent += " "; - trackingData.add(indent + curr + " (" + collectStepTrace.getContext() + ")"); + indent.append(" "); + trackingData.add(indent.toString() + curr + " (" + collectStepTrace.getContext() + ")"); } } } diff --git a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java index b380123955fd..15271e4cb985 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java +++ b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java @@ -138,9 +138,9 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginVersionResolutionException { - String goal = null; + StringBuilder goal = new StringBuilder(); - Plugin plugin = null; + Plugin plugin; String[] tok = task.split(":"); @@ -160,11 +160,11 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven plugin.setGroupId(tok[0]); plugin.setArtifactId(tok[1]); plugin.setVersion(tok[2]); - goal = tok[3]; + goal.append(tok[3]); // This won't be valid, but it constructs something easy to read in the error message for (int idx = 4; idx < tok.length; idx++) { - goal += ":" + tok[idx]; + goal.append(":").append(tok[idx]); } } else if (numTokens == 3) { // groupId:artifactId:goal or pluginPrefix:version:goal (since Maven 3.9.0) @@ -189,7 +189,7 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven plugin = findPluginForPrefix(firstToken, session); plugin.setVersion(tok[1]); } - goal = tok[2]; + goal.append(tok[2]); } else { // We have a prefix and goal // @@ -198,10 +198,7 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven String prefix = tok[0]; if (numTokens == 2) { - goal = tok[1]; - } else { - // goal was missing - pass through to MojoNotFoundException - goal = ""; + goal.append(tok[1]); } // This is the case where someone has executed a single goal from the command line @@ -216,9 +213,9 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven plugin = findPluginForPrefix(prefix, session); } - int executionIdx = goal.indexOf('@'); + int executionIdx = goal.indexOf("@"); if (executionIdx > 0) { - goal = goal.substring(0, executionIdx); + goal.setLength(executionIdx); } injectPluginDeclarationFromProject(plugin, project); @@ -231,7 +228,7 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven } return pluginManager.getMojoDescriptor( - plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession()); + plugin, goal.toString(), project.getRemotePluginRepositories(), session.getRepositorySession()); } // TODO take repo mans into account as one may be aggregating prefixes of many