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.Properties;
28
29
30
31
32 public class SystemPropertyManager
33 {
34
35
36
37
38
39
40
41
42 public static PropertiesWrapper loadProperties( InputStream inStream )
43 throws IOException
44 {
45 Properties p = new Properties();
46
47 try
48 {
49 p.load( inStream );
50 }
51 finally
52 {
53 close( inStream );
54 }
55
56 return new PropertiesWrapper( p );
57 }
58
59 private static PropertiesWrapper loadProperties( File file )
60 throws IOException
61 {
62 return loadProperties( new FileInputStream( file ) );
63 }
64
65
66 public static void setSystemProperties( File file )
67 throws IOException
68 {
69 PropertiesWrapper p = loadProperties( file );
70 p.setAsSystemProperties();
71 }
72
73 public static File writePropertiesFile( Properties properties, File tempDirectory, String name,
74 boolean isDebug )
75 throws IOException
76 {
77 File file = File.createTempFile( name, "tmp", tempDirectory );
78 if ( !isDebug )
79 {
80 file.deleteOnExit();
81 }
82
83 writePropertiesFile( file, name, properties );
84
85 return file;
86 }
87
88 public static void writePropertiesFile( File file, String name, Properties properties )
89 throws IOException
90 {
91 FileOutputStream out = new FileOutputStream( file );
92
93 try
94 {
95 properties.store( out, name );
96 }
97 finally
98 {
99 out.close();
100 }
101 }
102
103 public static void close( InputStream inputStream )
104 {
105 if ( inputStream == null )
106 {
107 return;
108 }
109
110 try
111 {
112 inputStream.close();
113 }
114 catch ( IOException ex )
115 {
116
117 }
118 }
119
120
121 }