use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.
the class ServerPluginRepository method isCompatible.
@VisibleForTesting
static boolean isCompatible(PluginInfo plugin, SonarRuntime runtime, Map<String, PluginInfo> allPluginsByKeys) {
if (Strings.isNullOrEmpty(plugin.getMainClass()) && Strings.isNullOrEmpty(plugin.getBasePlugin())) {
LOG.warn("Plugin {} [{}] is ignored because entry point class is not defined", plugin.getName(), plugin.getKey());
return false;
}
if (!plugin.isCompatibleWith(runtime.getApiVersion().toString())) {
throw MessageException.of(format("Plugin %s [%s] requires at least SonarQube %s", plugin.getName(), plugin.getKey(), plugin.getMinimalSqVersion()));
}
if (!Strings.isNullOrEmpty(plugin.getBasePlugin()) && !allPluginsByKeys.containsKey(plugin.getBasePlugin())) {
// it extends a plugin that is not installed
LOG.warn("Plugin {} [{}] is ignored because its base plugin [{}] is not installed", plugin.getName(), plugin.getKey(), plugin.getBasePlugin());
return false;
}
for (PluginInfo.RequiredPlugin requiredPlugin : plugin.getRequiredPlugins()) {
PluginInfo installedRequirement = allPluginsByKeys.get(requiredPlugin.getKey());
if (installedRequirement == null) {
// it requires a plugin that is not installed
LOG.warn("Plugin {} [{}] is ignored because the required plugin [{}] is not installed", plugin.getName(), plugin.getKey(), requiredPlugin.getKey());
return false;
}
Version installedRequirementVersion = installedRequirement.getVersion();
if (installedRequirementVersion != null && requiredPlugin.getMinimalVersion().compareToIgnoreQualifier(installedRequirementVersion) > 0) {
// it requires a more recent version
LOG.warn("Plugin {} [{}] is ignored because the version {} of required plugin [{}] is not supported", plugin.getName(), plugin.getKey(), requiredPlugin.getKey(), requiredPlugin.getMinimalVersion());
return false;
}
}
return true;
}
use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.
the class InstalledAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkIsSystemAdministrator();
Collection<PluginInfo> pluginInfoList = searchPluginInfoList();
JsonWriter jsonWriter = response.newJsonWriter();
jsonWriter.setSerializeEmptys(false);
jsonWriter.beginObject();
List<String> additionalFields = request.paramAsStrings(WebService.Param.FIELDS);
writePluginInfoList(jsonWriter, pluginInfoList, additionalFields == null ? Collections.<String>emptyList() : additionalFields);
jsonWriter.endObject();
jsonWriter.close();
}
use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.
the class PendingAction method writePlugins.
private void writePlugins(JsonWriter json, Map<String, Plugin> compatiblePluginsByKey) {
Collection<PluginInfo> uninstalledPlugins = installer.getUninstalledPlugins();
Collection<PluginInfo> downloadedPlugins = pluginDownloader.getDownloadedPlugins();
Collection<PluginInfo> installedPlugins = installer.getPluginInfos();
MatchPluginKeys matchPluginKeys = new MatchPluginKeys(from(installedPlugins).transform(PluginInfoToKey.INSTANCE).toSet());
Collection<PluginInfo> newPlugins = new ArrayList<>();
Collection<PluginInfo> updatedPlugins = new ArrayList<>();
for (PluginInfo pluginInfo : downloadedPlugins) {
if (matchPluginKeys.apply(pluginInfo)) {
updatedPlugins.add(pluginInfo);
} else {
newPlugins.add(pluginInfo);
}
}
pluginWSCommons.writePluginInfoList(json, newPlugins, compatiblePluginsByKey, ARRAY_INSTALLING);
pluginWSCommons.writePluginInfoList(json, updatedPlugins, compatiblePluginsByKey, ARRAY_UPDATING);
pluginWSCommons.writePluginInfoList(json, uninstalledPlugins, compatiblePluginsByKey, ARRAY_REMOVING);
}
use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.
the class GeneratePluginIndex method writeIndex.
void writeIndex(File indexFile) throws IOException {
FileUtils.forceMkdir(indexFile.getParentFile());
Writer writer = new OutputStreamWriter(new FileOutputStream(indexFile), StandardCharsets.UTF_8);
try {
for (PluginInfo pluginInfo : repository.getPluginInfos()) {
writer.append(RemotePlugin.create(pluginInfo).marshal());
writer.append(CharUtils.LF);
}
writer.flush();
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.
the class DebtModelPluginRepositoryTest method test_component_initialization.
@Test
public void test_component_initialization() throws Exception {
// we do have the "csharp-model.xml" file in src/test/resources
PluginInfo csharpPluginMetadata = new PluginInfo("csharp");
// but we don' have the "php-model.xml" one
PluginInfo phpPluginMetadata = new PluginInfo("php");
PluginRepository repository = mock(PluginRepository.class);
when(repository.getPluginInfos()).thenReturn(Lists.newArrayList(csharpPluginMetadata, phpPluginMetadata));
FakePlugin fakePlugin = new FakePlugin();
when(repository.getPluginInstance(anyString())).thenReturn(fakePlugin);
underTest = new DebtModelPluginRepository(repository, TEST_XML_PREFIX_PATH);
// when
underTest.start();
// assert
Collection<String> contributingPluginList = underTest.getContributingPluginList();
assertThat(contributingPluginList.size()).isEqualTo(2);
assertThat(contributingPluginList).containsOnly("technical-debt", "csharp");
}
Aggregations