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  
36  
37  @Named("packaging")
38  @Singleton
39  @Deprecated(since = "4.0.0")
40  public class PackagingProfileActivator implements ProfileActivator {
41  
42      @Override
43      public boolean isActive(
44              org.apache.maven.model.Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
45          return getActivationPackaging(profile).map(p -> isPackaging(context, p)).orElse(false);
46      }
47  
48      @Override
49      public boolean presentInConfig(
50              org.apache.maven.model.Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
51          return getActivationPackaging(profile).isPresent();
52      }
53  
54      private static boolean isPackaging(ProfileActivationContext context, String p) {
55          String packaging = context.getUserProperties().get(ProfileActivationContext.PROPERTY_NAME_PACKAGING);
56          return Objects.equals(p, packaging);
57      }
58  
59      private static Optional<String> getActivationPackaging(org.apache.maven.model.Profile profile) {
60          return Optional.ofNullable(profile)
61                  .map(org.apache.maven.model.Profile::getDelegate)
62                  .map(Profile::getActivation)
63                  .map(Activation::getPackaging);
64      }
65  }