1 From 3dbdc68093e90f0ef9b77b70490d8e0b1dcfbf8f Mon Sep 17 00:00:00 2001
2 From: Julien Lepiller <julien@lepiller.eu>
3 Date: Sun, 17 Sep 2017 21:08:45 +0200
4 Subject: [PATCH] Add ExceptionUtilsGenerator.java.
6 A gradle task (in gradle/utils.gradle) is normally used to generate an
7 ExceptionUtils class. Since gradle depends on groovy, we cannot use it, so
8 we copy the code from the gradle task to a new file. Running this file then
9 generates the required class.
11 .../codehaus/groovy/ExceptionUtilsGenerator.java | 75 ++++++++++++++++++++++
12 1 file changed, 75 insertions(+)
13 create mode 100644 config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java
15 diff --git a/config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java b/config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java
17 index 0000000..41f006d
19 +++ b/config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java
21 +package org.codehaus.groovy;
23 +import org.objectweb.asm.*;
25 +import java.io.BufferedOutputStream;
27 +import java.io.FileOutputStream;
28 +import java.io.IOException;
29 +import java.util.logging.Logger;
31 +public class ExceptionUtilsGenerator implements Opcodes {
32 + private final static Logger LOGGER = Logger.getLogger(ExceptionUtilsGenerator.class.getName());
34 + public static void main(String... args) {
35 + if (args==null || args.length==0) {
36 + throw new IllegalArgumentException("You must specify at least one file");
39 + ClassWriter cw = new ClassWriter(0);
42 + cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "org/codehaus/groovy/runtime/ExceptionUtils", null, "java/lang/Object", null);
44 + cw.visitSource("ExceptionUtils.java", null);
46 + mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
48 + Label l0 = new Label();
50 + mv.visitLineNumber(18, l0);
51 + mv.visitVarInsn(ALOAD, 0);
52 + mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
53 + mv.visitInsn(RETURN);
54 + Label l1 = new Label();
56 + mv.visitLocalVariable("this", "Lorg/codehaus/groovy/runtime/ExceptionUtils;", null, l0, l1, 0);
60 + mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "sneakyThrow", "(Ljava/lang/Throwable;)V", null, null);
62 + Label l2 = new Label();
64 + mv.visitLineNumber(20, l2);
65 + mv.visitVarInsn(ALOAD, 0);
66 + mv.visitInsn(ATHROW);
67 + Label l3 = new Label();
69 + mv.visitLocalVariable("e", "Ljava/lang/Throwable;", null, l2, l3, 0);
75 + LOGGER.info("Generating ExceptionUtils");
76 + byte[] bytes = cw.toByteArray();
77 + for (String classFilePath : args) {
78 + File classFile = new File(classFilePath);
79 + if (classFile.getParentFile().exists() || classFile.getParentFile().mkdirs()) {
81 + if (classFile.exists()) {
84 + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(classFile));
87 + } catch (IOException e) {
88 + LOGGER.warning("Unable to write file "+classFile);
91 + LOGGER.warning("Unable to create directory "+classFile.getParentFile());