From 66d6f7484be1ca152b9ae9e98723fda6c5dddbe4 Mon Sep 17 00:00:00 2001 From: Steve Marion Date: Wed, 6 Dec 2023 18:02:56 +0100 Subject: SONAR-21194 add requiredForLanguages response fields to plugins/installed endpoint. --- .../main/java/org/sonar/core/platform/PluginInfo.java | 19 ++++++++++++++++++- .../java/org/sonar/core/platform/PluginInfoTest.java | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java index ba2616b7860..2c3e9864457 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java @@ -36,9 +36,9 @@ import java.util.zip.ZipEntry; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; -import org.sonar.api.utils.MessageException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.utils.MessageException; import org.sonar.updatecenter.common.PluginManifest; import org.sonar.updatecenter.common.Version; @@ -100,6 +100,8 @@ public class PluginInfo implements Comparable { private final Set requiredPlugins = new HashSet<>(); + private final Set requiredForLanguages = new HashSet<>(); + public PluginInfo(String key) { requireNonNull(key, "Plugin key is missing from manifest"); this.key = key; @@ -210,6 +212,10 @@ public class PluginInfo implements Comparable { return requiredPlugins; } + public Set getRequiredForLanguages() { + return requiredForLanguages; + } + public PluginInfo setName(@Nullable String name) { this.name = (name != null ? name : this.key); return this; @@ -299,6 +305,11 @@ public class PluginInfo implements Comparable { return this; } + public PluginInfo addRequiredForLanguage(String lang) { + this.requiredForLanguages.add(lang); + return this; + } + /** * Find out if this plugin is compatible with a given version of Sonar Plugin API. * The version of plugin api embedded in SQ must be greater than or equal to the minimal version @@ -406,6 +417,12 @@ public class PluginInfo implements Comparable { .filter(t -> !"license".equals(t.key)) .forEach(this::addRequiredPlugin); } + + String[] requiredForLanguagesFromManifest = manifest.getRequiredForLanguages(); + if (requiredForLanguagesFromManifest != null) { + Arrays.stream(requiredForLanguagesFromManifest) + .forEach(this::addRequiredForLanguage); + } } private static String getDocumentationPath(File file) { diff --git a/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java b/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java index 5c8aefa2e4c..0ef6d8e5b3e 100644 --- a/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java @@ -190,6 +190,7 @@ public class PluginInfoTest { assertThat(pluginInfo.getMinimalSonarPluginApiVersion()).isNull(); assertThat(pluginInfo.getRequiredPlugins()).isEmpty(); assertThat(pluginInfo.isSonarLintSupported()).isFalse(); + assertThat(pluginInfo.getRequiredForLanguages()).isEmpty(); } @Test @@ -210,6 +211,7 @@ public class PluginInfoTest { manifest.setIssueTrackerUrl("http://jira.com"); manifest.setRequirePlugins(new String[] {"java:2.0", "pmd:1.3"}); manifest.setSonarLintSupported(true); + manifest.setRequiredForLanguages(new String[]{"java", "xml"}); File jarFile = temp.newFile(); PluginInfo pluginInfo = PluginInfo.create(jarFile, manifest); @@ -225,6 +227,7 @@ public class PluginInfoTest { assertThat(pluginInfo.getMinimalSonarPluginApiVersion().getName()).isEqualTo("4.5.1"); assertThat(pluginInfo.getRequiredPlugins()).extracting("key").containsOnly("java", "pmd"); assertThat(pluginInfo.isSonarLintSupported()).isTrue(); + assertThat(pluginInfo.getRequiredForLanguages()).containsOnly("java", "xml"); } @Test -- cgit v1.2.3