Skip to content

Commit

Permalink
1. Do not call toCommandLine twice to avoid 'java.lang.IllegalStateEx…
Browse files Browse the repository at this point in the history
…ception: environment was provided twice'

2. Fix running inside IDEA terminal

Close #3
  • Loading branch information
turbanoff committed May 22, 2021
1 parent 13a5fe1 commit 98200d7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
15 changes: 6 additions & 9 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>org.turbanov.execution.cmd</id>
<name>RunInCmd</name>
<version>1.7</version>
<version>1.8</version>
<vendor email="[email protected]" url="https://github.com/turbanoff/RunInCmdPlugin">Turbanov Andrey</vendor>

<description><![CDATA[
Expand All @@ -12,6 +12,11 @@
<!--Add change notes here.<br>-->
<!--<em>most HTML tags may be used</em>-->
<change-notes><![CDATA[
<h3>1.8</h3>
<ul>
<li>Fix IllegalStateException in IntelliJ IDEA 2020.1</li>
<li>Fix run inside IDEA terminal</li>
</ul>
<h3>1.7</h3>
<ul>
<li>Update to support IntelliJ IDEA 2019.x</li>
Expand Down Expand Up @@ -70,14 +75,6 @@
<projectService serviceImplementation="org.turbanov.execution.cmd.OptionsPatchConfiguration"/>
</extensions>

<application-components>
<!-- Add your application components here -->
</application-components>

<project-components>
<!-- Add your project components here -->
</project-components>

<actions>
<!-- Add your actions here -->
</actions>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RunInCmdPlugin
Plugin for IntelliJ IDEA. It allows to run your RunConfiguration inside cmd.exe instead of internal IDEA console
Also it provides ability to modify program and VM options on-the-fly before run
Plugin for IntelliJ IDEA. It allows to run your RunConfiguration inside cmd.exe instead of internal IDEA console.
Also it provides ability to modify a program and VM options on-the-fly before run.

# Repository link
https://plugins.jetbrains.com/plugin/7976-runincmd
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/org/turbanov/execution/cmd/InCmdRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ protected RunContentDescriptor doExecute(@NotNull RunProfileState runProfileStat
JavaCommandLineState state = (JavaCommandLineState) runProfileState;
JavaParameters javaParameters = state.getJavaParameters();
javaParameters.setUseDynamicClasspath(false);
GeneralCommandLine oldCommandLine = javaParameters.toCommandLine();
LOG.info("Old command line: " + oldCommandLine);
LOG.info("Old command line. JDK path: " + javaParameters.getJdkPath() +
" VM options: " + javaParameters.getVMParametersList() +
" Parameters: " + javaParameters.getProgramParametersList()
);

OptionsPatchConfiguration options = ServiceManager.getService(environment.getProject(), OptionsPatchConfiguration.class);
patchParameterList(javaParameters.getVMParametersList(), options.toAddVmOptions, options.toRemoveVmOptions, options.startPort);
Expand Down
26 changes: 19 additions & 7 deletions src/org/turbanov/execution/cmd/TerminalRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.terminal.LocalTerminalDirectRunner;
import org.jetbrains.plugins.terminal.TerminalProcessOptions;
import org.jetbrains.plugins.terminal.TerminalView;
import com.intellij.openapi.project.Project;
import com.intellij.terminal.JBTerminalWidget;
import com.pty4j.PtyProcess;

import java.io.IOException;
Expand All @@ -21,15 +23,25 @@ public static void runInIdeaTerminal(@NotNull Project project, @NotNull String[]
LocalTerminalDirectRunner runner = new LocalTerminalDirectRunner(project) {
@Override
protected PtyProcess createProcess(@Nullable String directory, @Nullable String commandHistoryFilePath) throws ExecutionException {
Map<String, String> envs = new HashMap<>(System.getenv());
envs.put("CLASSPATH", classPath);
try {
return PtyProcess.exec(command, envs, workingDirectory);
} catch (IOException e) {
throw new ExecutionException(e);
}
return createProcessImpl(classPath, command, workingDirectory);
}


@Override
public @NotNull PtyProcess createProcess(@NotNull TerminalProcessOptions options, @Nullable JBTerminalWidget widget) throws ExecutionException {
return createProcessImpl(classPath, command, workingDirectory);
}
};
terminalView.createNewSession(runner);
}

private static PtyProcess createProcessImpl(@NotNull String classPath, @NotNull String[] command, @NotNull String workingDirectory) throws ExecutionException {
Map<String, String> envs = new HashMap<>(System.getenv());
envs.put("CLASSPATH", classPath);
try {
return PtyProcess.exec(command, envs, workingDirectory);
} catch (IOException e) {
throw new ExecutionException(e);
}
}
}

0 comments on commit 98200d7

Please sign in to comment.