diff --git a/.gitignore b/.gitignore index 43810959f7eca0..9851496f4fa6cf 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ project.xcworkspace /ReactAndroid/gradle/ /ReactAndroid/gradlew /ReactAndroid/gradlew.bat +/android/annotations/build/ +/android/annotations-compiler/build/ # Buck .buckd @@ -51,7 +53,6 @@ buck-out .gradle local.properties *.iml -/android/ # Node node_modules diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 23d9fd5912bc9a..bca3c521df9648 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -437,6 +437,9 @@ android { } dependencies { + api(project(':react-native-annotations')) + annotationProcessor(project(':react-native-annotations-compiler')) + api("com.facebook.infer.annotation:infer-annotation:0.11.2") api("com.facebook.yoga:proguard-annotations:1.14.1") 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 754d86ec08d5c4..3b11f9c473651e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -7,19 +7,13 @@ package com.facebook.react; -import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END; -import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START; -import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_END; -import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_START; - import androidx.annotation.Nullable; + import com.facebook.react.bridge.NativeModule; 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.core.DefaultHardwareBackBtnHandler; import com.facebook.react.modules.core.DeviceEventManagerModule; @@ -30,21 +24,22 @@ 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.systrace.Systrace; -import java.util.HashMap; + import java.util.List; -import java.util.Map; + +import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END; +import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START; +import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_END; +import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_START; /** * 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, @@ -76,63 +71,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 - }; - - 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 24116e4f99db4e..bfaa384d7a7c8d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java @@ -10,19 +10,11 @@ import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.devsupport.JSCHeapCapture; -import com.facebook.react.devsupport.JSDevSupport; -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 = { @@ -44,45 +36,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, JSDevSupport.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/android/annotations-compiler/build.gradle b/android/annotations-compiler/build.gradle new file mode 100644 index 00000000000000..85d35e062075d3 --- /dev/null +++ b/android/annotations-compiler/build.gradle @@ -0,0 +1,18 @@ +// 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}") + } +} + +dependencies { + implementation('com.squareup:javapoet:1.8.0') + implementation('com.facebook.infer.annotation:infer-annotation:0.11.2') + implementation(project(':react-native-annotations')) +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK b/android/annotations-compiler/src/main/java/com/facebook/react/module/processing/BUCK similarity index 100% rename from ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK rename to android/annotations-compiler/src/main/java/com/facebook/react/module/processing/BUCK diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java b/android/annotations-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 android/annotations-compiler/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java diff --git a/android/annotations-compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/android/annotations-compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 00000000000000..31846ced5a51a8 --- /dev/null +++ b/android/annotations-compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +com.facebook.react.module.processing.ReactModuleSpecProcessor diff --git a/android/annotations/build.gradle b/android/annotations/build.gradle new file mode 100644 index 00000000000000..8d24dd49fbb477 --- /dev/null +++ b/android/annotations/build.gradle @@ -0,0 +1,5 @@ +apply plugin: 'java' + +dependencies { + +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/BUCK b/android/annotations/src/main/java/com/facebook/react/module/annotations/BUCK similarity index 100% rename from ReactAndroid/src/main/java/com/facebook/react/module/annotations/BUCK rename to android/annotations/src/main/java/com/facebook/react/module/annotations/BUCK diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java b/android/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 android/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/android/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 android/annotations/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java index efad29c134445e..c0c5209da17d6b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java +++ b/android/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/ReactAndroid/src/main/java/com/facebook/react/module/model/BUCK b/android/annotations/src/main/java/com/facebook/react/module/model/BUCK similarity index 100% rename from ReactAndroid/src/main/java/com/facebook/react/module/model/BUCK rename to android/annotations/src/main/java/com/facebook/react/module/model/BUCK diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java b/android/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 android/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/android/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 android/annotations/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java diff --git a/settings.gradle.kts b/settings.gradle.kts index 0c80447ca88928..eff2fde78b7e6e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,3 +9,9 @@ include( ":ReactAndroid", ":RNTester:android:app" ) + +include(":react-native-annotations") +project(":react-native-annotations").projectDir = File(rootProject.projectDir, "android/annotations") + +include(":react-native-annotations-compiler") +project(":react-native-annotations-compiler").projectDir = File(rootProject.projectDir, "android/annotations-compiler")