Skip to content

Commit

Permalink
Allow transformed classes to be dumped
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Sep 7, 2020
1 parent 2a6241b commit 7e05c1a
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.deployment.steps;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -22,6 +24,7 @@
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import io.quarkus.bootstrap.BootstrapDebug;
import io.quarkus.bootstrap.classloading.ClassPathElement;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.QuarkusClassWriter;
Expand Down Expand Up @@ -104,7 +107,22 @@ public TransformedClassesBuildItem.TransformedClass call() throws Exception {
visitor = i.apply(className, visitor);
}
cr.accept(visitor, 0);
return new TransformedClassesBuildItem.TransformedClass(className, writer.toByteArray(),
byte[] data = writer.toByteArray();
if (BootstrapDebug.DEBUG_TRANSFORMED_CLASSES_DIR != null) {
File debugPath = new File(BootstrapDebug.DEBUG_TRANSFORMED_CLASSES_DIR);
if (!debugPath.exists()) {
debugPath.mkdir();
}
File classFile = new File(debugPath, className.replace(".", "/") + ".class");
classFile.getParentFile().mkdirs();
try (FileOutputStream classWriter = new FileOutputStream(classFile)) {
classWriter.write(data);
} catch (Exception e) {
log.errorf(e, "Failed to write transformed class %s", className);
}
log.infof("Wrote transformed class to %s", classFile.getAbsolutePath());
}
return new TransformedClassesBuildItem.TransformedClass(className, data,
classFileName, eager.contains(className));
} finally {
Thread.currentThread().setContextClassLoader(old);
Expand Down

0 comments on commit 7e05c1a

Please sign in to comment.