Author: hboutemy Date: Sat Jul 16 12:21:44 2011 New Revision: 1147415 URL: http://svn.apache.org/viewvc?rev=1147415&view=rev Log: code simplification
Modified: maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypePrompter.java Modified: maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypePrompter.java URL: http://svn.apache.org/viewvc/maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypePrompter.java?rev=1147415&r1=1147414&r2=1147415&view=diff ============================================================================== --- maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypePrompter.java (original) +++ maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypePrompter.java Sat Jul 16 12:21:44 2011 @@ -49,53 +49,24 @@ public class ArchetypePrompter public String prompt( String message ) throws PrompterException { - try - { - writePrompt( message ); - } - - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); - } + writePrompt( message ); - try - { - return inputHandler.readLine(); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to read user response", e ); - } + return readLine(); } public String prompt( String message, String defaultReply ) throws PrompterException { - try - { - writePrompt( formatMessage( message, null, defaultReply ) ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); - } + writePrompt( formatMessage( message, null, defaultReply ) ); - try - { - String line = inputHandler.readLine(); + String line = readLine(); - if ( StringUtils.isEmpty( line ) ) - { - line = defaultReply; - } - - return line; - } - catch ( IOException e ) + if ( StringUtils.isEmpty( line ) ) { - throw new PrompterException( "Failed to read user response", e ); + line = defaultReply; } + + return line; } public String prompt( String message, List possibleValues, String defaultReply ) @@ -107,23 +78,9 @@ public class ArchetypePrompter do { - try - { - writePrompt( formattedMessage ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); - } + writePrompt( formattedMessage ); - try - { - line = inputHandler.readLine(); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to read user response", e ); - } + line = readLine(); if ( StringUtils.isEmpty( line ) ) { @@ -156,14 +113,7 @@ public class ArchetypePrompter public String promptForPassword( String message ) throws PrompterException { - try - { - writePrompt( message ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); - } + writePrompt( message ); try { @@ -195,23 +145,35 @@ public class ArchetypePrompter } private void writePrompt( String message ) - throws IOException + throws PrompterException { - outputHandler.write( message + ": " ); + showMessage( message + ": " ); } - public void showMessage( String message ) + private String readLine() throws PrompterException { try { - writePrompt( message ); + return inputHandler.readLine(); } catch ( IOException e ) { - throw new PrompterException( "Failed to present prompt", e ); + throw new PrompterException( "Failed to read user response", e ); } + } + public void showMessage( String message ) + throws PrompterException + { + try + { + outputHandler.write( message + ": " ); + } + catch ( IOException e ) + { + throw new PrompterException( "Failed to show message", e ); + } } }