Skip to content

Commit

Permalink
use single-threaded executor to avoid races when registering Run Conf…
Browse files Browse the repository at this point in the history
…iguration actions.

Closes #8
  • Loading branch information
turbanoff committed Apr 17, 2021
1 parent 5e1b34a commit 2b2001f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Plugins for Jetbrains IDEs. It's provides a way to use run configurations as buttons on toolbar. Or assign shortcuts to execute specific run configuration.

Plugin is compatible with all major IDEs based on IntelliJ Platform starting from version 2019.1:
Plugin is compatible with all major IDEs based on IntelliJ Platform starting from version 2019.2:
* IntelliJ IDEA
* Android Studio
* PhpStorm
Expand Down
9 changes: 7 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>org.turbanov.run.configuration.as.action</id>
<name>Run Configuration as Action</name>
<version>1.4.2</version>
<version>1.4.3</version>
<vendor email="turbanoff@gmail.com" url="https://github.com/turbanoff/RunConfigurationAsAction">Turbanov Andrey</vendor>

<description><![CDATA[
Expand All @@ -11,6 +11,11 @@ Also it allows to create button in toolbar to run specific configuration.<br>
]]></description>

<change-notes><![CDATA[
<h3>1.4.3</h3>
<ul>
<li>Fix race when registering many Run Configurations at once
</li>
</ul>
<h3>1.4.2</h3>
<ul>
<li>Properly show Run configurations with underscore character.
Expand Down Expand Up @@ -45,7 +50,7 @@ Also it allows to create button in toolbar to run specific configuration.<br>
]]>
</change-notes>

<idea-version since-build="191"/>
<idea-version since-build="192"/>

<depends>com.intellij.modules.platform</depends>

Expand Down
1 change: 1 addition & 0 deletions resources/META-INF/pluginIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src/org/turbanov/actions/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.IconUtil;
import com.intellij.util.ImageLoader;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.util.ui.JBImageIcon;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;

/**
* @author Andrey Turbanov
Expand All @@ -39,6 +41,7 @@ public class Bootstrap implements ProjectComponent {
private static final Logger log = Logger.getInstance(RunConfigurationAsAction.class);
private static final String ACTION_ID_PREFIX = "RunConfigurationAsAction";
private static final PluginId PLUGIN_ID = PluginId.getId("org.turbanov.run.configuration.as.action");
private static final ExecutorService ourExecutor = AppExecutorUtil.createBoundedApplicationPoolExecutor("RunConfigurationAsAction", 1);

private final Project myProject;

Expand Down Expand Up @@ -117,6 +120,10 @@ private static String makeActionId(@NotNull Executor executor,
}

public void removeForAllExecutors(@NotNull RunnerAndConfigurationSettings runConfig) {
ourExecutor.execute(() -> removeForAllExecutorsImpl(runConfig));
}

private void removeForAllExecutorsImpl(@NotNull RunnerAndConfigurationSettings runConfig) {
List<Executor> executors = Executor.EXECUTOR_EXTENSION_NAME.getExtensionList();
ActionManager actionManager = ActionManager.getInstance();
List<ExecutionTarget> targets = getTargets(runConfig);
Expand All @@ -138,7 +145,11 @@ public void removeForAllExecutors(@NotNull RunnerAndConfigurationSettings runCon
}
}

private void registerForAllExecutors(@NotNull RunnerAndConfigurationSettings settings) {
private void registerForAllExecutors(@NotNull RunnerAndConfigurationSettings runConfig) {
ourExecutor.execute(() -> registerForAllExecutorsImpl(runConfig));
}

private void registerForAllExecutorsImpl(@NotNull RunnerAndConfigurationSettings settings) {
List<Executor> executors = Executor.EXECUTOR_EXTENSION_NAME.getExtensionList();
List<ExecutionTarget> targets = getTargets(settings);
for (Executor executor : executors) {
Expand Down

0 comments on commit 2b2001f

Please sign in to comment.