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.services;
20  
21  import java.util.List;
22  
23  import org.apache.maven.api.Service;
24  import org.apache.maven.api.annotations.Experimental;
25  import org.apache.maven.api.annotations.Nonnull;
26  import org.apache.maven.api.annotations.Nullable;
27  
28  /**
29   * Service used to interact with the end user.
30   *
31   * @since 4.0.0
32   */
33  @Experimental
34  public interface Prompter extends Service {
35      /**
36       * Prompts the user for a string.
37       *
38       * @param message the message to display to the user
39       * @return the string entered by the user
40       * @throws PrompterException if an exception occurs
41       */
42      @Nonnull
43      default String prompt(@Nullable String message) throws PrompterException {
44          return prompt(message, null, null);
45      }
46  
47      /**
48       * Prompts the user for a string using a default value.
49       *
50       * @param message the message to display
51       * @param defaultReply the default reply value
52       * @return the string entered by the user
53       * @throws PrompterException if an exception occurs
54       */
55      @Nonnull
56      default String prompt(@Nullable String message, @Nullable String defaultReply) throws PrompterException {
57          return prompt(message, null, defaultReply);
58      }
59  
60      /**
61       * Prompts the user for a string using a list of possible values.
62       *
63       * @param message the message to display
64       * @param possibleValues the list of possible values
65       * @return the string entered by the user
66       * @throws PrompterException if an exception occurs
67       */
68      @Nonnull
69      default String prompt(@Nullable String message, @Nullable List<String> possibleValues) throws PrompterException {
70          return prompt(message, possibleValues, null);
71      }
72  
73      /**
74       * Prompts the user for a string using a list of possible values and a default reply.
75       *
76       * @param message the message to display
77       * @param possibleValues the list of possible values
78       * @param defaultReply the default reply value
79       * @return the string entered by the user
80       * @throws PrompterException if an exception occurs
81       */
82      @Nonnull
83      String prompt(@Nullable String message, @Nullable List<String> possibleValues, @Nullable String defaultReply)
84              throws PrompterException;
85  
86      /**
87       * Prompts the user for a password.
88       *
89       * @param message the message to display
90       * @return the password entered by the user
91       * @throws PrompterException if an exception occurs
92       */
93      @Nonnull
94      String promptForPassword(@Nullable String message) throws PrompterException;
95  
96      /**
97       * Displays a message to the user.
98       *
99       * @param message the message to display
100      * @throws PrompterException if an exception occurs
101      */
102     void showMessage(@Nullable String message) throws PrompterException;
103 }