use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.
the class ServerPluginRepository method registerPluginInfo.
private void registerPluginInfo(PluginInfo info) {
String pluginKey = info.getKey();
if (blacklistedPluginKeys.contains(pluginKey)) {
LOG.warn("Plugin {} [{}] is blacklisted and is being uninstalled.", info.getName(), pluginKey);
deleteQuietly(info.getNonNullJarFile());
return;
}
if (FORBIDDEN_COMPATIBLE_PLUGINS.contains(pluginKey)) {
throw MessageException.of(String.format("Plugin '%s' is no more compatible with this version of SonarQube", pluginKey));
}
PluginInfo existing = pluginInfosByKeys.put(pluginKey, info);
if (existing != null) {
throw MessageException.of(format("Found two files for the same plugin [%s]: %s and %s", pluginKey, info.getNonNullJarFile().getName(), existing.getNonNullJarFile().getName()));
}
}
use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.
the class ServerPluginRepository method uninstall.
/**
* Uninstall a plugin and its dependents
*/
public void uninstall(String pluginKey) {
checkState(started.get(), NOT_STARTED_YET);
Set<String> uninstallKeys = new HashSet<>();
uninstallKeys.add(pluginKey);
appendDependentPluginKeys(pluginKey, uninstallKeys);
for (String uninstallKey : uninstallKeys) {
PluginInfo info = pluginInfosByKeys.get(uninstallKey);
try {
LOG.info("Uninstalling plugin {} [{}]", info.getName(), info.getKey());
// we don't reuse info.getFile() just to be sure that file is located in from extensions/plugins
File masterFile = new File(fs.getInstalledPluginsDir(), info.getNonNullJarFile().getName());
moveFileToDirectory(masterFile, uninstalledPluginsDir(), true);
} catch (IOException e) {
throw new IllegalStateException(format("Fail to uninstall plugin %s [%s]", info.getName(), info.getKey()), e);
}
}
}
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);
}
Aggregations