From 0132d6677fa9e3d4c9e55ac9ea13a8b700d443bb Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 15 Jan 2015 12:12:53 +0100 Subject: [PATCH] SONAR-5883 Drop snapshot data --- .../org/sonar/plugins/core/CorePlugin.java | 2 - .../plugins/core/sensors/FileHashSensor.java | 78 --------------- .../core/sensors/FileHashSensorTest.java | 99 ------------------- .../sonar/server/platform/BackendCleanup.java | 2 +- .../db/migrate/768_drop_snapshot_data.rb | 32 ++++++ .../batch/index/FileHashesPersister.java | 63 ------------ .../DefaultProjectReferentialsLoader.java | 34 ++----- .../sonar/batch/scan/ModuleScanContainer.java | 2 - .../batch/scan/ProjectScanContainer.java | 2 - .../filesystem/PreviousFileHashLoader.java | 73 -------------- .../batch/index/FileHashesPersisterTest.java | 71 ------------- .../DefaultProjectReferentialsLoaderTest.java | 3 +- .../PreviousFileHashLoaderTest.java | 99 ------------------- .../org/sonar/core/persistence/DaoUtils.java | 2 - .../core/persistence/DatabaseVersion.java | 3 +- .../org/sonar/core/persistence/MyBatis.java | 80 ++++++++++++--- .../persistence/PreviewDatabaseFactory.java | 25 +---- .../org/sonar/core/purge/PurgeCommands.java | 13 --- .../org/sonar/core/purge/PurgeMapper.java | 2 - .../sonar/core/source/SnapshotDataTypes.java | 6 -- .../sonar/core/source/db/SnapshotDataDao.java | 81 --------------- .../sonar/core/source/db/SnapshotDataDto.java | 73 -------------- .../core/source/db/SnapshotDataMapper.java | 38 ------- .../org/sonar/core/persistence/rows-h2.sql | 1 + .../org/sonar/core/persistence/schema-h2.ddl | 12 --- .../org/sonar/core/purge/PurgeMapper.xml | 7 -- .../PreviewDatabaseFactoryTest.java | 4 +- .../sonar/core/purge/PurgeCommandsTest.java | 5 +- .../core/source/db/SnapshotDataDaoTest.java | 80 --------------- .../multi-modules-with-issues.xml | 7 -- .../shouldDeleteSnapshot-result.xml | 3 - .../shouldDeleteSnapshot.xml | 4 - .../shouldPurgeSnapshot-result.xml | 3 - .../PurgeCommandsTest/shouldPurgeSnapshot.xml | 6 -- 34 files changed, 114 insertions(+), 901 deletions(-) delete mode 100644 plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java delete mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/768_drop_snapshot_data.rb delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDao.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDto.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataMapper.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/source/db/SnapshotDataDaoTest.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index fb1eb26c69d..cd9f54ee857 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -53,7 +53,6 @@ import org.sonar.plugins.core.sensors.BranchCoverageDecorator; import org.sonar.plugins.core.sensors.CommentDensityDecorator; import org.sonar.plugins.core.sensors.CoverageDecorator; import org.sonar.plugins.core.sensors.DirectoriesDecorator; -import org.sonar.plugins.core.sensors.FileHashSensor; import org.sonar.plugins.core.sensors.FilesDecorator; import org.sonar.plugins.core.sensors.ItBranchCoverageDecorator; import org.sonar.plugins.core.sensors.ItCoverageDecorator; @@ -373,7 +372,6 @@ public final class CorePlugin extends SonarPlugin { DirectoriesDecorator.class, FilesDecorator.class, ManualMeasureDecorator.class, - FileHashSensor.class, // time machine TendencyDecorator.class, diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java deleted file mode 100644 index 5f0bfb3a2dc..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.plugins.core.sensors; - -import com.google.common.collect.Maps; -import org.sonar.api.batch.Sensor; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.index.ComponentDataCache; -import org.sonar.batch.scan.filesystem.InputPathCache; -import org.sonar.core.DryRunIncompatible; -import org.sonar.core.source.SnapshotDataTypes; - -import java.util.Map; - -/** - * This sensor will retrieve hash of each file of the current module and store it in DB - * in order to compare it during next analysis and see if the file was modified. - * This is used by the incremental preview mode. - * - * @since 4.0 - */ -@DryRunIncompatible -public final class FileHashSensor implements Sensor { - - private final InputPathCache fileCache; - private final ComponentDataCache componentDataCache; - - public FileHashSensor(InputPathCache fileCache, ComponentDataCache componentDataCache) { - this.fileCache = fileCache; - this.componentDataCache = componentDataCache; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - @Override - public void analyse(Project project, SensorContext context) { - Map map = Maps.newHashMap(); - for (InputFile inputFile : fileCache.filesByModule(project.key())) { - String hash = ((DeprecatedDefaultInputFile) inputFile).hash(); - if (hash != null) { - map.put(inputFile.relativePath(), hash); - } - } - if (!map.isEmpty()) { - String data = KeyValueFormat.format(map); - componentDataCache.setStringData(project.key(), SnapshotDataTypes.FILE_HASHES, data); - } - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java deleted file mode 100644 index f0c32fad7c5..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.plugins.core.sensors; - -import com.google.common.collect.Lists; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile; -import org.sonar.api.resources.Project; -import org.sonar.batch.index.ComponentDataCache; -import org.sonar.batch.scan.filesystem.InputPathCache; -import org.sonar.core.source.SnapshotDataTypes; - -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class FileHashSensorTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - Project project = new Project("struts"); - InputPathCache fileCache = mock(InputPathCache.class); - ComponentDataCache componentDataCache = mock(ComponentDataCache.class); - FileHashSensor sensor = new FileHashSensor(fileCache, componentDataCache); - - @Test - public void store_file_hashes() throws Exception { - when(fileCache.filesByModule("struts")).thenReturn(Lists.newArrayList( - new DeprecatedDefaultInputFile("foo", "src/Foo.java").setFile(temp.newFile()).setHash("ABC"), - new DeprecatedDefaultInputFile("foo", "src/Bar.java").setFile(temp.newFile()).setHash("DEF"))); - - SensorContext sensorContext = mock(SensorContext.class); - sensor.analyse(project, sensorContext); - - verify(componentDataCache).setStringData("struts", SnapshotDataTypes.FILE_HASHES, "src/Foo.java=ABC;src/Bar.java=DEF"); - verifyZeroInteractions(sensorContext); - } - - @Test - public void store_file_hashes_for_branches() throws Exception { - project = new Project("struts", "branch-2.x", "Struts 2.x"); - when(fileCache.filesByModule("struts:branch-2.x")).thenReturn(Lists.newArrayList( - new DeprecatedDefaultInputFile("foo", "src/Foo.java").setFile(temp.newFile()).setHash("ABC"), - new DeprecatedDefaultInputFile("foo", "src/Bar.java").setFile(temp.newFile()).setHash("DEF"))); - - SensorContext sensorContext = mock(SensorContext.class); - sensor.analyse(project, sensorContext); - - verify(componentDataCache).setStringData("struts:branch-2.x", SnapshotDataTypes.FILE_HASHES, "src/Foo.java=ABC;src/Bar.java=DEF"); - verifyZeroInteractions(sensorContext); - } - - @Test - public void various_tests() throws Exception { - assertThat(sensor.shouldExecuteOnProject(project)).isTrue(); - assertThat(sensor.toString()).isEqualTo("FileHashSensor"); - } - - @Test - public void dont_save_hashes_if_no_files() throws Exception { - when(fileCache.filesByModule("struts")).thenReturn(Collections.emptyList()); - - SensorContext sensorContext = mock(SensorContext.class); - sensor.analyse(project, sensorContext); - - verifyZeroInteractions(componentDataCache); - verifyZeroInteractions(sensorContext); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java index 78a1b297eb1..2335fbc5e60 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java @@ -37,7 +37,7 @@ public class BackendCleanup implements ServerComponent { private static final String[] INSPECTION_TABLES = { "action_plans", "authors", "dependencies", "duplications_index", "events", "graphs", "issues", "issue_changes", "manual_measures", "notifications", "project_links", "project_measures", "projects", "resource_index", - "semaphores", "snapshots", "snapshot_data", "file_sources" + "semaphores", "snapshots", "file_sources" }; private static final String[] RESOURCE_RELATED_TABLES = { "group_roles", "user_roles", "properties" diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/768_drop_snapshot_data.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/768_drop_snapshot_data.rb new file mode 100644 index 00000000000..23f3e33c0f5 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/768_drop_snapshot_data.rb @@ -0,0 +1,32 @@ +# +# 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. +# + +# +# SonarQube 5.1 +# SONAR-5883 +# +class DropSnapshotData < ActiveRecord::Migration + + def self.up + remove_index :snapshot_data, :name => 'snapshot_data_resource_id' + drop_table :snapshot_data + end + +end diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java deleted file mode 100644 index 526ce7ba9f6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.batch.index; - -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.MyBatis; -import org.sonar.core.source.SnapshotDataTypes; -import org.sonar.core.source.db.SnapshotDataDao; -import org.sonar.core.source.db.SnapshotDataDto; - -/** - * Store file hashes in snapshot_data for reuse in next analysis to know if a file is modified - */ -public class FileHashesPersister implements ScanPersister { - private final ComponentDataCache data; - private final ResourceCache resourceCache; - private final SnapshotDataDao dao; - private final MyBatis mybatis; - - public FileHashesPersister(ComponentDataCache data, ResourceCache resourceCache, - SnapshotDataDao dao, MyBatis mybatis) { - this.data = data; - this.resourceCache = resourceCache; - this.dao = dao; - this.mybatis = mybatis; - } - - @Override - public void persist() { - try (DbSession session = mybatis.openSession(true)) { - for (BatchResource batchResource : resourceCache.all()) { - String componentKey = batchResource.resource().getEffectiveKey(); - String fileHashesdata = data.getStringData(componentKey, SnapshotDataTypes.FILE_HASHES); - if (fileHashesdata != null) { - SnapshotDataDto dto = new SnapshotDataDto(); - dto.setSnapshotId(batchResource.snapshotId()); - dto.setResourceId(batchResource.resource().getId()); - dto.setDataType(SnapshotDataTypes.FILE_HASHES); - dto.setData(fileHashesdata); - dao.insert(session, dto); - } - } - session.commit(); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java index cfae1f93276..90a10bc1191 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java @@ -31,26 +31,22 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.resources.Qualifiers; -import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.bootstrap.AnalysisMode; import org.sonar.batch.bootstrap.ServerClient; import org.sonar.batch.bootstrap.TaskProperties; import org.sonar.batch.protocol.input.FileData; import org.sonar.batch.protocol.input.ProjectReferentials; import org.sonar.batch.rule.ModuleQProfiles; -import org.sonar.core.source.SnapshotDataTypes; -import org.sonar.core.source.db.SnapshotDataDao; -import org.sonar.core.source.db.SnapshotDataDto; import javax.annotation.CheckForNull; import javax.persistence.NoResultException; import javax.persistence.Query; import java.util.Arrays; -import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Map.Entry; public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoader { @@ -60,22 +56,18 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad private final ServerClient serverClient; private final AnalysisMode analysisMode; - private final SnapshotDataDao dao; private final DatabaseSession session; - public DefaultProjectReferentialsLoader(DatabaseSession session, ServerClient serverClient, AnalysisMode analysisMode, - SnapshotDataDao dao) { + public DefaultProjectReferentialsLoader(DatabaseSession session, ServerClient serverClient, AnalysisMode analysisMode) { this.session = session; this.serverClient = serverClient; this.analysisMode = analysisMode; - this.dao = dao; } public DefaultProjectReferentialsLoader(ServerClient serverClient, AnalysisMode analysisMode) { this.session = null; this.serverClient = serverClient; this.analysisMode = analysisMode; - this.dao = null; } @Override @@ -93,9 +85,9 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad if (session != null) { for (ProjectDefinition module : reactor.getProjects()) { - for (Map.Entry hashByPaths : hashByRelativePath(module.getKeyWithBranch()).entrySet()) { - String path = hashByPaths.getKey(); - String hash = hashByPaths.getValue(); + for (Entry fileDataByPaths : ref.fileDataByPath(module.getKeyWithBranch()).entrySet()) { + String path = fileDataByPaths.getKey(); + FileData fileData = fileDataByPaths.getValue(); String lastCommits = null; String revisions = null; String authors = null; @@ -110,7 +102,7 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad authors = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_AUTHORS_BY_LINE); } } - ref.addFileData(module.getKeyWithBranch(), path, new FileData(hash, authors == null, lastCommits, revisions, authors)); + ref.addFileData(module.getKeyWithBranch(), path, new FileData(fileData.hash(), authors == null, lastCommits, revisions, authors)); } } ref.setLastAnalysisDate(lastSnapshotCreationDate(projectKey)); @@ -118,20 +110,6 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad return ref; } - public Map hashByRelativePath(String projectKey) { - Map map = Maps.newHashMap(); - Collection selectSnapshotData = dao.selectSnapshotDataByComponentKey( - projectKey, - Arrays.asList(SnapshotDataTypes.FILE_HASHES) - ); - if (!selectSnapshotData.isEmpty()) { - SnapshotDataDto snapshotDataDto = selectSnapshotData.iterator().next(); - String data = snapshotDataDto.getData(); - map = KeyValueFormat.parse(data); - } - return map; - } - public List query(String resourceKey, String... metricKeys) { StringBuilder sb = new StringBuilder(); Map params = Maps.newHashMap(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java index 98598f57f33..a7af5621465 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java @@ -91,7 +91,6 @@ import org.sonar.batch.scan.filesystem.InputFileBuilderFactory; import org.sonar.batch.scan.filesystem.LanguageDetectionFactory; import org.sonar.batch.scan.filesystem.ModuleFileSystemInitializer; import org.sonar.batch.scan.filesystem.ModuleInputFileCache; -import org.sonar.batch.scan.filesystem.PreviousFileHashLoader; import org.sonar.batch.scan.filesystem.ProjectFileSystemAdapter; import org.sonar.batch.scan.filesystem.StatusDetectionFactory; import org.sonar.batch.scan.maven.MavenPluginsConfigurator; @@ -162,7 +161,6 @@ public class ModuleScanContainer extends ComponentContainer { InputFileBuilderFactory.class, StatusDetectionFactory.class, LanguageDetectionFactory.class, - PreviousFileHashLoader.class, FileIndexer.class, ComponentIndexer.class, LanguageVerifier.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index a1f115568b6..397e074d546 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -51,7 +51,6 @@ import org.sonar.batch.index.DefaultIndex; import org.sonar.batch.index.DependencyPersister; import org.sonar.batch.index.DuplicationPersister; import org.sonar.batch.index.EventPersister; -import org.sonar.batch.index.FileHashesPersister; import org.sonar.batch.index.LinkPersister; import org.sonar.batch.index.MeasurePersister; import org.sonar.batch.index.ResourceCache; @@ -146,7 +145,6 @@ public class ProjectScanContainer extends ComponentContainer { Caches.class, ResourceCache.class, ComponentDataCache.class, - FileHashesPersister.class, // file system InputPathCache.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java deleted file mode 100644 index 79b1019e362..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.batch.scan.filesystem; - -import com.google.common.collect.Maps; -import org.sonar.api.BatchComponent; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.components.PastSnapshot; -import org.sonar.batch.components.PastSnapshotFinder; -import org.sonar.batch.index.ResourceCache; -import org.sonar.core.source.SnapshotDataTypes; -import org.sonar.core.source.db.SnapshotDataDao; -import org.sonar.core.source.db.SnapshotDataDto; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - -public class PreviousFileHashLoader implements BatchComponent { - - private final SnapshotDataDao dao; - private final PastSnapshotFinder pastSnapshotFinder; - private final Project project; - private final ResourceCache resourceCache; - - public PreviousFileHashLoader(Project project, ResourceCache resourceCache, SnapshotDataDao dao, PastSnapshotFinder pastSnapshotFinder) { - this.project = project; - this.resourceCache = resourceCache; - this.dao = dao; - this.pastSnapshotFinder = pastSnapshotFinder; - } - - /** - * Extract hash of the files parsed during the previous analysis - */ - public Map hashByRelativePath() { - Snapshot snapshot = resourceCache.get(project.getEffectiveKey()).snapshot(); - Map map = Maps.newHashMap(); - PastSnapshot pastSnapshot = pastSnapshotFinder.findPreviousAnalysis(snapshot); - if (pastSnapshot.isRelatedToSnapshot()) { - Collection selectSnapshotData = dao.selectSnapshotData( - pastSnapshot.getProjectSnapshot().getId().longValue(), - Arrays.asList(SnapshotDataTypes.FILE_HASHES) - ); - if (!selectSnapshotData.isEmpty()) { - SnapshotDataDto snapshotDataDto = selectSnapshotData.iterator().next(); - String data = snapshotDataDto.getData(); - map = KeyValueFormat.parse(data); - } - } - return map; - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java deleted file mode 100644 index 5d01dde9045..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.batch.index; - -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Project; -import org.sonar.core.persistence.AbstractDaoTestCase; -import org.sonar.core.source.SnapshotDataTypes; -import org.sonar.core.source.db.SnapshotDataDao; - -public class FileHashesPersisterTest extends AbstractDaoTestCase { - - @ClassRule - public static TemporaryFolder temp = new TemporaryFolder(); - - ResourceCache resourceCache; - ComponentDataCache data; - Caches caches; - - @Before - public void start() throws Exception { - resourceCache = new ResourceCache(); - caches = CachesTest.createCacheOnTemp(temp); - caches.start(); - } - - @After - public void stop() { - caches.stop(); - } - - @Test - public void should_persist_component_data() throws Exception { - setupData("should_persist_component_data"); - Snapshot snapshot = new Snapshot(); - snapshot.setId(100); - snapshot.setResourceId(200); - resourceCache.add(new Project("myProject").setId(200), null).setSnapshot(snapshot); - - data = new ComponentDataCache(caches); - data.setStringData("myProject", SnapshotDataTypes.FILE_HASHES, "org/struts/Action.java=123ABC"); - - SnapshotDataDao dataDao = new SnapshotDataDao(getMyBatis()); - FileHashesPersister persister = new FileHashesPersister(data, resourceCache, dataDao, getMyBatis()); - persister.persist(); - - checkTables("should_persist_component_data", new String[] {"id", "created_at", "updated_at"}, "snapshot_data"); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java index 9da2dbf5cb7..2a66a09cc59 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java @@ -29,7 +29,6 @@ import org.sonar.batch.bootstrap.AnalysisMode; import org.sonar.batch.bootstrap.ServerClient; import org.sonar.batch.bootstrap.TaskProperties; import org.sonar.batch.rule.ModuleQProfiles; -import org.sonar.core.source.db.SnapshotDataDao; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; @@ -50,7 +49,7 @@ public class DefaultProjectReferentialsLoaderTest { public void prepare() { serverClient = mock(ServerClient.class); analysisMode = mock(AnalysisMode.class); - loader = new DefaultProjectReferentialsLoader(mock(DatabaseSession.class), serverClient, analysisMode, mock(SnapshotDataDao.class)); + loader = new DefaultProjectReferentialsLoader(mock(DatabaseSession.class), serverClient, analysisMode); loader = spy(loader); doReturn(null).when(loader).lastSnapshotCreationDate(anyString()); when(serverClient.request(anyString())).thenReturn("{}"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java deleted file mode 100644 index efcd5b3894d..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.batch.scan.filesystem; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Project; -import org.sonar.batch.components.PastSnapshot; -import org.sonar.batch.components.PastSnapshotFinder; -import org.sonar.batch.index.ResourceCache; -import org.sonar.core.source.SnapshotDataTypes; -import org.sonar.core.source.db.SnapshotDataDao; -import org.sonar.core.source.db.SnapshotDataDto; - -import java.util.Arrays; -import java.util.Date; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class PreviousFileHashLoaderTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class); - private Snapshot snapshot = mock(Snapshot.class); - private SnapshotDataDao snapshotDataDao = mock(SnapshotDataDao.class); - private Project project = new Project("foo"); - private ResourceCache resourceCache; - private PreviousFileHashLoader loader; - - @Before - public void prepare() { - resourceCache = new ResourceCache(); - resourceCache.add(project, null).setSnapshot(snapshot); - loader = new PreviousFileHashLoader(project, resourceCache, snapshotDataDao, pastSnapshotFinder); - } - - @Test - public void should_return_null_if_no_previous_snapshot() throws Exception { - when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(new PastSnapshot("foo")); - - Map hashByRelativePath = loader.hashByRelativePath(); - assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull(); - } - - @Test - public void should_return_null_if_no_remote_hashes() throws Exception { - Snapshot previousSnapshot = mock(Snapshot.class); - PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot); - when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot); - - Map hashByRelativePath = loader.hashByRelativePath(); - assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull(); - } - - @Test - public void should_return_remote_hash() throws Exception { - Snapshot previousSnapshot = mock(Snapshot.class); - when(previousSnapshot.getId()).thenReturn(123); - PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot); - when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot); - - SnapshotDataDto snapshotDataDto = new SnapshotDataDto(); - snapshotDataDto.setData("src/main/java/foo/Bar.java=abcd1234"); - when(snapshotDataDao.selectSnapshotData(123, Arrays.asList(SnapshotDataTypes.FILE_HASHES))) - .thenReturn(Arrays.asList(snapshotDataDto)); - - Map hashByRelativePath = loader.hashByRelativePath(); - assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isEqualTo("abcd1234"); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java index b7436623a00..be4df84ff01 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java @@ -42,7 +42,6 @@ import org.sonar.core.resource.ResourceIndexerDao; import org.sonar.core.resource.ResourceKeyUpdaterDao; import org.sonar.core.rule.RuleDao; import org.sonar.core.source.db.FileSourceDao; -import org.sonar.core.source.db.SnapshotDataDao; import org.sonar.core.technicaldebt.db.CharacteristicDao; import org.sonar.core.template.LoadedTemplateDao; import org.sonar.core.user.AuthorDao; @@ -91,7 +90,6 @@ public final class DaoUtils { RoleDao.class, RuleDao.class, SemaphoreDao.class, - SnapshotDataDao.class, UserDao.class ); } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 0c9e7238831..7e8d536c4d7 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 767; + public static final int LAST_VERSION = 768; /** * List of all the tables.n @@ -84,7 +84,6 @@ public class DatabaseVersion implements BatchComponent, ServerComponent { "semaphores", "schema_migrations", "snapshots", - "snapshot_data", "users", "user_roles", "widgets", diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 922ac8e7be2..62e559e59fc 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -25,7 +25,11 @@ import com.google.common.io.Closeables; import org.apache.ibatis.builder.xml.XMLMapperBuilder; import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.Environment; -import org.apache.ibatis.session.*; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.ibatis.type.JdbcType; import org.slf4j.LoggerFactory; @@ -43,7 +47,14 @@ import org.sonar.core.component.db.SnapshotMapper; import org.sonar.core.computation.db.AnalysisReportDto; import org.sonar.core.computation.db.AnalysisReportMapper; import org.sonar.core.config.Logback; -import org.sonar.core.dashboard.*; +import org.sonar.core.dashboard.ActiveDashboardDto; +import org.sonar.core.dashboard.ActiveDashboardMapper; +import org.sonar.core.dashboard.DashboardDto; +import org.sonar.core.dashboard.DashboardMapper; +import org.sonar.core.dashboard.WidgetDto; +import org.sonar.core.dashboard.WidgetMapper; +import org.sonar.core.dashboard.WidgetPropertyDto; +import org.sonar.core.dashboard.WidgetPropertyMapper; import org.sonar.core.dependency.DependencyDto; import org.sonar.core.dependency.DependencyMapper; import org.sonar.core.dependency.ResourceSnapshotDto; @@ -52,11 +63,32 @@ import org.sonar.core.duplication.DuplicationMapper; import org.sonar.core.duplication.DuplicationUnitDto; import org.sonar.core.graph.jdbc.GraphDto; import org.sonar.core.graph.jdbc.GraphDtoMapper; -import org.sonar.core.issue.db.*; -import org.sonar.core.measure.db.*; +import org.sonar.core.issue.db.ActionPlanDto; +import org.sonar.core.issue.db.ActionPlanMapper; +import org.sonar.core.issue.db.ActionPlanStatsDto; +import org.sonar.core.issue.db.ActionPlanStatsMapper; +import org.sonar.core.issue.db.IssueChangeDto; +import org.sonar.core.issue.db.IssueChangeMapper; +import org.sonar.core.issue.db.IssueDto; +import org.sonar.core.issue.db.IssueFilterDto; +import org.sonar.core.issue.db.IssueFilterFavouriteDto; +import org.sonar.core.issue.db.IssueFilterFavouriteMapper; +import org.sonar.core.issue.db.IssueFilterMapper; +import org.sonar.core.issue.db.IssueMapper; +import org.sonar.core.measure.db.MeasureDto; +import org.sonar.core.measure.db.MeasureFilterDto; +import org.sonar.core.measure.db.MeasureFilterMapper; +import org.sonar.core.measure.db.MeasureMapper; +import org.sonar.core.measure.db.MetricDto; +import org.sonar.core.measure.db.MetricMapper; import org.sonar.core.notification.db.NotificationQueueDto; import org.sonar.core.notification.db.NotificationQueueMapper; -import org.sonar.core.permission.*; +import org.sonar.core.permission.GroupWithPermissionDto; +import org.sonar.core.permission.PermissionTemplateDto; +import org.sonar.core.permission.PermissionTemplateGroupDto; +import org.sonar.core.permission.PermissionTemplateMapper; +import org.sonar.core.permission.PermissionTemplateUserDto; +import org.sonar.core.permission.UserWithPermissionDto; import org.sonar.core.persistence.dialect.Dialect; import org.sonar.core.persistence.migration.v44.Migration44Mapper; import org.sonar.core.persistence.migration.v45.Migration45Mapper; @@ -66,21 +98,44 @@ import org.sonar.core.properties.PropertyDto; import org.sonar.core.purge.IdUuidPair; import org.sonar.core.purge.PurgeMapper; import org.sonar.core.purge.PurgeableSnapshotDto; -import org.sonar.core.qualitygate.db.*; -import org.sonar.core.qualityprofile.db.*; -import org.sonar.core.resource.*; +import org.sonar.core.qualitygate.db.ProjectQgateAssociationDto; +import org.sonar.core.qualitygate.db.ProjectQgateAssociationMapper; +import org.sonar.core.qualitygate.db.QualityGateConditionDto; +import org.sonar.core.qualitygate.db.QualityGateConditionMapper; +import org.sonar.core.qualitygate.db.QualityGateDto; +import org.sonar.core.qualitygate.db.QualityGateMapper; +import org.sonar.core.qualityprofile.db.ActiveRuleDto; +import org.sonar.core.qualityprofile.db.ActiveRuleMapper; +import org.sonar.core.qualityprofile.db.ActiveRuleParamDto; +import org.sonar.core.qualityprofile.db.QualityProfileDto; +import org.sonar.core.qualityprofile.db.QualityProfileMapper; +import org.sonar.core.resource.ResourceDto; +import org.sonar.core.resource.ResourceIndexDto; +import org.sonar.core.resource.ResourceIndexerMapper; +import org.sonar.core.resource.ResourceKeyUpdaterMapper; +import org.sonar.core.resource.ResourceMapper; import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleMapper; import org.sonar.core.rule.RuleParamDto; import org.sonar.core.source.db.FileSourceMapper; -import org.sonar.core.source.db.SnapshotDataDto; -import org.sonar.core.source.db.SnapshotDataMapper; import org.sonar.core.technicaldebt.db.CharacteristicDto; import org.sonar.core.technicaldebt.db.CharacteristicMapper; import org.sonar.core.technicaldebt.db.RequirementMigrationDto; import org.sonar.core.template.LoadedTemplateDto; import org.sonar.core.template.LoadedTemplateMapper; -import org.sonar.core.user.*; +import org.sonar.core.user.AuthorDto; +import org.sonar.core.user.AuthorMapper; +import org.sonar.core.user.GroupDto; +import org.sonar.core.user.GroupMapper; +import org.sonar.core.user.GroupMembershipDto; +import org.sonar.core.user.GroupMembershipMapper; +import org.sonar.core.user.GroupRoleDto; +import org.sonar.core.user.RoleMapper; +import org.sonar.core.user.UserDto; +import org.sonar.core.user.UserGroupDto; +import org.sonar.core.user.UserGroupMapper; +import org.sonar.core.user.UserMapper; +import org.sonar.core.user.UserRoleDto; import java.io.InputStream; @@ -166,7 +221,6 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "IssueChange", IssueChangeDto.class); loadAlias(conf, "IssueFilter", IssueFilterDto.class); loadAlias(conf, "IssueFilterFavourite", IssueFilterFavouriteDto.class); - loadAlias(conf, "SnapshotData", SnapshotDataDto.class); loadAlias(conf, "ActionPlanIssue", ActionPlanDto.class); loadAlias(conf, "ActionPlanStats", ActionPlanStatsDto.class); loadAlias(conf, "PermissionTemplate", PermissionTemplateDto.class); @@ -196,7 +250,7 @@ public class MyBatis implements BatchComponent, ServerComponent { LoadedTemplateMapper.class, MeasureFilterMapper.class, Migration44Mapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class, ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceSnapshotMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, GroupMapper.class, UserGroupMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, - org.sonar.api.database.model.MeasureMapper.class, SnapshotDataMapper.class, FileSourceMapper.class, ActionPlanMapper.class, + org.sonar.api.database.model.MeasureMapper.class, FileSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class, NotificationQueueMapper.class, CharacteristicMapper.class, GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class, diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java index a61f4d8f081..8b1cbf45992 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java @@ -26,7 +26,6 @@ import org.sonar.api.utils.SonarException; import org.sonar.core.profiling.Profiling; import org.sonar.core.profiling.Profiling.Level; import org.sonar.core.profiling.StopWatch; -import org.sonar.core.source.SnapshotDataTypes; import javax.annotation.Nullable; import javax.sql.DataSource; @@ -100,31 +99,9 @@ public class PreviewDatabaseFactory implements ServerComponent { StringBuilder snapshotQuery = new StringBuilder() // All snapshots of root_project for alerts on differential periods .append("SELECT * FROM snapshots WHERE project_id=") - .append(projectId) - // Plus all last snapshots of all modules having hash data for partial analysis - .append(" UNION SELECT snap.* FROM snapshots snap") - .append(" INNER JOIN (") - .append(projectQuery(projectId, true)) - .append(") res") - .append(" ON snap.project_id=res.id") - .append(" INNER JOIN snapshot_data data") - .append(" ON snap.id=data.snapshot_id") - .append(" AND data.data_type='").append(SnapshotDataTypes.FILE_HASHES).append("'") - .append(" AND snap.islast=").append(database.getDialect().getTrueSqlValue()); + .append(projectId); template.copyTable(source, dest, "snapshots", snapshotQuery.toString()); - StringBuilder snapshotDataQuery = new StringBuilder() - .append("SELECT data.* FROM snapshot_data data") - .append(" INNER JOIN snapshots s") - .append(" ON s.id=data.snapshot_id") - .append(" AND s.islast=").append(database.getDialect().getTrueSqlValue()) - .append(" INNER JOIN (") - .append(projectQuery(projectId, true)) - .append(") res") - .append(" ON data.resource_id=res.id") - .append(" AND data.data_type='").append(SnapshotDataTypes.FILE_HASHES).append("'"); - template.copyTable(source, dest, "snapshot_data", snapshotDataQuery.toString()); - // All measures of snapshots of root project for alerts on differential periods template.copyTable(source, dest, "project_measures", "SELECT m.* FROM project_measures m INNER JOIN snapshots s on m.snapshot_id=s.id " + "WHERE s.project_id=" + projectId); diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java index 3bdb2248a16..546cf8c3d33 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -182,8 +182,6 @@ class PurgeCommands { deleteSnapshotGraphs(snapshotIdsPartition); - deleteSnapshotData(snapshotIdsPartition); - profiler.start("deleteSnapshot (snapshots)"); for (List partSnapshotIds : snapshotIdsPartition) { purgeMapper.deleteSnapshot(partSnapshotIds); @@ -207,8 +205,6 @@ class PurgeCommands { deleteSnapshotGraphs(snapshotIdsPartition); - deleteSnapshotData(snapshotIdsPartition); - profiler.start("deleteSnapshotWastedMeasures (project_measures)"); List metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData(); for (List partSnapshotIds : snapshotIdsPartition) { @@ -225,15 +221,6 @@ class PurgeCommands { profiler.stop(); } - private void deleteSnapshotData(final List> snapshotIdsPartition) { - profiler.start("deleteSnapshotData (snapshot_data)"); - for (List partSnapshotIds : snapshotIdsPartition) { - purgeMapper.deleteSnapshotData(partSnapshotIds); - } - session.commit(); - profiler.stop(); - } - private void deleteSnapshotGraphs(final List> snapshotIdsPartition) { profiler.start("deleteSnapshotGraphs (graphs)"); for (List partSnapshotIds : snapshotIdsPartition) { diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index 81e0d2d973e..54cffca45c3 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -50,8 +50,6 @@ public interface PurgeMapper { void deleteSnapshotGraphs(@Param("snapshotIds") List snapshotIds); - void deleteSnapshotData(@Param("snapshotIds") List snapshotIds); - List selectMetricIdsWithoutHistoricalData(); void deleteSnapshotWastedMeasures(@Param("snapshotIds") List snapshotIds, @Param("mids") List metricIds); diff --git a/sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java b/sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java index 745b21b8c97..96d11d51652 100644 --- a/sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java +++ b/sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java @@ -24,10 +24,4 @@ public interface SnapshotDataTypes { String SYNTAX_HIGHLIGHTING = "highlight_syntax"; String SYMBOL_HIGHLIGHTING = "symbol"; - - /** - * Key-values [relative path, hash] of all files. Stored on modules. - * @since 4.0 - */ - String FILE_HASHES = "file_hashes"; } diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDao.java b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDao.java deleted file mode 100644 index 0b9ad5040d2..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDao.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.core.source.db; - -import org.apache.ibatis.session.SqlSession; -import org.sonar.api.BatchComponent; -import org.sonar.api.ServerComponent; -import org.sonar.core.persistence.MyBatis; - -import java.util.Collection; -import java.util.List; - -/** - * @since 3.6 - */ -public class SnapshotDataDao implements BatchComponent, ServerComponent { - - private final MyBatis mybatis; - - public SnapshotDataDao(MyBatis mybatis) { - this.mybatis = mybatis; - } - - public Collection selectSnapshotData(long snapshotId, List dataTypes) { - SqlSession session = mybatis.openSession(false); - try { - SnapshotDataMapper mapper = session.getMapper(SnapshotDataMapper.class); - return mapper.selectSnapshotData(snapshotId, dataTypes); - } finally { - MyBatis.closeQuietly(session); - } - } - - - public Collection selectSnapshotDataByComponentKey(String componentKey, List dataTypes) { - SqlSession session = mybatis.openSession(false); - try { - return selectSnapshotDataByComponentKey(componentKey, dataTypes, session); - } finally { - MyBatis.closeQuietly(session); - } - } - - public Collection selectSnapshotDataByComponentKey(String componentKey, List dataTypes, SqlSession session) { - SnapshotDataMapper mapper = session.getMapper(SnapshotDataMapper.class); - return mapper.selectSnapshotDataByComponentKey(componentKey, dataTypes); - } - - void insert(SnapshotDataDto snapshotData) { - SqlSession session = mybatis.openSession(false); - try { - insert(session, snapshotData); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } - - public void insert(SqlSession session, SnapshotDataDto snapshotData) { - SnapshotDataMapper mapper = session.getMapper(SnapshotDataMapper.class); - mapper.insert(snapshotData); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDto.java b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDto.java deleted file mode 100644 index 8770b507487..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataDto.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.core.source.db; - -/** - * @since 3.6 - */ -public class SnapshotDataDto { - - private long id; - private long snapshotId; - private long resourceId; - private String data; - private String dataType; - - public long getSnapshotId() { - return snapshotId; - } - - public long getResourceId() { - return resourceId; - } - - public String getData() { - return data; - } - - public String getDataType() { - return dataType; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public void setSnapshotId(long snapshotId) { - this.snapshotId = snapshotId; - } - - public void setResourceId(long resourceId) { - this.resourceId = resourceId; - } - - public void setData(String data) { - this.data = data; - } - - public void setDataType(String dataType) { - this.dataType = dataType; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataMapper.java b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataMapper.java deleted file mode 100644 index d840bb3c42a..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotDataMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.core.source.db; - -import org.apache.ibatis.annotations.Param; - -import java.util.Collection; -import java.util.List; - -/** - * @since 3.6 - */ -public interface SnapshotDataMapper { - - void insert(SnapshotDataDto snapshotData); - - Collection selectSnapshotData(@Param("sid") long snapshotId, @Param("dataTypes") List dataTypes); - - Collection selectSnapshotDataByComponentKey(@Param("componentKey") String componentKey, @Param("dataTypes") List dataTypes); -} diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index c5d83d90316..39ac9d738fc 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -296,6 +296,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('764'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('765'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('766'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('767'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('768'); 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', '1418215735482', '1418215735482', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 8a6fae8a07f..835280c1787 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -497,16 +497,6 @@ CREATE TABLE "ISSUE_FILTER_FAVOURITES" ( "CREATED_AT" TIMESTAMP ); -CREATE TABLE "SNAPSHOT_DATA" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "SNAPSHOT_ID" INTEGER, - "RESOURCE_ID" INTEGER, - "SNAPSHOT_DATA" VARCHAR(16777215), - "DATA_TYPE" VARCHAR(50), - "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP, -); - CREATE TABLE "PERMISSION_TEMPLATES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(100) NOT NULL, @@ -712,8 +702,6 @@ CREATE UNIQUE INDEX "QUALITY_GATES_UNIQUE" ON "QUALITY_GATES" ("NAME"); CREATE UNIQUE INDEX "ACTIVE_RULES_UNIQUE" ON "ACTIVE_RULES" ("PROFILE_ID","RULE_ID"); -CREATE INDEX "SNAPSHOT_DATA_RESOURCE_IDS" ON "SNAPSHOT_DATA" ("RESOURCE_ID"); - CREATE UNIQUE INDEX "PROFILE_UNIQUE_KEY" ON "RULES_PROFILES" ("KEE"); CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID"); diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 95aeeebeb3c..c3464bee196 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -270,13 +270,6 @@ update snapshots set islast=${_false} where project_id=#{id} - - delete from snapshot_data where snapshot_id in - - #{snapshotId} - - - delete from issue_changes ic where exists (select * from issues i where i.kee=ic.issue_key and i.component_id in diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java index 1df75d5fade..de7a7241fb1 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java @@ -32,6 +32,7 @@ import org.sonar.api.config.Settings; import org.sonar.core.profiling.Profiling; import javax.sql.DataSource; + import java.io.File; import java.io.IOException; import java.sql.Connection; @@ -110,8 +111,7 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { dataSource = createDatabase(database); assertThat(countRows("issues")).isEqualTo(1); assertThat(countRows("projects")).isEqualTo(4); - assertThat(countRows("snapshots")).isEqualTo(4); - assertThat(countRows("snapshot_data")).isEqualTo(2); + assertThat(countRows("snapshots")).isEqualTo(2); assertThat(countRows("project_measures")).isEqualTo(4); } diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java index 704c13903db..42fa52604aa 100644 --- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java @@ -52,8 +52,7 @@ public class PurgeCommandsTest extends AbstractDaoTestCase { } finally { MyBatis.closeQuietly(session); } - checkTables("shouldDeleteSnapshot", - "snapshots", "project_measures", "duplications_index", "events", "dependencies", "snapshot_data"); + checkTables("shouldDeleteSnapshot", "snapshots", "project_measures", "duplications_index", "events", "dependencies"); } /** @@ -84,7 +83,7 @@ public class PurgeCommandsTest extends AbstractDaoTestCase { MyBatis.closeQuietly(session); } checkTables("shouldPurgeSnapshot", - "snapshots", "project_measures", "duplications_index", "events", "dependencies", "snapshot_data"); + "snapshots", "project_measures", "duplications_index", "events", "dependencies"); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotDataDaoTest.java b/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotDataDaoTest.java deleted file mode 100644 index 5f567aa414c..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotDataDaoTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.core.source.db; - -import com.google.common.collect.Lists; -import org.junit.Before; -import org.junit.Test; -import org.sonar.core.persistence.AbstractDaoTestCase; - -import java.util.Collection; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SnapshotDataDaoTest extends AbstractDaoTestCase { - - private SnapshotDataDao dao; - - @Before - public void createDao() { - dao = new SnapshotDataDao(getMyBatis()); - setupData("shared"); - } - - @Test - public void select_snapshot_data_by_snapshot_id() throws Exception { - Collection data = dao.selectSnapshotData(10L, Lists.newArrayList("highlight_syntax", "symbol")); - - assertThat(data).extracting("snapshotId").containsOnly(10L, 10L); - assertThat(data).extracting("dataType").containsOnly("highlight_syntax", "symbol"); - assertThat(data).extracting("data").containsOnly("0,10,k;", "20,25,20,35,45;"); - } - - @Test - public void serialize_snapshot_data() throws Exception { - String data = "0,10,k;"; - String dataType = "highlight_syntax"; - - SnapshotDataDto dto = new SnapshotDataDto(); - dto.setResourceId(1L); - dto.setSnapshotId(11L); - dto.setData(data); - dto.setDataType(dataType); - - dao.insert(dto); - - Collection serializedData = dao.selectSnapshotData(11L, Lists.newArrayList("highlight_syntax")); - - assertThat(serializedData).extracting("snapshotId").containsOnly(11L); - assertThat(serializedData).extracting("dataType").containsOnly(dataType); - assertThat(serializedData).extracting("data").containsOnly(data); - } - - @Test - public void select_snapshot_data_by_project_id() throws Exception { - Collection data = dao.selectSnapshotDataByComponentKey("org.apache.struts:struts:Dispatcher", Lists.newArrayList("highlight_syntax", "symbol")); - - assertThat(data).isNotEmpty(); - assertThat(data).extracting("snapshotId").containsOnly(10L, 10L); - assertThat(data).extracting("dataType").containsOnly("highlight_syntax", "symbol"); - assertThat(data).extracting("data").containsOnly("0,10,k;", "20,25,20,35,45;"); - } -} diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/multi-modules-with-issues.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/multi-modules-with-issues.xml index 8ec9c6a4e0e..121c528c366 100644 --- a/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/multi-modules-with-issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/multi-modules-with-issues.xml @@ -40,13 +40,6 @@ - - - - - - - diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml index d2711e08506..0cbd194c972 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml @@ -29,7 +29,4 @@ event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/> - - diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml index 2ff3064a175..972a17da0eb 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml @@ -28,8 +28,6 @@ event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/> - @@ -63,8 +61,6 @@ event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/> - diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml index d48051136b5..b7e8e2ecc67 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml @@ -88,7 +88,4 @@ Note that measures, events and reviews are not deleted. - - diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml index 262efa6af05..2eac727f667 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml @@ -34,9 +34,6 @@ - - - - -- 2.39.5