|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.maven.model.profile; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | + |
| 23 | +import org.apache.maven.model.Model; |
| 24 | +import org.apache.maven.model.Plugin; |
| 25 | +import org.apache.maven.model.building.DefaultModelBuilderFactory; |
| 26 | +import org.apache.maven.model.building.DefaultModelBuildingRequest; |
| 27 | +import org.apache.maven.model.building.FileModelSource; |
| 28 | +import org.apache.maven.model.building.ModelBuilder; |
| 29 | +import org.apache.maven.model.building.ModelBuildingRequest; |
| 30 | +import org.apache.maven.model.building.ModelBuildingResult; |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +import static org.junit.Assert.assertEquals; |
| 34 | +import static org.junit.Assert.assertNotNull; |
| 35 | + |
| 36 | +/** |
| 37 | + * Tests model builder profile interpolation. |
| 38 | + */ |
| 39 | +public class DefaultProfileInterpolationTest { |
| 40 | + private File getPom(String name) { |
| 41 | + return new File("src/test/resources/poms/profile/" + name); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * MNG-8188: profile interpolation was "undone" by mistake. This UT executes reproducer and ensures that |
| 46 | + * profile interpolated values (sans activation) are fully interpolated. |
| 47 | + */ |
| 48 | + @Test |
| 49 | + public void profilePropertiesInterpolation() throws Exception { |
| 50 | + ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); |
| 51 | + assertNotNull(builder); |
| 52 | + |
| 53 | + DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); |
| 54 | + request.setModelSource(new FileModelSource(getPom("mng8188.xml"))); |
| 55 | + request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1); |
| 56 | + |
| 57 | + ModelBuildingResult result = builder.build(request); |
| 58 | + assertNotNull(result); |
| 59 | + Model effectiveModel = result.getEffectiveModel(); |
| 60 | + assertNotNull(effectiveModel); |
| 61 | + |
| 62 | + Plugin interpolatedPlugin = null; |
| 63 | + |
| 64 | + // build/pluginManagement |
| 65 | + for (Plugin plugin : effectiveModel.getBuild().getPluginManagement().getPlugins()) { |
| 66 | + if ("spring-boot-maven-plugin".equals(plugin.getArtifactId())) { |
| 67 | + interpolatedPlugin = plugin; |
| 68 | + break; |
| 69 | + } |
| 70 | + } |
| 71 | + assertNotNull(interpolatedPlugin); |
| 72 | + assertEquals("3.3.1", interpolatedPlugin.getVersion()); |
| 73 | + |
| 74 | + // profiles/foo/build/pluginManagement |
| 75 | + interpolatedPlugin = null; |
| 76 | + for (Plugin plugin : effectiveModel |
| 77 | + .getProfiles() |
| 78 | + .get(0) |
| 79 | + .getBuild() |
| 80 | + .getPluginManagement() |
| 81 | + .getPlugins()) { |
| 82 | + if ("spring-boot-maven-plugin".equals(plugin.getArtifactId())) { |
| 83 | + interpolatedPlugin = plugin; |
| 84 | + break; |
| 85 | + } |
| 86 | + } |
| 87 | + assertNotNull(interpolatedPlugin); |
| 88 | + assertEquals("3.3.1", interpolatedPlugin.getVersion()); |
| 89 | + } |
| 90 | +} |
0 commit comments