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.api.cli;
20  
21  import java.util.Map;
22  import java.util.Optional;
23  import java.util.function.Consumer;
24  import java.util.function.UnaryOperator;
25  
26  import org.apache.maven.api.annotations.Experimental;
27  import org.apache.maven.api.annotations.Nonnull;
28  
29  /**
30   * Represents the base options supported by Maven tools.
31   * This interface defines methods to access various configuration options
32   * that can be set through command-line arguments or configuration files.
33   *
34   * @since 4.0.0
35   */
36  @Experimental
37  public interface Options {
38      /** Constant indicating that the options source is the command-line interface. */
39      String SOURCE_CLI = "CLI";
40  
41      /**
42       * Returns a simple designator of the options source, such as "cli", "maven.conf", etc.
43       *
44       * @return a string representing the source of the options
45       */
46      @Nonnull
47      String source();
48  
49      /**
50       * Returns the user-defined properties for the Maven execution.
51       *
52       * @return an {@link Optional} containing the map of user properties, or empty if not set
53       */
54      @Nonnull
55      Optional<Map<String, String>> userProperties();
56  
57      /**
58       * Indicates whether to show the version information and exit.
59       *
60       * @return an {@link Optional} containing the boolean flag, or empty if not set
61       */
62      @Nonnull
63      Optional<Boolean> showVersionAndExit();
64  
65      /**
66       * Indicates whether to show the version information.
67       *
68       * @return an {@link Optional} containing the boolean flag, or empty if not set
69       */
70      @Nonnull
71      Optional<Boolean> showVersion();
72  
73      /**
74       * Indicates whether to run in quiet mode.
75       *
76       * @return an {@link Optional} containing the boolean flag, or empty if not set
77       */
78      @Nonnull
79      Optional<Boolean> quiet();
80  
81      /**
82       * Indicates whether to run in verbose mode.
83       *
84       * @return an {@link Optional} containing the boolean flag, or empty if not set
85       */
86      @Nonnull
87      Optional<Boolean> verbose();
88  
89      /**
90       * Indicates whether to show error stack traces.
91       *
92       * @return an {@link Optional} containing the boolean flag, or empty if not set
93       */
94      @Nonnull
95      Optional<Boolean> showErrors();
96  
97      /**
98       * Returns the severity level at which the build should fail.
99       *
100      * @return an {@link Optional} containing the fail-on-severity string, or empty if not set
101      */
102     @Nonnull
103     Optional<String> failOnSeverity();
104 
105     /**
106      * Indicates whether to run in non-interactive mode.
107      *
108      * @return an {@link Optional} containing the boolean flag, or empty if not set
109      */
110     @Nonnull
111     Optional<Boolean> nonInteractive();
112 
113     /**
114      * Indicates whether to force interactive mode.
115      *
116      * @return an {@link Optional} containing the boolean flag, or empty if not set
117      */
118     @Nonnull
119     Optional<Boolean> forceInteractive();
120 
121     /**
122      * Returns the path to an alternate user settings file.
123      *
124      * @return an {@link Optional} containing the file path, or empty if not set
125      */
126     @Nonnull
127     Optional<String> altUserSettings();
128 
129     /**
130      * Returns the path to an alternate project settings file.
131      *
132      * @return an {@link Optional} containing the file path, or empty if not set
133      */
134     @Nonnull
135     Optional<String> altProjectSettings();
136 
137     /**
138      * Returns the path to an alternate installation settings file.
139      *
140      * @return an {@link Optional} containing the file path, or empty if not set
141      */
142     @Nonnull
143     Optional<String> altInstallationSettings();
144 
145     /**
146      * Returns the path to an alternate user toolchains file.
147      *
148      * @return an {@link Optional} containing the file path, or empty if not set
149      */
150     @Nonnull
151     Optional<String> altUserToolchains();
152 
153     /**
154      * Returns the path to an alternate installation toolchains file.
155      *
156      * @return an {@link Optional} containing the file path, or empty if not set
157      */
158     @Nonnull
159     Optional<String> altInstallationToolchains();
160 
161     /**
162      * Returns the path to the log file.
163      *
164      * @return an {@link Optional} containing the file path, or empty if not set
165      */
166     @Nonnull
167     Optional<String> logFile();
168 
169     /**
170      * Returns whether raw streams should be logged.
171      *
172      * @return a boolean indicating whether raw streams should be logged
173      */
174     @Nonnull
175     Optional<Boolean> rawStreams();
176 
177     /**
178      * Returns the color setting for console output.
179      *
180      * @return an {@link Optional} containing the color setting, or empty if not set
181      */
182     @Nonnull
183     Optional<String> color();
184 
185     /**
186      * Indicates whether Maven should operate in offline mode.
187      *
188      * @return an {@link Optional} containing true if offline mode is enabled, false if disabled, or empty if not specified
189      */
190     @Nonnull
191     Optional<Boolean> offline();
192 
193     /**
194      * Indicates whether to show help information.
195      *
196      * @return an {@link Optional} containing the boolean flag, or empty if not set
197      */
198     @Nonnull
199     Optional<Boolean> help();
200 
201     /**
202      * Returns a new instance of {@link Options} with values interpolated using the given properties.
203      *
204      * @param callback the callback to use for interpolation
205      * @return a new {@link Options} instance with interpolated values
206      */
207     @Nonnull
208     Options interpolate(@Nonnull UnaryOperator<String> callback);
209 
210     /**
211      * Emits warning messages if deprecated options are used.
212      *
213      * @param printWriter the string consumer to use for output
214      */
215     default void warnAboutDeprecatedOptions(@Nonnull ParserRequest request, @Nonnull Consumer<String> printWriter) {}
216 
217     /**
218      * Displays help information for these options.
219      *
220      * @param printWriter the string consumer to use for output
221      */
222     void displayHelp(@Nonnull ParserRequest request, @Nonnull Consumer<String> printWriter);
223 }