From 998e2543747a1545200644387ec6986df3c64b6d Mon Sep 17 00:00:00 2001 From: Brad Corso Date: Fri, 31 Dec 2021 13:46:45 -0800 Subject: [PATCH] Add Gradle test that repros issues in https://github.com/google/dagger/issues/3090. This CL adds a repro test for the issues in #3090 when a transitive annotation is no longer on the classpath. Follow-up CLs will fix the remaining issues. RELNOTES=N/A PiperOrigin-RevId: 419130258 --- javatests/artifacts/dagger/settings.gradle | 3 + .../transitive-annotation-app/build.gradle | 31 ++++++++++ .../library1/build.gradle | 31 ++++++++++ .../library1/src/main/java/library1/Foo.java | 62 +++++++++++++++++++ .../src/main/java/library1/FooBase.java | 50 +++++++++++++++ .../library2/build.gradle | 25 ++++++++ .../java/library2/MyTransitiveAnnotation.java | 24 +++++++ .../src/main/java/app/MyComponent.java | 33 ++++++++++ 8 files changed, 259 insertions(+) create mode 100644 javatests/artifacts/dagger/transitive-annotation-app/build.gradle create mode 100644 javatests/artifacts/dagger/transitive-annotation-app/library1/build.gradle create mode 100644 javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/Foo.java create mode 100644 javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java create mode 100644 javatests/artifacts/dagger/transitive-annotation-app/library2/build.gradle create mode 100644 javatests/artifacts/dagger/transitive-annotation-app/library2/src/main/java/library2/MyTransitiveAnnotation.java create mode 100644 javatests/artifacts/dagger/transitive-annotation-app/src/main/java/app/MyComponent.java diff --git a/javatests/artifacts/dagger/settings.gradle b/javatests/artifacts/dagger/settings.gradle index 57a7cec6727..6ba1baebe2f 100644 --- a/javatests/artifacts/dagger/settings.gradle +++ b/javatests/artifacts/dagger/settings.gradle @@ -3,3 +3,6 @@ include ':build-tests' include ':java-app' include ':kotlin-app' include ':kotlin-app:kotlin-library' +include ':transitive-annotation-app' +include ':transitive-annotation-app:library1' +include ':transitive-annotation-app:library2' diff --git a/javatests/artifacts/dagger/transitive-annotation-app/build.gradle b/javatests/artifacts/dagger/transitive-annotation-app/build.gradle new file mode 100644 index 00000000000..90d40f71a0d --- /dev/null +++ b/javatests/artifacts/dagger/transitive-annotation-app/build.gradle @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 The Dagger 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. + */ + +plugins { + id 'java' + id 'application' +} + +java { + // Make sure the generated source is compatible with Java 7. + sourceCompatibility = JavaVersion.VERSION_1_7 +} + +dependencies { + implementation project(":transitive-annotation-app:library1") + implementation "com.google.dagger:dagger:$dagger_version" + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" +} diff --git a/javatests/artifacts/dagger/transitive-annotation-app/library1/build.gradle b/javatests/artifacts/dagger/transitive-annotation-app/library1/build.gradle new file mode 100644 index 00000000000..2126f0923d8 --- /dev/null +++ b/javatests/artifacts/dagger/transitive-annotation-app/library1/build.gradle @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 The Dagger 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. + */ + +plugins { + id 'java' + id 'java-library' +} + +java { + // Make sure the generated source is compatible with Java 7. + sourceCompatibility = JavaVersion.VERSION_1_7 +} + +dependencies { + implementation project(":transitive-annotation-app:library2") + implementation "com.google.dagger:dagger:$dagger_version" + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" +} diff --git a/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/Foo.java b/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/Foo.java new file mode 100644 index 00000000000..77d86d05a16 --- /dev/null +++ b/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/Foo.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2021 The Dagger 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 library1; + +import static library2.MyTransitiveAnnotation.VALUE; + +import javax.inject.Inject; +import javax.inject.Singleton; +import library2.MyTransitiveAnnotation; + +/** + * A class used to test that Dagger won't fail when non-dagger related annotations cannot be + * resolved. + * + *

During the compilation of {@code :app}, {@link MyTransitiveAnnotation} will no longer be on + * the classpath. In most cases, Dagger shouldn't care that the annotation isn't on the classpath + */ +@Singleton +// @MyTransitiveAnnotation(VALUE): Not supported on inject-types yet. +public final class Foo extends FooBase { + @MyTransitiveAnnotation(VALUE) + int nonDaggerField; + + // @MyTransitiveAnnotation(VALUE): Not supported on inject-fields yet. + @Inject int daggerField; + + @MyTransitiveAnnotation(VALUE) + Foo(@MyTransitiveAnnotation(VALUE) String str) { + super(str); + } + + // @MyTransitiveAnnotation(VALUE): Not supported on inject-constructors yet. + @Inject + Foo( + // @MyTransitiveAnnotation(VALUE): Not supported on inject-constructor parameters yet. + int i) { + super(i); + } + + @MyTransitiveAnnotation(VALUE) + void nonDaggerMethod(@MyTransitiveAnnotation(VALUE) int i) {} + + // @MyTransitiveAnnotation(VALUE): Not supported on inject-method yet. + @Inject + void daggerMethod( + // @MyTransitiveAnnotation(VALUE): Not supported on inject-method parameters yet. + int i) {} +} diff --git a/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java b/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java new file mode 100644 index 00000000000..2627ee50935 --- /dev/null +++ b/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 The Dagger 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 library1; + +import static library2.MyTransitiveAnnotation.VALUE; + +import javax.inject.Inject; +import library2.MyTransitiveAnnotation; + +/** A baseclass for {@link Foo}. */ +// @MyTransitiveAnnotation(VALUE): Not supported on base-types yet. +public class FooBase { + @MyTransitiveAnnotation(VALUE) + int baseNonDaggerField; + + // @MyTransitiveAnnotation(VALUE): Not supported on inject-method parameters yet. + @Inject int baseDaggerField; + + @MyTransitiveAnnotation(VALUE) + FooBase(@MyTransitiveAnnotation(VALUE) String str) {} + + // @MyTransitiveAnnotation(VALUE): Not supported on inject-constructors yet. + @Inject + FooBase( + // @MyTransitiveAnnotation(VALUE): Not supported on inject-constructor parameters yet. + int i) {} + + @MyTransitiveAnnotation(VALUE) + void baseNonDaggerMethod(@MyTransitiveAnnotation(VALUE) int i) {} + + // @MyTransitiveAnnotation(VALUE): Not supported on inject-method yet. + @Inject + void baseDaggerMethod( + // @MyTransitiveAnnotation(VALUE): Not supported on inject-method parameters yet. + int i) {} +} diff --git a/javatests/artifacts/dagger/transitive-annotation-app/library2/build.gradle b/javatests/artifacts/dagger/transitive-annotation-app/library2/build.gradle new file mode 100644 index 00000000000..b4d45e47565 --- /dev/null +++ b/javatests/artifacts/dagger/transitive-annotation-app/library2/build.gradle @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 The Dagger 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. + */ + +plugins { + id 'java' + id 'java-library' +} + +java { + // Make sure the generated source is compatible with Java 7. + sourceCompatibility = JavaVersion.VERSION_1_7 +} diff --git a/javatests/artifacts/dagger/transitive-annotation-app/library2/src/main/java/library2/MyTransitiveAnnotation.java b/javatests/artifacts/dagger/transitive-annotation-app/library2/src/main/java/library2/MyTransitiveAnnotation.java new file mode 100644 index 00000000000..c92db189831 --- /dev/null +++ b/javatests/artifacts/dagger/transitive-annotation-app/library2/src/main/java/library2/MyTransitiveAnnotation.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 The Dagger 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 library2; + +/** An annotation that is a transitive dependency of the app. */ +public @interface MyTransitiveAnnotation { + int value(); + + public static int VALUE = 0; +} diff --git a/javatests/artifacts/dagger/transitive-annotation-app/src/main/java/app/MyComponent.java b/javatests/artifacts/dagger/transitive-annotation-app/src/main/java/app/MyComponent.java new file mode 100644 index 00000000000..06f45693b1e --- /dev/null +++ b/javatests/artifacts/dagger/transitive-annotation-app/src/main/java/app/MyComponent.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 The Dagger 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 app; + +import dagger.BindsInstance; +import dagger.Component; +import javax.inject.Singleton; +import library1.Foo; + +@Singleton +@Component +interface MyComponent { + Foo foo(); + + @Component.Factory + interface Factory { + MyComponent create(@BindsInstance int i); + } +}