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.api.services.model;
20
21 import org.apache.maven.api.annotations.Nonnull;
22 import org.apache.maven.api.annotations.Nullable;
23 import org.apache.maven.api.model.Model;
24 import org.apache.maven.api.services.InterpolatorException;
25 import org.apache.maven.api.services.ModelBuilderException;
26
27 /**
28 * Describes the environmental context used to determine the activation status of profiles.
29 *
30 * The {@link Model} is available from the activation context, but only static parts of it
31 * are allowed to be used, i.e. those that do not change between file model and effective model.
32 *
33 */
34 public interface ProfileActivationContext {
35
36 /**
37 * Checks if the specified profile has been explicitly activated.
38 *
39 * @param profileId the profile id
40 * @return whether the profile has been activated
41 */
42 boolean isProfileActive(@Nonnull String profileId);
43
44 /**
45 * Checks if the specified profile has been explicitly deactivated.
46 *
47 * @param profileId the profile id
48 * @return whether the profile has been deactivated
49 */
50 boolean isProfileInactive(@Nonnull String profileId);
51
52 /**
53 * Gets the system property 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 * @param key the name of the system property
57 * @return the system property for the specified key, or {@code null}
58 */
59 @Nullable
60 String getSystemProperty(@Nonnull String key);
61
62 /**
63 * Gets the user property to use for interpolation and profile activation. The user properties have been
64 * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command line.
65 *
66 * @param key the name of the user property
67 * @return The user property for the specified key, or {@code null}.
68 */
69 @Nullable
70 String getUserProperty(@Nonnull String key);
71
72 /**
73 * Gets the model property to use for interpolation and profile activation.
74 *
75 * @param key the name of the model property
76 * @return The model property for the specified key, or {@code null};
77 */
78 @Nullable
79 String getModelProperty(@Nonnull String key);
80
81 /**
82 * Gets the artifactId from the current model.
83 *
84 * @return The artifactId of the current model, or {@code null} if not set.
85 */
86 @Nullable
87 String getModelArtifactId();
88
89 /**
90 * Gets the packaging type from the current model.
91 *
92 * @return The packaging type of the current model, or {@code null} if not set.
93 */
94 @Nullable
95 String getModelPackaging();
96
97 /**
98 * Gets the root directory of the current model.
99 *
100 * @return The root directory path of the current model, or {@code null} if not set.
101 */
102 @Nullable
103 String getModelRootDirectory();
104
105 /**
106 * Gets the base directory of the current model.
107 *
108 * @return The base directory path of the current model, or {@code null} if not set.
109 */
110 @Nullable
111 String getModelBaseDirectory();
112
113 /**
114 * Interpolates the given path string using the current context's properties.
115 *
116 * @param path The path string to interpolate
117 * @return The interpolated path string
118 * @throws InterpolatorException if an error occurs during interpolation
119 */
120 @Nullable
121 String interpolatePath(@Nullable String path);
122
123 /**
124 * Checks if a file or directory matching the given glob pattern exists at the specified path.
125 *
126 * @param path the base path to check
127 * @param glob whether the path can be a glob expression
128 * @return {@code true} if a matching file exists, {@code false} otherwise
129 * @throws ModelBuilderException if an error occurs while checking the path
130 * @throws InterpolatorException if an error occurs during interpolation
131 */
132 boolean exists(@Nullable String path, boolean glob);
133 }