Skip to content

Commit

Permalink
#924 Improved No such method : traces
Browse files Browse the repository at this point in the history
- Added proper exception handling to Maven mojo.
  • Loading branch information
mirkosertic committed Jun 15, 2023
1 parent 99e37aa commit d9915fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ public ResolvedMethod resolveMethod(final String methodName, final Type methodTy
}
return m;
}

private String printStackTrace(AnalysisStack analysisStack) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintStream stringStream = new PrintStream(bos);
analysisStack.dumpAnalysisStack(stringStream);
return "\n" + bos;
}

private ResolvedMethod resolveMethodInternal(final String methodName, final Type methodType, final AnalysisStack analysisStack, final boolean onlyImplementations) {
for (final ResolvedMethod m : resolvedMethods) {
final MethodNode methodNode = m.methodNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.mirkosertic.bytecoder.core.backend.wasm.WasmBackend;
import de.mirkosertic.bytecoder.core.backend.wasm.WasmCompileResult;
import de.mirkosertic.bytecoder.core.backend.wasm.WasmIntrinsics;
import de.mirkosertic.bytecoder.core.ir.AnalysisException;
import de.mirkosertic.bytecoder.core.ir.AnalysisStack;
import de.mirkosertic.bytecoder.core.loader.BytecoderLoader;
import de.mirkosertic.bytecoder.core.optimizer.Optimizations;
Expand All @@ -38,8 +39,10 @@
import org.apache.maven.project.MavenProject;
import org.objectweb.asm.Type;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down Expand Up @@ -120,7 +123,7 @@ public void execute() throws MojoExecutionException {
if ("js".equals(backend)) {

final CompileUnit compileUnit = new CompileUnit(loader, new Slf4JLogger(), new JSIntrinsics());
final Type invokedType = Type.getObjectType(mainClass.replace('.','/'));
final Type invokedType = Type.getObjectType(mainClass.replace('.', '/'));

compileUnit.resolveMainMethod(invokedType, "main", Type.getMethodType(Type.VOID_TYPE, Type.getType("[Ljava/lang/String;")));

Expand All @@ -147,7 +150,7 @@ public void execute() throws MojoExecutionException {

} else {
final CompileUnit compileUnit = new CompileUnit(loader, new Slf4JLogger(), new WasmIntrinsics());
final Type invokedType = Type.getObjectType(mainClass.replace('.','/'));
final Type invokedType = Type.getObjectType(mainClass.replace('.', '/'));

compileUnit.resolveMainMethod(invokedType, "main", Type.getMethodType(Type.VOID_TYPE, Type.getType("[Ljava/lang/String;")));

Expand All @@ -172,11 +175,20 @@ public void execute() throws MojoExecutionException {
}
}
}
} catch (final AnalysisException e) {
throw new MojoExecutionException("Error running Bytecoder : " + printStackTrace(e.getAnalysisStack()), e);
} catch (final Exception e) {
throw new MojoExecutionException("Error running bytecoder", e);
throw new MojoExecutionException("Error running Bytecoder", e);
}
}

private String printStackTrace(final AnalysisStack analysisStack) {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final PrintStream stringStream = new PrintStream(bos);
analysisStack.dumpAnalysisStack(stringStream);
return "\n" + bos;
}

protected boolean isSupportedScope(final String scope) {
switch (scope) {
case Artifact.SCOPE_COMPILE:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.8.22</kotlin.version>
<kotlin.version>1.8.21</kotlin.version>
<clojure.version>1.11.1</clojure.version>
</properties>

Expand Down

0 comments on commit d9915fe

Please sign in to comment.