@Override public int execute(String[] operationArgs) throws Exception { PluginOperationOptions operationOptions = parseOptions(operationArgs); PluginOperationResult operationResult = new PluginOperation(config, operationOptions).execute(); printResults(operationResult); return 0; }
private PluginOperationResult executeInstallFromUrl(String downloadJarUrl) throws Exception { eventBus.post(new PluginInstallExternalEvent(downloadJarUrl)); File tempPluginJarFile = downloadPluginJar(downloadJarUrl); PluginInfo pluginInfo = readPluginInfoFromJar(tempPluginJarFile); checkPluginNotInstalled(pluginInfo.getPluginId()); checkPluginCompatibility(pluginInfo); File targetPluginJarFile = installPlugin(tempPluginJarFile, pluginInfo); result.setSourcePluginPath(downloadJarUrl); result.setTargetPluginPath(targetPluginJarFile.getPath()); result.setAffectedPluginInfo(pluginInfo); result.setResultCode(PluginResultCode.OK); return result; }
@Override public PluginOperationResult execute() throws Exception { result.setAction(options.getAction()); switch (options.getAction()) { case LIST: return executeList(); case INSTALL: return executeInstall(); case REMOVE: return executeRemove(); case UPDATE: return executeUpdate(); default: throw new Exception("Unknown action: " + options.getAction()); } }
private PluginOperationResult executeInstall() throws Exception { String pluginId = options.getPluginId(); File potentialLocalPluginJarFile = new File(pluginId); if (pluginId.matches("^https?://.+")) { return executeInstallFromUrl(pluginId); } else if (potentialLocalPluginJarFile.exists()) { return executeInstallFromLocalFile(potentialLocalPluginJarFile); } else { return executeInstallFromApiHost(pluginId); } }
private PluginOperationResult executeInstallFromApiHost(String pluginId) throws Exception { checkPluginNotInstalled(pluginId); PluginInfo pluginInfo = getRemotePluginInfo(pluginId); if (pluginInfo == null) { throw new Exception("Plugin with ID '" + pluginId + "' not found"); } checkPluginCompatibility(pluginInfo); eventBus.post(new PluginInstallExternalEvent(pluginInfo.getDownloadUrl())); File tempPluginJarFile = downloadPluginJar(pluginInfo.getDownloadUrl()); String expectedChecksum = pluginInfo.getSha256sum(); String actualChecksum = calculateChecksum(tempPluginJarFile); if (expectedChecksum == null || !expectedChecksum.equals(actualChecksum)) { throw new Exception("Checksum mismatch. Expected: " + expectedChecksum + ", but was: " + actualChecksum); } logger.log(Level.INFO, "Plugin JAR checksum verified: " + actualChecksum); File targetPluginJarFile = installPlugin(tempPluginJarFile, pluginInfo); result.setSourcePluginPath(pluginInfo.getDownloadUrl()); result.setTargetPluginPath(targetPluginJarFile.getAbsolutePath()); result.setAffectedPluginInfo(pluginInfo); result.setResultCode(PluginResultCode.OK); return result; }
for (PluginInfo localPluginInfo : getLocalList()) { if (options.getPluginId() != null && !localPluginInfo.getPluginId().equals(options.getPluginId())) { continue; File pluginJarFile = getJarFile(plugin); boolean canUninstall = canUninstall(pluginJarFile); for (PluginInfo remotePluginInfo : getRemotePluginInfoList()) { if (options.getPluginId() != null && !remotePluginInfo.getPluginId().equals(options.getPluginId())) { continue;
File pluginJarFile = getJarFile(plugin); boolean canUninstall = canUninstall(pluginJarFile); PluginInfo pluginInfo = readPluginInfoFromJar(pluginJarFile);
private PluginOperationResult executeUpdate() throws Exception { List<String> updateablePlugins = findUpdateCandidates(); List<String> erroneousPlugins = Lists.newArrayList(); List<String> delayedPlugins = Lists.newArrayList(); PluginOperationResult removeResult = executeRemove(pluginId); PluginOperationResult installResult = executeInstallFromApiHost(pluginId);
public PluginOperationResult plugin(PluginOperationOptions options) throws Exception { return new PluginOperation(config, options).execute(); }
private PluginOperationResult executeInstallFromLocalFile(File pluginJarFile) throws Exception { eventBus.post(new PluginInstallExternalEvent(pluginJarFile.getAbsolutePath())); PluginInfo pluginInfo = readPluginInfoFromJar(pluginJarFile); checkPluginNotInstalled(pluginInfo.getPluginId()); checkPluginCompatibility(pluginInfo); File targetPluginJarFile = installPlugin(pluginJarFile, pluginInfo); result.setSourcePluginPath(pluginJarFile.getPath()); result.setTargetPluginPath(targetPluginJarFile.getPath()); result.setAffectedPluginInfo(pluginInfo); result.setResultCode(PluginResultCode.OK); return result; }
@Override public void run() { try { PluginOperation pluginOperation = new PluginOperation(null, concreteRequest.getOptions()); PluginOperationResult operationResult = pluginOperation.execute(); switch (operationResult.getResultCode()) { case OK: eventBus.post(new PluginManagementResponse(PluginManagementResponse.OK, operationResult, request.getId())); break; case NOK: eventBus.post(new PluginManagementResponse(PluginManagementResponse.NOK_FAILED_UNKNOWN, operationResult, request.getId())); break; } } catch (Exception e) { logger.log(Level.WARNING, "Error executing plugin management request.", e); eventBus.post(new PluginManagementResponse(PluginManagementResponse.NOK_OPERATION_FAILED, new PluginOperationResult(), request.getId())); } } }, "PlugRq/" + concreteRequest.getOptions().getAction());