18
18
import java .io .File ;
19
19
import java .io .FileWriter ;
20
20
import java .io .IOException ;
21
+ import java .util .HashMap ;
21
22
import java .util .Map ;
22
23
import java .util .Properties ;
23
24
24
25
import javax .xml .bind .JAXBException ;
25
26
27
+ import org .lpe .common .config .ConfigParameterDescription ;
26
28
import org .spotter .shared .environment .model .XMeasurementEnvironment ;
27
29
import org .spotter .shared .hierarchy .model .XPerformanceProblem ;
28
30
import org .spotter .shared .util .JAXBUtil ;
@@ -68,10 +70,11 @@ public static synchronized FileManager getInstance() {
68
70
* the location where to place this file (without the filename)
69
71
* @param properties
70
72
* the project specific properties to write
73
+ * @return the filename of the created file
71
74
* @throws IOException
72
75
* if an I/O error occurs
73
76
*/
74
- public void writeSpotterConfig (String location , Properties properties ) throws IOException {
77
+ public String writeSpotterConfig (String location , Properties properties ) throws IOException {
75
78
Properties general = createGeneralSpotterProperties (location );
76
79
77
80
String file = stripFileSeparator (location ) + "/" + FileManager .SPOTTER_CONFIG_FILENAME ;
@@ -84,6 +87,8 @@ public void writeSpotterConfig(String location, Properties properties) throws IO
84
87
fileWriter .close ();
85
88
}
86
89
}
90
+
91
+ return file ;
87
92
}
88
93
89
94
/**
@@ -93,12 +98,14 @@ public void writeSpotterConfig(String location, Properties properties) throws IO
93
98
* the location where to place this file (without the filename)
94
99
* @param environment
95
100
* the environment object to write
101
+ * @return the filename of the created file
96
102
* @throws JAXBException
97
103
* if a problem with the marshalling occurs
98
104
*/
99
- public void writeEnvironmentConfig (String location , XMeasurementEnvironment environment ) throws JAXBException {
105
+ public String writeEnvironmentConfig (String location , XMeasurementEnvironment environment ) throws JAXBException {
100
106
String file = stripFileSeparator (location ) + "/" + FileManager .ENVIRONMENT_FILENAME ;
101
107
JAXBUtil .writeElementToFile (new File (file ), environment );
108
+ return file ;
102
109
}
103
110
104
111
/**
@@ -108,12 +115,14 @@ public void writeEnvironmentConfig(String location, XMeasurementEnvironment envi
108
115
* the location where to place this file (without the filename)
109
116
* @param hierarchy
110
117
* the hierarchy object to write
118
+ * @return the filename of the created file
111
119
* @throws JAXBException
112
120
* if a problem with the marshalling occurs
113
121
*/
114
- public void writeHierarchyConfig (String location , XPerformanceProblem hierarchy ) throws JAXBException {
122
+ public String writeHierarchyConfig (String location , XPerformanceProblem hierarchy ) throws JAXBException {
115
123
String file = stripFileSeparator (location ) + "/" + FileManager .HIERARCHY_FILENAME ;
116
124
JAXBUtil .writeElementToFile (new File (file ), hierarchy );
125
+ return file ;
117
126
}
118
127
119
128
/**
@@ -157,8 +166,12 @@ public String createSpotterConfigFileContent(Map<String, String> descriptionMapp
157
166
sb .append ("\r \n \r \n " );
158
167
writeHeading (sb , "SPECIFIED SETTINGS" );
159
168
169
+ if (descriptionMapping == null ) {
170
+ descriptionMapping = createDescriptionMapping ();
171
+ }
172
+
160
173
for (String key : properties .stringPropertyNames ()) {
161
- String comment = descriptionMapping == null ? null : descriptionMapping .get (key );
174
+ String comment = descriptionMapping .get (key );
162
175
writeKeyValuePair (sb , properties , key , comment );
163
176
}
164
177
return sb .toString ();
@@ -177,6 +190,15 @@ private void writeKeyValuePair(StringBuilder sb, Properties prop, String key, St
177
190
sb .append (key + " = " + prop .getProperty (key ) + "\r \n " );
178
191
}
179
192
193
+ private Map <String , String > createDescriptionMapping () {
194
+ Map <String , String > descriptionMapping = new HashMap <>();
195
+
196
+ for (ConfigParameterDescription desc : ConfigKeys .getSpotterConfigParamters ()) {
197
+ descriptionMapping .put (desc .getName (), desc .getDescription ());
198
+ }
199
+ return descriptionMapping ;
200
+ }
201
+
180
202
private String stripFileSeparator (String path ) {
181
203
if (path .endsWith ("/" ) || path .endsWith ("\\ " )) {
182
204
return path .substring (0 , path .length () - 1 );
0 commit comments