Skip to content

Commit aafab74

Browse files
committed
api: Use package-private IgnoreJRERequirement
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.
1 parent ebe2b48 commit aafab74

File tree

10 files changed

+42
-6
lines changed

10 files changed

+42
-6
lines changed

api/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ java_library(
1313
artifact("com.google.errorprone:error_prone_annotations"),
1414
artifact("com.google.guava:failureaccess"), # future transitive dep of Guava. See #5214
1515
artifact("com.google.guava:guava"),
16-
artifact("org.codehaus.mojo:animal-sniffer-annotations"),
1716
],
1817
)

api/build.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ tasks.named("jar").configure {
3636
dependencies {
3737
compileOnly sourceSets.context.output
3838
api libraries.jsr305,
39-
libraries.animalsniffer.annotations,
4039
libraries.errorprone.annotations
4140
implementation libraries.guava
4241

@@ -61,6 +60,10 @@ dependencies {
6160
}
6261
}
6362

63+
animalsniffer {
64+
annotation = 'io.grpc.IgnoreJRERequirement'
65+
}
66+
6467
tasks.named("javadoc").configure {
6568
source sourceSets.context.allSource
6669
// We want io.grpc.Internal, but not io.grpc.Internal*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2024 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Target;
21+
22+
/**
23+
* Disables Animal Sniffer's signature checking. This is our own package-private version to avoid
24+
* dependening on animalsniffer-annotations.
25+
*
26+
* <p>FIELD is purposefully not supported, as Android wouldn't be able to ignore a field. Instead,
27+
* the entire class would need to be avoided on Android.
28+
*/
29+
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
30+
@interface IgnoreJRERequirement {}

api/src/main/java/io/grpc/TimeUtils.java

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package io.grpc;
1818

1919
import java.time.Duration;
20-
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
2120

2221
final class TimeUtils {
2322
private TimeUtils() {}

api/src/test/java/io/grpc/CallOptionsTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import io.grpc.internal.SerializingExecutor;
3535
import java.time.Duration;
3636
import java.util.concurrent.Executor;
37-
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
3837
import org.junit.Test;
3938
import org.junit.runner.RunWith;
4039
import org.junit.runners.JUnit4;

api/src/test/java/io/grpc/SynchronizationContextTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.concurrent.TimeUnit;
3737
import java.util.concurrent.atomic.AtomicBoolean;
3838
import java.util.concurrent.atomic.AtomicReference;
39-
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
4039
import org.junit.After;
4140
import org.junit.Rule;
4241
import org.junit.Test;

api/src/test/java/io/grpc/TimeUtilsTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.junit.Assert.assertEquals;
2020

2121
import java.time.Duration;
22-
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
2322
import org.junit.Test;
2423
import org.junit.runner.RunWith;
2524
import org.junit.runners.JUnit4;

buildscripts/checkstyle.xml

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
3939
</module>
4040

41+
<module name="SuppressionSingleFilter">
42+
<!-- Prefer using the same name as in Animal Sniffer -->
43+
<property name="checks" value="AbbreviationAsWordInName"/>
44+
<property name="files" value="IgnoreJRERequirement.java"/>
45+
</module>
46+
4147
<module name="TreeWalker">
4248
<module name="OuterTypeFilename"/>
4349
<module name="IllegalTokenText">

netty/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tasks.named("jar").configure {
1717

1818
dependencies {
1919
api project(':grpc-api'),
20+
libraries.animalsniffer.annotations,
2021
libraries.netty.codec.http2
2122
implementation project(':grpc-core'),
2223
libs.netty.handler.proxy,

stub/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tasks.named("jar").configure {
1616

1717
dependencies {
1818
api project(':grpc-api'),
19+
libraries.animalsniffer.annotations,
1920
libraries.guava
2021
implementation libraries.errorprone.annotations
2122
testImplementation libraries.truth,

0 commit comments

Comments
 (0)