Skip to content

Commit

Permalink
Version 1.13 to fix error with 2021.2 version of IDE.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhmelyuk committed Aug 1, 2021
1 parent 0de07ab commit a5cf853
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.ArrayList;
import java.util.List;

public class MultirunRunConfiguration extends RunConfigurationBase {
public class MultirunRunConfiguration extends RunConfigurationBase implements RunnerSettings {

public static final String PROP_SEPARATE_TABS = "separateTabs";
public static final String PROP_REUSE_TABS_WITH_FAILURE = "reuseTabsWithFailures";
Expand Down
38 changes: 35 additions & 3 deletions src/main/java/com/khmelyuk/multirun/MultirunRunner.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package com.khmelyuk.multirun;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.intellij.coverage.CoverageExecutor;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionManager;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.executors.DefaultDebugExecutor;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.execution.runners.DefaultProgramRunner;
import org.jetbrains.annotations.NotNull;
import com.intellij.execution.runners.DefaultProgramRunnerKt;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.khmelyuk.multirun.ui.MultirunRunConfigurationEditor;

/**
* Runner for Multirun configurations.
*
* @author Ruslan Khmelyuk
*/
public class MultirunRunner extends DefaultProgramRunner {
public class MultirunRunner implements ProgramRunner<MultirunRunConfiguration> {

public static final String JREBEL_EXECUTOR_ID = "JRebel Executor";
public static final String JREBEL_DEBUG_ID = "JRebel Debug";
Expand All @@ -23,6 +35,26 @@ public String getRunnerId() {
return "multirun";
}

@Override
public void execute(@NotNull final ExecutionEnvironment environment) throws ExecutionException {
final RunProfileState runProfileState = environment.getState();
if (runProfileState != null) {
final Project project = environment.getProject();

ExecutionManager.Companion.getInstance(project).startRunProfile(
environment,
runProfileState,
runProfileState1 -> DefaultProgramRunnerKt.executeState(runProfileState1, environment, MultirunRunner.this)
);
}
}

@Override
public @Nullable
SettingsEditor<MultirunRunConfiguration> getSettingsEditor(final Executor executor, final RunConfiguration configuration) {
return new MultirunRunConfigurationEditor(configuration.getProject());
}

@Override
public boolean canRun(@NotNull String executorId, @NotNull RunProfile runProfile) {
return runProfile instanceof MultirunRunConfiguration &&
Expand Down
79 changes: 43 additions & 36 deletions src/main/java/com/khmelyuk/multirun/MultirunRunnerState.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package com.khmelyuk.multirun;

import com.intellij.execution.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.ExecutionTarget;
import com.intellij.execution.ExecutionTargetManager;
import com.intellij.execution.Executor;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.RunnerRegistry;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.impl.RunDialog;
Expand All @@ -25,13 +37,10 @@
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.LayeredIcon;
import com.intellij.ui.content.Content;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/** @author Ruslan Khmelyuk */
/**
* @author Ruslan Khmelyuk
*/
public class MultirunRunnerState implements RunProfileState {

private final double delayTime;
Expand Down Expand Up @@ -64,7 +73,8 @@ public MultirunRunnerState(List<RunConfiguration> runConfigurations,
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner programRunner) {
stopRunningMultirunConfiguration.beginStartingConfigurations();
runConfigurations(executor, runConfigurations, 0);
ApplicationManager.getApplication().executeOnPooledThread(() -> runConfigurations(executor, runConfigurations, 0));

return null;
}

Expand All @@ -87,8 +97,8 @@ private void runConfigurations(final Executor executor, final List<RunConfigurat
boolean started = false;
try {
final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), runConfiguration);
if (runner == null) { return; }
if (!checkRunConfiguration(executor, project, configuration)) { return; }
if (runner == null) {return;}
if (!checkRunConfiguration(executor, project, configuration)) {return;}

final ExecutionEnvironment executionEnvironment = new ExecutionEnvironment(executor, runner, configuration, project);

Expand All @@ -102,7 +112,8 @@ public void processStarted(final RunContentDescriptor descriptor) {
if (descriptor == null) {
if (startOneByOne) {
// start next configuration..
runConfigurations(executor, runConfigurations, index + 1);
ApplicationManager.getApplication().executeOnPooledThread(
() -> runConfigurations(executor, runConfigurations, index + 1));
}
return;
}
Expand Down Expand Up @@ -155,21 +166,23 @@ private void onTermination(final ProcessEvent processEvent, final boolean termin
return;
}

ApplicationManager.getApplication().invokeLater(new Runnable() {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
final Content content = descriptor.getAttachedContent();
if (content == null) { return; }
if (content == null) {return;}

// exit code is 0 if the process completed successfully
final boolean completedSuccessfully = (terminated && processEvent.getExitCode() == 0);

if (hideSuccessProcess && completedSuccessfully) {
// close the tab for the success process and exit - nothing else could be done
if (content.getManager() != null) {
content.getManager().removeContent(content, false);
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
if (content.getManager() != null) {
content.getManager().removeContent(content, false);
}
});
return;
}

if ((completedSuccessfully && !reuseTabs) || (!completedSuccessfully && !reuseTabsWithFailure)) {
Expand All @@ -185,12 +198,8 @@ public void run() {

// add the alert icon in case if process existed with non-0 status
if (markFailedProcess && processEvent.getExitCode() != 0) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
content.setIcon(LayeredIcon.create(content.getIcon(), AllIcons.Nodes.TabAlert));
}
});
ApplicationManager.getApplication().executeOnPooledThread(
() -> content.setIcon(LayeredIcon.create(content.getIcon(), AllIcons.Nodes.TabAlert)));
}
}
});
Expand Down Expand Up @@ -227,11 +236,8 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
} catch (InterruptedException ignored) {
return;
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
runConfigurations(executor, runConfigurations, index + 1);
}
});
ApplicationManager.getApplication().executeOnPooledThread(
() -> runConfigurations(executor, runConfigurations, index + 1));
}
});
} else if (delayTime < 0) {
Expand All @@ -248,15 +254,14 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
} catch (InterruptedException ignored) {
return;
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
runConfigurations(executor, runConfigurations, index + 1);
}
});
ApplicationManager.getApplication().executeOnPooledThread(
() -> runConfigurations(executor, runConfigurations, index + 1));
}
});
} else {
runConfigurations(executor, runConfigurations, index + 1);
ApplicationManager.getApplication().executeOnPooledThread(
() -> runConfigurations(executor, runConfigurations, index + 1));
// runConfigurations(executor, runConfigurations, index + 1);
}
} else {
stopRunningMultirunConfiguration.doneStaringConfigurations();
Expand All @@ -272,10 +277,12 @@ public void run() {
} finally {
// start the next one
if (!startOneByOne) {
runConfigurations(executor, runConfigurations, index + 1);
ApplicationManager.getApplication().executeOnPooledThread(
() -> runConfigurations(executor, runConfigurations, index + 1));
} else if (!started) {
// failed to start current, means the chain is broken
runConfigurations(executor, runConfigurations, index + 1);
ApplicationManager.getApplication().executeOnPooledThread(
() -> runConfigurations(executor, runConfigurations, index + 1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.khmelyuk.multirun;

import com.intellij.execution.KillableProcess;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import com.intellij.execution.KillableProcess;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;

/**
* The action to stop the running multirun configurations.
*
Expand Down Expand Up @@ -109,9 +109,8 @@ public boolean isStopMultirunTriggered() {
// TODO - move to some component

public void beginStartingConfigurations() {
if (startingCounter.incrementAndGet() == 1) {
stopStartingConfigurations.set(false);
}
stopStartingConfigurations.set(false);
startingCounter.incrementAndGet();
}

public void doneStaringConfigurations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</constraints>
<properties>
<text value="Start configurations one by one"/>
<toolTipText value="Start next configuration only after the previous configuration has been started. This may increase the start period, as &quot;before launch&quot; operations run one-by-one, not in parallel."/>
<toolTipText value="Start next configuration only after the previous configuration has been started. This may increase the start period, as &quot;before launch&quot; operations run one-by-one, not in parallel. Use negative delay to start next configuration only after previous has completed."/>
<verticalAlignment value="0"/>
<verticalTextPosition value="0"/>
</properties>
Expand Down Expand Up @@ -105,6 +105,7 @@
</constraints>
<properties>
<text value="with delay"/>
<toolTipText value="use negative delay to start next configuration only after previous has completed"/>
</properties>
</component>
<component id="da67e" class="javax.swing.JTextField" binding="delayTime">
Expand All @@ -117,6 +118,7 @@
</constraints>
<properties>
<text value="0"/>
<toolTipText value="use negative delay to start next configuration only after previous has completed"/>
</properties>
</component>
<component id="63973" class="javax.swing.JLabel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.ui.*;
import com.intellij.ui.components.JBList;
import com.khmelyuk.multirun.MultirunRunConfiguration;
Expand Down Expand Up @@ -47,10 +46,15 @@ public MultirunRunConfigurationEditor(final Project project) {

@Override
protected void resetEditorFrom(MultirunRunConfiguration multirunRunConfiguration) {
this.configuration = multirunRunConfiguration;
DefaultListModel listModel = new DefaultListModel();
for (RunConfiguration each : multirunRunConfiguration.getRunConfigurations()) {
listModel.addElement(each);
if (multirunRunConfiguration != null) {
this.configuration = multirunRunConfiguration;
}

final DefaultListModel listModel = new DefaultListModel();
if (this.configuration != null) {
for (RunConfiguration each : this.configuration.getRunConfigurations()) {
listModel.addElement(each);
}
}
configurations.setModel(listModel);
configurations.getModel().addListDataListener(new ListDataListener() {
Expand All @@ -68,22 +72,30 @@ public void intervalRemoved(ListDataEvent e) {
public void contentsChanged(ListDataEvent e) {
RunConfiguration[] buffer = new RunConfiguration[configurations.getModel().getSize()];
((DefaultListModel) configurations.getModel()).copyInto(buffer);
configuration.setRunConfigurations(Arrays.asList(buffer));
if (MultirunRunConfigurationEditor.this.configuration != null) {
configuration.setRunConfigurations(Arrays.asList(buffer));
}
fireEditorStateChanged();
}
});
configurations.setCellRenderer(new RunConfigurationListCellRenderer());

delayTime.setText(String.format("%.1f", multirunRunConfiguration.getDelayTime()));
reuseTabs.setSelected(multirunRunConfiguration.isReuseTabs());
reuseTabsWithFailure.setSelected(multirunRunConfiguration.isReuseTabsWithFailure());
startOneByOne.setSelected(multirunRunConfiguration.isStartOneByOne());
markFailedProcess.setSelected(multirunRunConfiguration.isMarkFailedProcess());
hideSuccessProcess.setSelected(multirunRunConfiguration.isHideSuccessProcess());
if (this.configuration != null) {
delayTime.setText(String.format("%.1f", this.configuration.getDelayTime()));
reuseTabs.setSelected(this.configuration.isReuseTabs());
reuseTabsWithFailure.setSelected(this.configuration.isReuseTabsWithFailure());
startOneByOne.setSelected(this.configuration.isStartOneByOne());
markFailedProcess.setSelected(this.configuration.isMarkFailedProcess());
hideSuccessProcess.setSelected(this.configuration.isHideSuccessProcess());
}
}

@Override
protected void applyEditorTo(MultirunRunConfiguration multirunRunConfiguration) {
if (multirunRunConfiguration == null) {
return;
}

multirunRunConfiguration.setReuseTabs(reuseTabs.isSelected());
multirunRunConfiguration.setReuseTabsWithFailure(reuseTabsWithFailure.isSelected());
multirunRunConfiguration.setStartOneByOne(startOneByOne.isSelected());
Expand Down Expand Up @@ -182,6 +194,10 @@ public void customize(JList list, RunConfiguration data, int index, boolean sele

private java.util.List<RunConfiguration> getConfigurationsToAdd() {
java.util.List<RunConfiguration> result = new ArrayList<RunConfiguration>();
if (this.configuration == null) {
return result;
}

java.util.List<RunConfiguration> allConfigurations = RunManager.getInstance(project).getAllConfigurationsList();
for (RunConfiguration configuration : allConfigurations) {
if (this.configuration.equals(configuration)) {
Expand Down
Loading

0 comments on commit a5cf853

Please sign in to comment.