diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-23 17:03:19 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-23 17:03:19 +0200 |
commit | 0556987242b2760f59dff632a9b60d8665d9526c (patch) | |
tree | 780d0110c9c46904a6cedf0e03247cd90b33e8dc /sonar-application | |
parent | c1651de4d5399a592c4537ebce4f7da2840424d1 (diff) | |
download | sonarqube-0556987242b2760f59dff632a9b60d8665d9526c.tar.gz sonarqube-0556987242b2760f59dff632a9b60d8665d9526c.zip |
Better error message when wrapper.conf is not correct
Diffstat (limited to 'sonar-application')
3 files changed, 27 insertions, 8 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/Env.java b/sonar-application/src/main/java/org/sonar/application/Env.java index 53f25a9b8d7..168664f0d0a 100644 --- a/sonar-application/src/main/java/org/sonar/application/Env.java +++ b/sonar-application/src/main/java/org/sonar/application/Env.java @@ -24,17 +24,23 @@ import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.net.URL; class Env { + static final String ERROR_MESSAGE = "Do not copy-paste the configuration files (conf directory) from the old version. Update the content of the new files instead."; private final File confFile; - Env(File confFile) { - this.confFile = confFile; + // visible for testing + Env(URL confUrl) throws URISyntaxException { + if (confUrl == null) { + throw new IllegalStateException(ERROR_MESSAGE); + } + this.confFile = new File(confUrl.toURI()); } Env() throws URISyntaxException { - this(new File(Env.class.getResource("/sonar.properties").toURI())); + this(Env.class.getResource("/sonar.properties")); } File rootDir() { diff --git a/sonar-application/src/test/java/org/sonar/application/EnvTest.java b/sonar-application/src/test/java/org/sonar/application/EnvTest.java index 27749840297..1400cc8f4ee 100644 --- a/sonar-application/src/test/java/org/sonar/application/EnvTest.java +++ b/sonar-application/src/test/java/org/sonar/application/EnvTest.java @@ -27,6 +27,7 @@ import org.junit.rules.TemporaryFolder; import java.io.File; import static org.fest.assertions.Assertions.assertThat; +import static org.fest.assertions.Fail.fail; public class EnvTest { @@ -48,7 +49,7 @@ public class EnvTest { FileUtils.touch(confFile); FileUtils.touch(logFile); - Env env = new Env(confFile); + Env env = new Env(confFile.toURL()); assertThat(env.rootDir()).isDirectory().exists().isEqualTo(home); assertThat(env.file("conf/sonar.properties")).isFile().exists().isEqualTo(confFile); @@ -65,7 +66,7 @@ public class EnvTest { FileUtils.touch(confFile); FileUtils.touch(logFile); - Env env = new Env(confFile); + Env env = new Env(confFile.toURL()); File data = env.freshDir("data/h2"); assertThat(data).isDirectory().exists(); @@ -80,7 +81,19 @@ public class EnvTest { @Test public void temp_dir_should_be_writable() throws Exception { - new Env(temp.newFile()).verifyWritableTempDir(); + new Env(temp.newFile().toURL()).verifyWritableTempDir(); // do not fail } + + @Test + public void fail_if_conf_file_not_found() throws Exception { + try { + // note that "new Env(null)" would be exact, but let's + // keep "new Env()" for increasing code coverage :-) + new Env(); + fail(); + } catch (IllegalStateException e) { + assertThat(e).hasMessage(Env.ERROR_MESSAGE); + } + } } diff --git a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java index 1a7c9b7e769..590385d939a 100644 --- a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java +++ b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java @@ -41,7 +41,7 @@ public class StartServerTest { public TemporaryFolder temp = new TemporaryFolder(); @Before - public void prepare_app() throws IOException { + public void prepare_app() throws Exception { File confFile = new File("src/test/fake-app/conf/sonar.properties"); if (!confFile.exists()) { confFile = new File("sonar-application/src/test/fake-app/conf/sonar.properties"); @@ -49,7 +49,7 @@ public class StartServerTest { File rootDir = temp.newFolder(); FileUtils.copyDirectory(confFile.getParentFile().getParentFile(), rootDir); - env = new Env(new File(rootDir, "conf/sonar.properties")); + env = new Env(new File(rootDir, "conf/sonar.properties").toURL()); starter = new StartServer(env); } |