From 4927b5be6d90e2e684b1c719068e97685eb3b450 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Fri, 2 Aug 2019 14:28:06 -0400 Subject: [PATCH] Enable module annotation processor in OSS --- .circleci/Dockerfiles/Dockerfile.android | 1 + .gitignore | 2 + ReactAndroid/build.gradle | 2 + .../facebook/react/CoreModulesPackage.java | 64 +------------------ .../com/facebook/react/DebugCorePackage.java | 49 +------------- .../main/java/com/facebook/react/bridge/BUCK | 1 + .../facebook/react/bridge/NativeModule.java | 3 +- .../facebook/react/module/annotations/BUCK | 9 +-- .../java/com/facebook/react/module/model/BUCK | 7 +- .../com/facebook/react/module/processing/BUCK | 20 +----- .../third-party/java/infer-annotations/BUCK | 2 +- .../src/main/third-party/java/javapoet/BUCK | 2 +- package.json | 1 + .../annotations/build.gradle | 17 +++++ .../facebook/react/module/annotations/BUCK | 12 ++++ .../module/annotations/BaseNativeModule.java | 15 +++++ .../react/module/annotations/ReactModule.java | 0 .../module/annotations/ReactModuleList.java | 3 +- .../java/com/facebook/react/module/model/BUCK | 11 ++++ .../react/module/model/ReactModuleInfo.java | 0 .../module/model/ReactModuleInfoProvider.java | 0 .../compiler/build.gradle | 25 ++++++++ .../com/facebook/react/module/processing/BUCK | 20 ++++++ .../processing/ReactModuleSpecProcessor.java | 0 .../javax.annotation.processing.Processor | 1 + packages/rn-tester/android/app/build.gradle | 1 + settings.gradle.kts | 5 ++ template/android/app/build.gradle | 1 + template/android/settings.gradle | 6 ++ 29 files changed, 137 insertions(+), 143 deletions(-) create mode 100644 packages/annotations-compiler/annotations/build.gradle create mode 100644 packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BUCK create mode 100644 packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BaseNativeModule.java rename {ReactAndroid => packages/annotations-compiler/annotations}/src/main/java/com/facebook/react/module/annotations/ReactModule.java (100%) rename {ReactAndroid => packages/annotations-compiler/annotations}/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java (89%) create mode 100644 packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/BUCK rename {ReactAndroid => packages/annotations-compiler/annotations}/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java (100%) rename {ReactAndroid => packages/annotations-compiler/annotations}/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java (100%) create mode 100644 packages/annotations-compiler/compiler/build.gradle create mode 100644 packages/annotations-compiler/compiler/src/main/java/com/facebook/react/module/processing/BUCK rename {ReactAndroid => packages/annotations-compiler/compiler}/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java (100%) create mode 100644 packages/annotations-compiler/compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor diff --git a/.circleci/Dockerfiles/Dockerfile.android b/.circleci/Dockerfiles/Dockerfile.android index d9937b5f8100ae..7e744660026f64 100644 --- a/.circleci/Dockerfiles/Dockerfile.android +++ b/.circleci/Dockerfiles/Dockerfile.android @@ -31,6 +31,7 @@ ADD ReactAndroid /app/ReactAndroid ADD ReactCommon /app/ReactCommon ADD React /app/React ADD keystores /app/keystores +ADD packages/annotations-compiler /app/packages/annotations-compiler ADD packages/react-native-codegen /app/packages/react-native-codegen ADD tools /app/tools diff --git a/.gitignore b/.gitignore index 748a43a7bba2bb..ab8538c13340e9 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ project.xcworkspace # Gradle /build/ /packages/react-native-gradle-plugin/build/ +/packages/annotations-compiler/annotations/build/ +/packages/annotations-compiler/compiler/build/ /packages/rn-tester/android/app/.cxx/ /packages/rn-tester/android/app/build/ /packages/rn-tester/android/app/gradle/ diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 47ca5dfc72bde1..d75caeb32df65f 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -353,6 +353,8 @@ android { } dependencies { + api(project(':react-native-annotations')) + annotationProcessor(project(':react-native-annotations-compiler')) api("com.facebook.infer.annotation:infer-annotation:0.18.0") api("com.facebook.yoga:proguard-annotations:1.19.0") api("javax.inject:javax.inject:1") diff --git a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java index 59c5c7759c52c6..2685dea9c56996 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -17,9 +17,7 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMarker; import com.facebook.react.devsupport.LogBoxModule; -import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.module.annotations.ReactModuleList; -import com.facebook.react.module.model.ReactModuleInfo; import com.facebook.react.module.model.ReactModuleInfoProvider; import com.facebook.react.modules.bundleloader.NativeDevSplitBundleLoaderModule; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; @@ -31,22 +29,17 @@ import com.facebook.react.modules.debug.SourceCodeModule; import com.facebook.react.modules.deviceinfo.DeviceInfoModule; import com.facebook.react.modules.systeminfo.AndroidInfoModule; -import com.facebook.react.turbomodule.core.interfaces.TurboModule; import com.facebook.react.uimanager.UIImplementationProvider; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManagerResolver; import com.facebook.systrace.Systrace; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * This is the basic module to support React Native. The debug modules are now in DebugCorePackage. */ @ReactModuleList( - // WARNING: If you modify this list, ensure that the list below in method - // getReactModuleInfoByInitialization is also updated nativeModules = { AndroidInfoModule.class, DeviceEventManagerModule.class, @@ -79,64 +72,9 @@ public CoreModulesPackage( mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs; } - /** - * This method is overridden, since OSS does not run the annotation processor to generate {@link - * CoreModulesPackage$$ReactModuleInfoProvider} class. Here we check if it exists. If it does not - * exist, we generate one manually in {@link - * CoreModulesPackage#getReactModuleInfoByInitialization()} and return that instead. - */ @Override public ReactModuleInfoProvider getReactModuleInfoProvider() { - try { - Class reactModuleInfoProviderClass = - Class.forName("com.facebook.react.CoreModulesPackage$$ReactModuleInfoProvider"); - return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance(); - } catch (ClassNotFoundException e) { - // In OSS case, the annotation processor does not run. We fall back on creating this byhand - Class[] moduleList = - new Class[] { - AndroidInfoModule.class, - DeviceEventManagerModule.class, - DeviceInfoModule.class, - DevSettingsModule.class, - ExceptionsManagerModule.class, - LogBoxModule.class, - HeadlessJsTaskSupportModule.class, - SourceCodeModule.class, - TimingModule.class, - UIManagerModule.class, - NativeDevSplitBundleLoaderModule.class, - }; - - final Map reactModuleInfoMap = new HashMap<>(); - for (Class moduleClass : moduleList) { - ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class); - - reactModuleInfoMap.put( - reactModule.name(), - new ReactModuleInfo( - reactModule.name(), - moduleClass.getName(), - reactModule.canOverrideExistingModule(), - reactModule.needsEagerInit(), - reactModule.hasConstants(), - reactModule.isCxxModule(), - TurboModule.class.isAssignableFrom(moduleClass))); - } - - return new ReactModuleInfoProvider() { - @Override - public Map getReactModuleInfos() { - return reactModuleInfoMap; - } - }; - } catch (InstantiationException e) { - throw new RuntimeException( - "No ReactModuleInfoProvider for CoreModulesPackage$$ReactModuleInfoProvider", e); - } catch (IllegalAccessException e) { - throw new RuntimeException( - "No ReactModuleInfoProvider for CoreModulesPackage$$ReactModuleInfoProvider", e); - } + return new CoreModulesPackage$$ReactModuleInfoProvider(); } @Override diff --git a/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java b/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java index 740182fbc0f7f1..98f565be4135b5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java @@ -10,19 +10,10 @@ import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.devsupport.JSCHeapCapture; -import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.module.annotations.ReactModuleList; -import com.facebook.react.module.model.ReactModuleInfo; import com.facebook.react.module.model.ReactModuleInfoProvider; -import com.facebook.react.turbomodule.core.interfaces.TurboModule; -import java.util.HashMap; -import java.util.Map; -/** - * Package defining core framework modules (e.g. UIManager). It should be used for modules that - * require special integration with other framework parts (e.g. with the list of packages to load - * view managers from). - */ +/** Package defining core debug only modules. */ @ReactModuleList( nativeModules = { JSCHeapCapture.class, @@ -43,42 +34,6 @@ public NativeModule getModule(String name, ReactApplicationContext reactContext) @Override public ReactModuleInfoProvider getReactModuleInfoProvider() { - try { - Class reactModuleInfoProviderClass = - Class.forName("com.facebook.react.DebugCorePackage$$ReactModuleInfoProvider"); - return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance(); - } catch (ClassNotFoundException e) { - // In OSS case, the annotation processor does not run. We fall back on creating this by hand - Class[] moduleList = new Class[] {JSCHeapCapture.class}; - - final Map reactModuleInfoMap = new HashMap<>(); - for (Class moduleClass : moduleList) { - ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class); - - reactModuleInfoMap.put( - reactModule.name(), - new ReactModuleInfo( - reactModule.name(), - moduleClass.getName(), - reactModule.canOverrideExistingModule(), - reactModule.needsEagerInit(), - reactModule.hasConstants(), - reactModule.isCxxModule(), - TurboModule.class.isAssignableFrom(moduleClass))); - } - - return new ReactModuleInfoProvider() { - @Override - public Map getReactModuleInfos() { - return reactModuleInfoMap; - } - }; - } catch (InstantiationException e) { - throw new RuntimeException( - "No ReactModuleInfoProvider for DebugCorePackage$$ReactModuleInfoProvider", e); - } catch (IllegalAccessException e) { - throw new RuntimeException( - "No ReactModuleInfoProvider for DebugCorePackage$$ReactModuleInfoProvider", e); - } + return new com.facebook.react.DebugCorePackage$$ReactModuleInfoProvider(); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/BUCK b/ReactAndroid/src/main/java/com/facebook/react/bridge/BUCK index 0f54a3c0b0b57f..339dc0c2cae472 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/BUCK @@ -89,5 +89,6 @@ rn_android_library( exported_deps = [ react_native_dep("java/com/facebook/proguard/annotations:annotations"), react_native_dep("third-party/java/jsr-330:jsr-330"), + react_native_target("java/com/facebook/react/module/annotations:annotations"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModule.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModule.java index 11f7117f2e9789..a2e79d846c258e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModule.java @@ -9,6 +9,7 @@ import androidx.annotation.NonNull; import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.module.annotations.BaseNativeModule; /** * A native module whose API can be provided to JS catalyst instances. {@link NativeModule}s whose @@ -18,7 +19,7 @@ * themselves using {@link CxxModuleWrapper}. */ @DoNotStrip -public interface NativeModule { +public interface NativeModule extends BaseNativeModule { interface NativeMethod { void invoke(JSInstance jsInstance, ReadableArray parameters); diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/BUCK b/ReactAndroid/src/main/java/com/facebook/react/module/annotations/BUCK index ec9fc4e9e07e9e..7b5a154f60c62a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/module/annotations/BUCK @@ -1,17 +1,14 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library") +load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library") rn_android_library( name = "annotations", - srcs = glob(["**/*.java"]), autoglob = False, labels = ["supermodule:xplat/default/public.react_native.infra"], required_for_source_only_abi = True, visibility = [ "PUBLIC", ], - deps = [ - react_native_dep("third-party/java/infer-annotations:infer-annotations"), - react_native_dep("third-party/java/jsr-305:jsr-305"), - react_native_target("java/com/facebook/react/bridge:interfaces"), + exported_deps = [ + "//packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations:annotations", ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/model/BUCK b/ReactAndroid/src/main/java/com/facebook/react/module/model/BUCK index 22d2f5a6625890..24c6ed03ccd686 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/model/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/module/model/BUCK @@ -1,14 +1,13 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library") +load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library") rn_android_library( name = "model", - srcs = glob(["**/*.java"]), autoglob = False, labels = ["supermodule:xplat/default/public.react_native.infra"], visibility = [ "PUBLIC", ], - deps = [ - react_native_dep("third-party/java/jsr-305:jsr-305"), + exported_deps = [ + "//packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model:model", ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK b/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK index cc44f729d1893a..b9399bd641131e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK @@ -1,4 +1,4 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_java_annotation_processor", "rn_java_library") +load("//tools/build_defs/oss:rn_defs.bzl", "rn_java_annotation_processor") rn_java_annotation_processor( name = "processing", @@ -8,22 +8,6 @@ rn_java_annotation_processor( "PUBLIC", ], deps = [ - ":processing-lib", - ], -) - -rn_java_library( - name = "processing-lib", - srcs = glob(["*.java"]), - labels = ["supermodule:xplat/default/public.react_native.infra"], - source = "8", - target = "8", - deps = [ - react_native_dep("third-party/java/infer-annotations:infer-annotations"), - react_native_dep("third-party/java/javapoet:javapoet"), - react_native_dep("third-party/java/jsr-305:jsr-305"), - react_native_target("java/com/facebook/react/module/annotations:annotations"), - react_native_target("java/com/facebook/react/module/model:model"), - react_native_target("java/com/facebook/react/turbomodule/core/interfaces:interfaces"), + "//packages/annotations-compiler/compiler/src/main/java/com/facebook/react/module/processing:processing-lib", ], ) diff --git a/ReactAndroid/src/main/third-party/java/infer-annotations/BUCK b/ReactAndroid/src/main/third-party/java/infer-annotations/BUCK index 2fd4c3bf633f34..b0baa6fa0267e4 100644 --- a/ReactAndroid/src/main/third-party/java/infer-annotations/BUCK +++ b/ReactAndroid/src/main/third-party/java/infer-annotations/BUCK @@ -4,7 +4,7 @@ load("//tools/build_defs/oss:rn_defs.bzl", "rn_prebuilt_jar") rn_prebuilt_jar( name = "infer-annotations", binary_jar = ":infer-annotations.jar", - visibility = ["//ReactAndroid/..."], + visibility = ["//ReactAndroid/...", "//packages/annotations-compiler/..."], ) fb_native.remote_file( diff --git a/ReactAndroid/src/main/third-party/java/javapoet/BUCK b/ReactAndroid/src/main/third-party/java/javapoet/BUCK index 3a50a70a433e81..8d3882bd08851c 100644 --- a/ReactAndroid/src/main/third-party/java/javapoet/BUCK +++ b/ReactAndroid/src/main/third-party/java/javapoet/BUCK @@ -4,7 +4,7 @@ load("//tools/build_defs/oss:rn_defs.bzl", "rn_prebuilt_jar") rn_prebuilt_jar( name = "javapoet", binary_jar = ":jsr305-binary.jar", - visibility = ["//ReactAndroid/..."], + visibility = ["//ReactAndroid/...", "//packages/annotations-compiler/..."], ) fb_native.remote_file( diff --git a/package.json b/package.json index 32ae4a2dec773c..891e2136c9fc3d 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "Libraries", "LICENSE", "local-cli", + "packages/annotations-compiler", "React-Core.podspec", "react-native.config.js", "react.gradle", diff --git a/packages/annotations-compiler/annotations/build.gradle b/packages/annotations-compiler/annotations/build.gradle new file mode 100644 index 00000000000000..e4bae3f4f9e34b --- /dev/null +++ b/packages/annotations-compiler/annotations/build.gradle @@ -0,0 +1,17 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +apply plugin: 'java' + +dependencies { + +} + +java { + sourceCompatibility(JavaVersion.VERSION_1_8) + targetCompatibility(JavaVersion.VERSION_1_8) +} diff --git a/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BUCK b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BUCK new file mode 100644 index 00000000000000..9fdfc278ae931c --- /dev/null +++ b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BUCK @@ -0,0 +1,12 @@ +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library") + +rn_android_library( + name = "annotations", + srcs = glob(["**/*.java"]), + autoglob = False, + labels = ["supermodule:xplat/default/public.react_native.infra"], + required_for_source_only_abi = True, + visibility = [ + "PUBLIC", + ], +) diff --git a/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BaseNativeModule.java b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BaseNativeModule.java new file mode 100644 index 00000000000000..fda3bb0eb7d2e8 --- /dev/null +++ b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/BaseNativeModule.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.module.annotations; + +/** + * Used to make sure classes passed to the ReactModule annotation are actually an instance of + * NativeModule without needing a dependency on NativeModule that is in the ReactAndroid target. + */ +public interface BaseNativeModule { +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/ReactModule.java similarity index 100% rename from ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java rename to packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/ReactModule.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java similarity index 89% rename from ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java rename to packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java index efad29c134445e..016f71b0549c70 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java +++ b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java @@ -10,7 +10,6 @@ import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.SOURCE; -import com.facebook.react.bridge.NativeModule; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -27,5 +26,5 @@ * * @return List of Native modules in the package. */ - Class[] nativeModules(); + Class[] nativeModules(); } diff --git a/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/BUCK b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/BUCK new file mode 100644 index 00000000000000..91d88dfbc5f012 --- /dev/null +++ b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/BUCK @@ -0,0 +1,11 @@ +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library") + +rn_android_library( + name = "model", + srcs = glob(["**/*.java"]), + autoglob = False, + labels = ["supermodule:xplat/default/public.react_native.infra"], + visibility = [ + "PUBLIC", + ], +) diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java similarity index 100% rename from ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java rename to packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java b/packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java similarity index 100% rename from ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java rename to packages/annotations-compiler/annotations/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java diff --git a/packages/annotations-compiler/compiler/build.gradle b/packages/annotations-compiler/compiler/build.gradle new file mode 100644 index 00000000000000..f80aef39bbb34c --- /dev/null +++ b/packages/annotations-compiler/compiler/build.gradle @@ -0,0 +1,25 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +apply plugin: 'java' + +sourceSets.configureEach { sourceSet -> + tasks.named(sourceSet.compileJavaTaskName).configure { + options.annotationProcessorGeneratedSourcesDirectory = file("$buildDir/generated/sources/annotationProcessor/java/${sourceSet.name}") + } +} + +java { + sourceCompatibility(JavaVersion.VERSION_1_8) + targetCompatibility(JavaVersion.VERSION_1_8) +} + +dependencies { + implementation('com.squareup:javapoet:1.13.0') + implementation('com.facebook.infer.annotation:infer-annotation:0.18.0') + implementation(project(':react-native-annotations')) +} diff --git a/packages/annotations-compiler/compiler/src/main/java/com/facebook/react/module/processing/BUCK b/packages/annotations-compiler/compiler/src/main/java/com/facebook/react/module/processing/BUCK new file mode 100644 index 00000000000000..365b76eed7c994 --- /dev/null +++ b/packages/annotations-compiler/compiler/src/main/java/com/facebook/react/module/processing/BUCK @@ -0,0 +1,20 @@ +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_java_library") + +rn_java_library( + name = "processing-lib", + srcs = glob(["*.java"]), + labels = ["supermodule:xplat/default/public.react_native.infra"], + source = "8", + target = "8", + visibility = [ + "PUBLIC", + ], + deps = [ + react_native_dep("third-party/java/infer-annotations:infer-annotations"), + react_native_dep("third-party/java/javapoet:javapoet"), + react_native_dep("third-party/java/jsr-305:jsr-305"), + react_native_target("java/com/facebook/react/module/annotations:annotations"), + react_native_target("java/com/facebook/react/module/model:model"), + react_native_target("java/com/facebook/react/turbomodule/core/interfaces:interfaces"), + ], +) diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java b/packages/annotations-compiler/compiler/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java similarity index 100% rename from ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java rename to packages/annotations-compiler/compiler/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java diff --git a/packages/annotations-compiler/compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/packages/annotations-compiler/compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 00000000000000..31846ced5a51a8 --- /dev/null +++ b/packages/annotations-compiler/compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +com.facebook.react.module.processing.ReactModuleSpecProcessor diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index a2de00ba8fec3b..b9ba9e873ebd66 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -227,6 +227,7 @@ dependencies { // Build React Native from source implementation project(':ReactAndroid') + annotationProcessor project(":react-native-annotations-compiler") implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" diff --git a/settings.gradle.kts b/settings.gradle.kts index 045b88e9ac0a3f..8247ab5ffb4c55 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -27,3 +27,8 @@ if (File("template/node_modules/").exists()) { name = "template-android" } } + +include(":react-native-annotations") +project(":react-native-annotations").projectDir = File(rootProject.projectDir, "packages/annotations-compiler/annotations") +include(":react-native-annotations-compiler") +project(":react-native-annotations-compiler").projectDir = File(rootProject.projectDir, "packages/annotations-compiler/compiler") diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index e1c91549c43251..e396418a50afe0 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -195,6 +195,7 @@ dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules + annotationProcessor project(':react-native-annotations-compiler') implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" diff --git a/template/android/settings.gradle b/template/android/settings.gradle index e50c29d6298864..43cd215b62fe2f 100644 --- a/template/android/settings.gradle +++ b/template/android/settings.gradle @@ -1,3 +1,9 @@ rootProject.name = 'HelloWorld' + +include(":react-native-annotations") +project(":react-native-annotations").projectDir = File(rootProject.projectDir, "../node_modules/react-native/packages/annotations-compiler/annotations") +include(":react-native-annotations-compiler") +project(":react-native-annotations-compiler").projectDir = File(rootProject.projectDir, "../node_modules/react-native/packages/annotations-compiler/compiler") + apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app'