mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Report error in JPS when TeaVM build crashes
This commit is contained in:
parent
ba7f07de4b
commit
91a7f69bee
|
@ -24,6 +24,8 @@ public interface TeaVMBuildResult {
|
|||
|
||||
boolean isErrorOccurred();
|
||||
|
||||
String getStackTrace();
|
||||
|
||||
ProblemProvider getProblems();
|
||||
|
||||
Collection<String> getUsedResources();
|
||||
|
|
|
@ -31,4 +31,5 @@ public class TeaVMRemoteBuildResponse implements Serializable {
|
|||
public final Set<String> usedResources = new HashSet<>();
|
||||
public final Set<String> classes = new HashSet<>();
|
||||
public final Set<String> generatedFiles = new HashSet<>();
|
||||
public String stackTrace;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2017 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.idea.jps.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public final class ExceptionUtil {
|
||||
private ExceptionUtil() {
|
||||
}
|
||||
|
||||
public static String exceptionToString(Throwable e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter output = new PrintWriter(writer);
|
||||
e.printStackTrace(output);
|
||||
output.close();
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import org.teavm.callgraph.CallGraph;
|
|||
import org.teavm.diagnostics.ProblemProvider;
|
||||
import org.teavm.idea.jps.model.TeaVMBuildResult;
|
||||
import org.teavm.idea.jps.model.TeaVMBuildStrategy;
|
||||
import org.teavm.idea.jps.util.ExceptionUtil;
|
||||
import org.teavm.tooling.EmptyTeaVMToolLog;
|
||||
import org.teavm.tooling.TeaVMTargetType;
|
||||
import org.teavm.tooling.TeaVMTool;
|
||||
|
@ -135,10 +136,12 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
|
|||
}
|
||||
|
||||
boolean errorOccurred = false;
|
||||
String stackTrace = null;
|
||||
try {
|
||||
tool.generate();
|
||||
} catch (TeaVMToolException | RuntimeException | Error e) {
|
||||
e.printStackTrace(System.err);
|
||||
stackTrace = ExceptionUtil.exceptionToString(e);
|
||||
context.processMessage(new CompilerMessage("TeaVM", e));
|
||||
errorOccurred = true;
|
||||
}
|
||||
|
@ -147,7 +150,7 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
|
|||
.map(File::getAbsolutePath)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return new InProcessBuildResult(tool.getDependencyInfo().getCallGraph(), errorOccurred,
|
||||
return new InProcessBuildResult(tool.getDependencyInfo().getCallGraph(), errorOccurred, stackTrace,
|
||||
tool.getProblemProvider(), tool.getClasses(), tool.getUsedResources(), generatedFiles);
|
||||
}
|
||||
|
||||
|
@ -168,15 +171,18 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
|
|||
static class InProcessBuildResult implements TeaVMBuildResult {
|
||||
private CallGraph callGraph;
|
||||
private boolean errorOccurred;
|
||||
private String stackTrace;
|
||||
private ProblemProvider problemProvider;
|
||||
private Collection<String> classes;
|
||||
private Collection<String> usedResources;
|
||||
private Collection<String> generatedFiles;
|
||||
|
||||
InProcessBuildResult(CallGraph callGraph, boolean errorOccurred, ProblemProvider problemProvider,
|
||||
Collection<String> classes, Collection<String> usedResources, Collection<String> generatedFiles) {
|
||||
InProcessBuildResult(CallGraph callGraph, boolean errorOccurred, String stackTrace,
|
||||
ProblemProvider problemProvider, Collection<String> classes, Collection<String> usedResources,
|
||||
Collection<String> generatedFiles) {
|
||||
this.callGraph = callGraph;
|
||||
this.errorOccurred = errorOccurred;
|
||||
this.stackTrace = stackTrace;
|
||||
this.problemProvider = problemProvider;
|
||||
this.classes = classes;
|
||||
this.usedResources = usedResources;
|
||||
|
@ -193,6 +199,11 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
|
|||
return errorOccurred;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStackTrace() {
|
||||
return stackTrace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProblemProvider getProblems() {
|
||||
return problemProvider;
|
||||
|
|
|
@ -133,6 +133,11 @@ public class RemoteBuildStrategy implements TeaVMBuildStrategy {
|
|||
return response.errorOccurred;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStackTrace() {
|
||||
return response.stackTrace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProblemProvider getProblems() {
|
||||
return problems;
|
||||
|
|
|
@ -122,8 +122,16 @@ class TeaVMBuild {
|
|||
|
||||
reportProblems(buildResult.getProblems(), buildResult.getCallGraph());
|
||||
|
||||
for (String fileName : buildResult.getGeneratedFiles()) {
|
||||
outputConsumer.registerOutputFile(new File(fileName), Collections.emptyList());
|
||||
if (!buildResult.isErrorOccurred()) {
|
||||
for (String fileName : buildResult.getGeneratedFiles()) {
|
||||
outputConsumer.registerOutputFile(new File(fileName), Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
if (buildResult.getStackTrace() != null) {
|
||||
context.processMessage(new CompilerMessage("TeaVM", BuildMessage.Kind.ERROR,
|
||||
"Compiler crashed:\n" + buildResult.getStackTrace(), "",
|
||||
-1, -1, -1, -1, -1));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.teavm.idea.jps.remote.TeaVMRemoteBuildCallback;
|
|||
import org.teavm.idea.jps.remote.TeaVMRemoteBuildRequest;
|
||||
import org.teavm.idea.jps.remote.TeaVMRemoteBuildResponse;
|
||||
import org.teavm.idea.jps.remote.TeaVMRemoteBuildService;
|
||||
import org.teavm.idea.jps.util.ExceptionUtil;
|
||||
import org.teavm.tooling.EmptyTeaVMToolLog;
|
||||
import org.teavm.tooling.TeaVMTool;
|
||||
import org.teavm.tooling.TeaVMToolException;
|
||||
|
@ -191,16 +192,18 @@ public class TeaVMBuildDaemon extends UnicastRemoteObject implements TeaVMRemote
|
|||
}
|
||||
|
||||
boolean errorOccurred = false;
|
||||
String stackTrace = null;
|
||||
try {
|
||||
tool.generate();
|
||||
System.out.println("Build complete");
|
||||
} catch (TeaVMToolException | RuntimeException | Error e) {
|
||||
e.printStackTrace(System.err);
|
||||
stackTrace = ExceptionUtil.exceptionToString(e);
|
||||
errorOccurred = true;
|
||||
}
|
||||
|
||||
TeaVMRemoteBuildResponse response = new TeaVMRemoteBuildResponse();
|
||||
response.errorOccurred = errorOccurred;
|
||||
response.stackTrace = stackTrace;
|
||||
response.callGraph = tool.getDependencyInfo().getCallGraph();
|
||||
response.problems.addAll(tool.getProblemProvider().getProblems());
|
||||
response.severeProblems.addAll(tool.getProblemProvider().getSevereProblems());
|
||||
|
|
Loading…
Reference in New Issue
Block a user