1
+ buildscript {
2
+ dependencies {
3
+ classpath ' com.google.guava:guava:30.0-android'
4
+ }
5
+ }
6
+
1
7
plugins {
2
8
id " java-library"
3
9
id " maven-publish"
@@ -7,6 +13,10 @@ plugins {
7
13
id " ru.vyarus.animalsniffer"
8
14
}
9
15
16
+ import static java.nio.charset.StandardCharsets.US_ASCII;
17
+
18
+ import com.google.common.primitives.Bytes ;
19
+
10
20
description = ' gRPC: Core'
11
21
12
22
evaluationDependsOn(project(' :grpc-context' ). path)
@@ -53,7 +63,47 @@ animalsniffer {
53
63
54
64
import net.ltgt.gradle.errorprone.CheckSeverity
55
65
66
+ def replaceBytes (byte [] haystack , byte [] needle , byte [] replacement ) {
67
+ int i = Bytes . indexOf(haystack, needle);
68
+ assert i != -1 ;
69
+ byte [] result = new byte [haystack. length - needle. length + replacement. length];
70
+ System . arraycopy(haystack, 0 , result, 0 , i);
71
+ System . arraycopy(replacement, 0 , result, i, replacement. length);
72
+ System . arraycopy(haystack, i + needle. length, result, i + replacement. length, haystack. length - i - needle. length);
73
+ return result;
74
+ }
75
+
76
+ def bigEndian (int value ) {
77
+ return [value >> 8 , value & 0xFF ] as byte [];
78
+ }
79
+
80
+ def replaceConstant (File file , String needle , String replacement ) {
81
+ // CONSTANT_Utf8_info. https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7
82
+ byte [] needleBytes = Bytes . concat(
83
+ [1 ] as byte [], bigEndian(needle. length()), needle. getBytes(US_ASCII ));
84
+ byte [] replacementBytes = Bytes . concat(
85
+ [1 ] as byte [], bigEndian(replacement. length()), replacement. getBytes(US_ASCII ));
86
+ file. setBytes(replaceBytes(file. getBytes(), needleBytes, replacementBytes));
87
+ }
88
+
56
89
plugins. withId(" java" ) {
90
+ compileJava {
91
+ doLast {
92
+ // Replace value of Signature Attribute.
93
+ // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.9
94
+ project. replaceConstant(
95
+ destinationDirectory. file(
96
+ " io/grpc/internal/AbstractManagedChannelImplBuilder.class" ). get(). getAsFile(),
97
+ " <T:Lio/grpc/internal/AbstractManagedChannelImplBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;" ,
98
+ " <T:Lio/grpc/ManagedChannelBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;" );
99
+ project. replaceConstant(
100
+ destinationDirectory. file(
101
+ " io/grpc/internal/AbstractServerImplBuilder.class" ). get(). getAsFile(),
102
+ " <T:Lio/grpc/internal/AbstractServerImplBuilder<TT;>;>Lio/grpc/ServerBuilder<TT;>;" ,
103
+ " <T:Lio/grpc/ServerBuilder<TT;>;>Lio/grpc/ServerBuilder<TT;>;" );
104
+ }
105
+ }
106
+
57
107
compileJmhJava {
58
108
// This project targets Java 7 (no method references)
59
109
options. errorprone. check(" UnnecessaryAnonymousClass" , CheckSeverity . OFF )
0 commit comments