1
package org.apache.maven.surefire.booter;
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
12
* http://www.apache.org/licenses/LICENSE-2.0
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
23
import java.util.ArrayList;
24
import java.util.Iterator;
25
import java.util.List;
26
import java.util.Properties;
27
import org.apache.maven.surefire.util.internal.StringUtils;
30
* @author Kristian Rosenvold
32
public class PropertiesWrapper
34
private final Properties properties;
36
public PropertiesWrapper( Properties properties )
38
if ( properties == null )
40
throw new IllegalStateException( "Properties cannot be null" );
42
this.properties = properties;
45
public Properties getProperties()
50
public void setAsSystemProperties()
52
for ( Iterator i = properties.keySet().iterator(); i.hasNext(); )
54
String key = (String) i.next();
56
System.setProperty( key, properties.getProperty( key ) );
60
public String getProperty( String key )
62
return properties.getProperty( key );
65
public boolean getBooleanProperty( String propertyName )
67
final Boolean aBoolean = Boolean.valueOf( properties.getProperty( propertyName ) );
68
return aBoolean.booleanValue();
71
public Boolean getBooleanObjectProperty( String propertyName )
73
return Boolean.valueOf( properties.getProperty( propertyName ) );
76
public File getFileProperty( String key )
78
final String property = getProperty( key );
79
if ( property == null )
83
TypeEncodedValue typeEncodedValue = new TypeEncodedValue( File.class.getName(), property );
84
return (File) typeEncodedValue.getDecodedValue();
87
public List getStringList( String propertyPrefix )
90
List result = new ArrayList();
92
for ( int i = 0; ( value = getProperty( propertyPrefix + i ) ) != null; i++ )
100
* Retrieves as single object that is persisted with type encoding
102
* @param key The key for the propery
103
* @return The object, of a supported type
105
public TypeEncodedValue getTypeEncodedValue( String key )
107
String typeEncoded = getProperty( key );
108
if ( typeEncoded == null )
112
int typeSep = typeEncoded.indexOf( "|" );
113
String type = typeEncoded.substring( 0, typeSep );
114
String value = typeEncoded.substring( typeSep + 1 );
115
return new TypeEncodedValue( type, value );
119
public void setProperty( String key, File file )
123
setProperty( key, file.toString() );
127
public void setProperty( String key, Boolean aBoolean )
129
if ( aBoolean != null )
131
setProperty( key, aBoolean.toString() );
135
Classpath getClasspath( String prefix )
137
List elements = getStringList( prefix );
138
return new Classpath( elements );
141
public void setClasspath( String prefix, Classpath classpath )
143
List classpathElements = classpath.getClassPath();
144
for ( int i = 0; i < classpathElements.size(); ++i )
146
String element = (String) classpathElements.get( i );
147
setProperty( prefix + i, element );
152
public void setProperty( String key, String value )
156
properties.setProperty( key, value );
160
public void addList( List items, String propertyPrefix )
162
if ( items == null || items.size() == 0 )
167
for ( Iterator iterator = items.iterator(); iterator.hasNext(); )
169
Object item = iterator.next();
172
throw new NullPointerException( propertyPrefix + i + " has null value" );
175
String[] stringArray = StringUtils.split( item.toString(), "," );
177
for ( int j = 0; j < stringArray.length; j++ )
179
properties.setProperty( propertyPrefix + i, stringArray[j] );