@@ -135,8 +135,6 @@ public class ConfigProperties {
135
135
136
136
private static final String KARAF_DELAY_CONSOLE = "karaf.delay.console" ;
137
137
138
- private static final String DEFAULT_SHUTDOWN_COMMAND = "SHUTDOWN" ;
139
-
140
138
private static final String PROPERTY_LOCK_CLASS_DEFAULT = SimpleFileLock .class .getName ();
141
139
142
140
private static final String SECURITY_PROVIDERS = "org.apache.karaf.security.providers" ;
@@ -187,8 +185,9 @@ public ConfigProperties() throws Exception {
187
185
this .karafInstances = Utils .getKarafDirectory (PROP_KARAF_INSTANCES , ENV_KARAF_INSTANCES , new File (karafHome , "instances" ), false , false );
188
186
189
187
Package p = Package .getPackage ("org.apache.karaf.main" );
190
- if (p != null && p .getImplementationVersion () != null )
188
+ if (p != null && p .getImplementationVersion () != null ) {
191
189
System .setProperty (PROP_KARAF_VERSION , p .getImplementationVersion ());
190
+ }
192
191
System .setProperty (PROP_KARAF_HOME , karafHome .getPath ());
193
192
System .setProperty (PROP_KARAF_BASE , karafBase .getPath ());
194
193
System .setProperty (PROP_KARAF_DATA , karafData .getPath ());
@@ -199,39 +198,18 @@ public ConfigProperties() throws Exception {
199
198
}
200
199
PropertiesLoader .loadSystemProperties (new File (karafEtc , SYSTEM_PROPERTIES_FILE_NAME ));
201
200
202
- File cleanAllIndicatorFile = new File (karafData , "clean_all" );
203
- File cleanCacheIndicatorFile = new File (karafData , "clean_cache" );
204
- if (Boolean .getBoolean ("karaf.clean.all" ) || cleanAllIndicatorFile .exists ()) {
205
- if (cleanAllIndicatorFile .exists ()) {
206
- cleanAllIndicatorFile .delete ();
207
- }
208
- Utils .deleteDirectory (this .karafData );
209
- this .karafData = Utils .getKarafDirectory (PROP_KARAF_DATA , ENV_KARAF_DATA , new File (karafBase , "data" ), true , true );
210
- } else {
211
- if (Boolean .getBoolean ("karaf.clean.cache" ) || cleanCacheIndicatorFile .exists ()) {
212
- if (cleanCacheIndicatorFile .exists ()) {
213
- cleanCacheIndicatorFile .delete ();
214
- }
215
- File karafCache = Utils .validateDirectoryExists (new File (karafData , "cache" ).getPath (), "Invalid cache directory" , true , true );
216
- Utils .deleteDirectory (karafCache );
217
- }
218
- }
219
-
220
- File file = new File (karafEtc , CONFIG_PROPERTIES_FILE_NAME );
221
- this .props = PropertiesLoader .loadConfigProperties (file );
201
+ this .props = PropertiesLoader .loadConfigProperties (new File (karafEtc , CONFIG_PROPERTIES_FILE_NAME ));
222
202
223
- String prop = props .getProperty (SECURITY_PROVIDERS );
224
- this .securityProviders = (prop != null ) ? prop .split ("," ) : new String [] {};
203
+ this .securityProviders = getSecurityProviders ();
225
204
this .defaultStartLevel = Integer .parseInt (props .getProperty (Constants .FRAMEWORK_BEGINNING_STARTLEVEL ));
226
205
System .setProperty (Constants .FRAMEWORK_BEGINNING_STARTLEVEL , Integer .toString (this .defaultStartLevel ));
227
- this .lockStartLevel = Integer .parseInt (props .getProperty (PROPERTY_LOCK_LEVEL , Integer .toString (lockStartLevel )));
206
+ this .lockStartLevel = Integer .parseInt (props .getProperty (PROPERTY_LOCK_LEVEL , Integer .toString (lockStartLevel )));
228
207
this .lockDelay = Integer .parseInt (props .getProperty (PROPERTY_LOCK_DELAY , DEFAULT_LOCK_DELAY ));
229
208
this .lockSlaveBlock = Boolean .parseBoolean (props .getProperty (PROPERTY_LOCK_SLAVE_BLOCK , "false" ));
230
209
this .props .setProperty (Constants .FRAMEWORK_BEGINNING_STARTLEVEL , Integer .toString (lockDefaultBootLevel ));
231
210
this .shutdownTimeout = Integer .parseInt (props .getProperty (KARAF_SHUTDOWN_TIMEOUT , Integer .toString (shutdownTimeout )));
232
211
this .useLock = Boolean .parseBoolean (props .getProperty (PROPERTY_USE_LOCK , "true" ));
233
212
this .lockClass = props .getProperty (PROPERTY_LOCK_CLASS , PROPERTY_LOCK_CLASS_DEFAULT );
234
- initFrameworkStorage (karafData );
235
213
this .frameworkFactoryClass = props .getProperty (KARAF_FRAMEWORK_FACTORY );
236
214
this .frameworkBundle = getFramework ();
237
215
this .defaultRepo = System .getProperty (DEFAULT_REPO , "system" );
@@ -245,11 +223,42 @@ public ConfigProperties() throws Exception {
245
223
this .startupMessage = props .getProperty (KARAF_STARTUP_MESSAGE , "Apache Karaf starting up. Press Enter to open the shell now..." );
246
224
this .delayConsoleStart = Boolean .parseBoolean (props .getProperty (KARAF_DELAY_CONSOLE , "false" ));
247
225
System .setProperty (KARAF_DELAY_CONSOLE , new Boolean (this .delayConsoleStart ).toString ());
226
+ }
227
+
228
+ public void performInit () throws Exception {
229
+ File cleanAllIndicatorFile = new File (karafData , "clean_all" );
230
+ File cleanCacheIndicatorFile = new File (karafData , "clean_cache" );
231
+ if (Boolean .getBoolean ("karaf.clean.all" ) || cleanAllIndicatorFile .exists ()) {
232
+ if (cleanAllIndicatorFile .exists ()) {
233
+ cleanAllIndicatorFile .delete ();
234
+ }
235
+ Utils .deleteDirectory (this .karafData );
236
+ this .karafData = Utils .getKarafDirectory (PROP_KARAF_DATA , ENV_KARAF_DATA , new File (karafBase , "data" ), true , true );
237
+ } else {
238
+ if (Boolean .getBoolean ("karaf.clean.cache" ) || cleanCacheIndicatorFile .exists ()) {
239
+ if (cleanCacheIndicatorFile .exists ()) {
240
+ cleanCacheIndicatorFile .delete ();
241
+ }
242
+ File karafCache = Utils .validateDirectoryExists (new File (karafData , "cache" ).getPath (), "Invalid cache directory" , true , true );
243
+ Utils .deleteDirectory (karafCache );
244
+ }
245
+ }
246
+
247
+ String frameworkStoragePath = props .getProperty (Constants .FRAMEWORK_STORAGE );
248
+ if (frameworkStoragePath == null ) {
249
+ File storage = new File (karafData .getPath (), "cache" );
250
+ try {
251
+ storage .mkdirs ();
252
+ } catch (SecurityException se ) {
253
+ throw new Exception (se .getMessage ());
254
+ }
255
+ props .setProperty (Constants .FRAMEWORK_STORAGE , storage .getAbsolutePath ());
256
+ }
248
257
249
258
if (shutdownCommand == null || shutdownCommand .isEmpty ()) {
250
259
try {
251
260
shutdownCommand = UUID .randomUUID ().toString ();
252
- Properties temp = new Properties (file );
261
+ Properties temp = new Properties (new File ( karafEtc , CONFIG_PROPERTIES_FILE_NAME ) );
253
262
temp .put (KARAF_SHUTDOWN_COMMAND , Arrays .asList ("" , "#" , "# Generated command shutdown" , "#" ), shutdownCommand );
254
263
temp .save ();
255
264
} catch (IOException ioException ) {
@@ -265,26 +274,18 @@ private String getPropertyOrFail(String propertyName) {
265
274
}
266
275
return value ;
267
276
}
268
-
277
+
278
+ private String [] getSecurityProviders () {
279
+ String prop = props .getProperty (SECURITY_PROVIDERS );
280
+ return (prop != null ) ? prop .split ("," ) : new String [] {};
281
+ }
282
+
269
283
private URI getFramework () throws URISyntaxException {
270
284
String framework = getPropertyOrFail (KARAF_FRAMEWORK );
271
285
String frameworkBundleUri = getPropertyOrFail (KARAF_FRAMEWORK + "." + framework );
272
286
return new URI (frameworkBundleUri );
273
287
}
274
288
275
- private void initFrameworkStorage (File karafData ) throws Exception {
276
- String frameworkStoragePath = props .getProperty (Constants .FRAMEWORK_STORAGE );
277
- if (frameworkStoragePath == null ) {
278
- File storage = new File (karafData .getPath (), "cache" );
279
- try {
280
- storage .mkdirs ();
281
- } catch (SecurityException se ) {
282
- throw new Exception (se .getMessage ());
283
- }
284
- props .setProperty (Constants .FRAMEWORK_STORAGE , storage .getAbsolutePath ());
285
- }
286
- }
287
-
288
289
private int getDefaultBundleStartLevel (int ibsl ) {
289
290
try {
290
291
String str = props .getProperty ("karaf.startlevel.bundle" );
0 commit comments