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.component.annotations.Component;
24 import org.codehaus.plexus.component.annotations.Requirement;
25 import org.codehaus.plexus.components.interactivity.Prompter;
26 import org.codehaus.plexus.components.interactivity.PrompterException;
27 import org.codehaus.plexus.logging.AbstractLogEnabled;
28
29 @Component( role = ArchetypeGenerationQueryer.class, hint = "default" )
30 public class DefaultArchetypeGenerationQueryer
31 extends AbstractLogEnabled
32 implements ArchetypeGenerationQueryer
33 {
34 @Requirement
35 private Prompter prompter;
36
37 public boolean confirmConfiguration( ArchetypeConfiguration archetypeConfiguration )
38 throws PrompterException
39 {
40 StringBuilder query = new StringBuilder( "Confirm properties configuration:\n" );
41
42 for ( String property : archetypeConfiguration.getRequiredProperties() )
43 {
44 query.append( property + ": " + archetypeConfiguration.getProperty( property ) + "\n" );
45 }
46
47 String answer = prompter.prompt( query.toString(), "Y" );
48
49 return "Y".equalsIgnoreCase( answer );
50 }
51
52 public String getPropertyValue( String requiredProperty, String defaultValue )
53 throws PrompterException
54 {
55 String query = "Define value for property '" + requiredProperty + "': ";
56 String answer;
57
58 if ( ( defaultValue != null ) && !defaultValue.equals( "null" ) )
59 {
60 answer = prompter.prompt( query, defaultValue );
61 }
62 else
63 {
64 answer = prompter.prompt( query );
65 }
66 return answer;
67 }
68 }