Search in sources :

Example 11 with UrlClassLoader

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFile(java.util.jar.JarFile) UrlClassLoader(com.intellij.util.lang.UrlClassLoader)

Aggregations

UrlClassLoader (com.intellij.util.lang.UrlClassLoader)11 URL (java.net.URL)8 NotNull (org.jetbrains.annotations.NotNull)5 IOException (java.io.IOException)3 URLClassLoader (java.net.URLClassLoader)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 Method (java.lang.reflect.Method)2 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 XmlSerializationException (com.intellij.util.xmlb.XmlSerializationException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 MalformedURLException (java.net.MalformedURLException)1 Enumeration (java.util.Enumeration)1 NoSuchElementException (java.util.NoSuchElementException)1 JarFile (java.util.jar.JarFile)1 Element (org.jdom.Element)1