1 package org.apache.maven.surefire.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.Map;
28 import java.util.Properties;
29 import java.util.concurrent.ConcurrentHashMap;
30
31
32
33
34 public class SystemPropertyManager
35 {
36
37
38
39
40
41
42
43
44 public static PropertiesWrapper loadProperties( InputStream inStream )
45 throws IOException
46 {
47 try
48 {
49 Properties p = new Properties();
50 p.load( inStream );
51 Map<String, String> map = new ConcurrentHashMap<String, String>( p.size() );
52 for ( String key : p.stringPropertyNames() )
53 {
54 map.put( key, p.getProperty( key ) );
55 }
56 return new PropertiesWrapper( map );
57 }
58 finally
59 {
60 close( inStream );
61 }
62 }
63
64 private static PropertiesWrapper loadProperties( File file )
65 throws IOException
66 {
67 return loadProperties( new FileInputStream( file ) );
68 }
69
70 public static void setSystemProperties( File file )
71 throws IOException
72 {
73 PropertiesWrapper p = loadProperties( file );
74 p.setAsSystemProperties();
75 }
76
77 public static File writePropertiesFile( Properties properties, File tempDirectory, String name,
78 boolean keepForkFiles )
79 throws IOException
80 {
81 File file = File.createTempFile( name, "tmp", tempDirectory );
82 if ( !keepForkFiles )
83 {
84 file.deleteOnExit();
85 }
86
87 writePropertiesFile( file, name, properties );
88
89 return file;
90 }
91
92 public static void writePropertiesFile( File file, String name, Properties properties )
93 throws IOException
94 {
95 FileOutputStream out = new FileOutputStream( file );
96
97 try
98 {
99 properties.store( out, name );
100 }
101 finally
102 {
103 out.close();
104 }
105 }
106
107 public static void close( InputStream inputStream )
108 {
109 if ( inputStream == null )
110 {
111 return;
112 }
113
114 try
115 {
116 inputStream.close();
117 }
118 catch ( IOException ex )
119 {
120
121 }
122 }
123
124
125 }