mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] AppMain improvements: ability to operate as a Java agent
This commit is contained in:
+25
-14
@@ -24,27 +24,42 @@ import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ProcessProxyFactoryImpl extends ProcessProxyFactory {
|
||||
private static final String DONT_USE_LAUNCHER_PROPERTY = "idea.no.launcher";
|
||||
private static final boolean ourMayUseLauncher = !Boolean.getBoolean("idea.no.launcher");
|
||||
|
||||
@Override
|
||||
public ProcessProxy createCommandLineProxy(JavaCommandLine javaCmdLine) throws ExecutionException {
|
||||
JavaParameters javaParameters = javaCmdLine.getJavaParameters();
|
||||
if (useLauncher(javaParameters)) {
|
||||
String mainClass = javaParameters.getMainClass();
|
||||
if (mainClass != null) {
|
||||
String mainClass = javaParameters.getMainClass();
|
||||
|
||||
if (ourMayUseLauncher && mainClass != null) {
|
||||
String moduleName = javaParameters.getModuleName();
|
||||
String rtJarPath = JavaSdkUtil.getIdeaRtJarPath();
|
||||
|
||||
if (moduleName == null || new File(rtJarPath).isFile()) {
|
||||
try {
|
||||
ProcessProxyImpl proxy = new ProcessProxyImpl();
|
||||
|
||||
JavaSdkUtil.addRtJar(javaParameters.getClassPath());
|
||||
ParametersList vmParametersList = javaParameters.getVMParametersList();
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, String.valueOf(proxy.getPortNumber()));
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_BIN_PATH, PathManager.getBinPath());
|
||||
String port = String.valueOf(proxy.getPortNumber());
|
||||
String binPath = PathManager.getBinPath();
|
||||
|
||||
if (moduleName == null) {
|
||||
JavaSdkUtil.addRtJar(javaParameters.getClassPath());
|
||||
|
||||
ParametersList vmParametersList = javaParameters.getVMParametersList();
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, port);
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_BIN_PATH, binPath);
|
||||
|
||||
javaParameters.getProgramParametersList().prepend(mainClass);
|
||||
javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS);
|
||||
}
|
||||
else {
|
||||
javaParameters.getVMParametersList().add("-javaagent:" + rtJarPath + '=' + port + ':' + binPath);
|
||||
}
|
||||
|
||||
javaParameters.getProgramParametersList().prepend(mainClass);
|
||||
javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS);
|
||||
return proxy;
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -60,8 +75,4 @@ public class ProcessProxyFactoryImpl extends ProcessProxyFactory {
|
||||
public ProcessProxy getAttachedProxy(ProcessHandler processHandler) {
|
||||
return processHandler != null ? processHandler.getUserData(ProcessProxyImpl.KEY) : null;
|
||||
}
|
||||
|
||||
private static boolean useLauncher(JavaParameters parameters) {
|
||||
return !Boolean.getBoolean(DONT_USE_LAUNCHER_PROPERTY) && parameters.getModuleName() == null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user