/dev-java/groovy/files/groovy-2.4.10-utils.gradle.patch

https://github.com/masayuko/hiidulu · Patch · 119 lines · 108 code · 11 blank · 0 comment · 0 complexity · 674bc8ceb2cdc18c1d194cd60d882bb0 MD5 · raw file

  1. diff --git a/gradle/utils.gradle b/gradle/utils.gradle
  2. index b485933..69df164 100644
  3. --- a/gradle/utils.gradle
  4. +++ b/gradle/utils.gradle
  5. @@ -17,60 +17,48 @@
  6. * under the License.
  7. */
  8. -import org.objectweb.asm.MethodVisitor
  9. -import org.objectweb.asm.ClassWriter
  10. -import org.objectweb.asm.Label
  11. +import java.io.File;
  12. +import java.io.FileOutputStream;
  13. -import static org.objectweb.asm.Opcodes.ACC_PUBLIC
  14. -import static org.objectweb.asm.Opcodes.ACC_STATIC
  15. -import static org.objectweb.asm.Opcodes.ACC_SUPER
  16. -import static org.objectweb.asm.Opcodes.ALOAD
  17. -import static org.objectweb.asm.Opcodes.ATHROW
  18. -import static org.objectweb.asm.Opcodes.INVOKESPECIAL
  19. -import static org.objectweb.asm.Opcodes.RETURN
  20. -import static org.objectweb.asm.Opcodes.V1_5
  21. +import org.objectweb.asm.MethodVisitor;
  22. +import org.objectweb.asm.ClassWriter;
  23. +import org.objectweb.asm.Label;
  24. -buildscript {
  25. - repositories {
  26. - mavenCentral()
  27. - }
  28. - dependencies {
  29. - classpath "org.ow2.asm:asm:$asmVersion"
  30. - }
  31. -}
  32. +import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
  33. +import static org.objectweb.asm.Opcodes.ACC_STATIC;
  34. +import static org.objectweb.asm.Opcodes.ACC_SUPER;
  35. +import static org.objectweb.asm.Opcodes.ALOAD;
  36. +import static org.objectweb.asm.Opcodes.ATHROW;
  37. +import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
  38. +import static org.objectweb.asm.Opcodes.RETURN;
  39. +import static org.objectweb.asm.Opcodes.V1_5;
  40. -/**
  41. - * This tasks generates an utility class which allows sneaky throwing.
  42. - */
  43. -task exceptionUtils {
  44. - ext.classFiles = [
  45. - "${buildDir}/generated-classes/org/codehaus/groovy/runtime/ExceptionUtils.class",
  46. - "${compileJava.destinationDir}/org/codehaus/groovy/runtime/ExceptionUtils.class"]
  47. - outputs.files classFiles
  48. +public class ExceptionUtils {
  49. + private final static String gentooClassDestination = "target/classes/org/codehaus/groovy/runtime/ExceptionUtils.class";
  50. - doLast {
  51. + public static void main(String[] args) {
  52. ClassWriter cw = new ClassWriter(0);
  53. MethodVisitor mv;
  54. - cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, 'org/codehaus/groovy/runtime/ExceptionUtils', null, 'java/lang/Object', null);
  55. + cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "org/codehaus/groovy/runtime/ExceptionUtils", null, "java/lang/Object", null);
  56. - cw.visitSource('ExceptionUtils.java', null);
  57. + cw.visitSource("ExceptionUtils.java", null);
  58. - mv = cw.visitMethod(ACC_PUBLIC, '<init>', '()V', null, null);
  59. + mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
  60. mv.visitCode();
  61. Label l0 = new Label();
  62. mv.visitLabel(l0);
  63. mv.visitLineNumber(18, l0);
  64. mv.visitVarInsn(ALOAD, 0);
  65. - mv.visitMethodInsn(INVOKESPECIAL, 'java/lang/Object', '<init>', '()V', false);
  66. + mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
  67. mv.visitInsn(RETURN);
  68. Label l1 = new Label();
  69. mv.visitLabel(l1);
  70. - mv.visitLocalVariable('this', 'Lorg/codehaus/groovy/runtime/ExceptionUtils;', null, l0, l1, 0);
  71. + mv.visitLocalVariable("this", "Lorg/codehaus/groovy/runtime/ExceptionUtils;", null, l0, l1, 0);
  72. mv.visitMaxs(1, 1);
  73. mv.visitEnd();
  74. - mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, 'sneakyThrow', '(Ljava/lang/Throwable;)V', null, null);
  75. + mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "sneakyThrow", "(Ljava/lang/Throwable;)V", null, null);
  76. mv.visitCode();
  77. Label l2 = new Label();
  78. mv.visitLabel(l2);
  79. @@ -79,19 +67,21 @@ task exceptionUtils {
  80. mv.visitInsn(ATHROW);
  81. Label l3 = new Label();
  82. mv.visitLabel(l3);
  83. - mv.visitLocalVariable('e', 'Ljava/lang/Throwable;', null, l2, l3, 0);
  84. + mv.visitLocalVariable("e", "Ljava/lang/Throwable;", null, l2, l3, 0);
  85. mv.visitMaxs(1, 1);
  86. mv.visitEnd();
  87. cw.visitEnd();
  88. + FileOutputStream fos = null;
  89. - logger.lifecycle('Generating ExceptionUtils')
  90. - classFiles.each { classFile ->
  91. - def output = file(classFile)
  92. - output.parentFile.mkdirs()
  93. - output.withOutputStream {
  94. - it << cw.toByteArray()
  95. - }
  96. - }
  97. - }
  98. + File f = new File(gentooClassDestination);
  99. + f.getParentFile().mkdirs();
  100. + try {
  101. + fos = new FileOutputStream(f);
  102. + fos.write(cw.toByteArray());
  103. + fos.close();
  104. + } catch (Exception e) {
  105. + e.printStackTrace();
  106. + }
  107. + }
  108. }