Skip to content

Commit

Permalink
Merge pull request #135 from jborgers/master
Browse files Browse the repository at this point in the history
PR for compatibility with IntelliJ 2022.3.1 and 2023.1; and json export format fix
  • Loading branch information
amitdev authored Mar 31, 2023
2 parents 80ffbc1 + 5596b2c commit 5e9d149
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ val pmdVersion = "6.55.0"
plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "1.6.20"
id("org.jetbrains.intellij") version "1.13.2"
id("org.jetbrains.intellij") version "1.13.3"
id("org.jetbrains.changelog") version "1.1.2"
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ pluginVersion = 1.8.26

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 211.0
pluginUntilBuild = 240.0
pluginSinceBuild = 222.4
pluginUntilBuild = 240

# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions = 2021.1.1, 2022.1.3
pluginVerifierIdeVersions = 2022.2.4, 2022.3.1, 2023.1

platformType = IC
platformVersion = 2021.1.1
platformVersion = 2022.2.4
platformDownloadSources = true

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.plugins.bodhi.pmd.core.PMDJsonExportingRenderer;
Expand Down Expand Up @@ -64,8 +63,8 @@ public PMDConfigurationForm(final Project project) {
actionGroup.removeAll();
//Add the toolbar actions associated to this form to it
actionGroup.add(new AddRuleSetAction("Add", "Add a custom ruleset", PlatformIcons.ADD_ICON));
actionGroup.add(new EditRuleSetAction("Edit", "Edit selected ruleset", IconLoader.getIcon("/actions/editSource.png", PMDConfigurationForm.class)));
actionGroup.add(new DeleteRuleSetAction("Delete", "Remove selected ruleset", IconLoader.getIcon("/general/remove.png", PMDConfigurationForm.class)));
actionGroup.add(new EditRuleSetAction("Edit", "Edit selected ruleset", PlatformIcons.EDIT));
actionGroup.add(new DeleteRuleSetAction("Delete", "Remove selected ruleset", PlatformIcons.DELETE_ICON));
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("modify actions", actionGroup, true);
toolbar.getComponent().setVisible(true);
buttonPanel.setLayout(new BorderLayout());
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/intellij/plugins/bodhi/pmd/PMDInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
Expand Down Expand Up @@ -93,14 +94,14 @@ public void runPMD(AnActionEvent actionEvent, String ruleSetPaths, boolean isCus
VirtualFile[] selectedFiles;
switch (actionEvent.getPlace()) {
case ActionPlaces.CHANGES_VIEW_POPUP:
selectedFiles = VcsContextFactory.SERVICE.getInstance().createContextOn(actionEvent).getSelectedFiles();
selectedFiles = actionEvent.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
break;
case ActionPlaces.MAIN_MENU:
VirtualFile[] contentRoots = ProjectRootManager.getInstance(project).getContentRoots();
selectedFiles = VfsUtil.getCommonAncestors(contentRoots);
break;
default:
selectedFiles = actionEvent.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
selectedFiles = actionEvent.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.intellij.plugins.bodhi.pmd;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
Expand Down Expand Up @@ -39,7 +40,7 @@
value = "$PROJECT_FILE$"
)}
)
public class PMDProjectComponent implements ProjectComponent, PersistentStateComponent<PersistentData> {
public class PMDProjectComponent implements ProjectComponent, PersistentStateComponent<PersistentData>, Disposable {

/**
* The Tool ID of the results panel.
Expand Down Expand Up @@ -151,7 +152,7 @@ public void actionPerformed(AnActionEvent e) {
actionGroup.addAll(newActionList);
}

public void disposeComponent() {
public void dispose() {
numProjectsOpen.decrementAndGet();
}

Expand All @@ -171,7 +172,7 @@ public void projectOpened() {
private void registerToolWindow() {
if (toolWindowManager.getToolWindow(TOOL_ID) == null) {
resultWindow = toolWindowManager.registerToolWindow(TOOL_ID, true, ToolWindowAnchor.BOTTOM);
Content content = ContentFactory.SERVICE.getInstance().createContent(resultPanel, "", false);
Content content = ContentFactory.getInstance().createContent(resultPanel, "", false);
resultWindow.getContentManager().addContent(content);
resultWindow.setType(ToolWindowType.DOCKED, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.intellij.plugins.bodhi.pmd;

import com.intellij.CommonBundle;
import com.intellij.icons.AllIcons;
import com.intellij.ide.*;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
Expand All @@ -10,7 +11,6 @@
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
Expand Down Expand Up @@ -454,7 +454,7 @@ public void addProcessingErrorsNodeToRootIfHasAny() {
*/
private class ReRunAction extends AnAction {
public ReRunAction() {
super(CommonBundle.message("action.rerun"), UsageViewBundle.message("action.description.rerun"), IconLoader.getIcon("/actions/refreshUsages.png", ReRunAction.class));
super(CommonBundle.message("action.rerun"), UsageViewBundle.message("action.description.rerun"), AllIcons.Actions.Rerun);
registerCustomShortcutSet(CommonShortcuts.getRerun(), PMDResultPanel.this);
}

Expand All @@ -480,7 +480,7 @@ private static class CloseAction extends AnAction {
private static final String ACTION_CLOSE = "action.close";

private CloseAction() {
super(CommonBundle.message(ACTION_CLOSE), null, IconLoader.getIcon("/actions/cancel.png", CloseAction.class));
super(CommonBundle.message(ACTION_CLOSE), null, AllIcons.Actions.Cancel);
}

public void actionPerformed(AnActionEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import net.sourceforge.pmd.renderers.AbstractIncrementingRenderer;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.config.RequestConfig;
//import org.apache.http.client.fluent.Request;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.File;
import java.io.IOException;
Expand All @@ -22,6 +27,10 @@
import java.util.Iterator;
import java.util.UUID;

/**
* For exporting anonymized PMD results to a server in JSON format.
* Can be tested e.g. with nc -lvk 8080.
*/
public class PMDJsonExportingRenderer extends AbstractIncrementingRenderer {
private static final String NAME = "json exporter";
private static final int FORMAT_VERSION = 0;
Expand Down Expand Up @@ -227,15 +236,19 @@ public String exportJsonData() {
*/
public static String tryJsonExport(String content, String url) {
String msg = "";
HttpPost httpPost = new HttpPost(url);
StringEntity contentEntity = new StringEntity(content,
ContentType.create("application/json", "UTF-8"));
try {
Request.Post(url)
.body(contentEntity)
.socketTimeout(SOCKET_TIMEOUT)
.connectTimeout(CONNECT_TIMEOUT)
.execute();
} catch (SocketTimeoutException e) {
httpPost.setEntity(contentEntity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");

RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(CONNECT_TIMEOUT).setConnectTimeout(CONNECT_TIMEOUT)
.setSocketTimeout(SOCKET_TIMEOUT).build();
try (CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpPost)) {
} catch (SocketTimeoutException e) {
// no-op, expected because no response back
}
catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private PMDJsonExportingRenderer addExportRenderer(Map<String, String> options)
}
if (exportStats) {
exportingRenderer = new PMDJsonExportingRenderer(exportUrl);
exportingRenderer.start();
// exportingRenderer.start(); is already called from PmdAnalysis for all renderers, issue #114
}
return exportingRenderer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.intellij.plugins.bodhi.pmd.tree;

import com.intellij.openapi.util.IconLoader;
import com.intellij.icons.AllIcons;
import com.intellij.ui.ColoredTreeCellRenderer;
import net.sourceforge.pmd.RulePriority;
import org.jetbrains.annotations.NotNull;
Expand All @@ -23,8 +23,8 @@ public class PMDCellRenderer extends ColoredTreeCellRenderer {

//Try to load idea specific icons for the tree.
static {
CLOSED_ICON = IconLoader.getIcon("/nodes/TreeClosed.png", PMDCellRenderer.class);
OPEN_ICON = IconLoader.getIcon("/nodes/TreeOpen.png", PMDCellRenderer.class);
CLOSED_ICON = AllIcons.Nodes.Folder;
OPEN_ICON = AllIcons.Nodes.Folder;
}

public void customizeCellRenderer(@NotNull JTree tree,
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/intellij/plugins/bodhi/pmd/tree/Severity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.intellij.plugins.bodhi.pmd.tree;

import com.intellij.openapi.util.IconLoader;
import com.intellij.icons.AllIcons;
import net.sourceforge.pmd.RulePriority;
import org.jetbrains.annotations.NotNull;

Expand All @@ -17,11 +17,11 @@
* @author jborgers
*/
public enum Severity {
BLOCKER(RulePriority.HIGH, "Blocker", IconLoader.getIcon("/ide/fatalError.png", Severity.class), new Color(188, 98, 98)),
CRITICAL(RulePriority.MEDIUM_HIGH, "Critical", IconLoader.getIcon("/runConfigurations/testError.png", Severity.class), new Color(152, 98, 90)),
MAJOR(RulePriority.MEDIUM, "Major", IconLoader.getIcon("/general/warning.png", Severity.class), new Color(142, 122, 38)),
MINOR(RulePriority.MEDIUM_LOW, "Minor", IconLoader.getIcon("/nodes/warningIntroduction.png", Severity.class), new Color(126, 126, 126)),
INFO(RulePriority.LOW, "Info", IconLoader.getIcon("/general/information.png", Severity.class), new Color(48, 116, 148));
BLOCKER(RulePriority.HIGH, "Blocker", AllIcons.Ide.FatalError, new Color(188, 98, 98)),
CRITICAL(RulePriority.MEDIUM_HIGH, "Critical", AllIcons.RunConfigurations.TestError, new Color(152, 98, 90)),
MAJOR(RulePriority.MEDIUM, "Major", AllIcons.General.Warning, new Color(142, 122, 38)),
MINOR(RulePriority.MEDIUM_LOW, "Minor", AllIcons.Nodes.WarningIntroduction, new Color(126, 126, 126)),
INFO(RulePriority.LOW, "Info", AllIcons.General.Information, new Color(48, 116, 148));

private final RulePriority rulePriority;
private final String name;
Expand Down

0 comments on commit 5e9d149

Please sign in to comment.