1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.maven.archetype.ui;
21
22 import org.apache.maven.archetype.common.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 import java.util.Iterator;
28
29
30 public class DefaultArchetypeGenerationQueryer
31 extends AbstractLogEnabled
32 implements ArchetypeGenerationQueryer
33 {
34
35 private Prompter prompter;
36
37 public boolean confirmConfiguration( ArchetypeConfiguration archetypeConfiguration )
38 throws
39 PrompterException
40 {
41 String query = "Confirm properties configuration:\n";
42
43 Iterator requiredPropertiesIter =
44 archetypeConfiguration.getRequiredProperties().iterator();
45
46 while ( requiredPropertiesIter.hasNext() )
47 {
48 String property = (String) requiredPropertiesIter.next();
49 query += property + ": " + archetypeConfiguration.getProperty( property ) + "\n";
50 }
51
52 String answer = prompter.prompt( query, "Y" );
53
54 return "Y".equalsIgnoreCase( answer );
55 }
56
57 public String getPropertyValue( String requiredProperty,
58 String defaultValue )
59 throws
60 PrompterException
61 {
62 String query = "Define value for " + requiredProperty + ": ";
63 String answer;
64
65 if ( ( defaultValue != null ) && !defaultValue.equals( "null" ) )
66 {
67 answer = prompter.prompt( query, defaultValue );
68 }
69 else
70 {
71 answer = prompter.prompt( query );
72 }
73 return answer;
74 }
75 }