aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/extension/CoreExtension.java10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/extension/CoreExtensionsLoader.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/extension/ServiceLoaderWrapper.java36
-rw-r--r--sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionTest.java44
-rw-r--r--sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionsLoaderTest.java2
5 files changed, 91 insertions, 10 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/extension/CoreExtension.java b/sonar-core/src/main/java/org/sonar/core/extension/CoreExtension.java
index 16541f4122d..1be315494cf 100644
--- a/sonar-core/src/main/java/org/sonar/core/extension/CoreExtension.java
+++ b/sonar-core/src/main/java/org/sonar/core/extension/CoreExtension.java
@@ -19,7 +19,9 @@
*/
package org.sonar.core.extension;
+import com.google.common.collect.ImmutableMap;
import java.util.Collection;
+import java.util.Map;
import org.sonar.api.SonarRuntime;
import org.sonar.api.config.Configuration;
@@ -51,4 +53,12 @@ public interface CoreExtension {
}
void load(Context context);
+
+ /**
+ * Properties with (optionally) default values defined by the extension.
+ * @return map of property names as keys and property default value as values
+ */
+ default Map<String, String> getExtensionProperties() {
+ return ImmutableMap.of();
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/extension/CoreExtensionsLoader.java b/sonar-core/src/main/java/org/sonar/core/extension/CoreExtensionsLoader.java
index 41866c16a34..c571b349fab 100644
--- a/sonar-core/src/main/java/org/sonar/core/extension/CoreExtensionsLoader.java
+++ b/sonar-core/src/main/java/org/sonar/core/extension/CoreExtensionsLoader.java
@@ -19,9 +19,7 @@
*/
package org.sonar.core.extension;
-import com.google.common.collect.ImmutableSet;
import java.util.Map;
-import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.api.utils.log.Logger;
@@ -70,11 +68,4 @@ public class CoreExtensionsLoader {
"Multiple core extensions declare the following names: %s",
duplicatedNames.stream().sorted().collect(Collectors.joining(", ")));
}
-
- static class ServiceLoaderWrapper {
- Set<CoreExtension> load(ClassLoader classLoader) {
- ServiceLoader<CoreExtension> loader = ServiceLoader.load(CoreExtension.class, classLoader);
- return ImmutableSet.copyOf(loader.iterator());
- }
- }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/extension/ServiceLoaderWrapper.java b/sonar-core/src/main/java/org/sonar/core/extension/ServiceLoaderWrapper.java
new file mode 100644
index 00000000000..f2770a9d68c
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/extension/ServiceLoaderWrapper.java
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.core.extension;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.ServiceLoader;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+public class ServiceLoaderWrapper {
+ public Set<CoreExtension> load(@Nullable ClassLoader classLoader) {
+ ServiceLoader<CoreExtension> loader = ServiceLoader.load(CoreExtension.class, classLoader);
+ return ImmutableSet.copyOf(loader.iterator());
+ }
+
+ public Set<CoreExtension> load() {
+ return load(null);
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionTest.java b/sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionTest.java
new file mode 100644
index 00000000000..b3acb7608da
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionTest.java
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.core.extension;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CoreExtensionTest {
+
+ private CoreExtension underTest = new CoreExtension() {
+ @Override
+ public String getName() {
+ return "fake";
+ }
+
+ @Override
+ public void load(Context context) {
+ // nothing to do here
+ }
+ };
+
+ @Test
+ public void getExtensionProperties_by_default_does_not_contain_any_overridden_property_defaults() {
+ assertThat(underTest.getExtensionProperties()).isEmpty();
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionsLoaderTest.java b/sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionsLoaderTest.java
index eb727ff8249..0fe863d1cdf 100644
--- a/sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionsLoaderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/extension/CoreExtensionsLoaderTest.java
@@ -40,7 +40,7 @@ public class CoreExtensionsLoaderTest {
public ExpectedException expectedException = ExpectedException.none();
private CoreExtensionRepository coreExtensionRepository = mock(CoreExtensionRepository.class);
- private CoreExtensionsLoader.ServiceLoaderWrapper serviceLoaderWrapper = mock(CoreExtensionsLoader.ServiceLoaderWrapper.class);
+ private ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
private CoreExtensionsLoader underTest = new CoreExtensionsLoader(coreExtensionRepository, serviceLoaderWrapper);
@Test