View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.model.profile;
20  
21  import java.io.File;
22  import java.util.List;
23  import java.util.Map;
24  
25  /**
26   * Describes the environmental context used to determine the activation status of profiles.
27   *
28   * @author Benjamin Bentmann
29   */
30  public interface ProfileActivationContext {
31      /**
32       * Key of the property containing the project's packaging.
33       * Available in {@link #getUserProperties()}.
34       * @since 3.9
35       */
36      String PROPERTY_NAME_PACKAGING = "packaging";
37  
38      /**
39       * Gets the identifiers of those profiles that should be activated by explicit demand.
40       *
41       * @return The identifiers of those profiles to activate, never {@code null}.
42       */
43      List<String> getActiveProfileIds();
44  
45      /**
46       * Gets the identifiers of those profiles that should be deactivated by explicit demand.
47       *
48       * @return The identifiers of those profiles to deactivate, never {@code null}.
49       */
50      List<String> getInactiveProfileIds();
51  
52      /**
53       * Gets the system properties to use for interpolation and profile activation. The system properties are collected
54       * from the runtime environment like {@link System#getProperties()} and environment variables.
55       *
56       * @return The execution properties, never {@code null}.
57       */
58      Map<String, String> getSystemProperties();
59  
60      /**
61       * Gets the user properties to use for interpolation and profile activation. The user properties have been
62       * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
63       * line.
64       * <p>
65       * <b>In repository-resolved (external) model builds</b> (dependency POMs, parent POMs, imported BOMs), this
66       * map is intentionally empty. Consumer {@code -D} flags are not propagated to dependency profile activation:
67       * the consumer did not set those flags for the dependency, and doing so would make dependency resolution
68       * non-deterministic and open to accidental (or malicious) profile injection.
69       *
70       * @return The user properties, never {@code null}.
71       */
72      Map<String, String> getUserProperties();
73  
74      /**
75       * Gets the base directory of the current project (if any).
76       *
77       * @return The base directory of the current project or {@code null} if none.
78       */
79      File getProjectDirectory();
80  
81      /**
82       * Gets current calculated project properties
83       * <p>
84       * These are the properties declared in the model's own {@code <properties>} section.
85       * They are part of the artifact's published identity and are consulted for profile activation
86       * in all contexts, including repository-resolved (external) model builds. Unlike
87       * {@link #getUserProperties()}, these are never suppressed when evaluating dependency profiles.
88       *
89       * @return The project properties, never {@code null}.
90       */
91      Map<String, String> getProjectProperties();
92  }