summaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-02-05 14:48:50 +0100
committerJanos Gyerik <janos.gyerik@sonarsource.com>2018-02-06 09:13:51 +0100
commit3c42d5d2e6b362d389c0058e069897bf26ef65f7 (patch)
tree567be18ebbb7c081e6f06ebe5ad65fd25048bd41 /sonar-scanner-engine
parentea77a805bfccb66c5943eb0bcaf36df3cb905227 (diff)
downloadsonarqube-3c42d5d2e6b362d389c0058e069897bf26ef65f7.tar.gz
sonarqube-3c42d5d2e6b362d389c0058e069897bf26ef65f7.zip
Add Java API Plugin.Context#getBootConfiguration()
That allows plugins to check configuration when providing the list of extensions.
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java13
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java18
2 files changed, 18 insertions, 13 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java
index 07abe2ffe3c..25ccc3bfeb0 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java
@@ -24,6 +24,8 @@ import javax.annotation.Nullable;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.Plugin;
import org.sonar.api.SonarRuntime;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.internal.PluginContextImpl;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
@@ -33,11 +35,14 @@ public class ExtensionInstaller {
private final SonarRuntime sonarRuntime;
private final PluginRepository pluginRepository;
private final GlobalAnalysisMode analysisMode;
+ private final Configuration bootConfiguration;
- public ExtensionInstaller(SonarRuntime sonarRuntime, PluginRepository pluginRepository, GlobalAnalysisMode analysisMode) {
+ public ExtensionInstaller(SonarRuntime sonarRuntime, PluginRepository pluginRepository, GlobalAnalysisMode analysisMode,
+ Configuration bootConfiguration) {
this.sonarRuntime = sonarRuntime;
this.pluginRepository = pluginRepository;
this.analysisMode = analysisMode;
+ this.bootConfiguration = bootConfiguration;
}
public ExtensionInstaller install(ComponentContainer container, ExtensionMatcher matcher) {
@@ -50,7 +55,11 @@ public class ExtensionInstaller {
// plugin extensions
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
Plugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey());
- Plugin.Context context = new Plugin.Context(sonarRuntime);
+ Plugin.Context context = new PluginContextImpl.Builder()
+ .setSonarRuntime(sonarRuntime)
+ .setBootConfiguration(bootConfiguration)
+ .build();
+
plugin.define(context);
for (Object extension : context.getExtensions()) {
doInstall(container, matcher, pluginInfo, extension);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java
index 08baf0285ad..09cfc454a41 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java
@@ -22,12 +22,12 @@ package org.sonar.scanner.bootstrap;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.ClassUtils;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.BatchExtension;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.SonarPlugin;
import org.sonar.api.SonarRuntime;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PluginInfo;
@@ -37,8 +37,9 @@ import static org.mockito.Mockito.when;
public class ExtensionInstallerTest {
- GlobalAnalysisMode mode;
- ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class);
+ private MapSettings settings = new MapSettings();
+ private GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class);
+ private ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class);
private static SonarPlugin newPluginInstance(final Object... extensions) {
return new SonarPlugin() {
@@ -48,18 +49,13 @@ public class ExtensionInstallerTest {
};
}
- @Before
- public void setUp() {
- mode = mock(GlobalAnalysisMode.class);
- }
-
@Test
public void should_filter_extensions_to_install() {
when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo")));
when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, Bar.class));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class));
+ ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mode, settings.asConfig());
installer.install(container, new FooMatcher());
assertThat(container.getComponentByType(Foo.class)).isNotNull();
@@ -71,7 +67,7 @@ public class ExtensionInstallerTest {
when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo")));
when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider()));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class));
+ ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mode, settings.asConfig());
installer.install(container, new FooMatcher());
@@ -84,7 +80,7 @@ public class ExtensionInstallerTest {
when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo")));
when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider()));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class));
+ ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mode, settings.asConfig());
installer.install(container, new TrueMatcher());