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;
DirectoriesDecorator.class,
FilesDecorator.class,
ManualMeasureDecorator.class,
- FileHashSensor.class,
// time machine
TendencyDecorator.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.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<String, String> 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();
- }
-}
+++ /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.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.<InputFile>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.<InputFile>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.<InputFile>emptyList());
-
- SensorContext sensorContext = mock(SensorContext.class);
- sensor.analyse(project, sensorContext);
-
- verifyZeroInteractions(componentDataCache);
- verifyZeroInteractions(sensorContext);
- }
-}
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"
--- /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.
+#
+
+#
+# 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
+++ /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.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();
- }
- }
-}
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 {
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
if (session != null) {
for (ProjectDefinition module : reactor.getProjects()) {
- for (Map.Entry<String, String> hashByPaths : hashByRelativePath(module.getKeyWithBranch()).entrySet()) {
- String path = hashByPaths.getKey();
- String hash = hashByPaths.getValue();
+ for (Entry<String, FileData> fileDataByPaths : ref.fileDataByPath(module.getKeyWithBranch()).entrySet()) {
+ String path = fileDataByPaths.getKey();
+ FileData fileData = fileDataByPaths.getValue();
String lastCommits = null;
String revisions = null;
String authors = null;
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));
return ref;
}
- public Map<String, String> hashByRelativePath(String projectKey) {
- Map<String, String> map = Maps.newHashMap();
- Collection<SnapshotDataDto> 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<Object[]> query(String resourceKey, String... metricKeys) {
StringBuilder sb = new StringBuilder();
Map<String, Object> params = Maps.newHashMap();
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;
InputFileBuilderFactory.class,
StatusDetectionFactory.class,
LanguageDetectionFactory.class,
- PreviousFileHashLoader.class,
FileIndexer.class,
ComponentIndexer.class,
LanguageVerifier.class,
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;
Caches.class,
ResourceCache.class,
ComponentDataCache.class,
- FileHashesPersister.class,
// file system
InputPathCache.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.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<String, String> hashByRelativePath() {
- Snapshot snapshot = resourceCache.get(project.getEffectiveKey()).snapshot();
- Map<String, String> map = Maps.newHashMap();
- PastSnapshot pastSnapshot = pastSnapshotFinder.findPreviousAnalysis(snapshot);
- if (pastSnapshot.isRelatedToSnapshot()) {
- Collection<SnapshotDataDto> 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;
- }
-
-}
+++ /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.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");
- }
-}
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;
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("{}");
+++ /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.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<String, String> 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<String, String> 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<String, String> hashByRelativePath = loader.hashByRelativePath();
- assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isEqualTo("abcd1234");
- }
-}
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;
RoleDao.class,
RuleDao.class,
SemaphoreDao.class,
- SnapshotDataDao.class,
UserDao.class
);
}
*/
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
"semaphores",
"schema_migrations",
"snapshots",
- "snapshot_data",
"users",
"user_roles",
"widgets",
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;
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;
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;
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;
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);
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,
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;
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);
deleteSnapshotGraphs(snapshotIdsPartition);
- deleteSnapshotData(snapshotIdsPartition);
-
profiler.start("deleteSnapshot (snapshots)");
for (List<Long> partSnapshotIds : snapshotIdsPartition) {
purgeMapper.deleteSnapshot(partSnapshotIds);
deleteSnapshotGraphs(snapshotIdsPartition);
- deleteSnapshotData(snapshotIdsPartition);
-
profiler.start("deleteSnapshotWastedMeasures (project_measures)");
List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
for (List<Long> partSnapshotIds : snapshotIdsPartition) {
profiler.stop();
}
- private void deleteSnapshotData(final List<List<Long>> snapshotIdsPartition) {
- profiler.start("deleteSnapshotData (snapshot_data)");
- for (List<Long> partSnapshotIds : snapshotIdsPartition) {
- purgeMapper.deleteSnapshotData(partSnapshotIds);
- }
- session.commit();
- profiler.stop();
- }
-
private void deleteSnapshotGraphs(final List<List<Long>> snapshotIdsPartition) {
profiler.start("deleteSnapshotGraphs (graphs)");
for (List<Long> partSnapshotIds : snapshotIdsPartition) {
void deleteSnapshotGraphs(@Param("snapshotIds") List<Long> snapshotIds);
- void deleteSnapshotData(@Param("snapshotIds") List<Long> snapshotIds);
-
List<Long> selectMetricIdsWithoutHistoricalData();
void deleteSnapshotWastedMeasures(@Param("snapshotIds") List<Long> snapshotIds, @Param("mids") List<Long> metricIds);
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";
}
+++ /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.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<SnapshotDataDto> selectSnapshotData(long snapshotId, List<String> dataTypes) {
- SqlSession session = mybatis.openSession(false);
- try {
- SnapshotDataMapper mapper = session.getMapper(SnapshotDataMapper.class);
- return mapper.selectSnapshotData(snapshotId, dataTypes);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
-
- public Collection<SnapshotDataDto> selectSnapshotDataByComponentKey(String componentKey, List<String> dataTypes) {
- SqlSession session = mybatis.openSession(false);
- try {
- return selectSnapshotDataByComponentKey(componentKey, dataTypes, session);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public Collection<SnapshotDataDto> selectSnapshotDataByComponentKey(String componentKey, List<String> 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);
- }
-}
+++ /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.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;
- }
-}
+++ /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.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<SnapshotDataDto> selectSnapshotData(@Param("sid") long snapshotId, @Param("dataTypes") List<String> dataTypes);
-
- Collection<SnapshotDataDto> selectSnapshotDataByComponentKey(@Param("componentKey") String componentKey, @Param("dataTypes") List<String> dataTypes);
-}
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;
"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,
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");
update snapshots set islast=${_false} where project_id=#{id}
</update>
- <delete id="deleteSnapshotData" parameterType="map">
- delete from snapshot_data where snapshot_id in
- <foreach collection="snapshotIds" open="(" close=")" item="snapshotId" separator=",">
- #{snapshotId}
- </foreach>
- </delete>
-
<delete id="deleteResourceIssueChanges" parameterType="map">
delete from issue_changes ic
where exists (select * from issues i where i.kee=ic.issue_key and i.component_id in
import org.sonar.core.profiling.Profiling;
import javax.sql.DataSource;
+
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
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);
}
} finally {
MyBatis.closeQuietly(session);
}
- checkTables("shouldDeleteSnapshot",
- "snapshots", "project_measures", "duplications_index", "events", "dependencies", "snapshot_data");
+ checkTables("shouldDeleteSnapshot", "snapshots", "project_measures", "duplications_index", "events", "dependencies");
}
/**
MyBatis.closeQuietly(session);
}
checkTables("shouldPurgeSnapshot",
- "snapshots", "project_measures", "duplications_index", "events", "dependencies", "snapshot_data");
+ "snapshots", "project_measures", "duplications_index", "events", "dependencies");
}
@Test
+++ /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.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<SnapshotDataDto> 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<SnapshotDataDto> 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<SnapshotDataDto> 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;");
- }
-}
<snapshots id="3012" project_id="302" root_project_id="300" root_snapshot_id="3010" path="3010." islast="[false]"/>
<snapshots id="3013" project_id="303" root_project_id="300" root_snapshot_id="3010" path="3010.3011." islast="[false]"/>
- <snapshot_data id="1" snapshot_id="3001" resource_id="301" snapshot_data="foo=AB12" data_type="file_hashes" />
- <snapshot_data id="2" snapshot_id="3001" resource_id="301" snapshot_data="bar" data_type="other" />
- <snapshot_data id="3" snapshot_id="3002" resource_id="302" snapshot_data="bar=DC12" data_type="file_hashes" />
-
- <snapshot_data id="4" snapshot_id="3011" resource_id="301" snapshot_data="foo=CD34" data_type="file_hashes" />
- <snapshot_data id="5" snapshot_id="3012" resource_id="302" snapshot_data="bar=EF78" data_type="file_hashes" />
-
<project_measures id="1" value="12" metric_id="1" snapshot_id="3000" />
<project_measures id="2" value="5" metric_id="1" snapshot_id="3001" />
<project_measures id="3" value="7" metric_id="1" snapshot_id="3002" />
event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/>
<duplications_index id="1" project_snapshot_id="1" snapshot_id="1" hash="bb" index_in_file="0" start_line="0"
end_line="0"/>
- <snapshot_data id="1" resource_id="1" snapshot_id="1" snapshot_data="0,10,k" data_type="highlight_syntax"
- created_at="[null]" updated_at="[null]"/>
-
</dataset>
event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/>
<duplications_index id="1" project_snapshot_id="1" snapshot_id="1" hash="bb" index_in_file="0" start_line="0"
end_line="0"/>
- <snapshot_data id="1" resource_id="1" snapshot_id="1" snapshot_data="0,10,k" data_type="highlight_syntax"
- created_at="[null]" updated_at="[null]"/>
<!-- snapshot to remove, id 5 on resource 5-->
event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/>
<duplications_index id="2" project_snapshot_id="5" snapshot_id="5" hash="bb" index_in_file="0" start_line="0"
end_line="0"/>
- <snapshot_data id="2" resource_id="5" snapshot_id="5" snapshot_data="0,10,k" data_type="highlight_syntax"
- created_at="[null]" updated_at="[null]"/>
</dataset>
<duplications_index id="2" project_snapshot_id="2" snapshot_id="2"
hash="bb" index_in_file="0" start_line="0" end_line="0"/>
- <snapshot_data id="2" resource_id="5" snapshot_id="5" snapshot_data="0,10,k" data_type="highlight_syntax"
- created_at="[null]" updated_at="[null]"/>
-
</dataset>
<duplications_index id="1" project_snapshot_id="1" snapshot_id="1"
hash="bb" index_in_file="0" start_line="0" end_line="0"/>
- <snapshot_data id="1" resource_id="1" snapshot_id="1" snapshot_data="0,10,k" data_type="highlight_syntax"
- created_at="[null]" updated_at="[null]"/>
-
<!-- The following is not purged but is kept for DBUnit -->
<snapshots id="2"
<duplications_index id="2" project_snapshot_id="2" snapshot_id="2"
hash="bb" index_in_file="0" start_line="0" end_line="0"/>
- <snapshot_data id="2" resource_id="5" snapshot_id="5" snapshot_data="0,10,k" data_type="highlight_syntax"
- created_at="[null]" updated_at="[null]"/>
-
</dataset>