guix-more/groovy-Add-exceptionutilsgenerator.patch

groovy-Add-exceptionutilsgenerator.patch

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 from previous versions
5
6
This is replaced by a gradle task, but gradle depends on groovy, so we
7
need so way to generate the file without gradle.
8
---
9
 .../codehaus/groovy/ExceptionUtilsGenerator.java   | 75 ++++++++++++++++++++++
10
 1 file changed, 75 insertions(+)
11
 create mode 100644 config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java
12
13
diff --git a/config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java b/config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java
14
new file mode 100644
15
index 0000000..41f006d
16
--- /dev/null
17
+++ b/config/ant/src/org/codehaus/groovy/ExceptionUtilsGenerator.java
18
@@ -0,0 +1,75 @@
19
+package org.codehaus.groovy;
20
+
21
+import org.objectweb.asm.*;
22
+
23
+import java.io.BufferedOutputStream;
24
+import java.io.File;
25
+import java.io.FileOutputStream;
26
+import java.io.IOException;
27
+import java.util.logging.Logger;
28
+
29
+public class ExceptionUtilsGenerator implements Opcodes {
30
+    private final static Logger LOGGER = Logger.getLogger(ExceptionUtilsGenerator.class.getName());
31
+
32
+	public static void main(String... args) {
33
+        if (args==null || args.length==0) {
34
+            throw new IllegalArgumentException("You must specify at least one file");
35
+        }
36
+
37
+		ClassWriter cw = new ClassWriter(0);
38
+        MethodVisitor mv;
39
+
40
+        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "org/codehaus/groovy/runtime/ExceptionUtils", null, "java/lang/Object", null);
41
+
42
+        cw.visitSource("ExceptionUtils.java", null);
43
+
44
+        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
45
+        mv.visitCode();
46
+        Label l0 = new Label();
47
+        mv.visitLabel(l0);
48
+        mv.visitLineNumber(18, l0);
49
+        mv.visitVarInsn(ALOAD, 0);
50
+        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
51
+        mv.visitInsn(RETURN);
52
+        Label l1 = new Label();
53
+        mv.visitLabel(l1);
54
+        mv.visitLocalVariable("this", "Lorg/codehaus/groovy/runtime/ExceptionUtils;", null, l0, l1, 0);
55
+        mv.visitMaxs(1, 1);
56
+        mv.visitEnd();
57
+
58
+        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "sneakyThrow", "(Ljava/lang/Throwable;)V", null, null);
59
+        mv.visitCode();
60
+        Label l2 = new Label();
61
+        mv.visitLabel(l2);
62
+        mv.visitLineNumber(20, l2);
63
+        mv.visitVarInsn(ALOAD, 0);
64
+        mv.visitInsn(ATHROW);
65
+        Label l3 = new Label();
66
+        mv.visitLabel(l3);
67
+        mv.visitLocalVariable("e", "Ljava/lang/Throwable;", null, l2, l3, 0);
68
+        mv.visitMaxs(1, 1);
69
+        mv.visitEnd();
70
+
71
+        cw.visitEnd();
72
+
73
+        LOGGER.info("Generating ExceptionUtils");
74
+        byte[] bytes = cw.toByteArray();
75
+        for (String classFilePath : args) {
76
+            File classFile = new File(classFilePath);
77
+            if (classFile.getParentFile().exists() || classFile.getParentFile().mkdirs()) {
78
+                try {
79
+                    if (classFile.exists()) {
80
+                        classFile.delete();
81
+                    }
82
+                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(classFile));
83
+                    bos.write(bytes);
84
+                    bos.close();
85
+                } catch (IOException e) {
86
+                    LOGGER.warning("Unable to write file "+classFile);
87
+                }
88
+            } else {
89
+                LOGGER.warning("Unable to create directory "+classFile.getParentFile());
90
+            }
91
+        }
92
+	}
93
+}
94
-- 
95
2.14.1
96
97