diff options
author | Steve Marion <steve.marion@sonarsource.com> | 2023-12-06 18:02:56 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-12-07 20:02:52 +0000 |
commit | 66d6f7484be1ca152b9ae9e98723fda6c5dddbe4 (patch) | |
tree | b66aac298adf776663240d08d4506b375aee4ac2 /sonar-core | |
parent | 1963d4aebc783e6cd1a418ea0ec3b0c2eed6cc7b (diff) | |
download | sonarqube-66d6f7484be1ca152b9ae9e98723fda6c5dddbe4.tar.gz sonarqube-66d6f7484be1ca152b9ae9e98723fda6c5dddbe4.zip |
SONAR-21194 add requiredForLanguages response fields to plugins/installed endpoint.
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java | 19 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java | 3 |
2 files changed, 21 insertions, 1 deletions
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<PluginInfo> { private final Set<RequiredPlugin> requiredPlugins = new HashSet<>(); + private final Set<String> 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<PluginInfo> { return requiredPlugins; } + public Set<String> 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<PluginInfo> { 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<PluginInfo> { .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 |