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