gnodet-bot commented on code in PR #14025:
URL: https://github.com/apache/maven/pull/14025#discussion_r4643455137
##########
impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java:
##########
@@ -233,13 +241,31 @@ public List<MojoExecution>
calculateMojoExecutions(MavenSession session, MavenPr
Map<String, List<MojoExecution>> phaseToMojoMapping =
calculateLifecycleMappings(session, project,
lifecyclePhase);
+ Set<String> alreadyPlannedPhases = mojoExecutions.stream()
+ .map(MojoExecution::getLifecyclePhase)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
for (List<MojoExecution> mojoExecutionsFromLifecycle :
phaseToMojoMapping.values()) {
+ mojoExecutionsFromLifecycle.stream()
+ .map(MojoExecution::getLifecyclePhase)
+ .filter(alreadyPlannedPhases::contains)
+ .forEach(duplicateLifecyclePhases::add);
mojoExecutions.addAll(mojoExecutionsFromLifecycle);
}
+
} else {
throw new IllegalStateException("unexpected task " + task);
}
}
+ if (!duplicateLifecyclePhases.isEmpty()) {
+ if (!duplicateLifecyclePhases.isEmpty()) {
+ LOG.warn(
+ "The following lifecycle phases overlap and will cause
some plugins to execute multiple times: {}."
+ + " If this is not intended, review the phases
passed on the command line.",
+ duplicateLifecyclePhases);
+ }
+ }
Review Comment:
🐛 **Duplicate `if` guard — copy-paste artifact**: There are two nested `if
(!duplicateLifecyclePhases.isEmpty())` checks wrapping the same `LOG.warn()`
call. The outer one is redundant and should be removed. While this compiles and
runs correctly (the outer gate just gates the inner one on the same condition),
the structure is confusing and will fail Checkstyle/review. Remove the outer
block:
```suggestion
if (!duplicateLifecyclePhases.isEmpty()) {
LOG.warn(
"The following lifecycle phases overlap and will cause
some plugins to execute multiple times: {}."
+ " If this is not intended, review the phases
passed on the command line.",
duplicateLifecyclePhases);
}
```
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5885LogParserTest.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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 org.junit.jupiter.api.Test;
+
+public class MavenITmng5885LogParserTest extends
AbstractMavenIntegrationTestCase {
+
+ private static final String OVERLAP_WARNING = "The given lifecycle phases
overlap. " +
+ "If this is not intended, you should check your Maven Build.";
Review Comment:
❌ **Test will fail — `OVERLAP_WARNING` does not match the actual warning
message**: The test checks for `"The given lifecycle phases overlap. If this is
not intended, you should check your Maven Build."`, but the production code
emits `"The following lifecycle phases overlap and will cause some plugins to
execute multiple times: [...]. If this is not intended, review the phases
passed on the command line."` — these are completely different strings.
`verifyTextInLog()` does a substring match, so none of the words in
`OVERLAP_WARNING` will be found in the actual log. The test for the positive
case (`testDuplicateLifecyclePhases`) will always fail.
Update the constant to a unique substring of the actual warning:
```suggestion
private static final String OVERLAP_WARNING = "The following lifecycle
phases overlap and will cause some plugins to execute multiple times";
```
--
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]