From 0fb5e45d935ad212aa3fe32202c33dd8395078c5 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 22 Jun 2022 16:17:26 -0500 Subject: SONAR-17044 Optimize Compute Engine issue tracking and persisting of measures when file is marked as unchanged --- .../sonar/api/batch/fs/internal/DefaultInputComponent.java | 2 ++ .../org/sonar/api/batch/fs/internal/DefaultInputFile.java | 12 ++++++++++++ .../sonar/api/batch/sensor/internal/SensorContextTester.java | 7 +++++-- 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'sonar-plugin-api-impl') diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java index cb37d133823..431575f1b54 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java @@ -52,6 +52,7 @@ public abstract class DefaultInputComponent implements InputComponent { return id; } + @Override public int hashCode() { return key().hashCode(); @@ -68,5 +69,6 @@ public abstract class DefaultInputComponent implements InputComponent { public boolean hasMeasureFor(Metric metric) { return storedMetricKeys.contains(metric.key()); + } } diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java index 888763dfdb7..382461fbc5a 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java @@ -70,6 +70,8 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile private Metadata metadata; private Collection ignoreIssuesOnlineRanges; private BitSet executableLines; + private boolean markedAsUnchanged; + public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer metadataGenerator) { this(indexedFile, metadataGenerator, null); @@ -81,6 +83,7 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile this.indexedFile = indexedFile; this.metadataGenerator = metadataGenerator; this.metadata = null; + this.markedAsUnchanged = false; this.published = false; this.excludedForCoverage = false; this.contents = contents; @@ -99,6 +102,15 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE); } + public boolean isMarkedAsUnchanged() { + return markedAsUnchanged; + } + + public DefaultInputComponent setMarkedAsUnchanged(boolean markedAsUnchanged) { + this.markedAsUnchanged = markedAsUnchanged; + return this; + } + @Override public String contents() throws IOException { if (contents != null) { diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java index 98b48f12382..5c03698dc68 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java @@ -413,6 +413,11 @@ public class SensorContextTester implements SensorContext { file.setPublished(true); } + @Override + public void markAsUnchanged(InputFile inputFile) { + ((DefaultInputFile) inputFile).setMarkedAsUnchanged(true); + } + @Override public WriteCache nextCache() { return writeCache; @@ -427,7 +432,6 @@ public class SensorContextTester implements SensorContext { return readCache; } - public void setPreviousCache(ReadCache cache) { this.readCache = cache; } @@ -437,7 +441,6 @@ public class SensorContextTester implements SensorContext { return cacheEnabled; } - public void setCacheEnabled(boolean enabled) { this.cacheEnabled = enabled; } -- cgit v1.2.3