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