Coverage Report - org.apache.maven.archetype.ui.ArchetypeConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
ArchetypeConfiguration
57 %
32/56
42 %
6/14
1,286
 
 1  
 package org.apache.maven.archetype.ui;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 import java.util.Properties;
 25  
 
 26  
 import org.apache.maven.archetype.common.Constants;
 27  
 import org.codehaus.plexus.util.StringUtils;
 28  
 
 29  5
 public class ArchetypeConfiguration
 30  
 {
 31  
     private String groupId;
 32  
 
 33  
     private String artifactId;
 34  
 
 35  
     private String version;
 36  
 
 37  
     private String name;
 38  
 
 39  
     private String goals;
 40  
 
 41  
     public String getDescription()
 42  
     {
 43  0
         return description;
 44  
     }
 45  
 
 46  
     public void setDescription( String description )
 47  
     {
 48  3
         this.description = description;
 49  3
     }
 50  
 
 51  
     public String getUrl()
 52  
     {
 53  0
         return url;
 54  
     }
 55  
 
 56  
     public void setUrl( String url )
 57  
     {
 58  3
         this.url = url;
 59  3
     }
 60  
 
 61  
     private String url;
 62  
 
 63  
     private String description;
 64  
 
 65  
     private List<String> requiredProperties;
 66  
 
 67  
     public void addRequiredProperty( String string )
 68  
     {
 69  16
         getRequiredProperties().add( string );
 70  16
     }
 71  
 
 72  
     public String getArtifactId()
 73  
     {
 74  0
         return artifactId;
 75  
     }
 76  
 
 77  
     public String getGoals()
 78  
     {
 79  0
         return goals;
 80  
     }
 81  
 
 82  
     public String getGroupId()
 83  
     {
 84  0
         return groupId;
 85  
     }
 86  
 
 87  
     public String getName()
 88  
     {
 89  0
         return name;
 90  
     }
 91  
 
 92  
     public List<String> getRequiredProperties()
 93  
     {
 94  26
         if ( requiredProperties == null )
 95  
         {
 96  5
             requiredProperties = new ArrayList<String>();
 97  
         }
 98  
 
 99  26
         return requiredProperties;
 100  
     }
 101  
 
 102  
     public String getVersion()
 103  
     {
 104  0
         return version;
 105  
     }
 106  
 
 107  
     public void removeRequiredProperty( String string )
 108  
     {
 109  0
         getRequiredProperties().remove( string );
 110  0
     }
 111  
 
 112  
     public void setArtifactId( String artifactId )
 113  
     {
 114  3
         this.artifactId = artifactId;
 115  3
     }
 116  
 
 117  
     public void setGoals( String goals )
 118  
     {
 119  0
         this.goals = goals;
 120  0
     }
 121  
 
 122  
     public void setGroupId( String groupId )
 123  
     {
 124  3
         this.groupId = groupId;
 125  3
     }
 126  
 
 127  
     public void setName( String name )
 128  
     {
 129  3
         this.name = name;
 130  3
     }
 131  
 
 132  
     public void setRequiredProperties( List<String> requiredProperties )
 133  
     {
 134  0
         this.requiredProperties = requiredProperties;
 135  0
     }
 136  
 
 137  
     public void setVersion( String version )
 138  
     {
 139  3
         this.version = version;
 140  3
     }
 141  
 
 142  
     public void reset()
 143  
     {
 144  0
         properties.clear();
 145  0
     }
 146  
 
 147  5
     private Properties properties = new Properties();
 148  
 
 149  
     public void setProperty( String requiredProperty, String propertyValue )
 150  
     {
 151  10
         properties.setProperty( requiredProperty, propertyValue );
 152  10
     }
 153  
 
 154  
     public String getProperty( String property )
 155  
     {
 156  23
         return properties.getProperty( property, null );
 157  
     }
 158  
 
 159  
     public Properties getProperties()
 160  
     {
 161  2
         return properties;
 162  
     }
 163  
 
 164  
     public Properties toProperties()
 165  
     {
 166  0
         Properties result = new Properties();
 167  
 
 168  0
         result.putAll( properties );
 169  
 
 170  0
         result.setProperty( Constants.ARCHETYPE_GROUP_ID, StringUtils.isNotEmpty( getGroupId() ) ? getGroupId() : "" );
 171  0
         result.setProperty( Constants.ARCHETYPE_ARTIFACT_ID,
 172  
                             StringUtils.isNotEmpty( getArtifactId() ) ? getArtifactId() : "" );
 173  0
         result.setProperty( Constants.ARCHETYPE_VERSION, StringUtils.isNotEmpty( getVersion() ) ? getVersion() : "" );
 174  
 
 175  0
         if ( StringUtils.isNotEmpty( getGoals() ) )
 176  
         {
 177  0
             result.setProperty( Constants.ARCHETYPE_POST_GENERATION_GOALS, getGoals() );
 178  
         }
 179  
 
 180  0
         return result;
 181  
     }
 182  
 
 183  
     public boolean isConfigured()
 184  
     {
 185  5
         for ( String requiredProperty : getRequiredProperties() )
 186  
         {
 187  13
             if ( StringUtils.isEmpty( properties.getProperty( requiredProperty ) ) )
 188  
             {
 189  3
                 return false;
 190  
             }
 191  
         }
 192  
 
 193  2
         return true;
 194  
     }
 195  
 
 196  
     public boolean isConfigured( String requiredProperties )
 197  
     {
 198  12
         return StringUtils.isNotEmpty( properties.getProperty( requiredProperties ) );
 199  
     }
 200  
 
 201  5
     private Properties defaultProperties = new Properties();
 202  
 
 203  
     public void setDefaultProperty( String requiredProperty, String propertyValue )
 204  
     {
 205  13
         defaultProperties.setProperty( requiredProperty, propertyValue );
 206  13
     }
 207  
 
 208  
     public String getDefaultValue( String requiredProperty )
 209  
     {
 210  8
         return defaultProperties.getProperty( requiredProperty, null );
 211  
     }
 212  
 
 213  
     public Properties getDefaultValues()
 214  
     {
 215  0
         return defaultProperties;
 216  
     }
 217  
 }