mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] module path in app. run configuration
This commit is contained in:
+65
-17
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.execution.application;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaModuleGraphUtil;
|
||||
import com.intellij.diagnostic.logging.LogConfigurationPanel;
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configuration.EnvironmentVariablesComponent;
|
||||
@@ -29,13 +30,19 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.options.SettingsEditorGroup;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiJavaModule;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.util.PsiMethodUtil;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.util.PathsList;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -43,6 +50,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule>
|
||||
implements CommonJavaRunConfigurationParameters, SingleClassConfiguration, RefactoringListenerProvider {
|
||||
@@ -206,24 +214,24 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
|
||||
@Override
|
||||
public boolean isAlternativeJrePathEnabled() {
|
||||
return ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
}
|
||||
return ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlternativeJrePathEnabled(boolean enabled) {
|
||||
ALTERNATIVE_JRE_PATH_ENABLED = enabled;
|
||||
}
|
||||
@Override
|
||||
public void setAlternativeJrePathEnabled(boolean enabled) {
|
||||
ALTERNATIVE_JRE_PATH_ENABLED = enabled;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getAlternativeJrePath() {
|
||||
return ALTERNATIVE_JRE_PATH;
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public String getAlternativeJrePath() {
|
||||
return ALTERNATIVE_JRE_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlternativeJrePath(String path) {
|
||||
ALTERNATIVE_JRE_PATH = path;
|
||||
}
|
||||
@Override
|
||||
public void setAlternativeJrePath(String path) {
|
||||
ALTERNATIVE_JRE_PATH = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Module> getValidModules() {
|
||||
@@ -258,9 +266,9 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
protected JavaParameters createJavaParameters() throws ExecutionException {
|
||||
final JavaParameters params = new JavaParameters();
|
||||
params.setUseClasspathJar(true);
|
||||
|
||||
final JavaRunConfigurationModule module = myConfiguration.getConfigurationModule();
|
||||
final String jreHome = myConfiguration.ALTERNATIVE_JRE_PATH_ENABLED ? myConfiguration.ALTERNATIVE_JRE_PATH : null;
|
||||
|
||||
if (module.getModule() != null) {
|
||||
final int classPathType = JavaParametersUtil.getClasspathType(module, myConfiguration.MAIN_CLASS_NAME, false);
|
||||
JavaParametersUtil.configureModule(module, params, classPathType, jreHome);
|
||||
@@ -268,10 +276,50 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
else {
|
||||
JavaParametersUtil.configureProject(module.getProject(), params, JavaParameters.JDK_AND_CLASSES_AND_TESTS, jreHome);
|
||||
}
|
||||
|
||||
params.setMainClass(myConfiguration.MAIN_CLASS_NAME);
|
||||
|
||||
setupJavaParameters(params);
|
||||
|
||||
setupModulePath(params, module);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
private static void setupModulePath(JavaParameters params, JavaRunConfigurationModule module) {
|
||||
PsiClass mainClass = module.findClass(params.getMainClass());
|
||||
if (mainClass != null) {
|
||||
PsiJavaModule mainModule = JavaModuleGraphUtil.findDescriptorByElement(mainClass);
|
||||
if (mainModule != null) {
|
||||
params.setModuleName(mainModule.getModuleName());
|
||||
|
||||
PathsList modulePath = params.getModulePath(), classPath = params.getClassPath();
|
||||
ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(module.getProject());
|
||||
JavaModuleGraphUtil.moduleDependencies(mainModule).stream()
|
||||
.map(PsiImplUtil::getModuleVirtualFile)
|
||||
.flatMap(f -> classRoots(f, index))
|
||||
.forEach(f -> {
|
||||
modulePath.add(f);
|
||||
classPath.remove(f);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Stream<VirtualFile> classRoots(VirtualFile file, ProjectFileIndex index) {
|
||||
if (index.isInSourceContent(file)) {
|
||||
Module module = index.getModuleForFile(file);
|
||||
if (module != null) {
|
||||
return Stream.of(OrderEnumerator.orderEntries(module).runtimeOnly().withoutSdk().withoutLibraries().withoutDepModules().getClassesRoots());
|
||||
}
|
||||
}
|
||||
else {
|
||||
VirtualFile root = index.getClassRootForFile(file);
|
||||
if (root != null) {
|
||||
return Stream.of(root);
|
||||
}
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
-23
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,42 +20,46 @@ import com.intellij.execution.configurations.JavaCommandLine;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ProcessProxyFactoryImpl extends ProcessProxyFactory {
|
||||
public ProcessProxy createCommandLineProxy(final JavaCommandLine javaCmdLine) throws ExecutionException {
|
||||
ProcessProxyImpl proxy = null;
|
||||
final JavaParameters javaParameters = javaCmdLine.getJavaParameters();
|
||||
String mainClass = javaParameters.getMainClass();
|
||||
if (ProcessProxyImpl.useLauncher() && mainClass != null) {
|
||||
try {
|
||||
proxy = new ProcessProxyImpl();
|
||||
JavaSdkUtil.addRtJar(javaParameters.getClassPath());
|
||||
final ParametersList vmParametersList = javaParameters.getVMParametersList();
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, String.valueOf(proxy.getPortNumber()));
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_BINPATH, PathManager.getBinPath());
|
||||
javaParameters.getProgramParametersList().prepend(mainClass);
|
||||
javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS);
|
||||
}
|
||||
catch (ProcessProxyImpl.NoMoreSocketsException e) {
|
||||
proxy = null;
|
||||
private static final String DONT_USE_LAUNCHER_PROPERTY = "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) {
|
||||
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());
|
||||
javaParameters.getProgramParametersList().prepend(mainClass);
|
||||
javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS);
|
||||
return proxy;
|
||||
}
|
||||
catch (ProcessProxyImpl.NoMoreSocketsException ignored) { }
|
||||
}
|
||||
}
|
||||
return proxy;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProcessProxy getAttachedProxy(final ProcessHandler processHandler) {
|
||||
@Override
|
||||
public ProcessProxy getAttachedProxy(ProcessHandler processHandler) {
|
||||
return processHandler != null ? processHandler.getUserData(ProcessProxyImpl.KEY) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBreakGenLibraryAvailable() {
|
||||
@NonNls final String libName;
|
||||
String libName;
|
||||
if (SystemInfo.isWindows) {
|
||||
libName = "breakgen.dll";
|
||||
}
|
||||
@@ -65,6 +69,10 @@ public class ProcessProxyFactoryImpl extends ProcessProxyFactory {
|
||||
else {
|
||||
libName = "libbreakgen.so";
|
||||
}
|
||||
return new File(PathManager.getBinPath() + File.separator + libName).exists();
|
||||
return new File(PathManager.getBinPath(), libName).exists();
|
||||
}
|
||||
|
||||
private static boolean useLauncher(JavaParameters parameters) {
|
||||
return !Boolean.getBoolean(DONT_USE_LAUNCHER_PROPERTY) && parameters.getModuleName() == null;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package com.intellij.execution.runners;
|
||||
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
@@ -33,11 +32,10 @@ import java.net.Socket;
|
||||
class ProcessProxyImpl implements ProcessProxy {
|
||||
public static final Key<ProcessProxyImpl> KEY = Key.create("ProcessProxyImpl");
|
||||
|
||||
@NonNls public static final String PROPERTY_BINPATH = "idea.launcher.bin.path";
|
||||
@NonNls public static final String PROPERTY_PORT_NUMBER = "idea.launcher.port";
|
||||
@NonNls public static final String LAUNCH_MAIN_CLASS = "com.intellij.rt.execution.application.AppMain";
|
||||
public static final String PROPERTY_BIN_PATH = "idea.launcher.bin.path";
|
||||
public static final String PROPERTY_PORT_NUMBER = "idea.launcher.port";
|
||||
public static final String LAUNCH_MAIN_CLASS = "com.intellij.rt.execution.application.AppMain";
|
||||
|
||||
@NonNls private static final String DONT_USE_LAUNCHER_PROPERTY = "idea.no.launcher";
|
||||
private static final int SOCKET_NUMBER_START = 7532;
|
||||
private static final int SOCKET_NUMBER = 100;
|
||||
private static final boolean[] ourUsedSockets = new boolean[SOCKET_NUMBER];
|
||||
@@ -46,8 +44,7 @@ class ProcessProxyImpl implements ProcessProxy {
|
||||
private PrintWriter myWriter;
|
||||
private Socket mySocket;
|
||||
|
||||
public static class NoMoreSocketsException extends Exception {
|
||||
}
|
||||
public static class NoMoreSocketsException extends Exception { }
|
||||
|
||||
public ProcessProxyImpl() throws NoMoreSocketsException {
|
||||
myPortNumber = findFreePort();
|
||||
@@ -91,7 +88,7 @@ class ProcessProxyImpl implements ProcessProxy {
|
||||
}
|
||||
|
||||
@SuppressWarnings({"SocketOpenedButNotSafelyClosed", "IOResourceOpenedButNotSafelyClosed"})
|
||||
private synchronized void writeLine(@NonNls final String s) {
|
||||
private synchronized void writeLine(String s) {
|
||||
if (myWriter == null) {
|
||||
try {
|
||||
if (mySocket == null) {
|
||||
@@ -116,8 +113,4 @@ class ProcessProxyImpl implements ProcessProxy {
|
||||
public void sendStop() {
|
||||
writeLine("STOP");
|
||||
}
|
||||
|
||||
public static boolean useLauncher() {
|
||||
return !Boolean.valueOf(System.getProperty(DONT_USE_LAUNCHER_PROPERTY));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user