use of org.sonar.api.Plugin in project sonarqube by SonarSource.
the class DebtModelPluginRepository method findAvailableXMLFiles.
private void findAvailableXMLFiles() {
if (contributingPluginKeyToClassLoader == null) {
contributingPluginKeyToClassLoader = Maps.newTreeMap();
// Add default model
contributingPluginKeyToClassLoader.put(DEFAULT_MODEL, getClass().getClassLoader());
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
String pluginKey = pluginInfo.getKey();
Plugin plugin = pluginRepository.getPluginInstance(pluginKey);
ClassLoader classLoader = plugin.getClass().getClassLoader();
if (classLoader.getResource(getXMLFilePath(pluginKey)) != null) {
contributingPluginKeyToClassLoader.put(pluginKey, classLoader);
}
}
}
contributingPluginKeyToClassLoader = Collections.unmodifiableMap(contributingPluginKeyToClassLoader);
}
use of org.sonar.api.Plugin in project sonarqube by SonarSource.
the class ServerPluginRepository method getPluginInstance.
@Override
public Plugin getPluginInstance(String key) {
checkState(started.get(), NOT_STARTED_YET);
Plugin plugin = pluginInstancesByKeys.get(key);
checkArgument(plugin != null, "Plugin [%s] does not exist", key);
return plugin;
}
use of org.sonar.api.Plugin in project sonarqube by SonarSource.
the class ScannerPluginRepository method start.
@Override
public void start() {
infosByKeys = new HashMap<>(installer.installRemotes());
pluginInstancesByKeys = new HashMap<>(loader.load(infosByKeys));
// this part is only used by tests
for (Map.Entry<String, Plugin> entry : installer.installLocals().entrySet()) {
String pluginKey = entry.getKey();
PluginInfo pluginInfo = new PluginInfo(pluginKey);
infosByKeys.put(pluginKey, pluginInfo);
pluginInstancesByKeys.put(pluginKey, entry.getValue());
}
keysByClassLoader = new HashMap<>();
for (Map.Entry<String, Plugin> e : pluginInstancesByKeys.entrySet()) {
keysByClassLoader.put(e.getValue().getClass().getClassLoader(), e.getKey());
}
logPlugins();
}
use of org.sonar.api.Plugin in project sonarqube by SonarSource.
the class ScannerPluginRepository method getPluginInstance.
@Override
public Plugin getPluginInstance(String key) {
Plugin instance = pluginInstancesByKeys.get(key);
Preconditions.checkState(instance != null, "Plugin [%s] does not exist", key);
return instance;
}
use of org.sonar.api.Plugin in project sonarqube by SonarSource.
the class ScannerPluginRepositoryTest method install_and_load_plugins.
@Test
public void install_and_load_plugins() {
PluginInfo info = new PluginInfo("squid");
ImmutableMap<String, PluginInfo> infos = ImmutableMap.of("squid", info);
Plugin instance = mock(Plugin.class);
when(loader.load(infos)).thenReturn(ImmutableMap.of("squid", instance));
when(installer.installRemotes()).thenReturn(infos);
underTest.start();
assertThat(underTest.getPluginInfos()).containsOnly(info);
assertThat(underTest.getPluginInfo("squid")).isSameAs(info);
assertThat(underTest.getPluginInstance("squid")).isSameAs(instance);
underTest.stop();
verify(loader).unload(anyCollectionOf(Plugin.class));
}
Aggregations