gnodet commented on code in PR #13041:
URL: https://github.com/apache/maven/pull/13041#discussion_r3951559498


##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5359PluginManagementExecutionTest.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.it;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Verifies that cross-lifecycle executions in {@code pluginManagement} 
require an explicit plugin declaration.
+ *
+ * @see <a href="https://github.com/apache/maven/issues/6918";>MNG-5359</a>
+ * @since 4.1.0
+ */
+class MavenITmng5359PluginManagementExecutionTest extends 
AbstractMavenIntegrationTestCase {
+
+    @Test
+    void testManagedExecutionNotActivatedWithoutDeclaration() throws Exception 
{
+        Path testDir = prepareProject("management-only");
+        // The clean plugin is introduced by the clean lifecycle, but the 
managed execution targets package.
+        Verifier verifier = newVerifier(testDir);
+        verifier.setAutoclean(false);
+        verifier.deleteDirectory("target");
+        verifier.addCliArgument("package");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+        verifier.verifyFileNotPresent("target/managed-clean.txt");
+    }
+
+    @Test
+    void testManagedExecutionActivatedWithExplicitDeclaration() throws 
Exception {
+        Path testDir = prepareProject("explicit-plugin");
+        Verifier verifier = newVerifier(testDir);
+        verifier.setAutoclean(false);
+        verifier.deleteDirectory("target");
+        verifier.addCliArgument("-Pactivate-clean-plugin");
+        verifier.addCliArgument("package");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+        verifier.verifyFilePresent("target/managed-clean.txt");
+    }
+
+    private Path prepareProject(String scenario) throws Exception {
+        Path testDir = extractResources("mng-5359");
+        Path project = testDir.resolve(scenario);
+        Files.createDirectories(project);
+        Files.copy(testDir.resolve("pom.xml"), project.resolve("pom.xml"), 
StandardCopyOption.REPLACE_EXISTING);

Review Comment:
   🔍 **Nit:** `extractResources("mng-5359")` returns the same path 
(`tmpdir/mng-5359`) for both test methods. Both tests call 
`Files.createDirectories(project)` on distinct subdirectories 
(`management-only/` and `explicit-plugin/`) and copy the same `pom.xml` there, 
so there is no inter-test collision. However, if both test methods run in 
parallel (JUnit 5 parallel execution) they race on creating subdirectories 
inside the shared parent — `Files.createDirectories` is idempotent so there is 
no crash, but `Files.copy(... REPLACE_EXISTING)` on the same destination 
concurrently is not atomic on all OS/filesystems.
   
   For robustness, consider using a unique working directory per test 
invocation, which is the pattern used by `MavenITmng8750NewScopesTest` 
(`testDir.resolve("compile-only-test")` after extracting a pre-existing 
subdirectory). Alternatively, annotate the class with `@TestMethodOrder` and 
`@Execution(ExecutionMode.SAME_THREAD)` if parallel execution is a concern in 
this test suite.
   
   Not blocking — this is a test-isolation nit, not a correctness bug in the 
production 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]

Reply via email to