private static void checkForUpdates() { PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(); long lastUpdate = propertiesComponent.getOrInitLong(KEY, 0); if (lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1)) { ApplicationManager.getApplication() .executeOnPooledThread( () -> { try { String buildNumber = ApplicationInfo.getInstance().getBuild().asString(); IdeaPluginDescriptor plugin = getPlugin(); String pluginVersion = plugin.getVersion(); String pluginId = plugin.getPluginId().getIdString(); String os = URLEncoder.encode( SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8); String uid = PermanentInstallationID.get(); String url = "https://plugins.jetbrains.com/plugins/list" + "?pluginId=" + pluginId + "&build=" + buildNumber + "&pluginVersion=" + pluginVersion + "&os=" + os + "&uuid=" + uid; PropertiesComponent.getInstance() .setValue(KEY, String.valueOf(System.currentTimeMillis())); HttpRequests.request(url) .connect( request -> { try { JDOMUtil.load(request.getReader()); LOG.info( (request.isSuccessful() ? "Successful" : "Unsuccessful") + " update: " + url); } catch (JDOMException e) { LOG.warn(e); } return null; }); } catch (UnknownHostException ignored) { } catch (IOException e) { LOG.warn(e); } }); } }
// Get version info of our Plugin private String getPluginVersion() { final IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId("com.microsoft.vso.idea")); final String v = plugin != null ? plugin.getVersion() : DEFAULT_VERSION; return StringUtils.isNotEmpty(v) ? v : DEFAULT_VERSION; }
private static boolean doSubmit( final IdeaLoggingEvent event, final Component parentComponent, final Consumer<SubmittedReportInfo> callback, final ErrorBean bean, final String description) { final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent); bean.setDescription(description); bean.setMessage(event.getMessage()); Throwable throwable = event.getThrowable(); if (throwable != null) { final PluginId pluginId = IdeErrorsDialog.findPluginId(throwable); if (pluginId != null) { final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId); if (ideaPluginDescriptor != null && !ideaPluginDescriptor.isBundled()) { bean.setPluginName(ideaPluginDescriptor.getName()); bean.setPluginVersion(ideaPluginDescriptor.getVersion()); } } } Object data = event.getData(); if (data instanceof LogMessageEx) { bean.setAttachments(((LogMessageEx) data).getAttachments()); } LinkedHashMap<String, String> reportValues = IdeaITNProxy.getKeyValuePairs( bean, ApplicationManager.getApplication(), (ApplicationInfoEx) ApplicationInfo.getInstance(), ApplicationNamesInfo.getInstance()); final Project project = CommonDataKeys.PROJECT.getData(dataContext); Consumer<String> successCallback = new Consumer<String>() { @Override public void consume(String token) { final SubmittedReportInfo reportInfo = new SubmittedReportInfo( null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE); callback.consume(reportInfo); ReportMessages.GROUP .createNotification( ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null) .setImportant(false) .notify(project); } }; Consumer<Exception> errorCallback = new Consumer<Exception>() { @Override public void consume(Exception e) { String message = GoBundle.message("go.error.report.message", e.getMessage()); ReportMessages.GROUP .createNotification( ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER) .setImportant(false) .notify(project); } }; AnonymousFeedbackTask task = new AnonymousFeedbackTask( project, "Submitting error report", true, reportValues, successCallback, errorCallback); if (project == null) { task.run(new EmptyProgressIndicator()); } else { ProgressManager.getInstance().run(task); } return true; }
public static void runCheck(@NotNull final Project project) { List<DependencyOnPlugin> dependencies = ExternalDependenciesManager.getInstance(project).getDependencies(DependencyOnPlugin.class); if (dependencies.isEmpty()) return; List<String> customRepositories = UpdateSettings.getInstance().getStoredPluginHosts(); final List<String> errorMessages = new ArrayList<String>(); final List<String> missingCustomRepositories = new ArrayList<String>(); final List<IdeaPluginDescriptor> disabled = new ArrayList<IdeaPluginDescriptor>(); final List<PluginId> notInstalled = new ArrayList<PluginId>(); for (DependencyOnPlugin dependency : dependencies) { PluginId pluginId = PluginId.getId(dependency.getPluginId()); String channel = dependency.getChannel(); String customRepository = getCustomRepository(pluginId, channel); if (!StringUtil.isEmpty(channel) && customRepositoryNotSpecified(customRepositories, customRepository)) { errorMessages.add( "Custom repository '" + customRepository + "' required for '" + project.getName() + "' project isn't installed."); missingCustomRepositories.add(customRepository); } IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId); if (plugin == null) { errorMessages.add( "Plugin '" + dependency.getPluginId() + "' required for '" + project.getName() + "' project isn't installed."); notInstalled.add(pluginId); continue; } if (!plugin.isEnabled()) { errorMessages.add( "Plugin '" + plugin.getName() + "' required for '" + project.getName() + "' project is disabled."); disabled.add(plugin); continue; } String minVersion = dependency.getMinVersion(); if (minVersion != null && VersionComparatorUtil.compare(plugin.getVersion(), minVersion) < 0) { errorMessages.add( "Project '" + project.getName() + "' requires plugin '" + plugin.getName() + "' version '" + minVersion + "' or higher, but '" + plugin.getVersion() + "' is installed."); } String maxVersion = dependency.getMaxVersion(); if (maxVersion != null && VersionComparatorUtil.compare(plugin.getVersion(), maxVersion) > 0) { errorMessages.add( "Project '" + project.getName() + "' requires plugin '" + plugin.getName() + "' version '" + minVersion + "' or lower, but '" + plugin.getVersion() + "' is installed."); } } if (!errorMessages.isEmpty()) { if (!missingCustomRepositories.isEmpty()) { errorMessages.add( "<a href=\"addRepositories\">Add custom repositories and install required plugins</a>"); } else if (!disabled.isEmpty() && notInstalled.isEmpty()) { String plugins = disabled.size() == 1 ? disabled.get(0).getName() : "required plugins"; errorMessages.add("<a href=\"enable\">Enable " + plugins + "</a>"); } else if (!disabled.isEmpty() || !notInstalled.isEmpty()) { errorMessages.add("<a href=\"install\">Install required plugins</a>"); } NOTIFICATION_GROUP .createNotification( "Required plugins weren't loaded", StringUtil.join(errorMessages, "<br>"), NotificationType.ERROR, new NotificationListener() { @Override public void hyperlinkUpdate( @NotNull final Notification notification, @NotNull HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if ("addRepositories".equals(event.getDescription())) { UpdateSettings.getInstance() .getStoredPluginHosts() .addAll(missingCustomRepositories); } if ("enable".equals(event.getDescription())) { notification.expire(); for (IdeaPluginDescriptor descriptor : disabled) { PluginManagerCore.enablePlugin(descriptor.getPluginId().getIdString()); } PluginManagerMain.notifyPluginsUpdated(project); } else if ("install".equals(event.getDescription()) || "addRepositories".equals(event.getDescription())) { Set<String> pluginIds = new HashSet<String>(); for (IdeaPluginDescriptor descriptor : disabled) { pluginIds.add(descriptor.getPluginId().getIdString()); } for (PluginId pluginId : notInstalled) { pluginIds.add(pluginId.getIdString()); } PluginsAdvertiser.installAndEnablePlugins( pluginIds, () -> notification.expire()); } } } }) .notify(project); } }