startupContainer.addSingleton(JdbcDriverDeployer.class);
startupContainer.addSingleton(RegisterDebtCharacteristicModel.class);
startupContainer.addSingleton(RegisterTechnicalDebtModel.class);
- startupContainer.addSingleton(DeleteDeprecatedMeasures.class);
startupContainer.addSingleton(GeneratePluginIndex.class);
startupContainer.addSingleton(GenerateBootstrapIndex.class);
startupContainer.addSingleton(RegisterNewMeasureFilters.class);
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.startup;
-
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.api.utils.Logs;
-import org.sonar.jpa.session.DatabaseSessionFactory;
-
-import javax.persistence.Query;
-import java.util.List;
-
-/**
- * This purge script can not be executed with ActiveRecord. It fails with an out of memory error.
- *
- * @since 2.5 this component could be removed after 4 or 5 releases.
- */
-public final class DeleteDeprecatedMeasures {
-
- private ServerUpgradeStatus status;
- private DatabaseSessionFactory sessionFactory;
- private static final int MAX_IN_ELEMENTS = 500;
-
- public DeleteDeprecatedMeasures(DatabaseSessionFactory sessionFactory, ServerUpgradeStatus status) {
- this.sessionFactory = sessionFactory;
- this.status = status;
- }
-
- public void start() {
- if (mustDoPurge()) {
- doPurge();
- }
- }
-
- boolean mustDoPurge() {
- return status.isUpgraded() && status.getInitialDbVersion() <= 162;
- }
-
- void doPurge() {
- Logs.INFO.info("Deleting measures with deprecated ISO category");
- deleteRows("SELECT m.id FROM " + MeasureModel.class.getSimpleName() + " m WHERE m.ruleId IS NULL AND m.rulesCategoryId IS NOT NULL");
-
- Logs.INFO.info("Deleting measures with deprecated priority");
- deleteRows("SELECT m.id FROM " + MeasureModel.class.getSimpleName() + " m WHERE m.ruleId IS NULL AND m.rulePriority IS NOT NULL");
- }
-
- private void deleteRows(String hql) {
- DatabaseSession session = sessionFactory.getSession();
- List ids = session.getEntityManager().createQuery(hql).getResultList();
- int index = 0;
- while (index < ids.size()) {
- List paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS));
- Query query = session.createQuery("DELETE FROM " + MeasureModel.class.getSimpleName() + " WHERE id IN (:ids)");
- query.setParameter("ids", paginedSids);
- query.executeUpdate();
- index += MAX_IN_ELEMENTS;
- session.commit();
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.startup;
-
-import org.junit.Test;
-import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.core.persistence.DatabaseVersion;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.util.List;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.internal.matchers.IsCollectionContaining.hasItems;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DeleteDeprecatedMeasuresTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldDeleteMeasuresWithCategory() {
- setupData("sharedFixture");
-
- ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
-
- final DeleteDeprecatedMeasures purge = new DeleteDeprecatedMeasures(getSessionFactory(), upgradeStatus);
- purge.doPurge();
-
- List rows = getSession().createQuery("from " + MeasureModel.class.getSimpleName() + " where ruleId is null and rulesCategoryId is not null").getResultList();
- assertThat(rows.size(), is(0));
- }
-
- @Test
- public void shouldDeleteMeasuresWithPriority() {
- setupData("sharedFixture");
-
- ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
- final DeleteDeprecatedMeasures purge = new DeleteDeprecatedMeasures(getSessionFactory(), upgradeStatus);
- purge.doPurge();
-
- List rowsToDelete = getSession().createQuery("from " + MeasureModel.class.getSimpleName() + " where ruleId is null and rulePriority is not null").getResultList();
- assertThat(rowsToDelete.size(), is(0));
-
- List<Long> rowIdsToKeep = getSession().createQuery("select id from " + MeasureModel.class.getSimpleName()).getResultList();
- assertThat(rowIdsToKeep, hasItems(1L, 2L, 4L, 6L));
- }
-
- @Test
- public void shouldDoPurgeOnUpgradeBefore162() {
- ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
- when(upgradeStatus.isUpgraded()).thenReturn(true);
- when(upgradeStatus.getInitialDbVersion()).thenReturn(50);
-
- final DeleteDeprecatedMeasures purge = new DeleteDeprecatedMeasures(getSessionFactory(), upgradeStatus);
- assertThat(purge.mustDoPurge(), is(true));
- }
-
- @Test
- public void shouldNotDoPurgeOnUpgradeAfter162() {
- ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
- when(upgradeStatus.isUpgraded()).thenReturn(true);
- when(upgradeStatus.getInitialDbVersion()).thenReturn(170);
-
- final DeleteDeprecatedMeasures purge = new DeleteDeprecatedMeasures(getSessionFactory(), upgradeStatus);
- assertThat(purge.mustDoPurge(), is(false));
- }
-
- @Test
- public void shouldNotDoPurgeOnFreshInstall() {
- ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
- when(upgradeStatus.isUpgraded()).thenReturn(false);
- when(upgradeStatus.getInitialDbVersion()).thenReturn(-1);
-
- final DeleteDeprecatedMeasures purge = new DeleteDeprecatedMeasures(getSessionFactory(), upgradeStatus);
- assertThat(purge.mustDoPurge(), is(false));
- }
-
- @Test
- public void shouldNotDoPurgeOnStandardStartup() {
- ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
- when(upgradeStatus.isUpgraded()).thenReturn(false);
- when(upgradeStatus.getInitialDbVersion()).thenReturn(DatabaseVersion.LAST_VERSION);
-
- final DeleteDeprecatedMeasures purge = new DeleteDeprecatedMeasures(getSessionFactory(), upgradeStatus);
- assertThat(purge.mustDoPurge(), is(false));
- }
-}
+++ /dev/null
-<dataset>
-
-
- <!-- classic measures -->
- <project_measures characteristic_id="[null]" url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- rule_priority="[null]"
- alert_text="[null]" ID="1" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="1" rules_category_id="[null]"
- RULE_ID="1"
- text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
- alert_status="[null]" description="[null]"/>
-
- <project_measures characteristic_id="[null]" url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- rule_priority="[null]"
- alert_text="[null]" ID="2" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="2" rules_category_id="[null]"
- RULE_ID="1"
- text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
- alert_status="[null]" description="[null]"/>
-
- <!-- measure with ISO category and no rule -->
- <project_measures characteristic_id="[null]" url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- rule_priority="[null]"
- alert_text="[null]" ID="3" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="3" rules_category_id="2"
- RULE_ID="[null]"
- text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
- alert_status="[null]" description="[null]"/>
-
- <!-- measures with ISO category and rule -->
- <project_measures characteristic_id="[null]" url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- rule_priority="1"
- alert_text="[null]" ID="4" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" rules_category_id="6"
- RULE_ID="1"
- text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
- alert_status="[null]" description="[null]"/>
-
-
- <!-- measures with priority and no rule -->
- <project_measures characteristic_id="[null]" url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- rule_priority="2"
- alert_text="[null]" ID="5" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="3" rules_category_id="[null]"
- RULE_ID="[null]"
- text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
- alert_status="[null]" description="[null]"/>
-
- <!-- measures with priority and rule -->
- <project_measures characteristic_id="[null]" url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- rule_priority="1"
- alert_text="[null]" ID="6" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" rules_category_id="[null]"
- RULE_ID="1"
- text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
- alert_status="[null]" description="[null]"/>
-
-</dataset>
\ No newline at end of file