From 58c19e3abc71d51e0a95c375039c272c53ece73e Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 25 Dec 2018 18:45:26 +0300 Subject: [PATCH] Minor fixes in development toolchain --- .../teavm/ast/optimization/ExprOptimizer.java | 2 +- .../src/main/js/chrome/contentscript.js | 4 ++- .../org/teavm/devserver/indicator.js | 10 +++---- .../idea/devserver/DevServerManager.java | 2 ++ .../teavm/idea/devserver/DevServerRunner.java | 27 ++++++++++++++----- .../idea/devserver/TeaVMDevServerRunner.java | 10 ++++--- .../devserver/ui/TeaVMDevServerConsole.java | 1 + 7 files changed, 40 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/teavm/ast/optimization/ExprOptimizer.java b/core/src/main/java/org/teavm/ast/optimization/ExprOptimizer.java index 86241a697..f141e3d32 100644 --- a/core/src/main/java/org/teavm/ast/optimization/ExprOptimizer.java +++ b/core/src/main/java/org/teavm/ast/optimization/ExprOptimizer.java @@ -43,7 +43,7 @@ final class ExprOptimizer { case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: - return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b); + return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b, expr.getLocation()); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: diff --git a/tools/chrome-rdp/src/main/js/chrome/contentscript.js b/tools/chrome-rdp/src/main/js/chrome/contentscript.js index 4e5149a5a..5859f1799 100644 --- a/tools/chrome-rdp/src/main/js/chrome/contentscript.js +++ b/tools/chrome-rdp/src/main/js/chrome/contentscript.js @@ -14,13 +14,15 @@ * limitations under the License. */ +var connected = false; window.addEventListener("message", function(event) { if (event.source !== window) { return; } var data = event.data; - if (typeof data.teavmDebugger !== "undefined") { + if (typeof data.teavmDebugger !== "undefined" && !connected) { + connected = true; chrome.runtime.sendMessage({ command: "debug", port: data.teavmDebugger.port }); } }, false); diff --git a/tools/devserver/src/main/resources/org/teavm/devserver/indicator.js b/tools/devserver/src/main/resources/org/teavm/devserver/indicator.js index c330209c0..2bcc9a04b 100644 --- a/tools/devserver/src/main/resources/org/teavm/devserver/indicator.js +++ b/tools/devserver/src/main/resources/org/teavm/devserver/indicator.js @@ -20,10 +20,7 @@ var debugPort = DEBUG_PORT; function createWebSocket() { - var loc = window.location; - var newUri = loc.protocol === "https:" ? "wss:" : "ws:"; - newUri += "//WS_PATH"; - return new WebSocket(newUri); + return new WebSocket("ws://WS_PATH"); } function createIndicator() { @@ -170,15 +167,18 @@ } if (debugPort > 0) { + var connected = false; function connectDebugAgent(event) { if (event.source !== window) { return; } var data = event.data; - if (typeof data.teavmDebuggerRequest !== "undefined") { + if (typeof data.teavmDebuggerRequest !== "undefined" && !connected) { + connected = true; window.postMessage({teavmDebugger: {port: debugPort}}, "*"); } } window.addEventListener("message", connectDebugAgent); + window.postMessage({teavmDebugger: {port: debugPort}}, "*"); } })(); \ No newline at end of file diff --git a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerManager.java b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerManager.java index 6341981dd..4c8df93b0 100644 --- a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerManager.java +++ b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerManager.java @@ -30,4 +30,6 @@ public interface DevServerManager extends Remote { void cancelBuild() throws RemoteException; void addListener(DevServerManagerListener listener) throws RemoteException; + + void removeListener(DevServerManagerListener listener) throws RemoteException; } diff --git a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerRunner.java b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerRunner.java index fc9c87c23..fc8c652d5 100644 --- a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerRunner.java +++ b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/DevServerRunner.java @@ -46,7 +46,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan private int port; private Registry registry; private DevServer server; - private List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); private DevServerRunner(DevServer server) throws RemoteException { super(); @@ -94,7 +94,16 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan @Override public void addListener(DevServerManagerListener listener) { - listeners.add(listener); + synchronized (listeners) { + listeners.add(listener); + } + } + + @Override + public void removeListener(DevServerManagerListener listener) { + synchronized (listeners) { + listeners.remove(listener); + } } public static void main(String[] args) throws Exception { @@ -265,10 +274,16 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan } } + private List getListeners() { + synchronized (listeners) { + return new ArrayList<>(listeners); + } + } + final DevServerListener devServerListener = new DevServerListener() { @Override public void compilationStarted() { - for (DevServerManagerListener listener : listeners) { + for (DevServerManagerListener listener : getListeners()) { try { listener.compilationStarted(); } catch (RemoteException e) { @@ -279,7 +294,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan @Override public void compilationProgress(double v) { - for (DevServerManagerListener listener : listeners) { + for (DevServerManagerListener listener : getListeners()) { try { listener.compilationProgress(v); } catch (RemoteException e) { @@ -293,7 +308,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan DevServerBuildResult result = new DevServerBuildResult(); result.callGraph = buildResult.getCallGraph(); result.problems.addAll(buildResult.getProblems().getProblems()); - for (DevServerManagerListener listener : listeners) { + for (DevServerManagerListener listener : getListeners()) { try { listener.compilationComplete(result); } catch (RemoteException e) { @@ -304,7 +319,7 @@ public class DevServerRunner extends UnicastRemoteObject implements DevServerMan @Override public void compilationCancelled() { - for (DevServerManagerListener listener : listeners) { + for (DevServerManagerListener listener : getListeners()) { try { listener.compilationCancelled(); } catch (RemoteException e) { diff --git a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMDevServerRunner.java b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMDevServerRunner.java index 2ed37ea36..fef3d2d0f 100644 --- a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMDevServerRunner.java +++ b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMDevServerRunner.java @@ -74,11 +74,15 @@ public class TeaVMDevServerRunner extends GenericProgramRunner { }); runContent = debugSession.getRunContentDescriptor(); - ProcessHandler debugProcessHandler = debugSession.getDebugProcess().getProcessHandler(); - debugProcessHandler.addProcessListener(new ProcessAdapter() { + runContent.getProcessHandler().addProcessListener(new ProcessAdapter() { + @Override + public void startNotified(@NotNull ProcessEvent event) { + processHandler.startNotify(); + } + @Override public void processTerminated(@NotNull ProcessEvent event) { - processHandler.destroyProcess(); + processHandler.detachProcess(); } }); } diff --git a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/ui/TeaVMDevServerConsole.java b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/ui/TeaVMDevServerConsole.java index c9e4665cc..ed3c09318 100644 --- a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/ui/TeaVMDevServerConsole.java +++ b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/ui/TeaVMDevServerConsole.java @@ -96,6 +96,7 @@ public class TeaVMDevServerConsole extends JPanel implements ConsoleView { } catch (RemoteException e) { throw new RuntimeException(e); } + serverListener = null; } underlyingConsole.dispose(); }