import com.sonarsource.decimal_scale_of_measures.DecimalScaleMetric;
import com.sonarsource.decimal_scale_of_measures.DecimalScaleProperty;
import com.sonarsource.decimal_scale_of_measures.DecimalScaleSensor;
-import java.util.Arrays;
-import java.util.List;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
-public class BatchPlugin extends SonarPlugin {
+import static java.util.Arrays.asList;
- public List getExtensions() {
- return Arrays.asList(
+public class BatchPlugin implements Plugin {
+
+ @Override
+ public void define(Context context) {
+ context.addExtensions(asList(
// SONAR-6939 decimal_scale_of_measures
DecimalScaleMeasureComputer.class,
DecimalScaleMetric.class,
DumpSettingsInitializer.class,
RaiseMessageException.class,
TempFolderExtension.class,
- WaitingSensor.class);
+ WaitingSensor.class
+ ));
}
-
}
import java.util.Collections;
import java.util.Map;
import org.picocontainer.Startable;
+import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
import org.sonar.api.server.ServerSide;
import org.sonar.core.platform.PluginInfo;
contributingPluginKeyToClassLoader.put(DEFAULT_MODEL, getClass().getClassLoader());
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
String pluginKey = pluginInfo.getKey();
- SonarPlugin plugin = pluginRepository.getPluginInstance(pluginKey);
+ Plugin plugin = pluginRepository.getPluginInstance(pluginKey);
ClassLoader classLoader = plugin.getClass().getClassLoader();
if (classLoader.getResource(getXMLFilePath(pluginKey)) != null) {
contributingPluginKeyToClassLoader.put(pluginKey, classLoader);
* Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order
* to tell more about them.
* <p/>
- * Instances of these classes must be declared in {@link org.sonar.api.SonarPlugin#getExtensions()}.
+ * Instances of these classes must be declared by {@link org.sonar.api.Plugin}.
*/
@ServerSide
public final class NotificationDispatcherMetadata {
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
+import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.utils.log.Logger;
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
String pluginKey = pluginInfo.getKey();
- SonarPlugin plugin = pluginRepository.getPluginInstance(pluginKey);
+ Plugin plugin = pluginRepository.getPluginInstance(pluginKey);
try {
deployRailsApp(appsDir, pluginKey, plugin.getClass().getClassLoader());
} catch (Exception e) {
import java.util.Map;
import org.sonar.api.Extension;
import org.sonar.api.ExtensionProvider;
+import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
+import org.sonar.api.SonarQubeVersion;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.core.platform.ComponentContainer;
@ServerSide
public class ServerExtensionInstaller {
+ private final SonarQubeVersion sonarQubeVersion;
private final PluginRepository pluginRepository;
- public ServerExtensionInstaller(PluginRepository pluginRepository) {
+ public ServerExtensionInstaller(SonarQubeVersion sonarQubeVersion, PluginRepository pluginRepository) {
+ this.sonarQubeVersion = sonarQubeVersion;
this.pluginRepository = pluginRepository;
}
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
try {
String pluginKey = pluginInfo.getKey();
- SonarPlugin plugin = pluginRepository.getPluginInstance(pluginKey);
+ Plugin plugin = pluginRepository.getPluginInstance(pluginKey);
container.addExtension(pluginInfo, plugin);
- for (Object extension : plugin.getExtensions()) {
+ Plugin.Context context = new Plugin.Context(sonarQubeVersion);
+ plugin.define(context);
+ for (Object extension : context.getExtensions()) {
if (installExtension(container, pluginInfo, extension, true) != null) {
installedExtensionsByPlugin.put(pluginInfo, extension);
} else {
import javax.annotation.Nonnull;
import org.apache.commons.io.FileUtils;
import org.picocontainer.Startable;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerUpgradeStatus;
import org.sonar.api.utils.MessageException;
import static com.google.common.collect.Lists.newArrayList;
import static java.lang.String.format;
import static org.apache.commons.io.FileUtils.copyFile;
-import static org.sonar.core.util.FileUtils.deleteQuietly;
import static org.apache.commons.io.FileUtils.moveFile;
import static org.apache.commons.io.FileUtils.moveFileToDirectory;
import static org.sonar.core.platform.PluginInfo.jarToPluginInfo;
+import static org.sonar.core.util.FileUtils.deleteQuietly;
/**
* Entry point to install and load plugins on server startup. It manages
// following fields are available after startup
private final Map<String, PluginInfo> pluginInfosByKeys = new HashMap<>();
- private final Map<String, SonarPlugin> pluginInstancesByKeys = new HashMap<>();
+ private final Map<String, Plugin> pluginInstancesByKeys = new HashMap<>();
public ServerPluginRepository(Server server, ServerUpgradeStatus upgradeStatus,
DefaultServerFileSystem fs, PluginLoader loader) {
}
@Override
- public SonarPlugin getPluginInstance(String key) {
- SonarPlugin plugin = pluginInstancesByKeys.get(key);
+ public Plugin getPluginInstance(String key) {
+ Plugin plugin = pluginInstancesByKeys.get(key);
if (plugin == null) {
throw new IllegalArgumentException(format("Plugin [%s] does not exist", key));
}
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
import org.sonar.api.config.License;
import org.sonar.api.config.PropertyDefinitions;
}
public Object getComponentByClassname(String pluginKey, String className) {
- SonarPlugin plugin = get(PluginRepository.class).getPluginInstance(pluginKey);
+ Plugin plugin = get(PluginRepository.class).getPluginInstance(pluginKey);
try {
Class componentClass = plugin.getClass().getClassLoader().loadClass(className);
return get(componentClass);
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
+import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
// there may be duplicated classloaders in the list.
List<ClassLoader> list = Lists.newArrayList();
for (PluginInfo info : pluginRepository.getPluginInfos()) {
- SonarPlugin plugin = pluginRepository.getPluginInstance(info.getKey());
+ Plugin plugin = pluginRepository.getPluginInstance(info.getKey());
list.add(plugin.getClass().getClassLoader());
}
list.add(I18nClassloader.class.getClassLoader());
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.SystemUtils;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.api.utils.log.Loggers;
import org.sonar.updatecenter.common.Version;
* Plugins have their own isolated classloader, inheriting only from API classes.
* Some plugins can extend a "base" plugin, sharing the same classloader.
* <p/>
- * This class is stateless. It does not keep pointers to classloaders and {@link org.sonar.api.SonarPlugin}.
+ * This class is stateless. It does not keep pointers to classloaders and {@link org.sonar.api.Plugin}.
*/
public class PluginLoader {
this.classloaderFactory = classloaderFactory;
}
- public Map<String, SonarPlugin> load(Map<String, PluginInfo> infoByKeys) {
+ public Map<String, Plugin> load(Map<String, PluginInfo> infoByKeys) {
Collection<PluginClassLoaderDef> defs = defineClassloaders(infoByKeys);
Map<PluginClassLoaderDef, ClassLoader> classloaders = classloaderFactory.create(defs);
return instantiatePluginClasses(classloaders);
}
/**
- * Instantiates collection of {@link org.sonar.api.SonarPlugin} according to given metadata and classloaders
+ * Instantiates collection of {@link org.sonar.api.Plugin} according to given metadata and classloaders
*
* @return the instances grouped by plugin key
* @throws IllegalStateException if at least one plugin can't be correctly loaded
*/
@VisibleForTesting
- Map<String, SonarPlugin> instantiatePluginClasses(Map<PluginClassLoaderDef, ClassLoader> classloaders) {
+ Map<String, Plugin> instantiatePluginClasses(Map<PluginClassLoaderDef, ClassLoader> classloaders) {
// instantiate plugins
- Map<String, SonarPlugin> instancesByPluginKey = new HashMap<>();
+ Map<String, Plugin> instancesByPluginKey = new HashMap<>();
for (Map.Entry<PluginClassLoaderDef, ClassLoader> entry : classloaders.entrySet()) {
PluginClassLoaderDef def = entry.getKey();
ClassLoader classLoader = entry.getValue();
String pluginKey = mainClassEntry.getKey();
String mainClass = mainClassEntry.getValue();
try {
- instancesByPluginKey.put(pluginKey, (SonarPlugin) classLoader.loadClass(mainClass).newInstance());
+ instancesByPluginKey.put(pluginKey, (Plugin) classLoader.loadClass(mainClass).newInstance());
} catch (UnsupportedClassVersionError e) {
throw new IllegalStateException(String.format("The plugin [%s] does not support Java %s",
pluginKey, SystemUtils.JAVA_VERSION_TRIMMED), e);
return instancesByPluginKey;
}
- public void unload(Collection<SonarPlugin> plugins) {
- for (SonarPlugin plugin : plugins) {
+ public void unload(Collection<Plugin> plugins) {
+ for (Plugin plugin : plugins) {
ClassLoader classLoader = plugin.getClass().getClassLoader();
if (classLoader instanceof Closeable && classLoader != classloaderFactory.baseClassLoader()) {
try {
package org.sonar.core.platform;
import java.util.Collection;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.server.ServerSide;
PluginInfo getPluginInfo(String key);
/**
- * @return the instance of {@link SonarPlugin} for the given plugin key. Never return null.
+ * @return the instance of {@link Plugin} for the given plugin key. Never return null.
*/
- SonarPlugin getPluginInstance(String key);
+ Plugin getPluginInstance(String key);
boolean hasPlugin(String key);
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
import org.sonar.updatecenter.common.Version;
PluginClassLoaderDef def = new PluginClassLoaderDef("fake");
def.addMainClass("fake", FakePlugin.class.getName());
- Map<String, SonarPlugin> instances = loader.instantiatePluginClasses(ImmutableMap.of(def, getClass().getClassLoader()));
+ Map<String, Plugin> instances = loader.instantiatePluginClasses(ImmutableMap.of(def, getClass().getClassLoader()));
assertThat(instances).containsOnlyKeys("fake");
assertThat(instances.get("fake")).isInstanceOf(FakePlugin.class);
}
public void plugin_is_not_recognised_as_system_extension_if_key_is_views_and_extends_another_plugin() throws IOException {
PluginInfo foo = create52PluginInfo("foo");
PluginInfo views = create52PluginInfo("views")
- .setBasePlugin("foo");
+ .setBasePlugin("foo");
Collection<PluginClassLoaderDef> defs = loader.defineClassloaders(ImmutableMap.of("foo", foo, "views", views));
private PluginInfo create52PluginInfo(String pluginKey) throws IOException {
File jarFile = temp.newFile();
return new PluginInfo(pluginKey)
- .setJarFile(jarFile)
- .setMainClass("org.foo." + pluginKey + "Plugin")
- .setMinimalSqVersion(Version.create("5.2"));
+ .setJarFile(jarFile)
+ .setMainClass("org.foo." + pluginKey + "Plugin")
+ .setMinimalSqVersion(Version.create("5.2"));
}
/**
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.api;
+
+import com.google.common.annotations.Beta;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Entry-point for plugins to inject extensions into SonarQube.
+ * <p>The JAR manifest must declare the name of the implementation class in the property <code>Plugin-Class</code>.
+ * This property is automatically set by sonar-packaging-maven-plugin when building plugin.</p>
+ * <p>Example of implementation:
+ * <pre>
+ * package com.mycompany.sonarqube;
+ * public class MyPlugin implements Plugin {
+ * {@literal @}Override
+ * public void define(Context context) {
+ * context.addExtensions(MySensor.class, MyRules.class);
+ * if (context.getSonarQubeVersion().isGreaterThanOrEqual(SonarQubeVersion.V5_6)) {
+ * // Extension which supports only versions 5.6 and greater
+ * // See org.sonar.api.SonarQubeVersion for more details.
+ * context.addExtension(MyNewExtension.class);
+ * }
+ * }
+ * }
+ * </pre>
+ * </p>
+ * <p>Example of pom.xml:</p>
+ * <pre>
+ * <project>
+ * ...
+ * <packaging>sonar-plugin</packaging>
+ *
+ * <build>
+ * <plugins>
+ * <plugin>
+ * <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
+ * <artifactId>sonar-packaging-maven-plugin</artifactId>
+ * <extensions>true</extensions>
+ * <configuration>
+ * <pluginClass>com.mycompany.sonarqube.MyPlugin</pluginClass>
+ * </configuration>
+ * </plugin>
+ * </plugins>
+ * </build>
+ * </project>
+ * </pre>
+ *
+ * @since 5.5
+ */
+@Beta
+public interface Plugin {
+
+ class Context {
+ private final SonarQubeVersion version;
+ private final List extensions = new ArrayList();
+
+ public Context(SonarQubeVersion version) {
+ this.version = version;
+ }
+
+ public SonarQubeVersion getSonarQubeVersion() {
+ return version;
+ }
+
+ /**
+ * Add an extension as :
+ * <ul>
+ * <li>a Class that is annotated with {@link org.sonar.api.batch.BatchSide} or {@link org.sonar.api.server.ServerSide}.
+ * The extension will be instantiated once. Its dependencies are injected through constructor parameters.</li>
+ * <li>an instance that is annotated with {@link org.sonar.api.batch.BatchSide} or {@link org.sonar.api.server.ServerSide}</li>
+ * </ul>
+ * Only a single component can be registered for a class. It's not allowed for example to register:
+ * <ul>
+ * <li>two MyExtension.class</li>
+ * <li>MyExtension.class and new MyExtension()</li>
+ * </ul>
+ */
+ public Context addExtension(Object extension) {
+ requireNonNull(extension);
+ this.extensions.add(extension);
+ return this;
+ }
+
+ /**
+ * @see #addExtension(Object)
+ */
+ public Context addExtensions(Collection extensions) {
+ this.extensions.addAll(extensions);
+ return this;
+ }
+
+ /**
+ * @see #addExtension(Object)
+ */
+ public Context addExtensions(Object first, Object second, Object... others) {
+ addExtension(first);
+ addExtension(second);
+ addExtensions(asList(others));
+ return this;
+ }
+
+ public List getExtensions() {
+ return extensions;
+ }
+ }
+
+ /**
+ * This method is executed at runtime when:
+ * <ul>
+ * <li>Web Server starts</li>
+ * <li>Compute Engine starts</li>
+ * <li>Scanner starts</li>
+ * </ul>
+ */
+ void define(Context context);
+}
*
* @since 2.8
*/
-public abstract class SonarPlugin {
+public abstract class SonarPlugin implements Plugin {
/**
* Classes of the implemented extensions.
return getClass().getSimpleName();
}
+ @Override
+ public void define(Context context) {
+ context.addExtensions(getExtensions());
+ }
}
* the ws is fully implemented in Java and does not require any Ruby on Rails code.
* <p/>
* <p/>
- * The classes implementing this extension point must be declared in {@link org.sonar.api.SonarPlugin#getExtensions()}.
+ * The classes implementing this extension point must be declared by {@link org.sonar.api.Plugin}.
* <p/>
* <h3>How to use</h3>
* <pre>
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.api;
+
+import java.util.Arrays;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.SonarQubeVersion.V5_5;
+
+public class PluginTest {
+
+ @Test
+ public void test_context() {
+ Plugin.Context context = new Plugin.Context(new SonarQubeVersion(V5_5));
+
+ assertThat(context.getSonarQubeVersion().get()).isEqualTo(V5_5);
+ assertThat(context.getExtensions()).isEmpty();
+
+ context.addExtension("foo");
+ assertThat(context.getExtensions()).containsOnly("foo");
+
+ context.addExtensions(Arrays.asList("bar", "baz"));
+ assertThat(context.getExtensions()).containsOnly("foo", "bar", "baz");
+
+ context.addExtensions("one", "two", "three", "four");
+ assertThat(context.getExtensions()).containsOnly("foo", "bar", "baz", "one", "two", "three", "four");
+ }
+}
import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.core.issue.tracking.Tracker;
-import org.sonar.core.platform.SonarQubeVersionProvider;
public class BatchComponents {
private BatchComponents() {
public static Collection<Object> all(AnalysisMode analysisMode) {
List<Object> components = Lists.newArrayList(
- new SonarQubeVersionProvider(),
DefaultResourceTypes.get(),
// Tasks
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.CharUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
* @see org.sonar.batch.mediumtest.BatchMediumTester
*/
@Override
- public Map<String, SonarPlugin> installLocals() {
+ public Map<String, Plugin> installLocals() {
return Collections.emptyMap();
}
*/
package org.sonar.batch.bootstrap;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.Map;
import org.picocontainer.Startable;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginLoader;
import org.sonar.core.platform.PluginRepository;
private final PluginInstaller installer;
private final PluginLoader loader;
- private Map<String, SonarPlugin> pluginInstancesByKeys;
+ private Map<String, Plugin> pluginInstancesByKeys;
private Map<String, PluginInfo> infosByKeys;
public BatchPluginRepository(PluginInstaller installer, PluginLoader loader) {
pluginInstancesByKeys = Maps.newHashMap(loader.load(infosByKeys));
// this part is only used by tests
- for (Map.Entry<String, SonarPlugin> entry : installer.installLocals().entrySet()) {
+ for (Map.Entry<String, Plugin> entry : installer.installLocals().entrySet()) {
String pluginKey = entry.getKey();
infosByKeys.put(pluginKey, new PluginInfo(pluginKey));
pluginInstancesByKeys.put(pluginKey, entry.getValue());
}
@Override
- public SonarPlugin getPluginInstance(String key) {
- SonarPlugin instance = pluginInstancesByKeys.get(key);
+ public Plugin getPluginInstance(String key) {
+ Plugin instance = pluginInstancesByKeys.get(key);
Preconditions.checkState(instance != null, String.format("Plugin [%s] does not exist", key));
return instance;
}
import java.util.List;
import javax.annotation.Nullable;
import org.sonar.api.ExtensionProvider;
+import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
+import org.sonar.api.SonarQubeVersion;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PluginInfo;
public class ExtensionInstaller {
+ private final SonarQubeVersion sonarQubeVersion;
private final PluginRepository pluginRepository;
private final AnalysisMode analysisMode;
- public ExtensionInstaller(PluginRepository pluginRepository, AnalysisMode analysisMode) {
+ public ExtensionInstaller(SonarQubeVersion sonarQubeVersion, PluginRepository pluginRepository, AnalysisMode analysisMode) {
+ this.sonarQubeVersion = sonarQubeVersion;
this.pluginRepository = pluginRepository;
this.analysisMode = analysisMode;
}
// plugin extensions
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
- SonarPlugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey());
- for (Object extension : plugin.getExtensions()) {
+ Plugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey());
+ Plugin.Context context = new Plugin.Context(sonarQubeVersion);
+ plugin.define(context);
+ for (Object extension : context.getExtensions()) {
doInstall(container, matcher, pluginInfo, extension);
}
}
import java.util.List;
import java.util.Map;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.batch.cache.GlobalPersistentCacheProvider;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginLoader;
import org.sonar.core.platform.PluginRepository;
+import org.sonar.core.platform.SonarQubeVersionProvider;
import org.sonar.core.util.DefaultHttpDownloader;
import org.sonar.core.util.UuidFactoryImpl;
BatchPluginPredicate.class,
ExtensionInstaller.class,
+ new SonarQubeVersionProvider(),
CachesManager.class,
GlobalSettings.class,
new BatchWsClientProvider(),
private void installPlugins() {
PluginRepository pluginRepository = getComponentByType(PluginRepository.class);
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
- SonarPlugin instance = pluginRepository.getPluginInstance(pluginInfo.getKey());
+ Plugin instance = pluginRepository.getPluginInstance(pluginInfo.getKey());
addExtension(pluginInfo, instance);
}
}
package org.sonar.batch.bootstrap;
import java.util.Map;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.api.batch.BatchSide;
import org.sonar.core.platform.PluginInfo;
* Used only by tests.
* @see org.sonar.batch.mediumtest.BatchMediumTester
*/
- Map<String, SonarPlugin> installLocals();
+ Map<String, Plugin> installLocals();
}
import java.io.File;
import java.util.HashMap;
import java.util.Map;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.batch.bootstrap.PluginInstaller;
import org.sonar.core.platform.PluginInfo;
public static final String MEDIUM_TEST_ENABLED = "sonar.mediumTest.enabled";
private final Map<String, PluginInfo> infosByKeys = new HashMap<>();
- private final Map<String, SonarPlugin> instancesByKeys = new HashMap<>();
+ private final Map<String, Plugin> instancesByKeys = new HashMap<>();
public FakePluginInstaller add(String pluginKey, File jarFile) {
infosByKeys.put(pluginKey, PluginInfo.create(jarFile));
return this;
}
- public FakePluginInstaller add(String pluginKey, SonarPlugin instance) {
+ public FakePluginInstaller add(String pluginKey, Plugin instance) {
instancesByKeys.put(pluginKey, instance);
return this;
}
}
@Override
- public Map<String, SonarPlugin> installLocals() {
+ public Map<String, Plugin> installLocals() {
return instancesByKeys;
}
}
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginLoader;
public void install_and_load_plugins() {
PluginInfo info = new PluginInfo("squid");
ImmutableMap<String, PluginInfo> infos = ImmutableMap.of("squid", info);
- SonarPlugin instance = mock(SonarPlugin.class);
+ Plugin instance = mock(Plugin.class);
when(loader.load(infos)).thenReturn(ImmutableMap.of("squid", instance));
when(installer.installRemotes()).thenReturn(infos);
assertThat(underTest.getPluginInstance("squid")).isSameAs(instance);
underTest.stop();
- verify(loader).unload(anyCollectionOf(SonarPlugin.class));
+ verify(loader).unload(anyCollectionOf(Plugin.class));
}
@Test
import org.sonar.api.BatchExtension;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.SonarPlugin;
+import org.sonar.api.SonarQubeVersion;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PluginInfo;
when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, Bar.class));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, mock(AnalysisMode.class));
+ ExtensionInstaller installer = new ExtensionInstaller(mock(SonarQubeVersion.class), pluginRepository, mock(AnalysisMode.class));
installer.install(container, new FooMatcher());
assertThat(container.getComponentByType(Foo.class)).isNotNull();
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(pluginRepository, mock(AnalysisMode.class));
+ ExtensionInstaller installer = new ExtensionInstaller(mock(SonarQubeVersion.class), pluginRepository, mock(AnalysisMode.class));
installer.install(container, new FooMatcher());
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(pluginRepository, mock(AnalysisMode.class));
+ ExtensionInstaller installer = new ExtensionInstaller(mock(SonarQubeVersion.class), pluginRepository, mock(AnalysisMode.class));
installer.install(container, new TrueMatcher());
import org.sonar.scanner.protocol.input.GlobalRepositories;
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
import com.google.common.base.Function;
-
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonar.api.CoreProperties;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.Plugin;
import org.sonar.api.batch.debt.internal.DefaultDebtModel;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.server.rule.RulesDefinition;
+import org.sonar.api.server.rule.RulesDefinition.Repository;
+import org.sonar.api.utils.DateUtils;
import org.sonar.batch.bootstrapper.Batch;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.batch.bootstrapper.IssueListener;
import org.sonar.batch.bootstrapper.LogOutput;
import org.sonar.batch.issue.tracking.ServerLineHashesLoader;
import org.sonar.batch.report.ReportPublisher;
+import org.sonar.batch.repository.FileData;
import org.sonar.batch.repository.GlobalRepositoriesLoader;
+import org.sonar.batch.repository.ProjectRepositories;
import org.sonar.batch.repository.ProjectRepositoriesLoader;
+import org.sonar.batch.repository.QualityProfileLoader;
import org.sonar.batch.repository.ServerIssuesLoader;
+import org.sonar.batch.rule.ActiveRulesLoader;
+import org.sonar.batch.rule.LoadedActiveRule;
+import org.sonar.batch.rule.RulesLoader;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
+import org.sonarqube.ws.Rules.ListResponse.Rule;
/**
* Main utility class for writing batch medium tests.
return this;
}
- public BatchMediumTesterBuilder registerPlugin(String pluginKey, SonarPlugin instance) {
+ public BatchMediumTesterBuilder registerPlugin(String pluginKey, Plugin instance) {
pluginInstaller.add(pluginKey, instance);
return this;
}
r.setTemplateRuleKey(templateRuleKey);
r.setLanguage(languag);
r.setSeverity(severity);
-
+
activeRules.addActiveRule(r);
return this;
}