mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[platform] unified SimpleJavaParameters to GeneralCommandLine conversion
This commit is contained in:
+12
-49
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -20,20 +20,13 @@
|
||||
package com.intellij.execution.configurations;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.JdkUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkTypeId;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
|
||||
public class CommandLineBuilder {
|
||||
private CommandLineBuilder() { }
|
||||
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters) throws CantRunException {
|
||||
return createFromJavaParameters(javaParameters, false);
|
||||
return javaParameters.toCommandLine();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +43,13 @@ public class CommandLineBuilder {
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
|
||||
final Project project,
|
||||
final boolean dynamicClasspath) throws CantRunException {
|
||||
return createFromJavaParameters(javaParameters, dynamicClasspath && JdkUtil.useDynamicClasspath(project));
|
||||
if (dynamicClasspath) {
|
||||
javaParameters.setUseDynamicClasspath(project);
|
||||
}
|
||||
else {
|
||||
javaParameters.setUseDynamicClasspath(false);
|
||||
}
|
||||
return javaParameters.toCommandLine();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,43 +60,7 @@ public class CommandLineBuilder {
|
||||
*/
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
|
||||
final boolean forceDynamicClasspath) throws CantRunException {
|
||||
try {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<GeneralCommandLine>() {
|
||||
public GeneralCommandLine compute() {
|
||||
try {
|
||||
final Sdk jdk = javaParameters.getJdk();
|
||||
if (jdk == null) {
|
||||
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
|
||||
}
|
||||
|
||||
final SdkTypeId sdkType = jdk.getSdkType();
|
||||
if (!(sdkType instanceof JavaSdkType)) {
|
||||
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
|
||||
}
|
||||
|
||||
final String exePath = ((JavaSdkType)sdkType).getVMExecutablePath(jdk);
|
||||
if (exePath == null) {
|
||||
throw new CantRunException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
|
||||
}
|
||||
if (javaParameters.getMainClass() == null && javaParameters.getJarPath() == null) {
|
||||
throw new CantRunException(ExecutionBundle.message("main.class.is.not.specified.error.message"));
|
||||
}
|
||||
|
||||
return JdkUtil.setupJVMCommandLine(exePath, javaParameters, forceDynamicClasspath);
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if (e.getCause() instanceof CantRunException) {
|
||||
throw (CantRunException)e.getCause();
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
javaParameters.setUseDynamicClasspath(forceDynamicClasspath);
|
||||
return javaParameters.toCommandLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user