|
58 | 58 | import org.apache.maven.api.di.Named; |
59 | 59 | import org.apache.maven.api.di.Singleton; |
60 | 60 | import org.apache.maven.api.model.Activation; |
61 | | -import org.apache.maven.api.model.ActivationFile; |
62 | 61 | import org.apache.maven.api.model.Dependency; |
63 | 62 | import org.apache.maven.api.model.DependencyManagement; |
64 | 63 | import org.apache.maven.api.model.Exclusion; |
|
71 | 70 | import org.apache.maven.api.services.BuilderProblem; |
72 | 71 | import org.apache.maven.api.services.BuilderProblem.Severity; |
73 | 72 | import org.apache.maven.api.services.Interpolator; |
74 | | -import org.apache.maven.api.services.InterpolatorException; |
75 | 73 | import org.apache.maven.api.services.MavenException; |
76 | 74 | import org.apache.maven.api.services.ModelBuilder; |
77 | 75 | import org.apache.maven.api.services.ModelBuilderException; |
|
111 | 109 | import org.apache.maven.api.spi.ModelParserException; |
112 | 110 | import org.apache.maven.api.spi.ModelTransformer; |
113 | 111 | import org.apache.maven.impl.util.PhasingExecutor; |
114 | | -import org.apache.maven.model.v4.MavenTransformer; |
115 | 112 | import org.slf4j.Logger; |
116 | 113 | import org.slf4j.LoggerFactory; |
117 | 114 |
|
@@ -1174,11 +1171,8 @@ private Model readEffectiveModel() throws ModelBuilderException { |
1174 | 1171 | // profile activation |
1175 | 1172 | profileActivationContext.setModel(model); |
1176 | 1173 |
|
1177 | | - List<Profile> interpolatedProfiles = |
1178 | | - interpolateActivations(model.getProfiles(), profileActivationContext, this); |
1179 | | - |
1180 | 1174 | // profile injection |
1181 | | - List<Profile> activePomProfiles = getActiveProfiles(interpolatedProfiles, profileActivationContext); |
| 1175 | + List<Profile> activePomProfiles = getActiveProfiles(model.getProfiles(), profileActivationContext); |
1182 | 1176 | model = profileInjector.injectProfiles(model, activePomProfiles, request, this); |
1183 | 1177 | model = profileInjector.injectProfiles(model, activeExternalProfiles, request, this); |
1184 | 1178 |
|
@@ -1505,11 +1499,8 @@ protected void mergeModel_Subprojects( |
1505 | 1499 | .assembleModelInheritance(raw, parentData, request, this); |
1506 | 1500 |
|
1507 | 1501 | // activate profiles |
1508 | | - List<Profile> parentInterpolatedProfiles = |
1509 | | - interpolateActivations(parent.getProfiles(), profileActivationContext, this); |
| 1502 | + List<Profile> parentActivePomProfiles = getActiveProfiles(parent.getProfiles(), profileActivationContext); |
1510 | 1503 | // profile injection |
1511 | | - List<Profile> parentActivePomProfiles = |
1512 | | - getActiveProfiles(parentInterpolatedProfiles, profileActivationContext); |
1513 | 1504 | Model injectedParentModel = profileInjector |
1514 | 1505 | .injectProfiles(parent, parentActivePomProfiles, request, this) |
1515 | 1506 | .withProfiles(List.of()); |
@@ -1741,79 +1732,6 @@ boolean isBuildRequestWithActivation() { |
1741 | 1732 | return request.getRequestType() != ModelBuilderRequest.RequestType.BUILD_CONSUMER; |
1742 | 1733 | } |
1743 | 1734 |
|
1744 | | - private List<Profile> interpolateActivations( |
1745 | | - List<Profile> profiles, DefaultProfileActivationContext context, ModelProblemCollector problems) { |
1746 | | - if (profiles.stream() |
1747 | | - .map(org.apache.maven.api.model.Profile::getActivation) |
1748 | | - .noneMatch(Objects::nonNull)) { |
1749 | | - return profiles; |
1750 | | - } |
1751 | | - Interpolator interpolator = request.getSession().getService(Interpolator.class); |
1752 | | - |
1753 | | - class ProfileInterpolator extends MavenTransformer implements UnaryOperator<Profile> { |
1754 | | - ProfileInterpolator() { |
1755 | | - super(s -> { |
1756 | | - try { |
1757 | | - return interpolator.interpolate( |
1758 | | - s, Interpolator.chain(context::getUserProperty, context::getSystemProperty)); |
1759 | | - } catch (InterpolatorException e) { |
1760 | | - problems.add(Severity.ERROR, Version.BASE, e.getMessage(), e); |
1761 | | - } |
1762 | | - return s; |
1763 | | - }); |
1764 | | - } |
1765 | | - |
1766 | | - @Override |
1767 | | - public Profile apply(Profile p) { |
1768 | | - return Profile.newBuilder(p) |
1769 | | - .activation(transformActivation(p.getActivation())) |
1770 | | - .build(); |
1771 | | - } |
1772 | | - |
1773 | | - @Override |
1774 | | - protected Activation.Builder transformActivation_Condition( |
1775 | | - Supplier<? extends Activation.Builder> creator, Activation.Builder builder, Activation target) { |
1776 | | - // do not interpolate the condition activation |
1777 | | - return builder; |
1778 | | - } |
1779 | | - |
1780 | | - @Override |
1781 | | - protected ActivationFile.Builder transformActivationFile_Missing( |
1782 | | - Supplier<? extends ActivationFile.Builder> creator, |
1783 | | - ActivationFile.Builder builder, |
1784 | | - ActivationFile target) { |
1785 | | - String path = target.getMissing(); |
1786 | | - String xformed = transformPath(path, target, "missing"); |
1787 | | - return xformed != path ? (builder != null ? builder : creator.get()).missing(xformed) : builder; |
1788 | | - } |
1789 | | - |
1790 | | - @Override |
1791 | | - protected ActivationFile.Builder transformActivationFile_Exists( |
1792 | | - Supplier<? extends ActivationFile.Builder> creator, |
1793 | | - ActivationFile.Builder builder, |
1794 | | - ActivationFile target) { |
1795 | | - final String path = target.getExists(); |
1796 | | - final String xformed = transformPath(path, target, "exists"); |
1797 | | - return xformed != path ? (builder != null ? builder : creator.get()).exists(xformed) : builder; |
1798 | | - } |
1799 | | - |
1800 | | - private String transformPath(String path, ActivationFile target, String locationKey) { |
1801 | | - try { |
1802 | | - return context.interpolatePath(path); |
1803 | | - } catch (InterpolatorException e) { |
1804 | | - problems.add( |
1805 | | - Severity.ERROR, |
1806 | | - Version.BASE, |
1807 | | - "Failed to interpolate file location " + path + ": " + e.getMessage(), |
1808 | | - target.getLocation(locationKey), |
1809 | | - e); |
1810 | | - } |
1811 | | - return path; |
1812 | | - } |
1813 | | - } |
1814 | | - return profiles.stream().map(new ProfileInterpolator()).toList(); |
1815 | | - } |
1816 | | - |
1817 | 1735 | record ModelResolverResult(ModelSource source, String resolvedVersion) {} |
1818 | 1736 |
|
1819 | 1737 | class CachingModelResolver implements ModelResolver { |
|
0 commit comments