[Major] add subpath to StrolchBootstrapper.setupByUserDir()
This commit is contained in:
parent
55e6121633
commit
5360d4c0fb
|
@ -87,7 +87,7 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
* </p>
|
||||
*
|
||||
* @param appClass
|
||||
* the class where the {@link #APP_VERSION_PROPERTIES} resource resides
|
||||
* the class where the {@link #APP_VERSION_PROPERTIES} resource resides
|
||||
*/
|
||||
public StrolchBootstrapper(Class<?> appClass) {
|
||||
DBC.PRE.assertNotNull("appClass must be set!", appClass);
|
||||
|
@ -108,11 +108,12 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
this.environmentOverride = environmentOverride;
|
||||
}
|
||||
|
||||
public StrolchAgent setupByUserDir(String environment) {
|
||||
public StrolchAgent setupByUserDir(String environment, String subPath) {
|
||||
DBC.PRE.assertNotEmpty("Environment must be set!", environment);
|
||||
DBC.PRE.assertNotEmpty("Sub Path must be set!", subPath);
|
||||
this.environment = environment;
|
||||
|
||||
File rootPathF = new File(System.getProperty(SYS_PROP_USER_DIR));
|
||||
File rootPathF = new File(System.getProperty(SYS_PROP_USER_DIR), subPath);
|
||||
this.configPathF = new File(rootPathF, PATH_CONFIG);
|
||||
this.dataPathF = new File(rootPathF, PATH_DATA);
|
||||
this.tempPathF = new File(rootPathF, PATH_TEMP);
|
||||
|
@ -195,9 +196,9 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
* and then delegating to {@link #setupByBootstrapFile(String, File)}
|
||||
*
|
||||
* @param clazz
|
||||
* the class from which to load the resource as stream
|
||||
* the class from which to load the resource as stream
|
||||
* @param bootstrapFile
|
||||
* the bootstrap file to load
|
||||
* the bootstrap file to load
|
||||
*
|
||||
* @return the Agent which is setup
|
||||
*/
|
||||
|
@ -214,9 +215,9 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
* and then delegating to {@link #setupByBootstrapFile(String, File)}
|
||||
*
|
||||
* @param clazz
|
||||
* the class from which to load the resource as stream
|
||||
* the class from which to load the resource as stream
|
||||
* @param bootstrapFile
|
||||
* the input stream to the bootstrap file to load
|
||||
* the input stream to the bootstrap file to load
|
||||
*
|
||||
* @return the Agent which is setup
|
||||
*/
|
||||
|
@ -232,9 +233,9 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
* Set up Strolch by loading the given bootstrap file for configuration
|
||||
*
|
||||
* @param environment
|
||||
* the environment to load from the boostrap file
|
||||
* the environment to load from the boostrap file
|
||||
* @param bootstrapFile
|
||||
* the bootstrap file to load
|
||||
* the bootstrap file to load
|
||||
*
|
||||
* @return the Agent which is setup
|
||||
*/
|
||||
|
@ -250,9 +251,9 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
* Set up Strolch by loading the given bootstrap file for configuration
|
||||
*
|
||||
* @param environment
|
||||
* the environment to load from the boostrap file
|
||||
* the environment to load from the boostrap file
|
||||
* @param bootstrapFile
|
||||
* the input stream to the bootstrap file to load
|
||||
* the input stream to the bootstrap file to load
|
||||
*
|
||||
* @return the Agent which is setup
|
||||
*/
|
||||
|
@ -332,8 +333,9 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
XmlHelper.parseDocument(bootstrapFile, this);
|
||||
|
||||
if (!this.envFound) {
|
||||
throw new StrolchConfigurationException("Environment " + this.environment
|
||||
+ " not configured in bootstrap configuration " + bootstrapFile.getAbsolutePath());
|
||||
throw new StrolchConfigurationException(
|
||||
"Environment " + this.environment + " not configured in bootstrap configuration " + bootstrapFile
|
||||
.getAbsolutePath());
|
||||
}
|
||||
|
||||
evaluatePaths();
|
||||
|
@ -356,8 +358,8 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
|
||||
// validate the parsed data
|
||||
if (!this.defaultAllowed) {
|
||||
if (StringHelper.isEmpty(this.configS) || StringHelper.isEmpty(this.dataS)
|
||||
|| StringHelper.isEmpty(this.tempS)) {
|
||||
if (StringHelper.isEmpty(this.configS) || StringHelper.isEmpty(this.dataS) || StringHelper
|
||||
.isEmpty(this.tempS)) {
|
||||
String msg = "One element of " + Arrays.toString(new String[] { CONFIG, DATA, TEMP })
|
||||
+ " is not set and environment " + this.environment + " does not have attribute " + DEFAULT
|
||||
+ "=\"true\". Either set the value or allow using default values!";
|
||||
|
@ -365,9 +367,9 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
}
|
||||
}
|
||||
|
||||
String root = StringHelper.isEmpty(this.rootS)
|
||||
? new File(System.getProperty(SYS_PROP_USER_DIR)).getAbsolutePath()
|
||||
: this.rootS;
|
||||
String root = StringHelper.isEmpty(this.rootS) ?
|
||||
new File(System.getProperty(SYS_PROP_USER_DIR)).getAbsolutePath() :
|
||||
this.rootS;
|
||||
String config = StringHelper.isEmpty(this.configS) ? PATH_CONFIG : this.configS;
|
||||
String data = StringHelper.isEmpty(this.dataS) ? PATH_DATA : this.dataS;
|
||||
String temp = StringHelper.isEmpty(this.tempS) ? PATH_TEMP : this.tempS;
|
||||
|
|
|
@ -17,7 +17,7 @@ public class BootstrapperTest {
|
|||
public void shouldSetupByUserDir() {
|
||||
|
||||
File rootSrcPath = new File("src/test/resources/configtest");
|
||||
File rootDstPath = new File("target/shouldSetupByUserDir");
|
||||
File rootDstPath = new File("target/shouldSetupByUserDir/runtime");
|
||||
if (rootDstPath.exists() && !FileHelper.deleteFile(rootDstPath, true)) {
|
||||
throw new RuntimeException("Could not delete target " + rootDstPath);
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ public class BootstrapperTest {
|
|||
}
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
System.setProperty("user.dir", rootDstPath.getAbsolutePath());
|
||||
System.setProperty("user.dir", rootDstPath.getParentFile().getAbsolutePath());
|
||||
try {
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion()).setupByUserDir("dev");
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion()).setupByUserDir("dev", "runtime");
|
||||
assertEquals("dev", agent.getStrolchConfiguration().getRuntimeConfiguration().getEnvironment());
|
||||
} finally {
|
||||
System.setProperty("user.dir", userDir);
|
||||
|
@ -68,8 +68,8 @@ public class BootstrapperTest {
|
|||
throw new RuntimeException("Could not delete target " + rootDstPath);
|
||||
}
|
||||
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion()).setupByCopyingRoot("dev", rootSrcPath,
|
||||
rootDstPath);
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion())
|
||||
.setupByCopyingRoot("dev", rootSrcPath, rootDstPath);
|
||||
assertEquals("dev", agent.getStrolchConfiguration().getRuntimeConfiguration().getEnvironment());
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,8 @@ public class BootstrapperTest {
|
|||
}
|
||||
|
||||
File bootstrapFile = new File("src/test/resources/bootstraptest/StrolchBootstrap.xml");
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion()).setupByBootstrapFile("dev",
|
||||
bootstrapFile);
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion())
|
||||
.setupByBootstrapFile("dev", bootstrapFile);
|
||||
assertEquals("dev", agent.getStrolchConfiguration().getRuntimeConfiguration().getEnvironment());
|
||||
agent.destroy();
|
||||
}
|
||||
|
@ -120,8 +120,8 @@ public class BootstrapperTest {
|
|||
|
||||
File bootstrapFile = new File("src/test/resources/bootstraptest/StrolchBootstrap.xml");
|
||||
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion()).setupByBootstrapFile("test.next",
|
||||
bootstrapFile);
|
||||
StrolchAgent agent = new StrolchBootstrapper(RuntimeMock.getAppVersion())
|
||||
.setupByBootstrapFile("test.next", bootstrapFile);
|
||||
assertEquals("test", agent.getStrolchConfiguration().getRuntimeConfiguration().getEnvironment());
|
||||
agent.destroy();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue