|
26 | 26 | package jdk.tools.jlink.internal.plugins;
|
27 | 27 |
|
28 | 28 | import jdk.tools.jlink.plugin.Plugin;
|
| 29 | +import jdk.tools.jlink.internal.JlinkTask; |
29 | 30 |
|
| 31 | +import java.io.File; |
| 32 | +import java.io.IOException; |
| 33 | +import java.nio.file.Files; |
| 34 | +import java.nio.file.Paths; |
30 | 35 | import java.util.Locale;
|
31 | 36 | import java.util.MissingResourceException;
|
32 | 37 | import java.util.ResourceBundle;
|
| 38 | +import jdk.internal.org.objectweb.asm.ClassReader; |
33 | 39 |
|
34 | 40 | public abstract class AbstractPlugin implements Plugin {
|
35 | 41 |
|
@@ -61,6 +67,35 @@ protected AbstractPlugin(String name, ResourceBundle bundle) {
|
61 | 67 | this.name = name;
|
62 | 68 | this.pluginsBundle = bundle;
|
63 | 69 | }
|
| 70 | + |
| 71 | + private void dumpClassFile(String path, byte[] buf) { |
| 72 | + try { |
| 73 | + String fullPath = String.format("%d-%s%s%s", |
| 74 | + ProcessHandle.current().pid(), |
| 75 | + getName(), File.separator, |
| 76 | + path.replace('/', File.separatorChar)); |
| 77 | + System.err.printf("Dumping class file %s\n", fullPath); |
| 78 | + new File(fullPath.substring(0, fullPath.lastIndexOf('/'))).mkdirs(); |
| 79 | + Files.write(Paths.get(fullPath), buf); |
| 80 | + } catch (IOException ioExp) { |
| 81 | + System.err.println("writing " + path + " failed"); |
| 82 | + ioExp.printStackTrace(); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + protected ClassReader newClassReader(String path, byte[] buf) { |
| 87 | + try { |
| 88 | + return new ClassReader(buf); |
| 89 | + } catch (IllegalArgumentException iae) { |
| 90 | + if (JlinkTask.DEBUG) { |
| 91 | + System.err.printf("Failed to parse class file: %s\n", path); |
| 92 | + iae.printStackTrace(); |
| 93 | + dumpClassFile(path, buf); |
| 94 | + } |
| 95 | + throw iae; |
| 96 | + } |
| 97 | + } |
| 98 | + |
64 | 99 | @Override
|
65 | 100 | public String getName() {
|
66 | 101 | return name;
|
|
0 commit comments