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.
This commit is contained in:
Eric Anderson 2024-12-23 09:38:55 -08:00
parent ebe2b48677
commit aafab74087
10 changed files with 42 additions and 6 deletions

View File

@ -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"),
],
)

View File

@ -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
@ -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*

View File

@ -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 {}

View File

@ -17,7 +17,6 @@
package io.grpc;
import java.time.Duration;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
final class TimeUtils {
private TimeUtils() {}

View File

@ -34,7 +34,6 @@ import io.grpc.ClientStreamTracer.StreamInfo;
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;

View File

@ -36,7 +36,6 @@ import java.util.concurrent.ScheduledFuture;
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;

View File

@ -19,7 +19,6 @@ package io.grpc;
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;

View File

@ -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">

View File

@ -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,

View File

@ -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,