|
28 | 28 | import java.util.Collection; |
29 | 29 | import java.util.Collections; |
30 | 30 | import java.util.HashMap; |
| 31 | +import java.util.HashSet; |
31 | 32 | import java.util.Iterator; |
32 | 33 | import java.util.LinkedHashSet; |
33 | 34 | import java.util.List; |
34 | 35 | import java.util.Map; |
35 | 36 | import java.util.Objects; |
36 | 37 | import java.util.Optional; |
37 | 38 | import java.util.Properties; |
38 | | -import java.util.Set; |
39 | 39 | import java.util.function.Consumer; |
40 | | -import java.util.stream.Collectors; |
41 | 40 |
|
42 | 41 | import org.apache.maven.artifact.versioning.DefaultArtifactVersion; |
43 | 42 | import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; |
@@ -305,18 +304,17 @@ protected ModelBuildingResult build(ModelBuildingRequest request, Collection<Str |
305 | 304 |
|
306 | 305 | profileActivationContext.setProjectProperties(tmpModel.getProperties()); |
307 | 306 |
|
308 | | - Map<String, Activation> interpolatedActivations = |
309 | | - getInterpolatedActivations(rawModel, profileActivationContext, problems); |
310 | | - injectProfileActivations(tmpModel, interpolatedActivations); |
| 307 | + List<Profile> interpolatedProfiles = getInterpolatedProfiles(rawModel, profileActivationContext, problems); |
| 308 | + tmpModel.setProfiles(interpolatedProfiles); |
311 | 309 |
|
312 | 310 | List<Profile> activePomProfiles = |
313 | 311 | profileSelector.getActiveProfiles(tmpModel.getProfiles(), profileActivationContext, problems); |
314 | 312 |
|
315 | | - Set<String> activeProfileIds = |
316 | | - activePomProfiles.stream().map(Profile::getId).collect(Collectors.toSet()); |
317 | | - currentData.setActiveProfiles(rawModel.getProfiles().stream() |
318 | | - .filter(p -> activeProfileIds.contains(p.getId())) |
319 | | - .collect(Collectors.toList())); |
| 313 | + List<Profile> rawProfiles = new ArrayList<>(); |
| 314 | + for (Profile activePomProfile : activePomProfiles) { |
| 315 | + rawProfiles.add(rawModel.getProfiles().get(interpolatedProfiles.indexOf(activePomProfile))); |
| 316 | + } |
| 317 | + currentData.setActiveProfiles(rawProfiles); |
320 | 318 |
|
321 | 319 | // profile injection |
322 | 320 | for (Profile activeProfile : activePomProfiles) { |
@@ -429,12 +427,12 @@ private interface InterpolateString { |
429 | 427 | String apply(String s) throws InterpolationException; |
430 | 428 | } |
431 | 429 |
|
432 | | - private Map<String, Activation> getInterpolatedActivations( |
| 430 | + private List<Profile> getInterpolatedProfiles( |
433 | 431 | Model rawModel, DefaultProfileActivationContext context, DefaultModelProblemCollector problems) { |
434 | | - Map<String, Activation> interpolatedActivations = getProfileActivations(rawModel, true); |
| 432 | + List<Profile> interpolatedActivations = getProfiles(rawModel, true); |
435 | 433 |
|
436 | 434 | if (interpolatedActivations.isEmpty()) { |
437 | | - return Collections.emptyMap(); |
| 435 | + return Collections.emptyList(); |
438 | 436 | } |
439 | 437 | RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); |
440 | 438 |
|
@@ -466,8 +464,14 @@ void performFor(String value, String locationKey, Consumer<String> mutator) { |
466 | 464 | } |
467 | 465 | } |
468 | 466 | } |
469 | | - for (Activation activation : interpolatedActivations.values()) { |
470 | | - Optional<Activation> a = Optional.of(activation); |
| 467 | + HashSet<String> profileIds = new HashSet<>(); |
| 468 | + for (Profile profile : interpolatedActivations) { |
| 469 | + if (!profileIds.add(profile.getId())) { |
| 470 | + problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE) |
| 471 | + .setMessage("Duplicate activation for profile " + profile.getId())); |
| 472 | + } |
| 473 | + Activation activation = profile.getActivation(); |
| 474 | + Optional<Activation> a = Optional.ofNullable(activation); |
471 | 475 | a.map(Activation::getFile).ifPresent(fa -> { |
472 | 476 | Interpolation nt = |
473 | 477 | new Interpolation(fa, s -> profileActivationFilePathInterpolator.interpolate(s, context)); |
@@ -753,41 +757,20 @@ private void assembleInheritance( |
753 | 757 | } |
754 | 758 | } |
755 | 759 |
|
756 | | - private Map<String, Activation> getProfileActivations(Model model, boolean clone) { |
757 | | - Map<String, Activation> activations = new HashMap<>(); |
| 760 | + private List<Profile> getProfiles(Model model, boolean clone) { |
| 761 | + ArrayList<Profile> profiles = new ArrayList<>(); |
758 | 762 | for (Profile profile : model.getProfiles()) { |
759 | | - Activation activation = profile.getActivation(); |
760 | | - |
761 | | - if (activation == null) { |
762 | | - continue; |
763 | | - } |
764 | | - |
765 | 763 | if (clone) { |
766 | | - activation = activation.clone(); |
| 764 | + profile = profile.clone(); |
767 | 765 | } |
768 | | - |
769 | | - activations.put(profile.getId(), activation); |
770 | | - } |
771 | | - |
772 | | - return activations; |
773 | | - } |
774 | | - |
775 | | - private void injectProfileActivations(Model model, Map<String, Activation> activations) { |
776 | | - for (Profile profile : model.getProfiles()) { |
777 | | - Activation activation = profile.getActivation(); |
778 | | - |
779 | | - if (activation == null) { |
780 | | - continue; |
781 | | - } |
782 | | - |
783 | | - // restore activation |
784 | | - profile.setActivation(activations.get(profile.getId())); |
| 766 | + profiles.add(profile); |
785 | 767 | } |
| 768 | + return profiles; |
786 | 769 | } |
787 | 770 |
|
788 | 771 | private Model interpolateModel(Model model, ModelBuildingRequest request, ModelProblemCollector problems) { |
789 | 772 | // save profile activations before interpolation, since they are evaluated with limited scope |
790 | | - Map<String, Activation> originalActivations = getProfileActivations(model, true); |
| 773 | + List<Profile> originalActivations = getProfiles(model, true); |
791 | 774 |
|
792 | 775 | Model interpolatedModel = |
793 | 776 | modelInterpolator.interpolateModel(model, model.getProjectDirectory(), request, problems); |
@@ -815,7 +798,7 @@ private Model interpolateModel(Model model, ModelBuildingRequest request, ModelP |
815 | 798 | interpolatedModel.setPomFile(model.getPomFile()); |
816 | 799 |
|
817 | 800 | // restore profiles with file activation to their value before full interpolation |
818 | | - injectProfileActivations(model, originalActivations); |
| 801 | + model.setProfiles(originalActivations); |
819 | 802 |
|
820 | 803 | return interpolatedModel; |
821 | 804 | } |
|
0 commit comments