Cleanup (warnings; typos; annotations; formatting)

GitOrigin-RevId: 5a6b9b5b8d85346b77faf6378138d50312758b76
This commit is contained in:
Roman Shevchenko
2020-03-21 22:02:26 +00:00
committed by intellij-monorepo-bot
parent 1249c0fa18
commit 8e9e6cb2f8
3 changed files with 99 additions and 142 deletions
@@ -18,12 +18,11 @@ import com.intellij.openapi.module.WorkingDirectoryProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ExternalProjectSystemRegistry;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.PathUtil;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.EnvironmentUtil;
import com.intellij.util.PathUtil;
import com.intellij.util.execution.ParametersListUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -38,17 +37,19 @@ import java.util.List;
import java.util.Map;
public class ProgramParametersConfigurator {
private static final ExtensionPointName<WorkingDirectoryProvider> WORKING_DIRECTORY_PROVIDER_EP_NAME= ExtensionPointName
.create("com.intellij.module.workingDirectoryProvider");
@SuppressWarnings("DeprecatedIsStillUsed")
private static final ExtensionPointName<WorkingDirectoryProvider> WORKING_DIRECTORY_PROVIDER_EP_NAME =
ExtensionPointName.create("com.intellij.module.workingDirectoryProvider");
/** @deprecated use {@link PathMacroUtil#MODULE_WORKING_DIR} instead */
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
public static final String MODULE_WORKING_DIR = "%MODULE_WORKING_DIR%";
public void configureConfiguration(SimpleProgramParameters parameters, CommonProgramRunConfigurationParameters configuration) {
public void configureConfiguration(@NotNull SimpleProgramParameters parameters, @NotNull CommonProgramRunConfigurationParameters configuration) {
Project project = configuration.getProject();
Module module = getModule(configuration);
final String parametersString = expandPathAndMacros(configuration.getProgramParameters(), module, project);
String parametersString = expandPathAndMacros(configuration.getProgramParameters(), module, project);
parameters.getProgramParametersList().addParametersString(parametersString);
parameters.setWorkingDirectory(getWorkingDir(configuration, project, module));
@@ -64,13 +65,12 @@ public class ProgramParametersConfigurator {
}
@Contract("!null, _, _ -> !null")
public @Nullable String expandPathAndMacros(String s, Module module, Project project) {
final String path = expandPath(s, module, project);
if (path == null) return null;
return expandMacros(path, projectContext(project, module), false);
public @Nullable String expandPathAndMacros(String s, @Nullable Module module, @NotNull Project project) {
String path = expandPath(s, module, project);
return path != null ? expandMacros(path, projectContext(project, module), false) : null;
}
private static @NotNull DataContext projectContext(Project project, Module module) {
private static DataContext projectContext(Project project, Module module) {
return dataId -> {
if (CommonDataKeys.PROJECT.is(dataId)) return project;
if (LangDataKeys.MODULE.is(dataId) || LangDataKeys.MODULE_CONTEXT.is(dataId)) return module;
@@ -86,21 +86,18 @@ public class ProgramParametersConfigurator {
* @see #expandPathAndMacros For paths: working directory, input file, etc.
*/
public static String expandMacros(@Nullable String path) {
if (StringUtil.isEmpty(path)) {
return path;
}
return expandMacros(path, DataContext.EMPTY_CONTEXT, false);
return !StringUtil.isEmpty(path) ? expandMacros(path, DataContext.EMPTY_CONTEXT, false) : path;
}
public static @NotNull List<String> expandMacrosAndParseParameters(@Nullable String parametersStringWithMacros) {
if (StringUtil.isEmpty(parametersStringWithMacros)) {
return Collections.emptyList();
}
final String expandedParametersString = expandMacros(parametersStringWithMacros, DataContext.EMPTY_CONTEXT, true);
String expandedParametersString = expandMacros(parametersStringWithMacros, DataContext.EMPTY_CONTEXT, true);
return ParametersListUtil.parse(expandedParametersString);
}
private static @NotNull String expandMacros(@NotNull String path, @NotNull DataContext dataContext, boolean applyParameterEscaping) {
private static String expandMacros(String path, DataContext dataContext, boolean applyParameterEscaping) {
if (!Registry.is("allow.macros.for.run.configurations")) {
return path;
}
@@ -122,36 +119,33 @@ public class ProgramParametersConfigurator {
return path;
}
private static @Nullable String previewOrExpandMacro(@NotNull Macro macro,
@NotNull DataContext dataContext) {
private static @Nullable String previewOrExpandMacro(Macro macro, DataContext dataContext) {
try {
return macro instanceof PromptingMacro
? ((PromptingMacro)macro).expand(dataContext)
: macro.preview();
return macro instanceof PromptingMacro ? ((PromptingMacro)macro).expand(dataContext) : macro.preview();
}
catch (Macro.ExecutionCancelledException e) {
return null;
}
}
@Nullable
public String getWorkingDir(CommonProgramRunConfigurationParameters configuration, Project project, Module module) {
public @Nullable String getWorkingDir(@NotNull CommonProgramRunConfigurationParameters configuration,
@NotNull Project project,
@Nullable Module module) {
String workingDirectory = configuration.getWorkingDirectory();
String defaultWorkingDir = getDefaultWorkingDir(project);
if (StringUtil.isEmptyOrSpaces(workingDirectory)) {
workingDirectory = defaultWorkingDir;
if (workingDirectory == null) {
return null;
}
if (workingDirectory == null) return null;
}
workingDirectory = expandPathAndMacros(workingDirectory, module, project);
if (!com.intellij.openapi.util.io.PathUtil.isAbsolute(workingDirectory) && defaultWorkingDir != null) {
if (!PathUtil.isAbsolute(workingDirectory) && defaultWorkingDir != null) {
if (PathMacroUtil.DEPRECATED_MODULE_DIR.equals(workingDirectory)) {
return defaultWorkingDir;
}
//noinspection deprecation
if (MODULE_WORKING_DIR.equals(workingDirectory)) {
workingDirectory = PathMacroUtil.MODULE_WORKING_DIR;
}
@@ -162,50 +156,49 @@ public class ProgramParametersConfigurator {
}
else {
String workingDir = getDefaultWorkingDir(module);
if (workingDir != null) {
return workingDir;
}
if (workingDir != null) return workingDir;
}
}
workingDirectory = defaultWorkingDir + "/" + workingDirectory;
}
return workingDirectory;
}
@Nullable
protected String getDefaultWorkingDir(@NotNull Project project) {
return PathUtil.getLocalPath(project.getBaseDir());
protected @Nullable String getDefaultWorkingDir(@NotNull Project project) {
return project.getBasePath();
}
@Nullable
protected String getDefaultWorkingDir(@NotNull Module module) {
protected @Nullable String getDefaultWorkingDir(@NotNull Module module) {
for (WorkingDirectoryProvider provider : WORKING_DIRECTORY_PROVIDER_EP_NAME.getExtensions()) {
@SystemIndependent String path = provider.getWorkingDirectoryPath(module);
if (path != null) return path;
}
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
if (roots.length > 0) {
return PathUtil.getLocalPath(roots[0]);
return roots[0].getPath();
}
return null;
}
public void checkWorkingDirectoryExist(CommonProgramRunConfigurationParameters configuration, Project project, Module module)
throws RuntimeConfigurationWarning {
final String workingDir = getWorkingDir(configuration, project, module);
public void checkWorkingDirectoryExist(@NotNull CommonProgramRunConfigurationParameters configuration,
@NotNull Project project,
@Nullable Module module) throws RuntimeConfigurationWarning {
String workingDir = getWorkingDir(configuration, project, module);
if (workingDir == null) {
throw new RuntimeConfigurationWarning("Working directory is null for "+
"project '" + project.getName() + "' ("+project.getBasePath()+")"
+ ", module " + (module == null? "null" : "'" + module.getName() + "' (" + module.getModuleFilePath() + ")"));
throw new RuntimeConfigurationWarning("Working directory is null for project '" + project.getName() + "' (" + project.getBasePath() + ")," +
" module " + (module == null ? "null" : "'" + module.getName() + "' (" + module.getModuleFilePath() + ")"));
}
if (!new File(workingDir).exists()) {
throw new RuntimeConfigurationWarning("Working directory '" + workingDir + "' doesn't exist");
}
}
protected String expandPath(@Nullable String path, Module module, Project project) {
protected String expandPath(@Nullable String path, @Nullable Module module, @NotNull Project project) {
// https://youtrack.jetbrains.com/issue/IDEA-190100
// if old macro is used (because stored in the default project and applied for a new imported project) and module file stored under .idea, use new module macro instead
// if an old macro is used (because stored in the default project and applied for a new imported project)
// and module file stored under .idea, use the new module macro instead
if (module != null && PathMacroUtil.DEPRECATED_MODULE_DIR.equals(path) &&
module.getModuleFilePath().contains("/" + Project.DIRECTORY_STORE_FOLDER + "/") &&
ExternalProjectSystemRegistry.getInstance().getExternalSource(module) != null /* not really required but to reduce possible impact */) {
@@ -219,11 +212,7 @@ public class ProgramParametersConfigurator {
return path;
}
@Nullable
protected Module getModule(CommonProgramRunConfigurationParameters configuration) {
if (configuration instanceof ModuleBasedConfiguration) {
return ((ModuleBasedConfiguration)configuration).getConfigurationModule().getModule();
}
return null;
protected @Nullable Module getModule(CommonProgramRunConfigurationParameters cp) {
return cp instanceof ModuleBasedConfiguration ? ((ModuleBasedConfiguration<?, ?>)cp).getConfigurationModule().getModule() : null;
}
}
}
@@ -1,19 +1,4 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.configurations;
import com.intellij.util.EnvironmentUtil;
@@ -67,9 +52,7 @@ public class SimpleProgramParameters {
myPassParentEnvs = passDefaultEnvs;
}
/**
* @deprecated Use {@link #setEnv(Map)} and {@link #setPassParentEnvs(boolean)} instead with already preprocessed variables.
*/
/** @deprecated Use {@link #setEnv(Map)} and {@link #setPassParentEnvs(boolean)} instead with already preprocessed variables */
@Deprecated
public void setupEnvs(Map<String, String> envs, boolean passDefault) {
if (!envs.isEmpty()) {
@@ -79,4 +62,4 @@ public class SimpleProgramParameters {
setEnv(envs);
setPassParentEnvs(passDefault);
}
}
}
@@ -154,10 +154,9 @@ public final class JdkUtil {
}
@ApiStatus.Internal
@NotNull
public static TargetedCommandLineBuilder setupJVMCommandLine(@NotNull SimpleJavaParameters javaParameters,
@NotNull TargetEnvironmentRequest request,
@Nullable TargetEnvironmentConfiguration targetConfiguration)
public static @NotNull TargetedCommandLineBuilder setupJVMCommandLine(@NotNull SimpleJavaParameters javaParameters,
@NotNull TargetEnvironmentRequest request,
@Nullable TargetEnvironmentConfiguration targetConfiguration)
throws CantRunException {
TargetedCommandLineBuilder commandLine = new TargetedCommandLineBuilder();
JavaLanguageRuntimeConfiguration javaConfiguration = targetConfiguration != null
@@ -178,24 +177,22 @@ public final class JdkUtil {
}
Platform platform = request.getTargetPlatform().getPlatform();
String java = platform == Platform.WINDOWS ? "java.exe" : "java";
commandLine.setExePath(StringUtil.join(new String[]{javaConfiguration.getHomePath(), "bin", java},
String.valueOf(platform.fileSeparator)));
commandLine.setExePath(StringUtil.join(new String[]{javaConfiguration.getHomePath(), "bin", java}, String.valueOf(platform.fileSeparator)));
}
setupCommandLine(commandLine, request, javaParameters, javaConfiguration);
return commandLine;
}
@NotNull
public static GeneralCommandLine setupJVMCommandLine(@NotNull SimpleJavaParameters javaParameters) throws CantRunException {
public static @NotNull GeneralCommandLine setupJVMCommandLine(@NotNull SimpleJavaParameters javaParameters) throws CantRunException {
LocalTargetEnvironmentFactory environmentFactory = new LocalTargetEnvironmentFactory();
TargetEnvironmentRequest request = environmentFactory.createRequest();
return environmentFactory.prepareRemoteEnvironment(request, new EmptyProgressIndicator())
.createGeneralCommandLine(setupJVMCommandLine(javaParameters, request, null).build());
}
private static void setupCommandLine(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
@NotNull SimpleJavaParameters javaParameters,
private static void setupCommandLine(TargetedCommandLineBuilder commandLine,
TargetEnvironmentRequest request,
SimpleJavaParameters javaParameters,
@Nullable JavaLanguageRuntimeConfiguration runtimeConfiguration) throws CantRunException {
String workingDirectory = javaParameters.getWorkingDirectory();
if (workingDirectory != null) {
@@ -214,7 +211,7 @@ public final class JdkUtil {
boolean dynamicParameters = dynamicClasspath && javaParameters.isDynamicParameters() && useDynamicParameters();
boolean dynamicMainClass = false;
// copies 'javaagent' .jar files to the beginning of the classpath to load agent classes faster
// copies agent .jar files to the beginning of the classpath to load agent classes faster
if (isUrlClassloader(vmParameters)) {
if (!(request instanceof LocalTargetEnvironmentRequest)) {
throw new CantRunException("Cannot run application with UrlClassPath on the remote target.");
@@ -222,8 +219,7 @@ public final class JdkUtil {
for (String parameter : vmParameters.getParameters()) {
if (parameter.startsWith(JAVAAGENT)) {
int agentArgsIdx = parameter.indexOf("=", JAVAAGENT.length());
javaParameters.getClassPath()
.addFirst(parameter.substring(JAVAAGENT.length() + 1, agentArgsIdx > -1 ? agentArgsIdx : parameter.length()));
javaParameters.getClassPath().addFirst(parameter.substring(JAVAAGENT.length() + 1, agentArgsIdx > -1 ? agentArgsIdx : parameter.length()));
}
}
}
@@ -269,19 +265,6 @@ public final class JdkUtil {
}
}
private static void setupCommandLine(@NotNull GeneralCommandLine commandLine, @NotNull SimpleJavaParameters javaParameters)
throws CantRunException {
TargetedCommandLineBuilder targetedCommandLineBuilder = new TargetedCommandLineBuilder();
LocalTargetEnvironmentFactory environmentFactory = new LocalTargetEnvironmentFactory();
TargetEnvironmentRequest request = environmentFactory.createRequest();
setupCommandLine(targetedCommandLineBuilder, request, javaParameters, null);
LocalTargetEnvironment environment = environmentFactory.prepareRemoteEnvironment(request, new EmptyProgressIndicator());
GeneralCommandLine generalCommandLine = environment.createGeneralCommandLine(targetedCommandLineBuilder.build());
commandLine.withParentEnvironmentType(javaParameters.isPassParentEnvs() ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE);
commandLine.getParametersList().addAll(generalCommandLine.getParametersList().getList());
commandLine.getEnvironment().putAll(generalCommandLine.getEnvironment());
}
private static boolean isUrlClassloader(ParametersList vmParameters) {
return UrlClassLoader.class.getName().equals(vmParameters.getPropertyValue("java.system.class.loader"));
}
@@ -294,11 +277,11 @@ public final class JdkUtil {
return vmParameters.hasParameter("-p") || vmParameters.hasParameter("--module-path");
}
private static void setArgFileParams(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
private static void setArgFileParams(TargetedCommandLineBuilder commandLine,
TargetEnvironmentRequest request,
@Nullable JavaLanguageRuntimeConfiguration runtimeConfiguration,
@NotNull SimpleJavaParameters javaParameters,
@NotNull ParametersList vmParameters,
SimpleJavaParameters javaParameters,
ParametersList vmParameters,
boolean dynamicVMOptions,
boolean dynamicParameters,
Charset cs) throws CantRunException {
@@ -384,12 +367,12 @@ public final class JdkUtil {
}
}
private static void setCommandLineWrapperParams(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
private static void setCommandLineWrapperParams(TargetedCommandLineBuilder commandLine,
TargetEnvironmentRequest request,
@Nullable JavaLanguageRuntimeConfiguration runtimeConfiguration,
@NotNull SimpleJavaParameters javaParameters,
@NotNull ParametersList vmParameters,
@NotNull Class<?> commandLineWrapper,
SimpleJavaParameters javaParameters,
ParametersList vmParameters,
Class<?> commandLineWrapper,
boolean dynamicVMOptions,
boolean dynamicParameters,
Charset cs) throws CantRunException {
@@ -492,9 +475,7 @@ public final class JdkUtil {
}
}
private static void addCommandLineContentOnResolve(@NotNull Map<String, String> commandLineContent,
@NotNull File localFile,
@NotNull TargetValue<String> value) {
private static void addCommandLineContentOnResolve(Map<String, String> commandLineContent, File localFile, TargetValue<String> value) {
value.getTargetValue().onSuccess(resolved -> {
try {
commandLineContent.put(resolved, FileUtil.loadFile(localFile));
@@ -505,12 +486,12 @@ public final class JdkUtil {
});
}
private static void setClasspathJarParams(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
private static void setClasspathJarParams(TargetedCommandLineBuilder commandLine,
TargetEnvironmentRequest request,
@Nullable JavaLanguageRuntimeConfiguration runtimeConfiguration,
@NotNull SimpleJavaParameters javaParameters,
@NotNull ParametersList vmParameters,
@NotNull Class<?> commandLineWrapper,
SimpleJavaParameters javaParameters,
ParametersList vmParameters,
Class<?> commandLineWrapper,
boolean dynamicVMOptions,
boolean dynamicParameters) throws CantRunException {
try {
@@ -573,7 +554,7 @@ public final class JdkUtil {
throw new ExecutionException("Couldn't resolve target value", null);
}
File file = new File(targetValue);
String url = (notEscape ? file.toURL() : file.toURI().toURL()).toString();
@SuppressWarnings("deprecation") String url = (notEscape ? file.toURL() : file.toURI().toURL()).toString();
classPath.append(!StringUtil.endsWithChar(url, '/') && new File(localValue).isDirectory() ? url + "/" : url);
}
CommandLineWrapperUtil.fillClasspathJarFile(manifest, classPath.toString(), classpathJarFile);
@@ -605,11 +586,11 @@ public final class JdkUtil {
throw new CantRunException("Failed to create a temporary file in " + FileUtilRt.getTempDirectory(), cause);
}
private static void appendParamsEncodingClasspath(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
private static void appendParamsEncodingClasspath(TargetedCommandLineBuilder commandLine,
TargetEnvironmentRequest request,
@Nullable JavaLanguageRuntimeConfiguration runtimeConfiguration,
@NotNull SimpleJavaParameters javaParameters,
@NotNull ParametersList vmParameters) {
SimpleJavaParameters javaParameters,
ParametersList vmParameters) {
appendVmParameters(commandLine, request, vmParameters);
appendEncoding(javaParameters, commandLine, vmParameters);
PathsList classPath = javaParameters.getClassPath();
@@ -627,17 +608,13 @@ public final class JdkUtil {
}
}
private static void appendVmParameters(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
@NotNull ParametersList vmParameters) {
private static void appendVmParameters(TargetedCommandLineBuilder commandLine, TargetEnvironmentRequest request, ParametersList vmParameters) {
for (String vmParameter : vmParameters.getList()) {
appendVmParameter(commandLine, request, vmParameter);
}
}
private static void appendVmParameter(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
@NotNull String vmParameter) {
private static void appendVmParameter(TargetedCommandLineBuilder commandLine, TargetEnvironmentRequest request, String vmParameter) {
if (request instanceof LocalTargetEnvironmentRequest ||
SystemProperties.getBooleanProperty("remote.servers.ignore.vm.parameter", false)) {
commandLine.addParameter(vmParameter);
@@ -655,10 +632,10 @@ public final class JdkUtil {
}
}
private static void appendVmAgentParameter(@NotNull TargetedCommandLineBuilder commandLine,
@NotNull TargetEnvironmentRequest request,
@NotNull String vmParameter,
@NotNull String prefix) {
private static void appendVmAgentParameter(TargetedCommandLineBuilder commandLine,
TargetEnvironmentRequest request,
String vmParameter,
String prefix) {
String value = StringUtil.trimStart(vmParameter, prefix);
int equalsSign = value.indexOf('=');
String path = equalsSign > -1 ? value.substring(0, equalsSign) : value;
@@ -670,10 +647,9 @@ public final class JdkUtil {
commandLine.addParameter(TargetValue.map(request.createUpload(path), v -> prefix + v + suffix));
}
@NotNull
private static List<TargetValue<String>> getClassPathValues(@NotNull TargetEnvironmentRequest request,
private static List<TargetValue<String>> getClassPathValues(TargetEnvironmentRequest request,
@Nullable JavaLanguageRuntimeConfiguration runtimeConfiguration,
@NotNull SimpleJavaParameters javaParameters) {
SimpleJavaParameters javaParameters) {
String localJdkPath = ObjectUtils.doIfNotNull(javaParameters.getJdk(), jdk -> jdk.getHomePath());
String remoteJdkPath = runtimeConfiguration != null ? runtimeConfiguration.getHomePath() : null;
@@ -690,9 +666,7 @@ public final class JdkUtil {
return result;
}
private static void appendEncoding(@NotNull SimpleJavaParameters javaParameters,
@NotNull TargetedCommandLineBuilder commandLine,
@NotNull ParametersList parametersList) {
private static void appendEncoding(SimpleJavaParameters javaParameters, TargetedCommandLineBuilder commandLine, ParametersList parametersList) {
// for correct handling of process's input and output, values of file.encoding and charset of CommandLine object should be in sync
String encoding = parametersList.getPropertyValue("file.encoding");
if (encoding == null) {
@@ -710,8 +684,7 @@ public final class JdkUtil {
}
}
private static List<TargetValue<String>> getMainClassParams(SimpleJavaParameters javaParameters,
@NotNull TargetEnvironmentRequest request) throws CantRunException {
private static List<TargetValue<String>> getMainClassParams(SimpleJavaParameters javaParameters, TargetEnvironmentRequest request) throws CantRunException {
String mainClass = javaParameters.getMainClass();
String moduleName = javaParameters.getModuleName();
String jarPath = javaParameters.getJarPath();
@@ -759,7 +732,7 @@ public final class JdkUtil {
//<editor-fold desc="Deprecated stuff.">
/** @deprecated use {@link SimpleJavaParameters#toCommandLine()} */
@ApiStatus.ScheduledForRemoval(inVersion = "2021.1")
@ApiStatus.ScheduledForRemoval(inVersion = "2022.1")
@Deprecated
public static GeneralCommandLine setupJVMCommandLine(String exePath, SimpleJavaParameters javaParameters, boolean forceDynamicClasspath) {
try {
@@ -772,5 +745,17 @@ public final class JdkUtil {
throw new RuntimeException(e);
}
}
private static void setupCommandLine(GeneralCommandLine commandLine, SimpleJavaParameters javaParameters) throws CantRunException {
TargetedCommandLineBuilder targetedCommandLineBuilder = new TargetedCommandLineBuilder();
LocalTargetEnvironmentFactory environmentFactory = new LocalTargetEnvironmentFactory();
TargetEnvironmentRequest request = environmentFactory.createRequest();
setupCommandLine(targetedCommandLineBuilder, request, javaParameters, null);
LocalTargetEnvironment environment = environmentFactory.prepareRemoteEnvironment(request, new EmptyProgressIndicator());
GeneralCommandLine generalCommandLine = environment.createGeneralCommandLine(targetedCommandLineBuilder.build());
commandLine.withParentEnvironmentType(javaParameters.isPassParentEnvs() ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE);
commandLine.getParametersList().addAll(generalCommandLine.getParametersList().getList());
commandLine.getEnvironment().putAll(generalCommandLine.getEnvironment());
}
//</editor-fold>
}