1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.osgi.test.platform;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.util.Properties;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26
27
28
29
30
31
32
33 abstract class AbstractOsgiPlatform implements OsgiPlatform {
34
35 private static final String TMP_DIR_FALLBACK = "./tmp-test";
36
37 private static final String DEFAULT_SUFFIX = "osgi";
38
39 private static final String TMP_PREFIX = "org.sfw.osgi";
40
41 final Log log = LogFactory.getLog(getClass());
42
43
44
45
46 String toString = getClass().getName();
47
48 private Properties configurationProperties = null;
49
50
51
52
53
54
55
56
57
58
59
60 public Properties getConfigurationProperties() {
61
62 if (configurationProperties == null) {
63 configurationProperties = new Properties();
64
65 configurationProperties.putAll(System.getProperties());
66
67 configurationProperties.putAll(getPlatformProperties());
68 return configurationProperties;
69 }
70 return configurationProperties;
71 }
72
73
74
75
76
77
78 abstract Properties getPlatformProperties();
79
80
81
82
83
84
85 public String toString() {
86 return toString;
87 }
88
89 File createTempDir(String suffix) {
90 if (suffix == null)
91 suffix = DEFAULT_SUFFIX;
92 File tempFileName;
93
94 try {
95 tempFileName = File.createTempFile(TMP_PREFIX, suffix);
96 }
97 catch (IOException ex) {
98 if (log.isWarnEnabled()) {
99 log.warn("Could not create temporary directory, returning a temp folder inside the current folder", ex);
100 }
101 return new File(TMP_DIR_FALLBACK);
102 }
103
104 tempFileName.delete();
105 File tempFolder = new File(tempFileName.getAbsolutePath());
106 tempFolder.mkdir();
107 return tempFolder;
108 }
109 }