1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl.model.profile;
20
21 import java.util.Objects;
22 import java.util.Optional;
23
24 import org.apache.maven.api.di.Named;
25 import org.apache.maven.api.di.Singleton;
26 import org.apache.maven.api.model.Activation;
27 import org.apache.maven.api.model.Profile;
28 import org.apache.maven.api.services.ModelProblemCollector;
29 import org.apache.maven.api.services.model.ProfileActivationContext;
30 import org.apache.maven.api.services.model.ProfileActivator;
31
32
33
34
35 @Named("packaging")
36 @Singleton
37 public class PackagingProfileActivator implements ProfileActivator {
38
39 @Override
40 public boolean isActive(Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
41 return getActivationPackaging(profile).map(p -> isPackaging(context, p)).orElse(false);
42 }
43
44 @Override
45 public boolean presentInConfig(Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
46 return getActivationPackaging(profile).isPresent();
47 }
48
49 private static boolean isPackaging(ProfileActivationContext context, String p) {
50 String packaging = context.getUserProperties().get(ProfileActivationContext.PROPERTY_NAME_PACKAGING);
51 return Objects.equals(p, packaging);
52 }
53
54 private static Optional<String> getActivationPackaging(Profile profile) {
55 return Optional.ofNullable(profile).map(Profile::getActivation).map(Activation::getPackaging);
56 }
57 }