gnodet-bot commented on code in PR #13249: URL: https://github.com/apache/maven/pull/13249#discussion_r4295225850
########## its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng13249ReactorXmlPhaseInjectionTest.java: ########## @@ -0,0 +1,128 @@ +/* + * 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.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Verifies that custom lifecycle phases defined in {@code .mvn/reactor.xml} are injected + * into the lifecycle DAG and that plugin goals bound to those phases execute correctly. + * + * @see <a href="https://github.com/apache/maven/pull/13249">#13249</a> + */ +class MavenITmng13249ReactorXmlPhaseInjectionTest extends AbstractMavenIntegrationTestCase { + + /** + * A plugin goal bound to a reactor.xml-injected phase must execute when running + * through that phase (via {@code verify}). + */ + @Test + void pluginBoundToInjectedPhaseExecutesDuringVerify() throws Exception { + Path testDir = extractResources("/mng-13249-reactor-xml-phase-injection"); + + Verifier verifier = newVerifier(testDir); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.addCliArgument("verify"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifier.verifyFilePresent("target/pre-integration-marker.txt"); + } + + /** + * The injected phase can be used as a direct CLI target. + */ + @Test + void injectedPhaseCanBeUsedAsCliTarget() throws Exception { + Path testDir = extractResources("/mng-13249-reactor-xml-phase-injection"); + + Verifier verifier = newVerifier(testDir); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.addCliArgument("pre-integration"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifier.verifyFilePresent("target/pre-integration-marker.txt"); + } + + /** + * The injected phase respects ordering: running only up to {@code compile} + * (which comes before {@code pre-integration}) must NOT trigger the plugin. + */ + @Test + void pluginDoesNotRunBeforeInjectedPhase() throws Exception { + Path testDir = extractResources("/mng-13249-reactor-xml-phase-injection"); + + Verifier verifier = newVerifier(testDir); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.addCliArgument("compile"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifier.verifyFileNotPresent("target/pre-integration-marker.txt"); + } + + /** + * Verify the injected phase runs in the correct position: after unit-test + * related phases but before integration-test phases. We check log ordering + * by looking for the touch plugin log line relative to known phase markers. + */ + @Test + void injectedPhaseRunsInCorrectOrder() throws Exception { + Path testDir = extractResources("/mng-13249-reactor-xml-phase-injection"); + + Verifier verifier = newVerifier(testDir); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.addCliArgument("verify"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + List<String> logLines = verifier.loadLogLines(); + + int touchIdx = -1; + int compileIdx = -1; + for (int i = 0; i < logLines.size(); i++) { + String line = logLines.get(i); + if (line.contains("maven-compiler-plugin") && line.contains("compile")) { + if (compileIdx == -1) { + compileIdx = i; + } + } + if (line.contains("pre-integration-marker.txt") || line.contains("touch-in-custom-phase")) { Review Comment: **Fragile log-line matching in ordering assertion** `injectedPhaseRunsInCorrectOrder` detects the compiler plugin by scanning for lines containing both `maven-compiler-plugin` and `compile`. This matches any compile-related log line — including the goal resolution line that appears before execution, which fires at plan-calculation time, not at phase-execution time. The index you capture may be earlier than the actual `compile` phase execution, making the ordering assertion trivially pass even if the ordering were wrong. A more reliable anchor: look for the `[INFO] --- maven-compiler-plugin` execution banner, or check for the `target/classes` directory creation timestamp (file-system ordering) rather than log-line position. Alternatively, assert ordering via the filesystem: after `verify`, both `target/classes` (compile output) and `target/pre-integration-marker.txt` must exist, and since the touch plugin runs in `pre-integration` which comes after `compile`, any successful `verify` already proves the ordering — the third test (`pluginDoesNotRunBeforeInjectedPhase`) already validates the boundary. A separate log-order test that can produce false positives adds noise, not confidence. -- 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]
