Skip to content

Commit

Permalink
api: Use package-private IgnoreJRERequirement
Browse files Browse the repository at this point in the history
This avoids the dependency on animalsniffer-annotations. grpc-api, and
particularly grpc-context, are used many low-level places and it is
beneficial for them to be very low dependency. This brings grpc-context
back to zero-dependency.
  • Loading branch information
ejona86 committed Dec 23, 2024
1 parent ebe2b48 commit aafab74
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 6 deletions.
1 change: 0 additions & 1 deletion api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ java_library(
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:failureaccess"), # future transitive dep of Guava. See #5214
artifact("com.google.guava:guava"),
artifact("org.codehaus.mojo:animal-sniffer-annotations"),
],
)
5 changes: 4 additions & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ tasks.named("jar").configure {
dependencies {
compileOnly sourceSets.context.output
api libraries.jsr305,
libraries.animalsniffer.annotations,
libraries.errorprone.annotations
implementation libraries.guava

Expand All @@ -61,6 +60,10 @@ dependencies {
}
}

animalsniffer {
annotation = 'io.grpc.IgnoreJRERequirement'
}

tasks.named("javadoc").configure {
source sourceSets.context.allSource
// We want io.grpc.Internal, but not io.grpc.Internal*
Expand Down
30 changes: 30 additions & 0 deletions api/src/main/java/io/grpc/IgnoreJRERequirement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.grpc;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

/**
* Disables Animal Sniffer's signature checking. This is our own package-private version to avoid
* dependening on animalsniffer-annotations.
*
* <p>FIELD is purposefully not supported, as Android wouldn't be able to ignore a field. Instead,
* the entire class would need to be avoided on Android.
*/
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
@interface IgnoreJRERequirement {}
1 change: 0 additions & 1 deletion api/src/main/java/io/grpc/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.grpc;

import java.time.Duration;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;

final class TimeUtils {
private TimeUtils() {}
Expand Down
1 change: 0 additions & 1 deletion api/src/test/java/io/grpc/CallOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.grpc.internal.SerializingExecutor;
import java.time.Duration;
import java.util.concurrent.Executor;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down
1 change: 0 additions & 1 deletion api/src/test/java/io/grpc/SynchronizationContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
Expand Down
1 change: 0 additions & 1 deletion api/src/test/java/io/grpc/TimeUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.Assert.assertEquals;

import java.time.Duration;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down
6 changes: 6 additions & 0 deletions buildscripts/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>

<module name="SuppressionSingleFilter">
<!-- Prefer using the same name as in Animal Sniffer -->
<property name="checks" value="AbbreviationAsWordInName"/>
<property name="files" value="IgnoreJRERequirement.java"/>
</module>

<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
Expand Down
1 change: 1 addition & 0 deletions netty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tasks.named("jar").configure {

dependencies {
api project(':grpc-api'),
libraries.animalsniffer.annotations,
libraries.netty.codec.http2
implementation project(':grpc-core'),
libs.netty.handler.proxy,
Expand Down
1 change: 1 addition & 0 deletions stub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tasks.named("jar").configure {

dependencies {
api project(':grpc-api'),
libraries.animalsniffer.annotations,
libraries.guava
implementation libraries.errorprone.annotations
testImplementation libraries.truth,
Expand Down

0 comments on commit aafab74

Please sign in to comment.