goutamadwant commented on code in PR #13041: URL: https://github.com/apache/maven/pull/13041#discussion_r3946795348
########## impl/maven-core/src/test/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjectorTest.java: ########## @@ -0,0 +1,167 @@ +/* + * 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.model.plugin; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.InputSource; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.model.PluginManagement; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class DefaultLifecycleBindingsInjectorTest { + + @Test + void mergePluginManagementOnlyActivatesExecutionsFromTheSameLifecycle() { + InputSource lifecycleSource = inputSource("lifecycle"); + InputSource managementSource = inputSource("plugin-management"); + + PluginExecution lifecycleExecution = execution("default-clean", "clean", lifecycleSource); + Plugin lifecyclePlugin = plugin("lifecycle-version", lifecycleExecution, lifecycleSource); + lifecyclePlugin.setConfiguration(configuration("shared", "lifecycle", "lifecycle", "default")); + + PluginExecution sameLifecycleExecution = execution("managed-clean", "clean", managementSource); + PluginExecution crossLifecycleExecution = execution("managed-initialize", "initialize", managementSource); + PluginExecution defaultPhaseExecution = execution("managed-default-phase", null, managementSource); + Plugin managedPlugin = plugin( + "managed-version", + managementSource, + sameLifecycleExecution, + crossLifecycleExecution, + defaultPhaseExecution); + managedPlugin.setConfiguration(configuration("shared", "managed", "managed", "configured")); + managedPlugin.setExtensions(true); + managedPlugin.setInherited(false); + managedPlugin.addDependency(dependency("managed-dependency")); + + Model target = modelWithPluginManagement(managedPlugin); + Model source = modelWithPlugin(lifecyclePlugin); + + new DefaultLifecycleBindingsInjector.LifecycleBindingsMerger(Map.of("clean", "clean", "initialize", "default")) + .merge(target, source); + + Plugin result = target.getBuild().getPlugins().get(0); + Xpp3Dom resultConfiguration = (Xpp3Dom) result.getConfiguration(); + + assertEquals("managed-version", result.getVersion()); + assertEquals("managed", resultConfiguration.getChild("shared").getValue()); + assertEquals("configured", resultConfiguration.getChild("managed").getValue()); + assertEquals("default", resultConfiguration.getChild("lifecycle").getValue()); + assertEquals(3, result.getExecutions().size()); + assertEquals( + Set.of("default-clean", "managed-clean", "managed-default-phase"), + result.getExecutions().stream().map(PluginExecution::getId).collect(Collectors.toSet())); + assertEquals( + List.of("managed-dependency"), + result.getDependencies().stream().map(Dependency::getArtifactId).toList()); + assertEquals("true", result.getExtensions()); + assertEquals("false", result.getInherited()); + assertEquals("plugin-management", result.getLocation("").getSource().getModelId()); + assertEquals( + "plugin-management", result.getLocation("version").getSource().getModelId()); + assertEquals( + "lifecycle", + result.getExecutions().stream() + .filter(execution -> "default-clean".equals(execution.getId())) Review Comment: Added the explicit assertion that managed-initialize is absent in both model tests. -- 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]
