1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
buildscript {
dependencies {
classpath 'com.google.guava:guava:30.0-android'
}
}
plugins {
id "java-library"
id "maven-publish"
}
import static java.nio.charset.StandardCharsets.US_ASCII;
import com.google.common.primitives.Bytes;
description = 'gRPC: Core'
evaluationDependsOn(project(':grpc-context').path)
evaluationDependsOn(project(':grpc-api').path)
dependencies {
api project(':grpc-api')
implementation libraries.gson,
libraries.android_annotations,
libraries.animalsniffer_annotations,
libraries.errorprone,
libraries.guava,
libraries.perfmark
testRuntimeOnly project(':grpc-census')
}
def replaceBytes(byte[] haystack, byte[] needle, byte[] replacement) {
int i = Bytes.indexOf(haystack, needle);
assert i != -1;
byte[] result = new byte[haystack.length - needle.length + replacement.length];
System.arraycopy(haystack, 0, result, 0, i);
System.arraycopy(replacement, 0, result, i, replacement.length);
System.arraycopy(haystack, i + needle.length, result, i + replacement.length, haystack.length - i - needle.length);
return result;
}
def bigEndianShortBytes(int value) {
return [value >> 8, value & 0xFF] as byte[];
}
def replaceConstant(File file, String needle, String replacement) {
// CONSTANT_Utf8_info. https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7
byte[] needleBytes = Bytes.concat(
[1] as byte[], bigEndianShortBytes(needle.length()), needle.getBytes(US_ASCII));
byte[] replacementBytes = Bytes.concat(
[1] as byte[], bigEndianShortBytes(replacement.length()), replacement.getBytes(US_ASCII));
file.setBytes(replaceBytes(file.getBytes(), needleBytes, replacementBytes));
}
plugins.withId("java") {
compileJava {
}
}
task versionFile() {
doLast {
new File(buildDir, "version").write("${project.version}\n")
}
}
|