Skip to content

Commit

Permalink
Ensure third-party classpath is reloaded by extracting common reset c…
Browse files Browse the repository at this point in the history
…ode to a single class (#630)
  • Loading branch information
jshiell committed Feb 4, 2024
1 parent 410e13e commit d27a1d9
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 79 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# CheckStyle-IDEA Changelog

* **5.87.1** New: Third-party classpath is re-read on configuration reset (#630).
* **5.87.0** Fixed: Exceptions when opening modal dialogues (#628).
* **5.87.0** New: Now built against IDEA 2023.1.5 (was 2022.1.4).
* **5.86.0** New: Added Checkstyle 10.13.0, 10.12.7.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
// Project Metadata
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

version = '5.87.0'
version = '5.87.1'

intellij {
version = 'IC-2023.1.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,31 @@
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
import org.infernus.idea.checkstyle.checker.CheckerFactoryCache;
import org.infernus.idea.checkstyle.config.PluginConfiguration;
import org.infernus.idea.checkstyle.config.PluginConfigurationBuilder;
import org.infernus.idea.checkstyle.config.PluginConfigurationManager;
import org.infernus.idea.checkstyle.model.ConfigurationLocation;
import org.infernus.idea.checkstyle.ui.CheckStyleConfigPanel;
import org.infernus.idea.checkstyle.util.TempDirProvider;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.util.List;


/**
* The "configurable component" required by IntelliJ IDEA to provide a Swing form for inclusion into the 'Settings'
* dialog. Registered in {@code plugin.xml} as a {@code projectConfigurable} extension.
*/
public class CheckStyleConfigurable
implements Configurable {
public class CheckStyleConfigurable implements Configurable {
private static final Logger LOG = Logger.getInstance(CheckStyleConfigurable.class);

private final Project project;

private final CheckStyleConfigPanel configPanel;
private final CheckstyleProjectService checkstyleProjectService;
private final PluginConfigurationManager pluginConfigurationManager;
private final CheckerFactoryCache checkerFactoryCache;
private final ConfigurationInvalidator configurationInvalidator;

CheckStyleConfigurable(@NotNull final Project project) {
this.project = project;

this.checkstyleProjectService = project.getService(CheckstyleProjectService.class);
this.checkerFactoryCache = project.getService(CheckerFactoryCache.class);
this.pluginConfigurationManager = project.getService(PluginConfigurationManager.class);
this.configurationInvalidator = project.getService(ConfigurationInvalidator.class);

this.configPanel = new CheckStyleConfigPanel(project, checkstyleProjectService, checkerFactoryCache);
this.configPanel = new CheckStyleConfigPanel(project);
}

public String getDisplayName() {
Expand All @@ -57,10 +46,7 @@ public JComponent createComponent() {
@Override
public boolean isModified() {
final PluginConfiguration oldConfig = pluginConfigurationManager.getCurrent();
final PluginConfiguration newConfig = PluginConfigurationBuilder
.from(configPanel.getPluginConfiguration())
.withScanBeforeCheckin(oldConfig.isScanBeforeCheckin())
.build();
final PluginConfiguration newConfig = PluginConfigurationBuilder.from(configPanel.getPluginConfiguration()).withScanBeforeCheckin(oldConfig.isScanBeforeCheckin()).build();

boolean result = !oldConfig.hasChangedFrom(newConfig);
if (LOG.isDebugEnabled()) {
Expand All @@ -70,36 +56,17 @@ public boolean isModified() {
}

public void apply() {
final PluginConfiguration newConfig = PluginConfigurationBuilder.from(configPanel.getPluginConfiguration())
.withScanBeforeCheckin(pluginConfigurationManager.getCurrent().isScanBeforeCheckin())
.build();
final PluginConfiguration newConfig = PluginConfigurationBuilder.from(configPanel.getPluginConfiguration()).withScanBeforeCheckin(pluginConfigurationManager.getCurrent().isScanBeforeCheckin()).build();
pluginConfigurationManager.setCurrent(newConfig, true);

activateCurrentCheckstyleVersion(newConfig.getCheckstyleVersion(), newConfig.getThirdPartyClasspath());
if (!newConfig.isCopyLibs()) {
new TempDirProvider().deleteCopiedLibrariesDir(project);
}
}

private void activateCurrentCheckstyleVersion(final String checkstyleVersion,
final List<String> thirdPartyClasspath) {
invalidateCachedResources();
checkstyleProjectService.activateCheckstyleVersion(checkstyleVersion, thirdPartyClasspath);
}

private void invalidateCachedResources() {
checkerFactoryCache.invalidate();
pluginConfigurationManager
.getCurrent()
.getLocations()
.forEach(ConfigurationLocation::reset);
configurationInvalidator.invalidateCachedResources();
}

public void reset() {
final PluginConfiguration pluginConfig = pluginConfigurationManager.getCurrent();
configPanel.showPluginConfiguration(pluginConfig);

activateCurrentCheckstyleVersion(pluginConfig.getCheckstyleVersion(), pluginConfig.getThirdPartyClasspath());
configurationInvalidator.invalidateCachedResources();
}

public void disposeUIResources() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.infernus.idea.checkstyle;

import com.intellij.openapi.project.Project;
import org.infernus.idea.checkstyle.checker.CheckerFactoryCache;
import org.infernus.idea.checkstyle.config.PluginConfiguration;
import org.infernus.idea.checkstyle.config.PluginConfigurationManager;
import org.infernus.idea.checkstyle.model.ConfigurationLocation;
import org.infernus.idea.checkstyle.util.TempDirProvider;
import org.jetbrains.annotations.NotNull;

public class ConfigurationInvalidator {

private final Project project;
private final CheckstyleProjectService checkstyleProjectService;
private final PluginConfigurationManager pluginConfigurationManager;
private final CheckerFactoryCache checkerFactoryCache;

ConfigurationInvalidator(@NotNull final Project project) {
this.project = project;
this.checkstyleProjectService = project.getService(CheckstyleProjectService.class);
this.checkerFactoryCache = project.getService(CheckerFactoryCache.class);
this.pluginConfigurationManager = project.getService(PluginConfigurationManager.class);
}

public void invalidateCachedResources() {
checkerFactoryCache.invalidate();

PluginConfiguration config = pluginConfigurationManager.getCurrent();
config.getLocations().forEach(ConfigurationLocation::reset);

checkstyleProjectService.activateCheckstyleVersion(config.getCheckstyleVersion(), config.getThirdPartyClasspath());
if (!config.isCopyLibs()) {
new TempDirProvider().deleteCopiedLibrariesDir(project);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import org.infernus.idea.checkstyle.config.PluginConfigurationManager;
import org.infernus.idea.checkstyle.checker.CheckerFactoryCache;
import org.infernus.idea.checkstyle.model.ConfigurationLocation;
import org.infernus.idea.checkstyle.ConfigurationInvalidator;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -26,12 +24,6 @@ public void actionPerformed(@NotNull final AnActionEvent event) {
});
}

project(event).ifPresent(project -> {
project.getService(PluginConfigurationManager.class)
.getCurrent()
.getLocations()
.forEach(ConfigurationLocation::reset);
project.getService(CheckerFactoryCache.class).invalidate();
});
project(event).ifPresent(project -> project.getService(ConfigurationInvalidator.class).invalidateCachedResources());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.AnActionButton;
import com.intellij.ui.AnActionButtonRunnable;
import com.intellij.ui.AnActionButtonUpdater;
import com.intellij.ui.TitledSeparator;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.*;
import com.intellij.ui.components.JBList;
import com.intellij.ui.table.JBTable;
import com.intellij.util.ui.JBUI;
Expand All @@ -29,24 +25,11 @@
import org.infernus.idea.checkstyle.util.Strings;
import org.jetbrains.annotations.NotNull;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.*;
import javax.swing.table.TableColumn;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -78,14 +61,13 @@ public class CheckStyleConfigPanel extends JPanel {
private final CheckstyleProjectService checkstyleProjectService;
private final CheckerFactoryCache checkerFactoryCache;

public CheckStyleConfigPanel(@NotNull final Project project,
@NotNull final CheckstyleProjectService checkstyleProjectService,
@NotNull final CheckerFactoryCache checkerFactoryCache) {
public CheckStyleConfigPanel(@NotNull final Project project) {
super(new BorderLayout());

this.project = project;
this.checkstyleProjectService = checkstyleProjectService;
this.checkerFactoryCache = checkerFactoryCache;

this.checkstyleProjectService = project.getService(CheckstyleProjectService.class);
this.checkerFactoryCache = project.getService(CheckerFactoryCache.class);

csVersionDropdown = buildCheckstyleVersionComboBox();

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</p>
]]>
</description>
<version>5.87.0</version>
<version>5.87.1</version>
<idea-version since-build="231.9392.1"/>
<vendor url="https://infernus.org/" email="[email protected]">Jamie Shiell</vendor>

Expand All @@ -24,6 +24,7 @@
<change-notes>
<![CDATA[
<ul>
<li>5.87.1: New: Third-party classpath is re-read on configuration reset (#630).</li>
<li>5.87.0: Fixed: Exceptions when opening modal dialogues (#628).</li>
<li>5.87.0: New: Now built against IDEA 2023.1.5 (was 2022.1.4).</li>
<li>5.86.0: New: Added Checkstyle 10.13.0, 10.12.7.</li>
Expand Down Expand Up @@ -59,6 +60,7 @@
<projectService serviceImplementation="org.infernus.idea.checkstyle.config.ProjectConfigurationState"/>
<projectService serviceImplementation="org.infernus.idea.checkstyle.CheckstylePluginApi"/>
<projectService serviceImplementation="org.infernus.idea.checkstyle.util.ProjectFilePaths"/>
<projectService serviceImplementation="org.infernus.idea.checkstyle.ConfigurationInvalidator"/>

<postStartupActivity implementation="org.infernus.idea.checkstyle.startup.NotifyUserIfPluginUpdated"/>
<postStartupActivity implementation="org.infernus.idea.checkstyle.startup.DisableCheckstyleLogging"/>
Expand Down

0 comments on commit d27a1d9

Please sign in to comment.