aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-12-06 16:58:03 +0100
committersonartech <sonartech@sonarsource.com>2024-01-04 20:02:48 +0000
commit7013e543f07fca1831fd1efee29997981b6ec19b (patch)
tree658cc82afdefacdfa1e1454cc78fd9c3dbf5d652 /sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest
parent8fd8c030e7dda6eb03c83eb4e59474f5e2d4e401 (diff)
downloadsonarqube-7013e543f07fca1831fd1efee29997981b6ec19b.tar.gz
sonarqube-7013e543f07fca1831fd1efee29997981b6ec19b.zip
SONAR-21195 Enhance scanner engine to download only required plugins
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakeLanguagesRepository.java83
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java13
2 files changed, 95 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakeLanguagesRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakeLanguagesRepository.java
new file mode 100644
index 00000000000..7443db29fa3
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakeLanguagesRepository.java
@@ -0,0 +1,83 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.mediumtest;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Priority;
+import org.jetbrains.annotations.Nullable;
+import org.sonar.api.resources.Languages;
+import org.sonar.scanner.repository.language.Language;
+import org.sonar.scanner.repository.language.LanguagesRepository;
+import org.sonar.scanner.repository.language.SupportedLanguageDto;
+
+@Priority(1)
+public class FakeLanguagesRepository implements LanguagesRepository {
+
+ private final Map<String, Language> languageMap = new HashMap<>();
+
+ public FakeLanguagesRepository() {
+ languageMap.put("xoo", new Language(new FakeLanguage("xoo", "xoo", new String[] { ".xoo" }, new String[0], true)));
+ }
+
+ public FakeLanguagesRepository(Languages languages) {
+ for (org.sonar.api.resources.Language language : languages.all()) {
+ languageMap.put(language.getKey(), new Language(new FakeLanguage(language.getKey(), language.getName(), language.getFileSuffixes(), language.filenamePatterns(), true)));
+ }
+ }
+
+ @Nullable
+ @Override
+ public Language get(String languageKey) {
+ return languageMap.get(languageKey);
+ }
+
+ @Override
+ public Collection<Language> all() {
+ return languageMap.values().stream()
+ // sorted for test consistency
+ .sorted(Comparator.comparing(Language::key)).toList();
+ }
+
+ public void addLanguage(String key, String name, String[] suffixes, String[] filenamePatterns) {
+ languageMap.put(key, new Language(new FakeLanguage(key, name, suffixes, filenamePatterns, true)));
+ }
+
+ public void addLanguage(String key, String name, String[] suffixes, String[] filenamePatterns, boolean publishAllFiles) {
+ languageMap.put(key, new Language(new FakeLanguage(key, name, suffixes, filenamePatterns, publishAllFiles)));
+ }
+
+ private static class FakeLanguage extends SupportedLanguageDto {
+
+ private final boolean publishAllFiles;
+
+ public FakeLanguage(String key, String name, String[] fileSuffixes, String[] filenamePatterns, boolean publishAllFiles) {
+ super(key, name, fileSuffixes, filenamePatterns);
+ this.publishAllFiles = publishAllFiles;
+ }
+
+ @Override
+ public boolean publishAllFiles() {
+ return publishAllFiles;
+ }
+ }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java
index e5697c9b7b8..36e2bbbd298 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.annotation.Priority;
import org.sonar.api.Plugin;
import org.sonar.core.platform.PluginInfo;
@@ -48,7 +49,17 @@ public class FakePluginInstaller implements PluginInstaller {
}
@Override
- public Map<String, ScannerPlugin> installRemotes() {
+ public Map<String, ScannerPlugin> installAllPlugins() {
+ return pluginsByKeys;
+ }
+
+ @Override
+ public Map<String, ScannerPlugin> installRequiredPlugins() {
+ return pluginsByKeys;
+ }
+
+ @Override
+ public Map<String, ScannerPlugin> installPluginsForLanguages(Set<String> languageKeys) {
return pluginsByKeys;
}