use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.
the class JdkUtil method setupCommandLine.
private static void setupCommandLine(GeneralCommandLine commandLine, SimpleJavaParameters javaParameters) throws CantRunException {
final ParametersList vmParameters = javaParameters.getVMParametersList();
commandLine.withEnvironment(javaParameters.getEnv());
commandLine.withParentEnvironmentType(javaParameters.isPassParentEnvs() ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE);
final Class commandLineWrapper;
boolean dynamicParameters = false;
if (javaParameters.isDynamicClasspath() && !explicitClassPath(vmParameters) && javaParameters.getModulePath().isEmpty() && (commandLineWrapper = getCommandLineWrapperClass()) != null) {
if (isClassPathJarEnabled(javaParameters, PathUtil.getJarPathForClass(ClassPath.class))) {
dynamicParameters = setClasspathJarParams(javaParameters, commandLine, vmParameters, commandLineWrapper);
} else {
dynamicParameters = setCommandLineWrapperParams(javaParameters, commandLine, vmParameters, commandLineWrapper);
}
} else {
appendParamsEncodingClasspath(javaParameters, commandLine, vmParameters);
}
final String mainClass = javaParameters.getMainClass();
final String moduleName = javaParameters.getModuleName();
final String jarPath = javaParameters.getJarPath();
if (moduleName != null && mainClass != null) {
commandLine.addParameter("-m");
commandLine.addParameter(moduleName + '/' + mainClass);
} else if (mainClass != null) {
commandLine.addParameter(mainClass);
} else if (jarPath != null) {
commandLine.addParameter("-jar");
commandLine.addParameter(jarPath);
} else {
throw new CantRunException(ExecutionBundle.message("main.class.is.not.specified.error.message"));
}
if (!dynamicParameters) {
commandLine.addParameters(javaParameters.getProgramParametersList().getList());
}
commandLine.withWorkDirectory(javaParameters.getWorkingDirectory());
}
use of com.intellij.execution.CantRunException in project intellij-plugins by JetBrains.
the class AbstractFrameworkRunner method createJavaParameters.
@Override
public JavaParameters createJavaParameters(@NotNull OsgiRunConfiguration runConfiguration, @NotNull List<SelectedBundle> bundles) throws ExecutionException {
myRunConfiguration = runConfiguration;
myInstance = myRunConfiguration.getInstanceToUse();
assert myInstance != null : myRunConfiguration;
myIntegrator = FrameworkIntegratorRegistry.getInstance().findIntegratorByInstanceDefinition(myInstance);
assert myIntegrator != null : myInstance;
myInstanceManager = myIntegrator.getFrameworkInstanceManager();
myAdditionalProperties = myRunConfiguration.getAdditionalProperties();
myBundles = bundles;
JavaParameters params = new JavaParameters();
if (myRunConfiguration.isGenerateWorkingDir()) {
myWorkingDir = new File(PathManager.getSystemPath(), "osmorc/run." + System.currentTimeMillis());
} else {
myWorkingDir = new File(myRunConfiguration.getWorkingDir());
}
if (!myWorkingDir.isDirectory() && !myWorkingDir.mkdirs()) {
throw new CantRunException("Cannot create work directory '" + myWorkingDir.getPath() + "'");
}
params.setWorkingDirectory(myWorkingDir);
// only add JDK classes to the classpath, the rest is to be provided by bundles
String jreHome = myRunConfiguration.isUseAlternativeJre() ? myRunConfiguration.getAlternativeJrePath() : null;
JavaParametersUtil.configureProject(myRunConfiguration.getProject(), params, JavaParameters.JDK_ONLY, jreHome);
// class path
Collection<SelectedBundle> systemBundles = myInstanceManager.getFrameworkBundles(myInstance, FrameworkBundleType.SYSTEM);
if (systemBundles.isEmpty()) {
throw new CantRunException("Libraries required to start the framework not found - please check the installation");
}
for (SelectedBundle bundle : systemBundles) {
String path = bundle.getBundlePath();
assert path != null : bundle;
params.getClassPath().add(path);
}
if (GenericRunProperties.isStartConsole(myAdditionalProperties)) {
Collection<SelectedBundle> shellBundles = myInstanceManager.getFrameworkBundles(myInstance, FrameworkBundleType.SHELL);
if (shellBundles.isEmpty()) {
throw new CantRunException("Console requested but no shell bundles can be found - please check the installation");
}
List<SelectedBundle> allBundles = ContainerUtil.newArrayList(shellBundles);
allBundles.addAll(myBundles);
myBundles = allBundles;
}
if (myRunConfiguration.isIncludeAllBundlesInClassPath()) {
for (SelectedBundle bundle : myBundles) {
String path = bundle.getBundlePath();
if (path != null) {
params.getClassPath().add(path);
}
}
}
// runner options
params.setUseDynamicVMOptions(!myBundles.isEmpty());
params.setUseDynamicParameters(!myBundles.isEmpty());
HttpConfigurable.getInstance().getJvmProperties(false, null).forEach(p -> params.getVMParametersList().addProperty(p.first, p.second));
params.getVMParametersList().addParametersString(myRunConfiguration.getVmParameters());
String additionalProgramParams = myRunConfiguration.getProgramParameters();
if (!StringUtil.isEmptyOrSpaces(additionalProgramParams)) {
params.getProgramParametersList().addParametersString(additionalProgramParams);
}
String bootDelegation = GenericRunProperties.getBootDelegation(myAdditionalProperties);
if (!StringUtil.isEmptyOrSpaces(bootDelegation)) {
params.getVMParametersList().addProperty("org.osgi.framework.bootdelegation", bootDelegation);
}
String systemPackages = GenericRunProperties.getSystemPackages(myAdditionalProperties);
if (!StringUtil.isEmptyOrSpaces(systemPackages)) {
params.getVMParametersList().addProperty("org.osgi.framework.system.packages.extra", systemPackages);
}
// framework-specific options
setupParameters(params);
return params;
}
Aggregations