summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-18 15:34:03 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-18 15:34:03 +0200
commit3e4449af1909853f3067760207d3a74886c16142 (patch)
tree900ce9315363cf1e78863337d4d1c2a4b89b2a88 /sonar-server
parentb2e367dd4ed05ce488e784b1d7d9181eea920c66 (diff)
downloadsonarqube-3e4449af1909853f3067760207d3a74886c16142.tar.gz
sonarqube-3e4449af1909853f3067760207d3a74886c16142.zip
Revert "When using H2, database migration is now automatically done"
This reverts commit eecc6c684656627d935169dfe5db20f3552278a3.
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/EmbeddedDatabase.java5
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java16
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb15
-rw-r--r--sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java2
5 files changed, 30 insertions, 22 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/EmbeddedDatabase.java b/sonar-server/src/main/java/org/sonar/server/db/EmbeddedDatabase.java
index 2ed48e023e9..ced29614549 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/EmbeddedDatabase.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/EmbeddedDatabase.java
@@ -23,7 +23,6 @@ import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
import org.h2.Driver;
import org.h2.tools.Server;
-import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
@@ -35,7 +34,7 @@ import java.io.File;
import java.sql.DriverManager;
import java.sql.SQLException;
-public class EmbeddedDatabase implements Startable {
+public class EmbeddedDatabase {
private static final Logger LOG = LoggerFactory.getLogger(EmbeddedDatabase.class);
private final Settings settings;
private Server server;
@@ -44,7 +43,6 @@ public class EmbeddedDatabase implements Startable {
this.settings = settings;
}
- @Override
public void start() {
File dbHome = getDataDirectory(settings);
if (!dbHome.exists()) {
@@ -73,7 +71,6 @@ public class EmbeddedDatabase implements Startable {
}
}
- @Override
public void stop() {
if (server != null) {
server.stop();
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java
index af25da2e929..833389ad924 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java
@@ -22,7 +22,6 @@ package org.sonar.server.db.migrations;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.dbutils.DbUtils;
import org.apache.ibatis.session.SqlSession;
-import org.picocontainer.Startable;
import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.Database;
@@ -37,7 +36,7 @@ import java.sql.Connection;
*
* @since 2.12
*/
-public class DatabaseMigrator implements ServerComponent, Startable {
+public class DatabaseMigrator implements ServerComponent {
private final MyBatis myBatis;
private final Database database;
@@ -49,21 +48,10 @@ public class DatabaseMigrator implements ServerComponent, Startable {
this.migrations = migrations;
}
- @Override
- public void start(){
- createDatabase();
- }
-
- @Override
- public void stop(){
- // Nothing to do
- }
-
/**
* @return true if the database has been created, false if this database is not supported
*/
- @VisibleForTesting
- boolean createDatabase() {
+ public boolean createDatabase() {
if (!DdlUtils.supportsDialect(database.getDialect().getId())) {
return false;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
index b3f764ebc58..222fbe111db 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
@@ -35,7 +35,11 @@ import org.sonar.api.test.MutableTestPlan;
import org.sonar.api.test.MutableTestable;
import org.sonar.api.test.TestPlan;
import org.sonar.api.test.Testable;
-import org.sonar.api.web.*;
+import org.sonar.api.web.Footer;
+import org.sonar.api.web.NavigationSection;
+import org.sonar.api.web.Page;
+import org.sonar.api.web.RubyRailsWebservice;
+import org.sonar.api.web.Widget;
import org.sonar.core.component.SnapshotPerspectives;
import org.sonar.core.measure.MeasureFilterEngine;
import org.sonar.core.measure.MeasureFilterResult;
@@ -50,7 +54,11 @@ import org.sonar.server.platform.Platform;
import org.sonar.server.platform.ServerIdGenerator;
import org.sonar.server.platform.ServerSettings;
import org.sonar.server.platform.SettingsChangeNotifier;
-import org.sonar.server.plugins.*;
+import org.sonar.server.plugins.InstalledPluginReferentialFactory;
+import org.sonar.server.plugins.PluginDownloader;
+import org.sonar.server.plugins.ServerPluginJarsInstaller;
+import org.sonar.server.plugins.ServerPluginRepository;
+import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.rule.RuleRepositories;
import org.sonar.server.source.CodeColorizers;
import org.sonar.server.user.NewUserNotifier;
@@ -60,7 +68,6 @@ import org.sonar.updatecenter.common.Version;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.net.InetAddress;
import java.sql.Connection;
import java.util.Collection;
@@ -236,7 +243,6 @@ public final class JRubyFacade {
return get(Database.class);
}
- // Only used by Java migration
public DatabaseMigrator databaseMigrator() {
return get(DatabaseMigrator.class);
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb b/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb
index 24415ce1c0e..eec43b43741 100644
--- a/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb
@@ -70,6 +70,7 @@ class DatabaseVersion
def self.automatic_setup
if current_version<=0
+ try_restore_structure_dump()
upgrade_and_start()
elsif uptodate?
load_java_web_services
@@ -83,6 +84,20 @@ class DatabaseVersion
ActiveRecord::Base.connected?
end
+ def self.try_restore_structure_dump()
+ ::Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().createDatabase()
+ end
+
+ def self.execute_sql_requests(requests)
+ requests.each do |request|
+ unless request.blank? || request.start_with?('--')
+ request.chomp!
+ request.chop! if request.end_with?(';')
+ ActiveRecord::Base.connection.execute(request)
+ end
+ end
+ end
+
def self.dialect
::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getActiveRecordDialectCode()
end
diff --git a/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java b/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
index 4a92e0a79b3..5f2f1f26f1e 100644
--- a/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
+++ b/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
@@ -22,6 +22,7 @@ package org.sonar.server.tester;
import org.apache.commons.io.FileUtils;
import org.sonar.api.CoreProperties;
+import org.sonar.server.db.migrations.DatabaseMigrator;
import org.sonar.server.platform.Platform;
import java.io.File;
@@ -48,6 +49,7 @@ public class ServerTester {
properties.setProperty("sonar.jdbc.url", "jdbc:h2:" + temp.getAbsolutePath() + "/h2");
platform.init(properties);
+ ((DatabaseMigrator) platform.getComponent(DatabaseMigrator.class)).createDatabase();
platform.doStart();
}