diff --git a/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMBuildStrategy.java b/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMBuildStrategy.java index 282ac3395..91efb2ce0 100644 --- a/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMBuildStrategy.java +++ b/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMBuildStrategy.java @@ -17,6 +17,7 @@ package org.teavm.idea.jps.model; import java.util.List; import org.teavm.tooling.TeaVMTargetType; +import org.teavm.vm.TeaVMProgressListener; public interface TeaVMBuildStrategy { void init(); @@ -39,5 +40,7 @@ public interface TeaVMBuildStrategy { void setSourceFilesCopied(boolean sourceFilesCopied); + void setProgressListener(TeaVMProgressListener progressListener); + TeaVMBuildResult build(); } diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/InProcessBuildStrategy.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/InProcessBuildStrategy.java index 3266dc91a..6465005fc 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/InProcessBuildStrategy.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/InProcessBuildStrategy.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.List; import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.incremental.messages.CompilerMessage; -import org.jetbrains.jps.incremental.messages.ProgressMessage; import org.teavm.callgraph.CallGraph; import org.teavm.diagnostics.ProblemProvider; import org.teavm.idea.jps.model.TeaVMBuildResult; @@ -35,8 +34,6 @@ import org.teavm.tooling.TeaVMToolException; import org.teavm.tooling.sources.DirectorySourceFileProvider; import org.teavm.tooling.sources.JarSourceFileProvider; import org.teavm.tooling.sources.SourceFileProvider; -import org.teavm.vm.TeaVMPhase; -import org.teavm.vm.TeaVMProgressFeedback; import org.teavm.vm.TeaVMProgressListener; public class InProcessBuildStrategy implements TeaVMBuildStrategy { @@ -49,6 +46,7 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy { private boolean debugInformationGenerated; private boolean sourceFilesCopied; private final List sourceFileProviders = new ArrayList<>(); + private TeaVMProgressListener progressListener; public InProcessBuildStrategy(CompileContext context) { this.context = context; @@ -105,10 +103,15 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy { this.sourceFilesCopied = sourceFilesCopied; } + @Override + public void setProgressListener(TeaVMProgressListener progressListener) { + this.progressListener = progressListener; + } + @Override public TeaVMBuildResult build() { TeaVMTool tool = new TeaVMTool(); - tool.setProgressListener(createProgressListener(context)); + tool.setProgressListener(progressListener); tool.setLog(new EmptyTeaVMToolLog()); tool.setTargetType(targetType); tool.setMainClass(mainClass); @@ -152,46 +155,6 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy { return classLoader; } - private TeaVMProgressListener createProgressListener(CompileContext context) { - return new TeaVMProgressListener() { - private TeaVMPhase currentPhase; - int expectedCount; - - @Override - public TeaVMProgressFeedback phaseStarted(TeaVMPhase phase, int count) { - expectedCount = count; - context.processMessage(new ProgressMessage(phaseName(phase), 0)); - currentPhase = phase; - return context.getCancelStatus().isCanceled() ? TeaVMProgressFeedback.CANCEL - : TeaVMProgressFeedback.CONTINUE; - } - - @Override - public TeaVMProgressFeedback progressReached(int progress) { - context.processMessage(new ProgressMessage(phaseName(currentPhase), (float) progress / expectedCount)); - return context.getCancelStatus().isCanceled() ? TeaVMProgressFeedback.CANCEL - : TeaVMProgressFeedback.CONTINUE; - } - }; - } - - private static String phaseName(TeaVMPhase phase) { - switch (phase) { - case DEPENDENCY_CHECKING: - return "Discovering classes to compile"; - case LINKING: - return "Resolving method invocations"; - case DECOMPILATION: - return "Compiling classes"; - case OPTIMIZATION: - return "Optimizing code"; - case RENDERING: - return "Building JS file"; - default: - throw new AssertionError(); - } - } - static class InProcessBuildResult implements TeaVMBuildResult { private CallGraph callGraph; private boolean errorOccurred; diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/RemoteBuildStrategy.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/RemoteBuildStrategy.java index 012df3976..f4b28d833 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/RemoteBuildStrategy.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/RemoteBuildStrategy.java @@ -19,8 +19,6 @@ import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import java.util.Collection; import java.util.List; -import org.jetbrains.jps.incremental.CompileContext; -import org.jetbrains.jps.incremental.messages.ProgressMessage; import org.teavm.callgraph.CallGraph; import org.teavm.diagnostics.Problem; import org.teavm.diagnostics.ProblemProvider; @@ -33,14 +31,14 @@ import org.teavm.idea.jps.remote.TeaVMRemoteBuildService; import org.teavm.tooling.TeaVMTargetType; import org.teavm.vm.TeaVMPhase; import org.teavm.vm.TeaVMProgressFeedback; +import org.teavm.vm.TeaVMProgressListener; public class RemoteBuildStrategy implements TeaVMBuildStrategy { - private final CompileContext context; private TeaVMRemoteBuildRequest request; private TeaVMRemoteBuildService buildService; + private TeaVMProgressListener progressListener; - public RemoteBuildStrategy(CompileContext context, TeaVMRemoteBuildService buildService) { - this.context = context; + public RemoteBuildStrategy(TeaVMRemoteBuildService buildService) { this.buildService = buildService; } @@ -94,11 +92,16 @@ public class RemoteBuildStrategy implements TeaVMBuildStrategy { request.sourceFilesCopied = sourceFilesCopied; } + @Override + public void setProgressListener(TeaVMProgressListener progressListener) { + this.progressListener = progressListener; + } + @Override public TeaVMBuildResult build() { TeaVMRemoteBuildResponse response; try { - response = buildService.build(request, new CallbackImpl(context)); + response = buildService.build(request, new CallbackImpl(progressListener)); } catch (Throwable e) { throw new RuntimeException(e); } @@ -143,46 +146,21 @@ public class RemoteBuildStrategy implements TeaVMBuildStrategy { } static class CallbackImpl extends UnicastRemoteObject implements TeaVMRemoteBuildCallback { - private CompileContext context; - int expectedCount; - TeaVMPhase currentPhase; + private TeaVMProgressListener listener; - public CallbackImpl(CompileContext context) throws RemoteException { + public CallbackImpl(TeaVMProgressListener listener) throws RemoteException { super(); - this.context = context; + this.listener = listener; } @Override public TeaVMProgressFeedback phaseStarted(TeaVMPhase phase, int count) throws RemoteException { - expectedCount = count; - context.processMessage(new ProgressMessage(phaseName(phase), 0)); - currentPhase = phase; - return context.getCancelStatus().isCanceled() ? TeaVMProgressFeedback.CANCEL - : TeaVMProgressFeedback.CONTINUE; + return listener.phaseStarted(phase, count); } @Override public TeaVMProgressFeedback progressReached(int progress) throws RemoteException { - context.processMessage(new ProgressMessage(phaseName(currentPhase), (float) progress / expectedCount)); - return context.getCancelStatus().isCanceled() ? TeaVMProgressFeedback.CANCEL - : TeaVMProgressFeedback.CONTINUE; - } - } - - private static String phaseName(TeaVMPhase phase) { - switch (phase) { - case DEPENDENCY_CHECKING: - return "Discovering classes to compile"; - case LINKING: - return "Resolving method invocations"; - case DECOMPILATION: - return "Compiling classes"; - case OPTIMIZATION: - return "Optimizing code"; - case RENDERING: - return "Building JS file"; - default: - throw new AssertionError(); + return listener.progressReached(progress); } } } diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java index ef7804275..718fce5f8 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java @@ -38,6 +38,7 @@ import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.incremental.ModuleBuildTarget; import org.jetbrains.jps.incremental.messages.BuildMessage; import org.jetbrains.jps.incremental.messages.CompilerMessage; +import org.jetbrains.jps.incremental.messages.ProgressMessage; import org.jetbrains.jps.model.JpsProject; import org.jetbrains.jps.model.java.JpsJavaExtensionService; import org.jetbrains.jps.model.library.JpsLibrary; @@ -65,6 +66,9 @@ import org.teavm.model.MethodReference; import org.teavm.model.TextLocation; import org.teavm.model.ValueType; import org.teavm.tooling.TeaVMTargetType; +import org.teavm.vm.TeaVMPhase; +import org.teavm.vm.TeaVMProgressFeedback; +import org.teavm.vm.TeaVMProgressListener; class TeaVMBuild { private final CompileContext context; @@ -123,6 +127,7 @@ class TeaVMBuild { buildStrategy.setMainClass(config.getMainClass()); buildStrategy.setTargetType(config.getTargetType()); buildStrategy.setTargetDirectory(config.getTargetDirectory()); + buildStrategy.setProgressListener(createProgressListener(context)); TeaVMBuildResult buildResult = buildStrategy.build(); if (!buildResult.isErrorOccurred() && buildResult.getProblems().getSevereProblems().isEmpty()) { @@ -134,6 +139,46 @@ class TeaVMBuild { return true; } + private TeaVMProgressListener createProgressListener(CompileContext context) { + return new TeaVMProgressListener() { + private TeaVMPhase currentPhase; + int expectedCount; + + @Override + public TeaVMProgressFeedback phaseStarted(TeaVMPhase phase, int count) { + expectedCount = count; + context.processMessage(new ProgressMessage(phaseName(phase), 0)); + currentPhase = phase; + return context.getCancelStatus().isCanceled() ? TeaVMProgressFeedback.CANCEL + : TeaVMProgressFeedback.CONTINUE; + } + + @Override + public TeaVMProgressFeedback progressReached(int progress) { + context.processMessage(new ProgressMessage(phaseName(currentPhase), (float) progress / expectedCount)); + return context.getCancelStatus().isCanceled() ? TeaVMProgressFeedback.CANCEL + : TeaVMProgressFeedback.CONTINUE; + } + }; + } + + private static String phaseName(TeaVMPhase phase) { + switch (phase) { + case DEPENDENCY_CHECKING: + return "Discovering classes to compile"; + case LINKING: + return "Resolving method invocations"; + case DECOMPILATION: + return "Compiling classes"; + case OPTIMIZATION: + return "Optimizing code"; + case RENDERING: + return "Building JS file"; + default: + throw new AssertionError(); + } + } + private void reportProblems(ProblemProvider problemProvider, CallGraph callGraph) { for (Problem problem : problemProvider.getProblems()) { BuildMessage.Kind kind; diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java index 0d5499cc1..3db7a635e 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java @@ -77,7 +77,7 @@ public class TeaVMBuilder extends ModuleLevelBuilder { boolean doneSomething = false; TeaVMBuildStrategy buildStrategy = buildService != null - ? new RemoteBuildStrategy(context, buildService) + ? new RemoteBuildStrategy(buildService) : new InProcessBuildStrategy(context); TeaVMBuild build = new TeaVMBuild(context, assistant, buildStrategy); for (JpsModule module : chunk.getModules()) {