diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-05-10 15:18:40 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-05-11 17:01:49 +0200 |
commit | 1eb0636088b70e8d744074fc6bccee8561c27c1c (patch) | |
tree | 34137367eef336e19b951e77e7985ab1c4501bd6 /server | |
parent | b58a70038cb0ad0d597c9e54ddc5461800a0c083 (diff) | |
download | sonarqube-1eb0636088b70e8d744074fc6bccee8561c27c1c.tar.gz sonarqube-1eb0636088b70e8d744074fc6bccee8561c27c1c.zip |
SONAR-7412 clear revision in DB when no changeset in report
Diffstat (limited to 'server')
2 files changed, 34 insertions, 9 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java index 38c94955002..074546d588f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java @@ -165,7 +165,7 @@ public class PersistFileSourcesStep implements ComputationStep { // Update only if data_hash has changed or if src_hash is missing or revision is missing (progressive migration) boolean binaryDataUpdated = !dataHash.equals(previousDto.getDataHash()); boolean srcHashUpdated = !srcHash.equals(previousDto.getSrcHash()); - String revision = computeRevision(previousDto, latestChange); + String revision = computeRevision(latestChange); boolean revisionUpdated = !ObjectUtils.equals(revision, previousDto.getRevision()); if (binaryDataUpdated || srcHashUpdated || revisionUpdated) { previousDto @@ -182,14 +182,6 @@ public class PersistFileSourcesStep implements ComputationStep { } @CheckForNull - private String computeRevision(FileSourceDto previousDto, @Nullable Changeset latestChange) { - if (latestChange == null) { - return previousDto.getRevision(); - } - return latestChange.getRevision(); - } - - @CheckForNull private String computeRevision(@Nullable Changeset latestChange) { if (latestChange == null) { return null; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java index c1c4a9964df..9303a915f21 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java @@ -431,6 +431,39 @@ public class PersistFileSourcesStepTest extends BaseStepTest { assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1"); } + @Test + public void clear_revision_when_no_ChangeSet() { + // Existing sources + long past = 150000L; + dbClient.fileSourceDao().insert(dbTester.getSession(), new FileSourceDto() + .setProjectUuid(PROJECT_UUID) + .setFileUuid(FILE_UUID) + .setDataType(Type.SOURCE) + .setSrcHash("137f72c3708c6bd0de00a0e5a69c699b") + .setLineHashes("137f72c3708c6bd0de00a0e5a69c699b") + .setDataHash("8e84c0d961cfe364e43833c4cc4ddef5") + // Revision is missing, update will be made + .setSourceData(DbFileSources.Data.newBuilder() + .addLines(DbFileSources.Line.newBuilder() + .setLine(1) + .setSource("line") + .build()) + .build()) + .setCreatedAt(past) + .setUpdatedAt(past)); + dbTester.getSession().commit(); + + initBasicReport(1); + + underTest.execute(); + + assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID); + assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past); + assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW); + assertThat(fileSourceDto.getRevision()).isNull(); + } + private void initBasicReport(int numberOfLines) { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren( ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE").setKey("MODULE_KEY").addChildren( |