use of com.intellij.util.lang.UrlClassLoader in project intellij-community by JetBrains.
the class JdkUtil method setCommandLineWrapperParams.
private static boolean setCommandLineWrapperParams(SimpleJavaParameters javaParameters, GeneralCommandLine commandLine, ParametersList vmParametersList, Class commandLineWrapper) throws CantRunException {
boolean dynamicVMOptions = javaParameters.isDynamicVMOptions() && useDynamicVMOptions();
boolean dynamicParameters = javaParameters.isDynamicParameters() && useDynamicParameters();
File vmParamsFile = null;
if (dynamicVMOptions) {
try {
vmParamsFile = FileUtil.createTempFile("idea_vm_params", null);
try (PrintWriter writer = new PrintWriter(vmParamsFile)) {
for (String param : vmParametersList.getList()) {
if (isUserDefinedProperty(param)) {
writer.println(param);
} else {
commandLine.addParameter(param);
}
}
}
} catch (IOException e) {
throwUnableToCreateTempFile(e);
}
} else {
commandLine.addParameters(vmParametersList.getList());
}
File appParamsFile = null;
if (dynamicParameters) {
try {
appParamsFile = FileUtil.createTempFile("idea_app_params", null);
try (PrintWriter writer = new PrintWriter(appParamsFile)) {
for (String path : javaParameters.getProgramParametersList().getList()) {
writer.println(path);
}
}
} catch (IOException e) {
throwUnableToCreateTempFile(e);
}
}
File classpathFile = null;
try {
classpathFile = FileUtil.createTempFile("idea_classpath", null);
try (PrintWriter writer = new PrintWriter(classpathFile)) {
for (String path : javaParameters.getClassPath().getPathList()) {
writer.println(path);
}
}
String classpath = PathUtil.getJarPathForClass(commandLineWrapper);
final String utilRtPath = PathUtil.getJarPathForClass(StringUtilRt.class);
if (!classpath.equals(utilRtPath)) {
classpath += File.pathSeparator + utilRtPath;
}
final Class<UrlClassLoader> ourUrlClassLoader = UrlClassLoader.class;
if (ourUrlClassLoader.getName().equals(vmParametersList.getPropertyValue("java.system.class.loader"))) {
classpath += File.pathSeparator + PathUtil.getJarPathForClass(ourUrlClassLoader);
classpath += File.pathSeparator + PathUtil.getJarPathForClass(THashMap.class);
}
commandLine.addParameter("-classpath");
commandLine.addParameter(classpath);
} catch (IOException e) {
throwUnableToCreateTempFile(e);
}
appendEncoding(javaParameters, commandLine, vmParametersList);
commandLine.addParameter(commandLineWrapper.getName());
commandLine.addParameter(classpathFile.getAbsolutePath());
if (vmParamsFile != null) {
commandLine.addParameter("@vm_params");
commandLine.addParameter(vmParamsFile.getAbsolutePath());
}
if (appParamsFile != null) {
commandLine.addParameter("@app_params");
commandLine.addParameter(appParamsFile.getAbsolutePath());
}
Set<File> filesToDelete = getFilesToDeleteUserData(commandLine);
ContainerUtil.addIfNotNull(filesToDelete, classpathFile);
ContainerUtil.addIfNotNull(filesToDelete, vmParamsFile);
ContainerUtil.addIfNotNull(filesToDelete, appParamsFile);
return dynamicParameters;
}
Aggregations