[Major] add subpath to StrolchBootstrapper.setupByUserDir()

This commit is contained in:
Robert von Burg 2019-09-10 13:21:04 +02:00
parent 55e6121633
commit 5360d4c0fb
2 changed files with 39 additions and 37 deletions

View File

@ -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);
@ -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;

View File

@ -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();
}