]> source.dussan.org Git - sonarqube.git/commitdiff
Indexation of resources during migration must be reentrant
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 29 Dec 2011 15:50:37 +0000 (16:50 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 29 Dec 2011 15:50:37 +0000 (16:50 +0100)
sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/startup/IndexProjects.java [deleted file]
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/241_index_resources.rb [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/startup/IndexProjectsTest.java [deleted file]

index 13360df8748b74764d3dac6c917b4a3e2669fb85..f7429e9ad503d2af4ac5bba4f2276ede72bf70af 100644 (file)
@@ -34,8 +34,8 @@ public class SchemaMigration {
 
   public final static int VERSION_UNKNOWN = -1;
 
-  public static final int LAST_VERSION = 240;
-  public static final int VERSION_2_13 = 240;
+  public static final int LAST_VERSION = 241;
+  public static final int VERSION_2_13 = 241;
 
   public final static String TABLE_NAME = "schema_migrations";
 
index ac666f114d50f564e9874327a6fbbece023ccf8a..a1bf630ef607f2ac29983a30b104217624a4a026 100644 (file)
@@ -167,6 +167,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('237');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('238');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('239');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('240');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('241');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 8b4e966fb3c3bf3f31930872abe471cc3e811dfd..492e5090f0c980c31abbffb03cfe3a387b968d46 100644 (file)
@@ -126,6 +126,7 @@ public final class Platform {
   }
 
   private void startDatabaseConnectors(ServletContext servletContext) {
+    System.out.println("Start database connectors");
     rootContainer = new ComponentContainer();
     rootContainer.addSingleton(servletContext);
     rootContainer.addSingleton(IocContainer.class); // for backward compatibility
@@ -134,7 +135,7 @@ public final class Platform {
     rootContainer.addSingleton(EmbeddedDatabaseFactory.class);
     rootContainer.addSingleton(DefaultDatabase.class);
     rootContainer.addSingleton(MyBatis.class);
-    rootContainer.addSingleton(ResourceIndexer.class); // for the migration -> see org.sonar.server.startup.IndexProjects
+    rootContainer.addSingleton(ResourceIndexer.class); // for the migration 241
     rootContainer.addSingleton(DefaultDatabaseConnector.class);
     rootContainer.addSingleton(DefaultServerUpgradeStatus.class);
     rootContainer.addSingleton(DatabaseMigrator.class);
@@ -235,7 +236,6 @@ public final class Platform {
     startupContainer.addSingleton(DeleteDeprecatedMeasures.class);
     startupContainer.addSingleton(GeneratePluginIndex.class);
     startupContainer.addSingleton(RegisterNewDashboards.class);
-    startupContainer.addSingleton(IndexProjects.class);
     startupContainer.startComponents();
 
     startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/IndexProjects.java b/sonar-server/src/main/java/org/sonar/server/startup/IndexProjects.java
deleted file mode 100644 (file)
index 14403ca..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.server.startup;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.api.utils.TimeProfiler;
-import org.sonar.core.resource.ResourceIndexer;
-import org.sonar.jpa.entity.SchemaMigration;
-
-/**
- * Index existing projects during migration to 2.13. Since this latter version, resources are automatically indexed
- * during project analysis.
- *
- * @since 2.13
- */
-public class IndexProjects implements ServerComponent {
-
-  private ServerUpgradeStatus upgradeStatus;
-  private ResourceIndexer indexer;
-
-  public IndexProjects(ServerUpgradeStatus upgradeStatus, ResourceIndexer indexer) {
-    this.upgradeStatus = upgradeStatus;
-    this.indexer = indexer;
-  }
-
-  public void start() {
-    if (shouldIndex()) {
-      index();
-    }
-  }
-
-  private boolean shouldIndex() {
-    return upgradeStatus.isUpgraded() && upgradeStatus.getInitialDbVersion() < SchemaMigration.VERSION_2_13;
-  }
-
-  private void index() {
-    TimeProfiler profiler = new TimeProfiler().start("Index projects");
-    indexer.indexAll();
-    profiler.stop();
-  }
-
-}
index cad0e11e695414e1edc8c4d4df035d79f0a16d34..927defeac4c5105737ad54f27a0bbc21f5f780f4 100644 (file)
@@ -34,9 +34,10 @@ import org.sonar.api.rules.RuleRepository;
 import org.sonar.api.utils.ValidationMessages;
 import org.sonar.api.web.*;
 import org.sonar.core.i18n.RuleI18nManager;
-import org.sonar.markdown.Markdown;
 import org.sonar.core.persistence.Database;
 import org.sonar.core.persistence.DatabaseMigrator;
+import org.sonar.core.resource.ResourceIndexer;
+import org.sonar.markdown.Markdown;
 import org.sonar.server.configuration.Backup;
 import org.sonar.server.configuration.ProfilesManager;
 import org.sonar.server.filters.Filter;
@@ -367,6 +368,10 @@ public final class JRubyFacade {
     return i18n.getJsDictionnary(rubyLocale);
   }
 
+  public void indexResources() {
+    getContainer().getComponentByType(ResourceIndexer.class).indexAll();
+  }
+
   public void logError(String message) {
     LoggerFactory.getLogger(getClass()).error(message);
   }
@@ -378,4 +383,6 @@ public final class JRubyFacade {
   public ComponentContainer getContainer() {
     return Platform.getInstance().getContainer();
   }
+
+
 }
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/241_index_resources.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/241_index_resources.rb
new file mode 100644 (file)
index 0000000..d0e4389
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2011 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+
+#
+# Note: this migration must be executed after 240_delete_resource_orphans.
+#
+# Sonar 2.13
+#
+class IndexResources < ActiveRecord::Migration
+
+  def self.up
+    Java::OrgSonarServerUi::JRubyFacade.getInstance().indexResources()
+  end
+
+end
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/IndexProjectsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/IndexProjectsTest.java
deleted file mode 100644 (file)
index b3d1f46..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.server.startup;
-
-import org.junit.Test;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.core.resource.ResourceIndexer;
-import org.sonar.jpa.entity.SchemaMigration;
-
-import static org.mockito.Mockito.*;
-
-public class IndexProjectsTest {
-
-  @Test
-  public void doNotIndexOnFreshInstalls() {
-    ResourceIndexer indexer = mock(ResourceIndexer.class);
-    ServerUpgradeStatus status = mock(ServerUpgradeStatus.class);
-    when(status.isUpgraded()).thenReturn(false);
-    when(status.isFreshInstall()).thenReturn(true);
-
-    new IndexProjects(status, indexer).start();
-
-    verifyZeroInteractions(indexer);
-  }
-
-  @Test
-  public void doNotIndexOnUpgradesSince213() {
-    ResourceIndexer indexer = mock(ResourceIndexer.class);
-    ServerUpgradeStatus status = mock(ServerUpgradeStatus.class);
-    when(status.isUpgraded()).thenReturn(true);
-    when(status.isFreshInstall()).thenReturn(false);
-    when(status.getInitialDbVersion()).thenReturn(SchemaMigration.VERSION_2_13 + 10);
-
-    new IndexProjects(status, indexer).start();
-
-    verifyZeroInteractions(indexer);
-  }
-
-  @Test
-  public void doIndexOnUpgradeBefore213() {
-    ResourceIndexer indexer = mock(ResourceIndexer.class);
-    ServerUpgradeStatus status = mock(ServerUpgradeStatus.class);
-    when(status.isUpgraded()).thenReturn(true);
-    when(status.isFreshInstall()).thenReturn(false);
-    when(status.getInitialDbVersion()).thenReturn(SchemaMigration.VERSION_2_13 - 10);
-
-    new IndexProjects(status, indexer).start();
-
-    verify(indexer).indexAll();
-  }
-}