Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ before_install:
- echo "checkstyle.ignoreFailures=false" >> $HOME/.gradle/gradle.properties
- echo "failOnWarnings=true" >> $HOME/.gradle/gradle.properties
- echo "errorProne=true" >> $HOME/.gradle/gradle.properties
- echo "skipAndroid=true" >> $HOME/.gradle/gradle.properties

install:
- ./gradlew assemble syncGeneratedSources publishToMavenLocal
Expand Down
5 changes: 5 additions & 0 deletions COMPILING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ developers don't have C compilers installed and don't need to run or modify the
codegen, the build can skip it. To skip, create the file
`<project-root>/gradle.properties` and add `skipCodegen=true`.

Some parts of grpc-java depend on Android. Since many Java developers don't have
the Android SDK installed and don't need to run or modify the Android
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there instructions to install the Android SDK in case someone doesn't want to "skipAndroid"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is basically download the SDK and set $ANDROID_HOME. But there's some complications that make it hard to be concise. I think I'll let @dapengzhang0 or @voidzcy add a documentation section later in this document, but after this is merged.

(Among the problems: ANDROID_HOME is actually deprecated now in favor of ANDROID_SDK_HOME, but we'd need to upgrade to a newer gradle plugin for ANDROID_SDK _HOME to work)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It's in #6593.

components, the build can skip it. To skip, create the file
`<project-root>/gradle.properties` and add `skipAndroid=true`.

Then, to build, run:
```
$ ./gradlew build
Expand Down
32 changes: 20 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "com.android.library" apply false // Necessary for Android plugin to find its classes
id "com.google.osdetector" apply false
id "me.champeau.gradle.japicmp" apply false
id "net.ltgt.errorprone" apply false
Expand Down Expand Up @@ -114,6 +115,8 @@ subprojects {
android_annotations: "com.google.android:annotations:4.1.1.4",
animalsniffer_annotations: "org.codehaus.mojo:animal-sniffer-annotations:1.18",
errorprone: "com.google.errorprone:error_prone_annotations:2.3.4",
cronet_api: 'org.chromium.net:cronet-api:76.3809.111',
cronet_embedded: 'org.chromium.net:cronet-embedded:66.3359.158',
gson: "com.google.code.gson:gson:2.8.6",
guava: "com.google.guava:guava:${guavaVersion}",
hpack: 'com.twitter:hpack:0.10.1',
Expand Down Expand Up @@ -154,6 +157,7 @@ subprojects {
mockito: 'org.mockito:mockito-core:2.28.2',
truth: 'com.google.truth:truth:1.0',
guava_testlib: "com.google.guava:guava-testlib:${guavaVersion}",
robolectric: "org.robolectric:robolectric:3.5.1",

// Benchmark dependencies
hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.10',
Expand Down Expand Up @@ -208,6 +212,22 @@ subprojects {
}
}

if (rootProject.properties.get('errorProne', true)) {
dependencies {
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
}
} else {
// Disable Error Prone
allprojects {
afterEvaluate { project ->
project.tasks.withType(JavaCompile) {
options.errorprone.enabled = false
}
}
}
}

plugins.withId("java") {
sourceCompatibility = 1.7
targetCompatibility = 1.7
Expand Down Expand Up @@ -263,20 +283,8 @@ subprojects {

if (rootProject.properties.get('errorProne', true)) {
dependencies {
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'

annotationProcessor 'com.google.guava:guava-beta-checker:1.0'
}
} else {
// Disable Error Prone
allprojects {
afterEvaluate { project ->
project.tasks.withType(JavaCompile) {
options.errorprone.enabled = false
}
}
}
}

compileJava {
Expand Down
8 changes: 7 additions & 1 deletion buildscripts/kokoro/android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ BASE_DIR="$(pwd)"

cd "$BASE_DIR/github/grpc-java"

export GRADLE_OPTS=-Xmx512m
export LDFLAGS=-L/tmp/protobuf/lib
export CXXFLAGS=-I/tmp/protobuf/include
export LD_LIBRARY_PATH=/tmp/protobuf/lib
export OS_NAME=$(uname)

cat <<EOF >> gradle.properties
# defaults to -Xmx512m -XX:MaxMetaspaceSize=256m
# https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory
# Increased due to java.lang.OutOfMemoryError: Metaspace failures
org.gradle.jvmargs=-Xmx512m -XX:MaxMetaspaceSize=512m
EOF

echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3"

# Proto deps
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/kokoro/gae-interop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cd "$GRPC_JAVA_DIR"
##
## Deploy the dummy 'default' version of the service
##
GRADLE_FLAGS="--stacktrace -DgaeStopPreviousVersion=false -PskipCodegen=true"
GRADLE_FLAGS="--stacktrace -DgaeStopPreviousVersion=false -PskipCodegen=true -PskipAndroid=true"

# Deploy the dummy 'default' version. We only require that it exists when cleanup() is called.
# It ok if we race with another run and fail here, because the end result is idempotent.
Expand Down
1 change: 0 additions & 1 deletion buildscripts/kokoro/linux_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ popd

pushd "$GRPC_JAVA_DIR/cronet"
../gradlew publish \
--include-build "$GRPC_JAVA_DIR" \
-Dorg.gradle.parallel=false \
-PskipCodegen=true \
-PrepositoryDir="$LOCAL_MVN_TEMP"
Expand Down
1 change: 1 addition & 0 deletions buildscripts/kokoro/unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ GRADLE_FLAGS+=" -PtargetArch=$ARCH"
GRADLE_FLAGS+=" -Pcheckstyle.ignoreFailures=false"
GRADLE_FLAGS+=" -PfailOnWarnings=true"
GRADLE_FLAGS+=" -PerrorProne=true"
GRADLE_FLAGS+=" -PskipAndroid=true"
GRADLE_FLAGS+=" -Dorg.gradle.parallel=true"
export GRADLE_OPTS="-Xmx512m"

Expand Down
2 changes: 1 addition & 1 deletion buildscripts/kokoro/windows32.bat
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SET TARGET_ARCH=x86_32
SET FAIL_ON_WARNINGS=true
SET VC_PROTOBUF_LIBS=%ESCWORKSPACE%\\grpc-java-helper32\\protobuf-%PROTOBUF_VER%\\cmake\\build\\Release
SET VC_PROTOBUF_INCLUDE=%ESCWORKSPACE%\\grpc-java-helper32\\protobuf-%PROTOBUF_VER%\\cmake\\build\\include
SET GRADLE_FLAGS=-PtargetArch=%TARGET_ARCH% -PfailOnWarnings=%FAIL_ON_WARNINGS% -PvcProtobufLibs=%VC_PROTOBUF_LIBS% -PvcProtobufInclude=%VC_PROTOBUF_INCLUDE%
SET GRADLE_FLAGS=-PtargetArch=%TARGET_ARCH% -PfailOnWarnings=%FAIL_ON_WARNINGS% -PvcProtobufLibs=%VC_PROTOBUF_LIBS% -PvcProtobufInclude=%VC_PROTOBUF_INCLUDE% -PskipAndroid=true

cmd.exe /C "%WORKSPACE%\gradlew.bat %GRADLE_FLAGS% build"
set GRADLEEXIT=%ERRORLEVEL%
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/kokoro/windows64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SET TARGET_ARCH=x86_64
SET FAIL_ON_WARNINGS=true
SET VC_PROTOBUF_LIBS=%ESCWORKSPACE%\\grpc-java-helper64\\protobuf-%PROTOBUF_VER%\\cmake\\build\\Release
SET VC_PROTOBUF_INCLUDE=%ESCWORKSPACE%\\grpc-java-helper64\\protobuf-%PROTOBUF_VER%\\cmake\\build\\include
SET GRADLE_FLAGS=-PtargetArch=%TARGET_ARCH% -PfailOnWarnings=%FAIL_ON_WARNINGS% -PvcProtobufLibs=%VC_PROTOBUF_LIBS% -PvcProtobufInclude=%VC_PROTOBUF_INCLUDE%
SET GRADLE_FLAGS=-PtargetArch=%TARGET_ARCH% -PfailOnWarnings=%FAIL_ON_WARNINGS% -PvcProtobufLibs=%VC_PROTOBUF_LIBS% -PvcProtobufInclude=%VC_PROTOBUF_INCLUDE% -PskipAndroid=true

@rem make sure no daemons have any files open
cmd.exe /C "%WORKSPACE%\gradlew.bat --stop"
Expand Down
117 changes: 13 additions & 104 deletions cronet/build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
apply plugin: 'com.android.library'
plugins {
id "maven-publish"

group = "io.grpc"
version = "1.27.0-SNAPSHOT" // CURRENT_GRPC_VERSION
description = "gRPC: Cronet Android"

buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.8.1'
classpath 'digital.wup:android-maven-publish:3.6.2'
}
id "com.android.library"
id "digital.wup.android-maven-publish"
}

apply plugin: "maven-publish"
apply plugin: "net.ltgt.errorprone"
apply plugin: "digital.wup.android-maven-publish"
apply plugin: "signing"
description = "gRPC: Cronet Android"

repositories {
google()
jcenter()
mavenCentral()
mavenLocal()
}

android {
Expand All @@ -51,18 +33,15 @@ android {
}

dependencies {
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
implementation project(':grpc-core')
testImplementation project(':grpc-testing')

implementation 'io.grpc:grpc-core:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION
testImplementation 'io.grpc:grpc-testing:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION
implementation libraries.cronet_api
testImplementation libraries.cronet_embedded

implementation 'org.chromium.net:cronet-api:76.3809.111'
testImplementation 'org.chromium.net:cronet-embedded:66.3359.158'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.28.2'
testImplementation "org.robolectric:robolectric:3.5.1"
testImplementation libraries.junit
testImplementation libraries.mockito
testImplementation libraries.robolectric
}

task javadocs(type: Javadoc) {
Expand Down Expand Up @@ -94,81 +73,11 @@ task sourcesJar(type: Jar) {

publishing {
publications {
maven(MavenPublication) {
maven {
from components.android

artifact javadocJar
artifact sourcesJar

pom {
name = project.group + ":" + project.name
url = 'https://github.com/grpc/grpc-java'
afterEvaluate {
// description is not available until evaluated.
description = project.description
}

scm {
connection = 'scm:git:https://github.com/grpc/grpc-java.git'
developerConnection = 'scm:git:git@github.com:grpc/grpc-java.git'
url = 'https://github.com/grpc/grpc-java'
}

licenses {
license {
name = 'Apache 2.0'
url = 'https://opensource.org/licenses/Apache-2.0'
}
}

developers {
developer {
id = "grpc.io"
name = "gRPC Contributors"
email = "grpc-io@googlegroups.com"
url = "https://grpc.io/"
organization = "gRPC Authors"
organizationUrl = "https://www.google.com"
}
}

withXml {
asNode().dependencies.'*'.findAll() { dep ->
dep.artifactId.text() in ['grpc-api', 'grpc-core']
}.each() { core ->
core.version*.value = "[" + core.version.text() + "]"
}
}
}
}
}
repositories {
maven {
if (rootProject.hasProperty('repositoryDir')) {
url = new File(rootProject.repositoryDir).toURI()
} else {
String stagingUrl
if (rootProject.hasProperty('repositoryId')) {
stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
rootProject.repositoryId
} else {
stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
credentials {
if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
username = rootProject.ossrhUsername
password = rootProject.ossrhPassword
}
}
def releaseUrl = stagingUrl
def snapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
url = version.endsWith('SNAPSHOT') ? snapshotUrl : releaseUrl
}
}
}
}

signing {
required false
sign publishing.publications.maven
}
1 change: 0 additions & 1 deletion cronet/settings.gradle

This file was deleted.

4 changes: 1 addition & 3 deletions cronet/src/main/java/io/grpc/cronet/CronetClientStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
Expand Down Expand Up @@ -258,7 +256,7 @@ public void cancel(Status reason) {
class TransportState extends Http2ClientStreamTransportState {
private final Object lock;
@GuardedBy("lock")
private Queue<PendingData> pendingData = new LinkedList<PendingData>();
private Collection<PendingData> pendingData = new ArrayList<PendingData>();
@GuardedBy("lock")
private boolean streamReady;
@GuardedBy("lock")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void read() {
callback.onReadCompleted(
cronetStream,
info,
(ByteBuffer) createMessageFrame(new String("response1").getBytes(Charset.forName("UTF-8"))),
createMessageFrame(new String("response1").getBytes(Charset.forName("UTF-8"))),
false);
// Haven't request any message, so no callback is called here.
verify(clientListener, times(0)).messagesAvailable(isA(MessageProducer.class));
Expand Down Expand Up @@ -308,7 +308,7 @@ public void streamSucceeded() {
callback.onReadCompleted(
cronetStream,
info,
(ByteBuffer) createMessageFrame(new String("response").getBytes(Charset.forName("UTF-8"))),
createMessageFrame(new String("response").getBytes(Charset.forName("UTF-8"))),
false);
verify(clientListener, times(1)).messagesAvailable(isA(MessageProducer.class));
verify(cronetStream, times(2)).read(isA(ByteBuffer.class));
Expand Down Expand Up @@ -573,6 +573,7 @@ public void reportTrailersWhenTrailersReceivedAfterReadClosed() {
assertEquals(Status.UNAUTHENTICATED.getCode(), status.getCode());
}

@SuppressWarnings("deprecation")
@Test
public void addCronetRequestAnnotation_deprecated() {
Object annotation = new Object();
Expand Down
21 changes: 21 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
pluginManagement {
plugins {
id "com.android.library" version "3.3.0"
id "com.github.johnrengelman.shadow" version "2.0.4"
id "com.github.kt3k.coveralls" version "2.0.1"
id "com.google.osdetector" version "1.4.0"
id "com.google.protobuf" version "0.8.8"
id "digital.wup.android-maven-publish" version "3.6.2"
id "me.champeau.gradle.japicmp" version "0.2.5"
id "me.champeau.gradle.jmh" version "0.4.5"
id "net.ltgt.errorprone" version "0.8.1"
id "ru.vyarus.animalsniffer" version "1.5.0"
}
resolutionStrategy {
eachPlugin {
if (target.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:${target.version}")
}
}
}
repositories {
gradlePluginPortal()
google()
}
}

rootProject.name = "grpc"
Expand Down Expand Up @@ -62,3 +75,11 @@ if (settings.hasProperty('skipCodegen') && skipCodegen.toBoolean()) {
include ":grpc-compiler"
project(':grpc-compiler').projectDir = "$rootDir/compiler" as File
}

if (settings.hasProperty('skipAndroid') && skipAndroid.toBoolean()) {
println ' * Skipping the build of Android projects because skipAndroid=true'
} else {
println '*** Android SDK is required. To avoid building Android projects, set -PskipAndroid=true'
include ":grpc-cronet"
project(':grpc-cronet').projectDir = "$rootDir/cronet" as File
}