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