Search in sources :

Example 1 with AppMainV2

use of com.intellij.rt.execution.application.AppMainV2 in project intellij-community by JetBrains.

the class ProcessProxyFactoryImpl method createCommandLineProxy.

@Override
public ProcessProxy createCommandLineProxy(JavaCommandLine javaCmdLine) throws ExecutionException {
    JavaParameters javaParameters = javaCmdLine.getJavaParameters();
    String mainClass = javaParameters.getMainClass();
    if (ourMayUseLauncher && mainClass != null) {
        String rtJarPath = JavaSdkUtil.getIdeaRtJarPath();
        boolean runtimeJarFile = new File(rtJarPath).isFile() && FileUtil.isAncestor(PathManager.getHomePath(), rtJarPath, true);
        if (runtimeJarFile || javaParameters.getModuleName() == null) {
            try {
                ProcessProxyImpl proxy = new ProcessProxyImpl(StringUtil.getShortName(mainClass));
                String port = String.valueOf(proxy.getPortNumber());
                String binPath = PathManager.getBinPath();
                if (runtimeJarFile && JavaSdkUtil.isJdkAtLeast(javaParameters.getJdk(), JavaSdkVersion.JDK_1_5)) {
                    javaParameters.getVMParametersList().add("-javaagent:" + rtJarPath + '=' + port + ':' + binPath);
                } else {
                    JavaSdkUtil.addRtJar(javaParameters.getClassPath());
                    ParametersList vmParametersList = javaParameters.getVMParametersList();
                    vmParametersList.defineProperty(AppMainV2.LAUNCHER_PORT_NUMBER, port);
                    vmParametersList.defineProperty(AppMainV2.LAUNCHER_BIN_PATH, binPath);
                    javaParameters.getProgramParametersList().prepend(mainClass);
                    javaParameters.setMainClass(AppMainV2.class.getName());
                }
                return proxy;
            } catch (Exception e) {
                Logger.getInstance(ProcessProxy.class).warn(e);
            }
        }
    }
    return null;
}
Also used : ParametersList(com.intellij.execution.configurations.ParametersList) JavaParameters(com.intellij.execution.configurations.JavaParameters) File(java.io.File) AppMainV2(com.intellij.rt.execution.application.AppMainV2) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 AppMainV2 (com.intellij.rt.execution.application.AppMainV2)1 File (java.io.File)1