diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-12-21 23:03:58 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-12-21 23:03:58 +0100 |
commit | 27ef81ee84252c85e3dd09d44d88fb441700182b (patch) | |
tree | de09fc298f72e31f7ac58adbd819cf3603e1272e /plugins | |
parent | b87e9dae5c6f0a10f60340f69e78bfe4146e4ac5 (diff) | |
download | sonarqube-27ef81ee84252c85e3dd09d44d88fb441700182b.tar.gz sonarqube-27ef81ee84252c85e3dd09d44d88fb441700182b.zip |
SONAR-983 i18n, better purge, fix NPE when deleted resource
Diffstat (limited to 'plugins')
9 files changed, 33 insertions, 92 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java index f449b5c38e0..f8454462dde 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java @@ -22,7 +22,6 @@ package org.sonar.plugins.dbcleaner; import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.SonarPlugin; -import org.sonar.plugins.dbcleaner.api.DbCleanerCommands; import org.sonar.plugins.dbcleaner.api.DbCleanerConstants; import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner; import org.sonar.plugins.dbcleaner.period.PeriodPurge; @@ -50,7 +49,6 @@ public final class DbCleanerPlugin extends SonarPlugin { return Arrays.asList( // shared components DefaultPeriodCleaner.class, - DbCleanerCommands.class, // purges PurgeOrphanResources.class, PurgeEntities.class, PurgeRuleMeasures.class, PurgeUnprocessed.class, PurgeDeletedResources.class, diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerCommands.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerCommands.java deleted file mode 100644 index b010988a0cd..00000000000 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerCommands.java +++ /dev/null @@ -1,56 +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.plugins.dbcleaner.api; - -import org.sonar.api.BatchExtension; -import org.sonar.api.database.DatabaseSession; -import org.sonar.api.database.model.ResourceModel; -import org.sonar.persistence.resource.ResourceIndexerDao; - -import java.util.List; - -/** - * @since 2.13 - */ -public class DbCleanerCommands implements BatchExtension { - - private DatabaseSession session; - private ResourceIndexerDao resourceIndexer; - - public DbCleanerCommands(DatabaseSession session, ResourceIndexerDao resourceIndexer) { - this.session = session; - this.resourceIndexer = resourceIndexer; - } - - public DbCleanerCommands deleteSnapshots(List<Integer> snapshotIds, boolean includeDependents) { - if (includeDependents) { - PurgeUtils.deleteSnapshotsData(session, snapshotIds); - } else { - PurgeUtils.deleteSnapshots(session, snapshotIds); - } - return this; - } - - public DbCleanerCommands deleteResources(List<Integer> resourceIds) { - PurgeUtils.executeQuery(session, "", resourceIds, "DELETE FROM " + ResourceModel.class.getSimpleName() + " WHERE id in (:ids)"); - resourceIndexer.delete(resourceIds); - return this; - } -} diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java index 93ec2d859ee..390f4f0736f 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java @@ -19,21 +19,16 @@ */ package org.sonar.plugins.dbcleaner.api; -import java.util.List; - -import javax.persistence.Query; - import org.apache.commons.configuration.Configuration; import org.sonar.api.batch.Event; import org.sonar.api.database.DatabaseSession; -import org.sonar.api.database.model.MeasureData; -import org.sonar.api.database.model.MeasureModel; -import org.sonar.api.database.model.RuleFailureModel; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.database.model.SnapshotSource; +import org.sonar.api.database.model.*; import org.sonar.api.design.DependencyDto; import org.sonar.api.utils.TimeProfiler; +import javax.persistence.Query; +import java.util.List; + /** * @since 2.5 */ @@ -106,7 +101,7 @@ public final class PurgeUtils { /** * Delete DUPLICATIONS_INDEX table - * + * * @since 2.11 */ private static void deleteDuplicationBlocks(DatabaseSession session, List<Integer> snapshotIds) { @@ -127,6 +122,18 @@ public final class PurgeUtils { executeQuery(session, "delete snapshots", snapshotIds, "delete from " + Snapshot.class.getSimpleName() + " s where s.id in (:ids)"); } + public static void deleteResources(DatabaseSession session, List<Integer> ids) { + executeQuery(session, "", ids, "DELETE FROM " + ResourceModel.class.getSimpleName() + " WHERE id in (:ids)"); + deleteResourceIndex(session, ids); + } + + /** + * Delete RESOURCE_INDEX table + */ + public static void deleteResourceIndex(DatabaseSession session, List<Integer> resourceIds) { + executeNativeQuery(session, "delete resource_index", resourceIds, "delete from resource_index where resource_id in (:ids)"); + } + /** * Paginate execution of SQL requests to avoid exceeding size of rollback segment */ diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java index dbf22a5004d..94d809c9bc4 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java @@ -22,9 +22,9 @@ package org.sonar.plugins.dbcleaner.purges; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; -import org.sonar.plugins.dbcleaner.api.DbCleanerCommands; import org.sonar.plugins.dbcleaner.api.Purge; import org.sonar.plugins.dbcleaner.api.PurgeContext; +import org.sonar.plugins.dbcleaner.api.PurgeUtils; import javax.persistence.Query; import java.util.List; @@ -34,16 +34,13 @@ import java.util.List; */ public final class PurgeDisabledResources extends Purge { - private DbCleanerCommands dbCleanerCommands; - - public PurgeDisabledResources(DatabaseSession session, DbCleanerCommands dbCleanerCommands) { + public PurgeDisabledResources(DatabaseSession session) { super(session); - this.dbCleanerCommands = dbCleanerCommands; } public void purge(PurgeContext context) { - dbCleanerCommands.deleteSnapshots(getSnapshotIds(), true); - dbCleanerCommands.deleteResources(getResourceIds()); + PurgeUtils.deleteSnapshotsData(getSession(), getSnapshotIds()); + PurgeUtils.deleteResources(getSession(), getResourceIds()); } private List<Integer> getResourceIds() { diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java index a38ead16fbb..0e20f75598d 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java @@ -21,9 +21,9 @@ package org.sonar.plugins.dbcleaner.purges; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; -import org.sonar.plugins.dbcleaner.api.DbCleanerCommands; import org.sonar.plugins.dbcleaner.api.Purge; import org.sonar.plugins.dbcleaner.api.PurgeContext; +import org.sonar.plugins.dbcleaner.api.PurgeUtils; import javax.persistence.Query; import java.util.List; @@ -33,11 +33,8 @@ import java.util.List; */ public final class PurgeOrphanResources extends Purge { - private DbCleanerCommands dbCleanerCommands; - - public PurgeOrphanResources(DatabaseSession session, DbCleanerCommands dbCleanerCommands) { + public PurgeOrphanResources(DatabaseSession session) { super(session); - this.dbCleanerCommands = dbCleanerCommands; } public void purge(PurgeContext context) { @@ -45,7 +42,7 @@ public final class PurgeOrphanResources extends Purge { " r1 WHERE r1.rootId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r2 WHERE r1.rootId=r2.id)"); List<Integer> idsToDelete = query.getResultList(); if (!idsToDelete.isEmpty()) { - dbCleanerCommands.deleteResources(idsToDelete); + PurgeUtils.deleteResources(getSession(), idsToDelete); } } } diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java index 97918dd3030..2b34186a8a5 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java @@ -22,7 +22,6 @@ package org.sonar.plugins.dbcleaner.api; import org.apache.commons.configuration.PropertiesConfiguration; import org.junit.Test; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import org.sonar.plugins.dbcleaner.api.PurgeUtils; import java.sql.SQLException; import java.util.Arrays; diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest.java index 2e87714e2e8..8ff3d3d84c3 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest.java @@ -21,13 +21,9 @@ package org.sonar.plugins.dbcleaner.purges; import org.junit.Test; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import org.sonar.persistence.resource.ResourceIndexerDao; -import org.sonar.plugins.dbcleaner.api.DbCleanerCommands; import java.sql.SQLException; -import static org.mockito.Mockito.mock; - public class PurgeDisabledResourcesTest extends AbstractDbUnitTestCase { @Test @@ -47,7 +43,7 @@ public class PurgeDisabledResourcesTest extends AbstractDbUnitTestCase { private void assertPurge(String testName) { setupData("sharedFixture", testName); - new PurgeDisabledResources(getSession(), new DbCleanerCommands(getSession(), mock(ResourceIndexerDao.class))).purge(null); + new PurgeDisabledResources(getSession()).purge(null); checkTables(testName, "snapshots", "project_measures"); } } diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest.java index 5f443998ce3..87ba7fb9c8b 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest.java @@ -21,13 +21,9 @@ package org.sonar.plugins.dbcleaner.purges; import org.junit.Test; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import org.sonar.persistence.resource.ResourceIndexerDao; -import org.sonar.plugins.dbcleaner.api.DbCleanerCommands; import java.sql.SQLException; -import static org.mockito.Mockito.mock; - public class PurgeOrphanResourcesTest extends AbstractDbUnitTestCase { @Test public void purgeOrphanResources() throws SQLException { @@ -36,7 +32,7 @@ public class PurgeOrphanResourcesTest extends AbstractDbUnitTestCase { private void assertPurge(String testName) { setupData(testName); - new PurgeOrphanResources(getSession(), new DbCleanerCommands(getSession(), mock(ResourceIndexerDao.class))).purge(null); + new PurgeOrphanResources(getSession()).purge(null); checkTables(testName, "projects"); } } diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index 772bec2e4c7..165578cefb2 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -536,6 +536,13 @@ dashboard.Dashboard.description=Default dashboard dashboard.Hotspots.name=Hotspots dashboard.Hotspots.description=Most useful hotspots widgets +#------------------------------------------------------------------------------ +# +# SEARCH ENGINE FOR RESOURCES +# +#------------------------------------------------------------------------------ +search.results=results +search.duration=({0} seconds) #------------------------------------------------------------------------------ # |