diff options
Diffstat (limited to 'sonar-scanner-engine/src/main')
12 files changed, 506 insertions, 15 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java new file mode 100644 index 00000000000..b93150ae944 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import org.sonar.api.config.Configuration; + +public class AnalysisCacheEnabled { + static final String PROP_KEY = "sonar.analysisCache.enabled"; + private final Configuration configuration; + + public AnalysisCacheEnabled(Configuration configuration) { + this.configuration = configuration; + } + + public boolean isEnabled() { + return configuration.getBoolean(PROP_KEY).orElse(false); + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java new file mode 100644 index 00000000000..420a5d5f852 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java @@ -0,0 +1,87 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.util.Optional; +import java.util.zip.InflaterInputStream; +import org.sonar.api.scanner.fs.InputProject; +import org.sonar.core.util.Protobuf; +import org.sonar.scanner.bootstrap.DefaultScannerWsClient; +import org.sonar.scanner.protocol.internal.ScannerInternal; +import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg; +import org.sonar.scanner.scan.branch.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchType; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsResponse; + +/** + * Loads plugin cache into the local storage + */ +public class AnalysisCacheLoader { + static final String CONTENT_ENCODING = "Content-Encoding"; + static final String ACCEPT_ENCODING = "Accept-Encoding"; + private static final String URL = "api/scanner_cache/get"; + + private final DefaultScannerWsClient wsClient; + private final InputProject project; + private final BranchConfiguration branchConfiguration; + + public AnalysisCacheLoader(DefaultScannerWsClient wsClient, InputProject project, BranchConfiguration branchConfiguration) { + this.project = project; + this.branchConfiguration = branchConfiguration; + this.wsClient = wsClient; + } + + public Optional<AnalysisCacheMsg> load() { + String url = URL + "?project=" + project.key(); + if (branchConfiguration.branchType() == BranchType.BRANCH && branchConfiguration.branchName() != null) { + url = url + "&branch=" + branchConfiguration.branchName(); + } + + GetRequest request = new GetRequest(url).setHeader(ACCEPT_ENCODING, "gzip"); + + try (WsResponse response = wsClient.call(request)) { + if (response.code() == HttpURLConnection.HTTP_NOT_FOUND) { + return Optional.empty(); + } + try (InputStream is = response.contentStream()) { + Optional<String> contentEncoding = response.header(CONTENT_ENCODING); + if (contentEncoding.isPresent() && contentEncoding.get().equals("gzip")) { + return Optional.of(decompress(is)); + } else { + return Optional.of(Protobuf.read(is, AnalysisCacheMsg.parser())); + } + } catch (IOException e) { + throw new IllegalStateException("Failed to download cache", e); + } + } + } + + private static AnalysisCacheMsg decompress(InputStream is) { + try (InflaterInputStream iis = new InflaterInputStream(is)) { + return Protobuf.read(iis, ScannerInternal.AnalysisCacheMsg.parser()); + } catch (IOException e) { + throw new IllegalStateException("Failed to decompress plugin cache", e); + } + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorage.java new file mode 100644 index 00000000000..420bd1711a8 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorage.java @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import java.io.InputStream; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg; + +public class AnalysisCacheMemoryStorage implements AnalysisCacheStorage { + private final AnalysisCacheLoader loader; + @Nullable + private AnalysisCacheMsg cache; + + public AnalysisCacheMemoryStorage(AnalysisCacheLoader loader) { + this.loader = loader; + } + + @Override + @CheckForNull + public InputStream get(String key) { + if (cache == null) { + return null; + } + if (cache.containsMap(key)) { + return cache.getMapOrThrow(key).newInput(); + } + return null; + } + + @Override + public boolean contains(String key) { + if (cache == null) { + return false; + } + return cache.containsMap(key); + } + + public void load() { + cache = loader.load().orElse(null); + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheProvider.java new file mode 100644 index 00000000000..b340261f569 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheProvider.java @@ -0,0 +1,83 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import java.io.InputStream; +import java.util.Map; +import org.jetbrains.annotations.Nullable; +import org.sonar.api.batch.sensor.cache.ReadCache; +import org.springframework.context.annotation.Bean; + +import static java.util.Collections.emptyMap; + +public class AnalysisCacheProvider { + @Bean("ReadCache") + public ReadCache provideReader(AnalysisCacheEnabled analysisCacheEnabled, AnalysisCacheMemoryStorage storage) { + if (analysisCacheEnabled.isEnabled()) { + storage.load(); + return new ReadCacheImpl(storage); + } + return new NoOpReadCache(); + } + + @Bean("WriteCache") + public ScannerWriteCache provideWriter(AnalysisCacheEnabled analysisCacheEnabled, ReadCache readCache) { + if (analysisCacheEnabled.isEnabled()) { + return new WriteCacheImpl(readCache); + } + return new NoOpWriteCache(); + } + + + static class NoOpWriteCache implements ScannerWriteCache { + @Override + public void write(String s, InputStream inputStream) { + // no op + } + + @Override + public void write(String s, byte[] bytes) { + // no op + } + + @Override + public void copyFromPrevious(String s) { + // no op + } + + @Override + public Map<String, byte[]> getCache() { + return emptyMap(); + } + } + + static class NoOpReadCache implements ReadCache { + @Nullable + @Override + public InputStream read(String s) { + return null; + } + + @Override + public boolean contains(String s) { + return false; + } + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheStorage.java new file mode 100644 index 00000000000..5fb7765da38 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheStorage.java @@ -0,0 +1,30 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import java.io.InputStream; +import javax.annotation.CheckForNull; + +public interface AnalysisCacheStorage { + @CheckForNull + InputStream get(String key); + + boolean contains(String key); +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/ReadCacheImpl.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/ReadCacheImpl.java new file mode 100644 index 00000000000..4a94e0ae7b0 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/ReadCacheImpl.java @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import java.io.InputStream; +import org.sonar.api.batch.sensor.cache.ReadCache; + +import static org.sonar.api.utils.Preconditions.checkArgument; +import static org.sonar.api.utils.Preconditions.checkNotNull; + +public class ReadCacheImpl implements ReadCache { + private final AnalysisCacheStorage cache; + + public ReadCacheImpl(AnalysisCacheStorage storage) { + this.cache = storage; + } + + @Override + public InputStream read(String key) { + checkNotNull(key); + checkArgument(contains(key)); + return cache.get(key); + } + + @Override + public boolean contains(String key) { + checkNotNull(key); + return cache.contains(key); + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/ScannerWriteCache.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/ScannerWriteCache.java new file mode 100644 index 00000000000..4087db134b5 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/ScannerWriteCache.java @@ -0,0 +1,27 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import java.util.Map; +import org.sonar.api.batch.sensor.cache.WriteCache; + +public interface ScannerWriteCache extends WriteCache { + Map<String, byte[]> getCache(); +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/WriteCacheImpl.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/WriteCacheImpl.java new file mode 100644 index 00000000000..adeb6216d23 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/WriteCacheImpl.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.cache; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import org.sonar.api.batch.sensor.cache.ReadCache; + +import static java.util.Collections.unmodifiableMap; +import static org.sonar.api.utils.Preconditions.checkArgument; +import static org.sonar.api.utils.Preconditions.checkNotNull; + +public class WriteCacheImpl implements ScannerWriteCache { + private final ReadCache readCache; + private final Map<String, byte[]> cache = new HashMap<>(); + + public WriteCacheImpl(ReadCache readCache) { + this.readCache = readCache; + } + + @Override + public void write(String key, InputStream data) { + checkNotNull(data); + checkKey(key); + try { + byte[] arr = data.readAllBytes(); + cache.put(key, arr); + } catch (IOException e) { + throw new IllegalStateException("Failed to read stream", e); + } + } + + @Override + public void write(String key, byte[] data) { + checkNotNull(data); + checkKey(key); + cache.put(key, Arrays.copyOf(data, data.length)); + } + + @Override + public void copyFromPrevious(String key) { + checkArgument(readCache.contains(key), "Previous cache doesn't contain key '%s'", key); + checkKey(key); + + try { + cache.put(key, readCache.read(key).readAllBytes()); + } catch (IOException e) { + throw new IllegalStateException("Failed to read plugin cache for key " + key, e); + } + } + + @Override + public Map<String, byte[]> getCache() { + return unmodifiableMap(cache); + } + + private void checkKey(String key) { + checkNotNull(key); + checkArgument(!cache.containsKey(key), "Cache already contains key '%s'", key); + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/PluginCachePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisCachePublisher.java index 048d95d1432..6daae79356d 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/PluginCachePublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisCachePublisher.java @@ -21,31 +21,32 @@ package org.sonar.scanner.report; import com.google.protobuf.ByteString; import java.util.Map; -import org.sonar.scanner.cache.PluginCacheEnabled; +import org.sonar.scanner.cache.AnalysisCacheEnabled; import org.sonar.scanner.cache.ScannerWriteCache; -import org.sonar.scanner.protocol.internal.ScannerInternal.PluginCacheMsg; +import org.sonar.scanner.protocol.internal.ScannerInternal; +import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg; import org.sonar.scanner.protocol.output.ScannerReportWriter; -public class PluginCachePublisher implements ReportPublisherStep { - private final PluginCacheEnabled pluginCacheEnabled; +public class AnalysisCachePublisher implements ReportPublisherStep { + private final AnalysisCacheEnabled analysisCacheEnabled; private final ScannerWriteCache cache; - public PluginCachePublisher(PluginCacheEnabled pluginCacheEnabled, ScannerWriteCache cache) { - this.pluginCacheEnabled = pluginCacheEnabled; + public AnalysisCachePublisher(AnalysisCacheEnabled analysisCacheEnabled, ScannerWriteCache cache) { + this.analysisCacheEnabled = analysisCacheEnabled; this.cache = cache; } @Override public void publish(ScannerReportWriter writer) { - if (!pluginCacheEnabled.isEnabled() || cache.getCache().isEmpty()) { + if (!analysisCacheEnabled.isEnabled() || cache.getCache().isEmpty()) { return; } - PluginCacheMsg.Builder pluginCacheMsg = PluginCacheMsg.newBuilder(); + AnalysisCacheMsg.Builder analysisCacheMsg = ScannerInternal.AnalysisCacheMsg.newBuilder(); for (Map.Entry<String, byte[]> entry : cache.getCache().entrySet()) { - pluginCacheMsg.putMap(entry.getKey(), ByteString.copyFrom(entry.getValue())); + analysisCacheMsg.putMap(entry.getKey(), ByteString.copyFrom(entry.getValue())); } - writer.writePluginCache(pluginCacheMsg.build()); + writer.writeAnalysisCache(analysisCacheMsg.build()); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java index 888f5661e8c..325032da593 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java @@ -35,6 +35,7 @@ import org.sonar.core.config.ScannerProperties; import org.sonar.core.extension.CoreExtensionsInstaller; import org.sonar.core.language.LanguagesProvider; import org.sonar.core.metric.ScannerMetrics; +import org.sonar.core.platform.SpringComponentContainer; import org.sonar.scanner.DefaultFileLinesContextFactory; import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.analysis.AnalysisTempFolderProvider; @@ -42,7 +43,10 @@ import org.sonar.scanner.bootstrap.ExtensionInstaller; import org.sonar.scanner.bootstrap.ExtensionMatcher; import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.bootstrap.PostJobExtensionDictionary; -import org.sonar.core.platform.SpringComponentContainer; +import org.sonar.scanner.cache.AnalysisCacheEnabled; +import org.sonar.scanner.cache.AnalysisCacheLoader; +import org.sonar.scanner.cache.AnalysisCacheMemoryStorage; +import org.sonar.scanner.cache.AnalysisCacheProvider; import org.sonar.scanner.ci.CiConfigurationProvider; import org.sonar.scanner.ci.vendors.AppVeyor; import org.sonar.scanner.ci.vendors.AwsCodeBuild; @@ -84,6 +88,7 @@ import org.sonar.scanner.report.ChangedLinesPublisher; import org.sonar.scanner.report.ComponentsPublisher; import org.sonar.scanner.report.ContextPropertiesPublisher; import org.sonar.scanner.report.MetadataPublisher; +import org.sonar.scanner.report.AnalysisCachePublisher; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.report.SourcePublisher; import org.sonar.scanner.report.TestExecutionPublisher; @@ -128,8 +133,8 @@ import org.sonar.scanner.sensor.ProjectSensorsExecutor; import org.sonar.scm.git.GitScmSupport; import org.sonar.scm.svn.SvnScmSupport; -import static org.sonar.api.utils.Preconditions.checkNotNull; import static org.sonar.api.batch.InstantiationStrategy.PER_BATCH; +import static org.sonar.api.utils.Preconditions.checkNotNull; import static org.sonar.core.extension.CoreExtensionsInstaller.noExtensionFilter; import static org.sonar.scanner.bootstrap.ExtensionUtils.isDeprecatedScannerSide; import static org.sonar.scanner.bootstrap.ExtensionUtils.isInstantiationStrategy; @@ -166,6 +171,7 @@ public class SpringProjectScanContainer extends SpringComponentContainer { new ProjectPullRequestsProvider(), ProjectRepositoriesSupplier.class, new ProjectServerSettingsProvider(), + AnalysisCacheEnabled.class, // temp new AnalysisTempFolderProvider(), @@ -223,6 +229,11 @@ public class SpringProjectScanContainer extends SpringComponentContainer { ProjectCoverageAndDuplicationExclusions.class, + // Plugin cache + AnalysisCacheProvider.class, + AnalysisCacheMemoryStorage.class, + AnalysisCacheLoader.class, + // Report ReferenceBranchSupplier.class, ScannerMetrics.class, @@ -232,6 +243,7 @@ public class SpringProjectScanContainer extends SpringComponentContainer { ActiveRulesPublisher.class, AnalysisWarningsPublisher.class, ComponentsPublisher.class, + AnalysisCachePublisher.class, TestExecutionPublisher.class, SourcePublisher.class, ChangedLinesPublisher.class, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java index 461fe146a76..86c54c41d69 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java @@ -25,9 +25,12 @@ import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.rule.ActiveRules; +import org.sonar.api.batch.sensor.cache.ReadCache; +import org.sonar.api.batch.sensor.cache.WriteCache; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; +import org.sonar.scanner.cache.AnalysisCacheEnabled; import org.sonar.scanner.scan.branch.BranchConfiguration; @ThreadSafe @@ -36,8 +39,9 @@ public class ModuleSensorContext extends ProjectSensorContext { private final InputModule module; public ModuleSensorContext(DefaultInputProject project, InputModule module, Configuration config, Settings mutableModuleSettings, FileSystem fs, ActiveRules activeRules, - SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration) { - super(project, config, mutableModuleSettings, fs, activeRules, sensorStorage, sonarRuntime, branchConfiguration); + SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration, + WriteCache writeCache, ReadCache readCache, AnalysisCacheEnabled analysisCacheEnabled) { + super(project, config, mutableModuleSettings, fs, activeRules, sensorStorage, sonarRuntime, branchConfiguration, writeCache, readCache, analysisCacheEnabled); this.module = module; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java index fc78598b80a..c3cd0ac0521 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java @@ -29,6 +29,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.SensorContext; +import org.sonar.api.batch.sensor.cache.ReadCache; +import org.sonar.api.batch.sensor.cache.WriteCache; import org.sonar.api.batch.sensor.code.NewSignificantCode; import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode; import org.sonar.api.batch.sensor.coverage.NewCoverage; @@ -53,6 +55,7 @@ import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; import org.sonar.api.scanner.fs.InputProject; import org.sonar.api.utils.Version; +import org.sonar.scanner.cache.AnalysisCacheEnabled; import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError; @@ -69,9 +72,13 @@ public class ProjectSensorContext implements SensorContext { private final SonarRuntime sonarRuntime; private final Configuration config; private final boolean skipUnchangedFiles; + private final WriteCache writeCache; + private final ReadCache readCache; + private final AnalysisCacheEnabled analysisCacheEnabled; public ProjectSensorContext(DefaultInputProject project, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules, - SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration) { + SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration, WriteCache writeCache, ReadCache readCache, + AnalysisCacheEnabled analysisCacheEnabled) { this.project = project; this.config = config; this.mutableSettings = mutableSettings; @@ -79,6 +86,9 @@ public class ProjectSensorContext implements SensorContext { this.activeRules = activeRules; this.sensorStorage = sensorStorage; this.sonarRuntime = sonarRuntime; + this.writeCache = writeCache; + this.readCache = readCache; + this.analysisCacheEnabled = analysisCacheEnabled; this.skipUnchangedFiles = branchConfiguration.isPullRequest(); } @@ -184,6 +194,21 @@ public class ProjectSensorContext implements SensorContext { } @Override + public WriteCache nextCache() { + return writeCache; + } + + @Override + public ReadCache previousAnalysisCache() { + return readCache; + } + + @Override + public boolean isCacheEnabled() { + return analysisCacheEnabled.isEnabled(); + } + + @Override public NewSignificantCode newSignificantCode() { return new DefaultSignificantCode(sensorStorage); } |