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 PrompterException
39 {
40 String query = "Confirm properties configuration:\n";
41
42 for ( Iterator requiredPropertiesIter = archetypeConfiguration.getRequiredProperties().iterator();
43 requiredPropertiesIter.hasNext(); )
44 {
45 String property = (String) requiredPropertiesIter.next();
46
47 query += property + ": " + archetypeConfiguration.getProperty( property ) + "\n";
48 }
49
50 String answer = prompter.prompt( query, "Y" );
51
52 return "Y".equalsIgnoreCase( answer );
53 }
54
55 public String getPropertyValue( String requiredProperty, String defaultValue )
56 throws PrompterException
57 {
58 String query = "Define value for property '" + requiredProperty + "': ";
59 String answer;
60
61 if ( ( defaultValue != null ) && !defaultValue.equals( "null" ) )
62 {
63 answer = prompter.prompt( query, defaultValue );
64 }
65 else
66 {
67 answer = prompter.prompt( query );
68 }
69 return answer;
70 }
71 }