View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  /** @plexus.component */
30  public class DefaultArchetypeGenerationQueryer
31      extends AbstractLogEnabled
32      implements ArchetypeGenerationQueryer
33  {
34      /** @plexus.requirement */
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  }