]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5869 Remove persistence of highlighting and symbols in snapshot_data
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 2 Dec 2014 16:56:08 +0000 (17:56 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 2 Dec 2014 21:09:29 +0000 (22:09 +0100)
server/sonar-server/src/main/java/org/sonar/server/source/HtmlSourceDecorator.java
sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/index/FileHashesPersister.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data-result.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data-result.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data.xml [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java

index 6eafe8355904dc3b90c139b0103846dcccfe47d8..52caca4d161fdfb9c76d75dd7b380fe9ce2812a6 100644 (file)
  */
 package org.sonar.server.source;
 
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
+import org.apache.commons.lang.StringUtils;
 import org.sonar.api.ServerComponent;
-import org.sonar.core.source.SnapshotDataTypes;
-import org.sonar.core.source.db.SnapshotDataDto;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
-import java.util.Collection;
 import java.util.List;
 
 public class HtmlSourceDecorator implements ServerComponent {
 
-  private static final String SINGLE_LINE_SYMBOLS = "single_line_symbols";
-
   @CheckForNull
   public String getDecoratedSourceAsHtml(@Nullable String sourceLine, @Nullable String highlighting, @Nullable String symbols) {
-    Collection<SnapshotDataDto> snapshotDataEntries = Lists.newArrayList();
-    if (highlighting != null) {
-      SnapshotDataDto highlightingDto = new SnapshotDataDto();
-      highlightingDto.setData(highlighting);
-      highlightingDto.setDataType(SnapshotDataTypes.SYNTAX_HIGHLIGHTING);
-      snapshotDataEntries.add(highlightingDto);
+    if (sourceLine == null) {
+      return null;
+    }
+    DecorationDataHolder decorationDataHolder = new DecorationDataHolder();
+    if (StringUtils.isNotBlank(highlighting)) {
+      decorationDataHolder.loadSyntaxHighlightingData(highlighting);
     }
-    if (symbols != null) {
-      SnapshotDataDto symbolsDto = new SnapshotDataDto();
-      symbolsDto.setData(symbols);
-      symbolsDto.setDataType(SINGLE_LINE_SYMBOLS);
-      snapshotDataEntries.add(symbolsDto);
+    if (StringUtils.isNotBlank(symbols)) {
+      decorationDataHolder.loadLineSymbolReferences(symbols);
     }
-    List<String> decoratedSource = decorate(sourceLine, snapshotDataEntries, 1, 1);
+    HtmlTextDecorator textDecorator = new HtmlTextDecorator();
+    List<String> decoratedSource = textDecorator.decorateTextWithHtml(sourceLine, decorationDataHolder, 1, 1);
     if (decoratedSource == null) {
       return null;
     } else {
@@ -62,29 +54,4 @@ public class HtmlSourceDecorator implements ServerComponent {
     }
   }
 
-  @CheckForNull
-  private List<String> decorate(@Nullable String snapshotSource, Collection<SnapshotDataDto> snapshotDataEntries, @Nullable Integer from, @Nullable Integer to) {
-    if (snapshotSource != null) {
-      DecorationDataHolder decorationDataHolder = new DecorationDataHolder();
-      for (SnapshotDataDto snapshotDataEntry : snapshotDataEntries) {
-        loadSnapshotData(decorationDataHolder, snapshotDataEntry);
-      }
-
-      HtmlTextDecorator textDecorator = new HtmlTextDecorator();
-      return textDecorator.decorateTextWithHtml(snapshotSource, decorationDataHolder, from, to);
-    }
-    return null;
-  }
-
-  private void loadSnapshotData(DecorationDataHolder dataHolder, SnapshotDataDto entry) {
-    if (!Strings.isNullOrEmpty(entry.getData())) {
-      if (SnapshotDataTypes.SYNTAX_HIGHLIGHTING.equals(entry.getDataType())) {
-        dataHolder.loadSyntaxHighlightingData(entry.getData());
-      } else if (SnapshotDataTypes.SYMBOL_HIGHLIGHTING.equals(entry.getDataType())) {
-        dataHolder.loadSymbolReferences(entry.getData());
-      } else if (SINGLE_LINE_SYMBOLS.equals(entry.getDataType())) {
-        dataHolder.loadLineSymbolReferences(entry.getData());
-      }
-    }
-  }
 }
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java
deleted file mode 100644 (file)
index f53f826..0000000
+++ /dev/null
@@ -1,68 +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.api.database.model.Snapshot;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.source.db.SnapshotDataDao;
-import org.sonar.core.source.db.SnapshotDataDto;
-
-import java.util.Map;
-
-public class ComponentDataPersister implements ScanPersister {
-  private final ComponentDataCache data;
-  private final SnapshotCache snapshots;
-  private final SnapshotDataDao dao;
-  private final MyBatis mybatis;
-
-  public ComponentDataPersister(ComponentDataCache data, SnapshotCache snapshots,
-    SnapshotDataDao dao, MyBatis mybatis) {
-    this.data = data;
-    this.snapshots = snapshots;
-    this.dao = dao;
-    this.mybatis = mybatis;
-  }
-
-  @Override
-  public void persist() {
-    DbSession session = mybatis.openSession(true);
-    try {
-      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);
-          }
-        }
-      }
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-}
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
new file mode 100644 (file)
index 0000000..9ecc91b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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.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;
+
+/**
+ * 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 FileHashesPersister(ComponentDataCache data, SnapshotCache snapshots,
+    SnapshotDataDao dao, MyBatis mybatis) {
+    this.data = data;
+    this.snapshots = snapshots;
+    this.dao = dao;
+    this.mybatis = mybatis;
+  }
+
+  @Override
+  public void persist() {
+    DbSession session = mybatis.openSession(true);
+    try {
+      for (Map.Entry<String, Snapshot> componentEntry : snapshots.snapshots()) {
+        String componentKey = componentEntry.getKey();
+        Snapshot snapshot = componentEntry.getValue();
+        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();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+}
index b22723814e0a845496cdcb68439b369d55818eb8..d9f23dc2a39cbb3e272867b6fd11f0a7e7b686c2 100644 (file)
@@ -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/ComponentDataPersisterTest.java
deleted file mode 100644 (file)
index 1fef441..0000000
+++ /dev/null
@@ -1,70 +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.core.persistence.AbstractDaoTestCase;
-import org.sonar.core.source.db.SnapshotDataDao;
-
-public class ComponentDataPersisterTest extends AbstractDaoTestCase {
-
-  @ClassRule
-  public static TemporaryFolder temp = new TemporaryFolder();
-
-  SnapshotCache snapshots = new SnapshotCache();
-  ComponentDataCache data;
-  Caches caches;
-
-  @Before
-  public void start() throws Exception {
-    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);
-    snapshots.put("org/struts/Action.java", 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");
-
-    SnapshotDataDao dataDao = new SnapshotDataDao(getMyBatis());
-    ComponentDataPersister persister = new ComponentDataPersister(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/java/org/sonar/batch/index/FileHashesPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/FileHashesPersisterTest.java
new file mode 100644 (file)
index 0000000..29c9e0c
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.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();
+
+  SnapshotCache snapshots = new SnapshotCache();
+  ComponentDataCache data;
+  Caches caches;
+
+  @Before
+  public void start() throws Exception {
+    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);
+    snapshots.put("myProject", 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, 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 (file)
index 647650b..0000000
+++ /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/ComponentDataPersisterTest/should_persist_component_data.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ComponentDataPersisterTest/should_persist_component_data.xml
deleted file mode 100644 (file)
index a83b8aa..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-  <snapshots id="100" project_id="200" islast="[true]"/>
-</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 (file)
index 0000000..b710ad3
--- /dev/null
@@ -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/FileHashesPersisterTest/should_persist_component_data.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/FileHashesPersisterTest/should_persist_component_data.xml
new file mode 100644 (file)
index 0000000..a83b8aa
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <snapshots id="100" project_id="200" islast="[true]"/>
+</dataset>
\ No newline at end of file
index cb7ff46ff60119bcfa003fe9bd3744a4c9bfec64..745b21b8c973cd092129a2ad3ccabc22b30872fc 100644 (file)
@@ -24,7 +24,6 @@ public interface SnapshotDataTypes {
 
   String SYNTAX_HIGHLIGHTING = "highlight_syntax";
   String SYMBOL_HIGHLIGHTING = "symbol";
-  String TOKEN = "token";
 
   /**
    * Key-values [relative path, hash] of all files. Stored on modules.