Tighten up PropertiesLauncher's contract
The main changes are: - Switch to `loader.properties` instead of `application.properties` - Search for `loader.properties` in `loader.home` as well as in the classpath - Placeholder replacements in MANIFEST.MF (using `loader.properties` or system/env vars) See gh-7221 Closes gh-8346
This commit is contained in:
committed by
Andy Wilkinson
parent
5278baca01
commit
e4c807b884
@@ -31,6 +31,7 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -50,6 +51,9 @@ public class PropertiesLauncherTests {
|
||||
@Rule
|
||||
public InternalOutputCapture output = new InternalOutputCapture();
|
||||
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@@ -72,9 +76,28 @@ public class PropertiesLauncherTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultHome() {
|
||||
System.clearProperty("loader.home");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory())
|
||||
.isEqualTo(new File(System.getProperty("user.dir")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternateHome() throws Exception {
|
||||
System.setProperty("loader.home", "src/test/resources/home");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory())
|
||||
.isEqualTo(new File(System.getProperty("loader.home")));
|
||||
assertThat(launcher.getMainClass()).isEqualTo("demo.HomeApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistentHome() throws Exception {
|
||||
System.setProperty("loader.home", "src/test/resources/nonexistent");
|
||||
this.expected.expectMessage("Invalid source folder");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory())
|
||||
.isNotEqualTo(new File(System.getProperty("loader.home")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,6 +116,13 @@ public class PropertiesLauncherTests {
|
||||
.isEqualTo("[etc/]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootOfClasspathFirst() throws Exception {
|
||||
System.setProperty("loader.config.name", "bar");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("my.BarApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedDotPath() throws Exception {
|
||||
System.setProperty("loader.path", ".");
|
||||
@@ -232,6 +262,13 @@ public class PropertiesLauncherTests {
|
||||
.containsExactly("/foo.jar", "/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManifestWithPlaceholders() throws Exception {
|
||||
System.setProperty("loader.home", "src/test/resources/placeholders");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("demo.FooApplication");
|
||||
}
|
||||
|
||||
private void waitFor(String value) throws Exception {
|
||||
int count = 0;
|
||||
boolean timeout = false;
|
||||
|
||||
@@ -1 +1 @@
|
||||
loader.main: demo.Application
|
||||
loader.main: demo.NoSuchApplication
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
loader.main: my.BootInfBarApplication
|
||||
@@ -0,0 +1 @@
|
||||
loader.main: demo.Application
|
||||
@@ -0,0 +1 @@
|
||||
loader.main: demo.HomeApplication
|
||||
@@ -0,0 +1 @@
|
||||
foo.main: demo.FooApplication
|
||||
Reference in New Issue
Block a user