mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -30,37 +30,32 @@ import java.net.Socket;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
|
||||
class ProcessProxyImpl implements ProcessProxy {
|
||||
public static final Key<ProcessProxyImpl> KEY = Key.create("ProcessProxyImpl");
|
||||
private final int myPortNumber;
|
||||
|
||||
@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";
|
||||
|
||||
@NonNls protected static final String LOCALHOST = "localhost";
|
||||
@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];
|
||||
|
||||
private final int myPortNumber;
|
||||
private PrintWriter myWriter;
|
||||
private Socket mySocket;
|
||||
@NonNls private static final String DONT_USE_LAUNCHER_PROPERTY = "idea.no.launcher";
|
||||
@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";
|
||||
@NonNls
|
||||
protected static final String LOCALHOST = "localhost";
|
||||
|
||||
public int getPortNumber() {
|
||||
return myPortNumber;
|
||||
}
|
||||
|
||||
public static class NoMoreSocketsException extends Exception {
|
||||
}
|
||||
|
||||
public ProcessProxyImpl () throws NoMoreSocketsException {
|
||||
myPortNumber = getPortNumer();
|
||||
public ProcessProxyImpl() throws NoMoreSocketsException {
|
||||
myPortNumber = findFreePort();
|
||||
if (myPortNumber == -1) throw new NoMoreSocketsException();
|
||||
}
|
||||
|
||||
private static int getPortNumer() {
|
||||
private static int findFreePort() {
|
||||
synchronized (ourUsedSockets) {
|
||||
for (int j = 0; j < SOCKET_NUMBER; j++) {
|
||||
if (ourUsedSockets[j]) continue;
|
||||
@@ -69,15 +64,19 @@ class ProcessProxyImpl implements ProcessProxy {
|
||||
s.close();
|
||||
ourUsedSockets[j] = true;
|
||||
return j + SOCKET_NUMBER_START;
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
}
|
||||
catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void finalize () throws Throwable {
|
||||
public int getPortNumber() {
|
||||
return myPortNumber;
|
||||
}
|
||||
|
||||
@SuppressWarnings("FinalizeDeclaration")
|
||||
protected synchronized void finalize() throws Throwable {
|
||||
if (myWriter != null) {
|
||||
myWriter.close();
|
||||
}
|
||||
@@ -89,13 +88,16 @@ class ProcessProxyImpl implements ProcessProxy {
|
||||
processHandler.putUserData(KEY, this);
|
||||
}
|
||||
|
||||
private synchronized void writeLine (@NonNls final String s) {
|
||||
@SuppressWarnings({"SocketOpenedButNotSafelyClosed", "IOResourceOpenedButNotSafelyClosed"})
|
||||
private synchronized void writeLine(@NonNls final String s) {
|
||||
if (myWriter == null) {
|
||||
try {
|
||||
if (mySocket == null)
|
||||
if (mySocket == null) {
|
||||
mySocket = new Socket(InetAddress.getByName(LOCALHOST), myPortNumber);
|
||||
}
|
||||
myWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mySocket.getOutputStream())));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -103,11 +105,11 @@ class ProcessProxyImpl implements ProcessProxy {
|
||||
myWriter.flush();
|
||||
}
|
||||
|
||||
public void sendBreak () {
|
||||
public void sendBreak() {
|
||||
writeLine("BREAK");
|
||||
}
|
||||
|
||||
public void sendStop () {
|
||||
public void sendStop() {
|
||||
writeLine("STOP");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -36,11 +36,12 @@ import com.intellij.psi.PsiFile;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: lex
|
||||
* Date: Nov 26, 2003
|
||||
* Time: 10:38:01 PM
|
||||
* @author lex
|
||||
* @since Nov 26, 2003
|
||||
*/
|
||||
public class JavaParametersUtil {
|
||||
private JavaParametersUtil() { }
|
||||
|
||||
public static void configureConfiguration(SimpleJavaParameters parameters, CommonJavaRunConfigurationParameters configuration) {
|
||||
ProgramParametersUtil.configureConfiguration(parameters, configuration);
|
||||
|
||||
|
||||
+26
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -22,7 +22,6 @@ package com.intellij.execution.configurations;
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.JdkUtil;
|
||||
@@ -31,34 +30,43 @@ import com.intellij.openapi.projectRoots.SdkType;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
|
||||
public class CommandLineBuilder {
|
||||
private static final Logger LOG = Logger.getInstance("#" + CommandLineBuilder.class.getName());
|
||||
private CommandLineBuilder() { }
|
||||
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters) throws CantRunException {
|
||||
return createFromJavaParameters(javaParameters, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to avoid too long cmd problem dynamic classpath can be used
|
||||
* In order to avoid too long cmd problem dynamic classpath can be used - if allowed by both {@code dynamicClasspath} parameter
|
||||
* and project settings.
|
||||
*
|
||||
* @param javaParameters parameters.
|
||||
* @param project a project to get a dynamic classpath setting from.
|
||||
* @param dynamicClasspath whether system properties and project settings will be able to cause using dynamic classpath. If false,
|
||||
* classpath will always be passed through the command line.
|
||||
* classpath will always be passed through the command line.
|
||||
* @return a command line.
|
||||
* @throws CantRunException if there are problems with JDK setup.
|
||||
*/
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters, final Project project, final boolean dynamicClasspath) throws CantRunException {
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
|
||||
final Project project,
|
||||
final boolean dynamicClasspath) throws CantRunException {
|
||||
return createFromJavaParameters(javaParameters, dynamicClasspath && JdkUtil.useDynamicClasspath(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param javaParameters parameters
|
||||
* @param forceDynamicClasspath whether dynamic classpath will be used for this execution, to prevent problems caused by too long command line
|
||||
* @return command line
|
||||
* @throws CantRunException if there are problems with JDK setup
|
||||
* @param javaParameters parameters.
|
||||
* @param forceDynamicClasspath whether dynamic classpath will be used for this execution, to prevent problems caused by too long command line.
|
||||
* @return a command line.
|
||||
* @throws CantRunException if there are problems with JDK setup.
|
||||
*/
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters, final boolean forceDynamicClasspath) throws CantRunException {
|
||||
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
|
||||
final boolean forceDynamicClasspath) throws CantRunException {
|
||||
try {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<GeneralCommandLine>() {
|
||||
public GeneralCommandLine compute() {
|
||||
try {
|
||||
final Sdk jdk = javaParameters.getJdk();
|
||||
if(jdk == null) {
|
||||
if (jdk == null) {
|
||||
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
|
||||
}
|
||||
|
||||
@@ -66,9 +74,9 @@ public class CommandLineBuilder {
|
||||
if (!(sdkType instanceof JavaSdkType)) {
|
||||
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
|
||||
}
|
||||
|
||||
|
||||
final String exePath = ((JavaSdkType)sdkType).getVMExecutablePath(jdk);
|
||||
if(exePath == null) {
|
||||
if (exePath == null) {
|
||||
throw new CantRunException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
|
||||
}
|
||||
if (javaParameters.getMainClass() == null) {
|
||||
@@ -84,11 +92,12 @@ public class CommandLineBuilder {
|
||||
});
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if(e.getCause() instanceof CantRunException)
|
||||
if (e.getCause() instanceof CantRunException) {
|
||||
throw (CantRunException)e.getCause();
|
||||
else
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user