diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-02 17:56:08 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-02 22:09:29 +0100 |
commit | d05179c1879b20aeb0d38d1e025516e72babdee5 (patch) | |
tree | 4cde672fd6b6ad21863bd516dd739b4622207ab9 /sonar-batch | |
parent | 08e74cebd49de12780885e2d6427e56d624daa02 (diff) | |
download | sonarqube-d05179c1879b20aeb0d38d1e025516e72babdee5.tar.gz sonarqube-d05179c1879b20aeb0d38d1e025516e72babdee5.zip |
SONAR-5869 Remove persistence of highlighting and symbols in snapshot_data
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java (renamed from sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java) | 26 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java | 4 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java) | 11 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data-result.xml | 5 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data-result.xml | 4 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data.xml) | 0 |
6 files changed, 25 insertions, 25 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java index f53f82675a4..9ecc91bf0cf 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java @@ -22,18 +22,22 @@ package org.sonar.batch.index; import org.sonar.api.database.model.Snapshot; 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; import java.util.Map; -public class ComponentDataPersister implements ScanPersister { +/** + * 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 SnapshotCache snapshots; private final SnapshotDataDao dao; private final MyBatis mybatis; - public ComponentDataPersister(ComponentDataCache data, SnapshotCache snapshots, + public FileHashesPersister(ComponentDataCache data, SnapshotCache snapshots, SnapshotDataDao dao, MyBatis mybatis) { this.data = data; this.snapshots = snapshots; @@ -48,16 +52,14 @@ public class ComponentDataPersister implements ScanPersister { for (Map.Entry<String, Snapshot> componentEntry : snapshots.snapshots()) { String componentKey = componentEntry.getKey(); Snapshot snapshot = componentEntry.getValue(); - for (Cache.Entry<Data> dataEntry : data.entries(componentKey)) { - Data value = dataEntry.value(); - if (value != null) { - SnapshotDataDto dto = new SnapshotDataDto(); - dto.setSnapshotId(snapshot.getId()); - dto.setResourceId(snapshot.getResourceId()); - dto.setDataType(dataEntry.key()[1].toString()); - dto.setData(value.writeString()); - dao.insert(session, dto); - } + String fileHashesdata = data.getStringData(componentKey, SnapshotDataTypes.FILE_HASHES); + if (fileHashesdata != null) { + SnapshotDataDto dto = new SnapshotDataDto(); + dto.setSnapshotId(snapshot.getId()); + dto.setResourceId(snapshot.getResourceId()); + 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/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index b22723814e0..d9f23dc2a39 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 @@ -46,7 +46,7 @@ import org.sonar.batch.duplication.BlockCache; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.Caches; import org.sonar.batch.index.ComponentDataCache; -import org.sonar.batch.index.ComponentDataPersister; +import org.sonar.batch.index.FileHashesPersister; import org.sonar.batch.index.DefaultIndex; import org.sonar.batch.index.DefaultPersistenceManager; import org.sonar.batch.index.DefaultResourcePersister; @@ -154,7 +154,7 @@ public class ProjectScanContainer extends ComponentContainer { SnapshotCache.class, ResourceCache.class, ComponentDataCache.class, - ComponentDataPersister.class, + FileHashesPersister.class, DefaultUserFinder.class, // file system diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java index 1fef4414d61..29c9e0cef1e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java @@ -26,9 +26,10 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.database.model.Snapshot; import org.sonar.core.persistence.AbstractDaoTestCase; +import org.sonar.core.source.SnapshotDataTypes; import org.sonar.core.source.db.SnapshotDataDao; -public class ComponentDataPersisterTest extends AbstractDaoTestCase { +public class FileHashesPersisterTest extends AbstractDaoTestCase { @ClassRule public static TemporaryFolder temp = new TemporaryFolder(); @@ -54,15 +55,13 @@ public class ComponentDataPersisterTest extends AbstractDaoTestCase { Snapshot snapshot = new Snapshot(); snapshot.setId(100); snapshot.setResourceId(200); - snapshots.put("org/struts/Action.java", snapshot); + snapshots.put("myProject", snapshot); data = new ComponentDataCache(caches); - data.setStringData("org/struts/Action.java", "SYMBOL", "content of symbol"); - data.setStringData("org/struts/Action.java", "SYNTAX", "content of syntax"); - data.setStringData("org/struts/Other.java", "SYMBOL", "unregistered component, should not be persisted"); + data.setStringData("myProject", SnapshotDataTypes.FILE_HASHES, "org/struts/Action.java=123ABC"); SnapshotDataDao dataDao = new SnapshotDataDao(getMyBatis()); - ComponentDataPersister persister = new ComponentDataPersister(data, snapshots, dataDao, getMyBatis()); + FileHashesPersister persister = new FileHashesPersister(data, snapshots, 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/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data-result.xml deleted file mode 100644 index 647650b1da0..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data-result.xml +++ /dev/null @@ -1,5 +0,0 @@ -<dataset> - <snapshots id="100" project_id="200" islast="[true]"/> - <snapshot_data id="1" snapshot_id="100" resource_id="200" snapshot_data="content of symbol" data_type="SYMBOL" created_at="[null]" updated_at="[null]"/> - <snapshot_data id="2" snapshot_id="100" resource_id="200" snapshot_data="content of syntax" data_type="SYNTAX" created_at="[null]" updated_at="[null]" /> -</dataset>
\ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data-result.xml new file mode 100644 index 00000000000..b710ad3c272 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data-result.xml @@ -0,0 +1,4 @@ +<dataset> + <snapshots id="100" project_id="200" islast="[true]"/> + <snapshot_data id="1" snapshot_id="100" resource_id="200" snapshot_data="org/struts/Action.java=123ABC" data_type="file_hashes" created_at="[null]" updated_at="[null]"/> +</dataset>
\ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data.xml index a83b8aad101..a83b8aad101 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data.xml |