diff options
author | Godin <mandrikov@gmail.com> | 2010-11-08 11:33:46 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-11-08 11:33:46 +0000 |
commit | f6b610279f15ea90afed29deb0df4e5928e9d8c0 (patch) | |
tree | b1a90a00c06dc233a97a1352a69f59f74a4dcf84 /sonar-server | |
parent | 6e582ed6c46a23140460648d5496bbf759a44914 (diff) | |
download | sonarqube-f6b610279f15ea90afed29deb0df4e5928e9d8c0.tar.gz sonarqube-f6b610279f15ea90afed29deb0df4e5928e9d8c0.zip |
SONAR-1705: Do not create directory for embedded database if sonar home directory not exists
Diffstat (limited to 'sonar-server')
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java | 8 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/platform/ServerFileSystemTest.java | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java b/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java index f1126ab529a..c9a5a7da3df 100644 --- a/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java +++ b/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java @@ -26,6 +26,7 @@ import org.sonar.api.CoreProperties; import org.sonar.api.database.DatabaseProperties; import org.sonar.api.utils.Logs; import org.sonar.api.utils.SonarException; +import org.sonar.server.platform.ServerStartException; import java.io.File; import java.io.FileOutputStream; @@ -62,7 +63,10 @@ public class EmbeddedDatabase { protected File autodetectDataDirectory(Configuration configuration) { String dirName = configuration.getString(DatabaseProperties.PROP_EMBEDDED_DATA_DIR); if (dirName == null) { - String sonarHome = configuration.getString(CoreProperties.SONAR_HOME); + File sonarHome = new File(configuration.getString(CoreProperties.SONAR_HOME)); + if ( !sonarHome.isDirectory() || !sonarHome.exists()) { + throw new ServerStartException("Sonar home directory does not exist"); + } return new File(sonarHome, "data"); } return new File(dirName); @@ -76,7 +80,7 @@ public class EmbeddedDatabase { if (dbHome.exists() && !dbHome.isDirectory()) { throw new SonarException("Database home " + dbHome.getPath() + " is not a directory"); } - if (!dbHome.exists()) { + if ( !dbHome.exists()) { dbHome.mkdirs(); } System.setProperty("derby.system.home", dbHome.getPath()); diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerFileSystemTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerFileSystemTest.java index 85c543c916e..5312ba08930 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/ServerFileSystemTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerFileSystemTest.java @@ -20,9 +20,9 @@ package org.sonar.server.platform; import org.junit.Test; -import org.sonar.jpa.session.DatabaseConnector; import org.sonar.jpa.dialect.Dialect; import org.sonar.jpa.dialect.MySql; +import org.sonar.jpa.session.DatabaseConnector; import org.sonar.test.TestUtils; import java.io.File; @@ -45,7 +45,6 @@ public class ServerFileSystemTest { assertNotNull(driver); } - @Test(expected = ServerStartException.class) public void failIfJdbcDriverNotFound() { DatabaseConnector databaseConnector = mock(DatabaseConnector.class); @@ -80,7 +79,6 @@ public class ServerFileSystemTest { assertEquals(3, jars.size()); } - @Test public void shouldNotFailIfNoCheckstyleExtensions() { DefaultServerFileSystem fs = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions"), null); @@ -91,4 +89,10 @@ public class ServerFileSystemTest { assertEquals(0, jars.size()); } + @Test(expected = ServerStartException.class) + public void shouldFailIfHomeDirectoryNotExists() { + DefaultServerFileSystem fs = new DefaultServerFileSystem(null, new File("/notexists"), null); + fs.start(); + } + } |