]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5883 Feed new column file_sources.src_hash
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 13 Jan 2015 14:50:58 +0000 (15:50 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 13 Jan 2015 15:00:40 +0000 (16:00 +0100)
17 files changed:
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/766_add_file_sources_src_hash.rb [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/file_sources.xml
sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistDontTouchUnchanged-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistEmptyFile-result.xml
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/source/db/FileSourceDto.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/main/resources/org/sonar/core/source/db/FileSourceMapper.xml
sonar-core/src/test/java/org/sonar/core/source/db/FileSourceDaoTest.java
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml
sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/insert-result.xml
sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/shared.xml
sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update-result.xml

diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/766_add_file_sources_src_hash.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/766_add_file_sources_src_hash.rb
new file mode 100644 (file)
index 0000000..752a352
--- /dev/null
@@ -0,0 +1,29 @@
+#
+# 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
+#
+class AddFileSourcesSrcHash < ActiveRecord::Migration
+
+  def self.up
+    add_column 'file_sources', :src_hash, :string, :limit => 50, :null => true
+  end
+end
index ab28752e392d94c167e61b342d47e41d20ad1e76..e83fb0b8962cabf66bcb720e636794fe0a0f0a5b 100644 (file)
@@ -141,6 +141,7 @@ public class SourcePersister implements ScanPersister {
         .setFileUuid(fileUuid)
         .setData(newData)
         .setDataHash(newDataHash)
+        .setSrcHash(inputFile.hash())
         .setLineHashes(lineHashesAsMd5Hex(inputFile))
         .setCreatedAt(now.getTime())
         .setUpdatedAt(now.getTime());
@@ -152,6 +153,7 @@ public class SourcePersister implements ScanPersister {
           .setData(newData)
           .setLineHashes(lineHashesAsMd5Hex(inputFile))
           .setDataHash(newDataHash)
+          .setSrcHash(inputFile.hash())
           .setUpdatedAt(now.getTime());
         mapper.update(previous);
         session.commit();
index 6e7d6d606f8a01e08656b9c38e43596f89e713c3..2edd8925c59597564cdd6c32d8866111f6eb2dc4 100644 (file)
@@ -127,6 +127,7 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
     FileUtils.write(sameFile, "changed\ncontent");
     DefaultInputFile inputFileNew = new DefaultInputFile(PROJECT_KEY, relativePathSame).setLines(2)
       .setAbsolutePath(sameFile.getAbsolutePath())
+      .setHash("123456")
       .setLineHashes(new byte[][] {md5("changed"), md5("content")});
     when(inputPathCache.all()).thenReturn(Arrays.<InputPath>asList(inputFileNew));
 
@@ -141,6 +142,7 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
       ",,,,,,,,,,,,,,,changed\r\n,,,,,,,,,,,,,,,content\r\n");
     assertThat(fileSourceDto.getLineHashes()).isEqualTo(md5Hex("changed") + "\n" + md5Hex("content"));
     assertThat(fileSourceDto.getDataHash()).isEqualTo("d1a4dd62422639f665a8d80b37c59f8d");
+    assertThat(fileSourceDto.getSrcHash()).isEqualTo("123456");
   }
 
   @Test
@@ -151,6 +153,7 @@ public class SourcePersisterTest extends AbstractDaoTestCase {
     String relativePathEmpty = "src/empty.java";
     DefaultInputFile inputFileEmpty = new DefaultInputFile(PROJECT_KEY, relativePathEmpty)
       .setLines(0)
+      .setHash("")
       .setLineHashes(new byte[][] {});
     when(inputPathCache.all()).thenReturn(Arrays.<InputPath>asList(inputFileEmpty));
 
index 2448332fb2e91994a096f9da0f421fe605c986bb..61fa8fc265a5d81327fef98d3831e229ea88f392 100644 (file)
@@ -3,6 +3,7 @@
       data=",,,,,,,,,,,,,,,unchanged&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;" 
       line_hashes="8d7b3d6b83c0a517eac07e1aac94b773&#10;9a0364b9e99bb480dd25e1f0284c8555" 
       data_hash="0263047cd758c68c27683625f072f010" 
+      src_hash="123456"
       created_at="1412952242000" updated_at="1412952242000" />
       
 </dataset>
index e17dd5542305bc385d7f63a0a53eb01eb94def8f..940080dc041f5771258bd997a0e2782053ec80ba 100644 (file)
@@ -4,6 +4,7 @@
       data=",,,,,,,,,,,,,,,unchanged&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;" 
       line_hashes="8d7b3d6b83c0a517eac07e1aac94b773&#10;9a0364b9e99bb480dd25e1f0284c8555" 
       data_hash="0263047cd758c68c27683625f072f010" 
+      src_hash="123456"
       created_at="1412952242000" updated_at="1412952242000" />
 
 </dataset>
index 6733f34a10038b6e252cca6498d71fc03ac56bdc..4fa778702d5e7432df604e1c31db16642c2a67c2 100644 (file)
@@ -3,10 +3,12 @@
       data=",,,,,,,,,,,,,,,unchanged&#13;&#10;,,,,,,,,,,,,,,,content&#13;&#10;" 
       line_hashes="8d7b3d6b83c0a517eac07e1aac94b773&#10;9a0364b9e99bb480dd25e1f0284c8555" 
       data_hash="0263047cd758c68c27683625f072f010" 
+      src_hash="123456"
       created_at="1412952242000" updated_at="1412952242000" />
       
     <file_sources id="102" project_uuid="projectUuid" file_uuid="uuidempty" data="[null]"
        line_hashes="[null]" 
+        src_hash=""
        data_hash="0" created_at="1414597442000" updated_at="1414597442000" />
 </dataset>
 
index eb1b82b063f300c226ab5852a6d983ff3fc43c84..5e4246893341b3ad7051f2a7bd4ef80e7df07efc 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 765;
+  public static final int LAST_VERSION = 766;
 
   /**
    * List of all the tables.n
index 722f10551fb47a5dde6e85783bacdf1b4224a31b..ac965c3170b8a82a144a3d0da3d3ae5c4b0326c1 100644 (file)
@@ -31,6 +31,7 @@ public class FileSourceDto {
   private String data;
   private String lineHashes;
   private String dataHash;
+  private String srcHash;
 
   public Long getId() {
     return id;
@@ -88,6 +89,15 @@ public class FileSourceDto {
     return this;
   }
 
+  public String getSrcHash() {
+    return srcHash;
+  }
+
+  public FileSourceDto setSrcHash(String srcHash) {
+    this.srcHash = srcHash;
+    return this;
+  }
+
   public long getCreatedAt() {
     return createdAt;
   }
index 398b51673554bdd7d03b2aa236dd0ef315f62e13..de0f44eed0789227698588f21254a78d4145695b 100644 (file)
@@ -294,6 +294,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('762');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('763');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('764');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('765');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('766');
 
 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;
index b5175c645c3e89a8fdd16a6dea9e48857abab2ea..8a6fae8a07fefd5cb79281582666b0179e248706 100644 (file)
@@ -567,6 +567,7 @@ CREATE TABLE "FILE_SOURCES" (
   "DATA" CLOB(2147483647),
   "LINE_HASHES" CLOB(2147483647),
   "DATA_HASH" VARCHAR(50) NOT NULL,
+  "SRC_HASH" VARCHAR(50) NULL,
   "CREATED_AT" BIGINT NOT NULL,
   "UPDATED_AT" BIGINT NOT NULL
 );
index c5c6e48f470a8df2ee21f16bf27e89abb1c6f09a..9ac62cef3e3840dd161adb4432f97af111d057d1 100644 (file)
@@ -5,7 +5,7 @@
 <mapper namespace="org.sonar.core.source.db.FileSourceMapper">
 
   <select id="select" parameterType="string" resultType="org.sonar.core.source.db.FileSourceDto">
-    SELECT id, project_uuid as projectUuid, file_uuid as fileUuid, created_at as createdAt, updated_at as updatedAt, data, line_hashes as lineHashes, data_hash as dataHash
+    SELECT id, project_uuid as projectUuid, file_uuid as fileUuid, created_at as createdAt, updated_at as updatedAt, data, line_hashes as lineHashes, data_hash as dataHash, src_hash as srcHash
     FROM file_sources
     WHERE file_uuid = #{fileUuid}
   </select>
@@ -17,8 +17,8 @@
   </select>
   
   <insert id="insert" parameterType="org.sonar.core.source.db.FileSourceDto" useGeneratedKeys="false">
-    insert into file_sources (project_uuid, file_uuid, created_at, updated_at, data, line_hashes, data_hash) 
-    values (#{projectUuid,jdbcType=VARCHAR}, #{fileUuid,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{data,jdbcType=CLOB}, #{lineHashes,jdbcType=CLOB}, #{dataHash,jdbcType=VARCHAR})
+    insert into file_sources (project_uuid, file_uuid, created_at, updated_at, data, line_hashes, data_hash, src_hash
+    values (#{projectUuid,jdbcType=VARCHAR}, #{fileUuid,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{data,jdbcType=CLOB}, #{lineHashes,jdbcType=CLOB}, #{dataHash,jdbcType=VARCHAR}, #{srcHash,jdbcType=VARCHAR})
   </insert>
   
   <update id="update" parameterType="org.sonar.core.source.db.FileSourceDto" useGeneratedKeys="false">
@@ -26,7 +26,8 @@
       updated_at = #{updatedAt},
       data = #{data},
       line_hashes = #{lineHashes},
-      data_hash = #{dataHash}
+      data_hash = #{dataHash},
+      src_hash = #{srcHash}
     where id = #{id}
   </update>
 
index 9e4644a657bff58675a9d253b37be7716ee502df..22bf2b89910631542d5abad27b6bffa8795b79ce 100644 (file)
@@ -70,6 +70,7 @@ public class FileSourceDaoTest extends AbstractDaoTestCase {
     dao.insert(new FileSourceDto().setProjectUuid("prj").setFileUuid("file").setData("bla bla")
       .setDataHash("hash2")
       .setLineHashes("foo\nbar")
+      .setSrcHash("hache")
       .setCreatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100").getTime())
       .setUpdatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100").getTime()));
 
@@ -81,6 +82,7 @@ public class FileSourceDaoTest extends AbstractDaoTestCase {
     dao.update(new FileSourceDto().setId(101L).setProjectUuid("prj").setFileUuid("file")
       .setData("updated data")
       .setDataHash("hash2")
+      .setSrcHash("123456")
       .setLineHashes("foo2\nbar2")
       .setUpdatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100").getTime()));
 
index c6eb7974211bd72b7aca6fdaa21af14be0e85c72..13b1c270dc4d4ec9882f712415df56c9febdd4a8 100644 (file)
@@ -1,5 +1,5 @@
 <dataset>
 
   <file_sources id="2" project_uuid="ABCD" file_uuid="KLMN" data="[null]" line_hashes="[null]" data_hash="321654988"
-                created_at="123456789" updated_at="123456789"/>
+                created_at="123456789" updated_at="123456789" src_hash="123456"/>
 </dataset>
index c461e9d5a40e0881ddb144762c60f31f5d0c8ce8..7a2eb5808a040a24c416fbd71d7ccbe22fdbbe5b 100644 (file)
@@ -73,7 +73,7 @@
              build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
 
   <file_sources id="1" project_uuid="ABCD" file_uuid="GHIJ" data="[null]" line_hashes="[null]" data_hash="321654987"
-                created_at="123456789" updated_at="123456789"/>
+                created_at="123456789" updated_at="123456789" src_hash="12345"/>
   <file_sources id="2" project_uuid="ABCD" file_uuid="KLMN" data="[null]" line_hashes="[null]" data_hash="321654988"
-                created_at="123456789" updated_at="123456789"/>
+                created_at="123456789" updated_at="123456789" src_hash="123456"/>
 </dataset>
index 49ea06706e5625f3dab0bb7043565bf2dde3dfc9..f43f9f06564dbcf711ac08c832f65b895d951f3c 100644 (file)
@@ -3,12 +3,14 @@
     <file_sources id="101" project_uuid="abcd" file_uuid="ab12"
                   data="aef12a,alice,2014-04-25T12:34:56+0100,,class Foo" data_hash="hash"
                   line_hashes="truc"
+                  src_hash="12345"
                   created_at="1414597442000" updated_at="1414683842000" />
 
 
     <file_sources id="102" project_uuid="prj" file_uuid="file"
                   data="bla bla" data_hash="hash2"
                   line_hashes="foo&#10;bar"
+                  src_hash="hache"
                   created_at="1414770242000" updated_at="1414770242000" />
 
 </dataset>
index 538240d2fac2aa1864985220a55687bc797126a1..fbfa94a6ddd7006143aa5c38c4f9468725831557 100644 (file)
@@ -3,6 +3,7 @@
     <file_sources id="101" project_uuid="abcd" file_uuid="ab12"
                   data="aef12a,alice,2014-04-25T12:34:56+0100,,class Foo" data_hash="hash"
                   line_hashes="truc"
+                  src_hash="12345"
                   created_at="1414597442000" updated_at="1414683842000" />
 
 </dataset>
index ddad2e2b41012bed3953c14e701077bf76d62f90..64ff997152f2ab7a6ca2bcdc403cc9e042396143 100644 (file)
@@ -3,6 +3,7 @@
     <file_sources id="101" project_uuid="abcd" file_uuid="ab12"
                   data="updated data" data_hash="hash2"
                   line_hashes="foo2&#10;bar2"
+                  src_hash="123456"
                   created_at="1414597442000" updated_at="1414770242000" />