1 package org.apache.maven.archetype.ui.generation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.archetype.ui.ArchetypeConfiguration;
23 import org.codehaus.plexus.components.interactivity.Prompter;
24 import org.codehaus.plexus.components.interactivity.PrompterException;
25 import org.codehaus.plexus.logging.AbstractLogEnabled;
26
27
28 public class DefaultArchetypeGenerationQueryer
29 extends AbstractLogEnabled
30 implements ArchetypeGenerationQueryer
31 {
32
33 private Prompter prompter;
34
35 public boolean confirmConfiguration( ArchetypeConfiguration archetypeConfiguration )
36 throws PrompterException
37 {
38 StringBuilder query = new StringBuilder( "Confirm properties configuration:\n" );
39
40 for ( String property : archetypeConfiguration.getRequiredProperties() )
41 {
42 query.append( property + ": " + archetypeConfiguration.getProperty( property ) + "\n" );
43 }
44
45 String answer = prompter.prompt( query.toString(), "Y" );
46
47 return "Y".equalsIgnoreCase( answer );
48 }
49
50 public String getPropertyValue( String requiredProperty, String defaultValue )
51 throws PrompterException
52 {
53 String query = "Define value for property '" + requiredProperty + "': ";
54 String answer;
55
56 if ( ( defaultValue != null ) && !defaultValue.equals( "null" ) )
57 {
58 answer = prompter.prompt( query, defaultValue );
59 }
60 else
61 {
62 answer = prompter.prompt( query );
63 }
64 return answer;
65 }
66 }