├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── RELEASING.md ├── build.gradle ├── checkstyle.xml ├── crumb-annotations ├── build.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── com │ └── uber │ └── crumb │ └── annotations │ ├── CrumbConsumable.java │ ├── CrumbConsumer.java │ ├── CrumbProducer.java │ ├── CrumbQualifier.java │ └── internal │ └── CrumbIndex.java ├── crumb-compiler-api ├── build.gradle ├── gradle.properties └── src │ └── main │ └── kotlin │ └── com │ └── uber │ └── crumb │ └── compiler │ └── api │ ├── CrumbConsumerExtension.kt │ ├── CrumbContext.kt │ ├── CrumbExtension.kt │ ├── CrumbProducerExtension.kt │ └── CrumbTypeAliases.kt ├── crumb-compiler ├── build.gradle ├── gradle.properties └── src │ └── main │ ├── kotlin │ └── com │ │ └── uber │ │ └── crumb │ │ ├── CrumbProcessor.kt │ │ ├── TypeElementExt.kt │ │ └── internal │ │ ├── model │ │ ├── Crumb.kt │ │ └── CrumbMetadata.kt │ │ └── wire │ │ ├── EnumAdapter.kt │ │ ├── FieldEncoding.kt │ │ ├── Message.kt │ │ ├── MessageSerializedForm.kt │ │ ├── MessageSink.kt │ │ ├── MessageSource.kt │ │ ├── ProtoAdapter.kt │ │ ├── ProtoReader.kt │ │ ├── ProtoWriter.kt │ │ ├── RuntimeEnumAdapter.kt │ │ ├── Service.kt │ │ ├── Wire.kt │ │ ├── WireEnum.kt │ │ ├── WireField.kt │ │ ├── WireRpc.kt │ │ └── internal │ │ ├── -Platform.kt │ │ ├── FieldBinding.kt │ │ ├── ImmutableList.kt │ │ ├── Internal.kt │ │ ├── InternalJvm.kt │ │ ├── MutableOnWriteList.kt │ │ ├── RuntimeMessageAdapter.kt │ │ └── Util.kt │ └── proto │ └── com │ └── uber │ └── crumb │ └── internal │ └── model │ └── crumb_model.proto ├── crumb-core ├── build.gradle ├── gradle.properties └── src │ └── main │ └── kotlin │ └── com │ └── uber │ └── crumb │ └── core │ ├── CrumbLog.kt │ ├── CrumbManager.kt │ └── CrumbOutputLanguage.kt ├── gradle.properties ├── gradle ├── checkstyle.gradle ├── config-kotlin-sources.gradle ├── dependencies.gradle ├── gradle-mvn-push.gradle ├── publish-docs.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── integration-test ├── annotations │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── integration │ │ └── annotations │ │ ├── GsonFactory.java │ │ └── MoshiFactory.java ├── compiler │ ├── build.gradle │ └── src │ │ ├── main │ │ └── kotlin │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── integration │ │ │ └── compiler │ │ │ ├── CompilerExtensions.kt │ │ │ ├── GsonSupport.kt │ │ │ └── MoshiSupport.kt │ │ └── test │ │ └── kotlin │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── integration │ │ └── compiler │ │ ├── CrumbProcessorTest.kt │ │ ├── GsonSupportTest.kt │ │ └── MoshiSupportTest.kt ├── integration │ ├── build.gradle │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── integration │ │ │ ├── consumer │ │ │ └── IntegrationConsumer.java │ │ │ └── localmodels │ │ │ ├── LocalEnum.java │ │ │ ├── LocalModel.java │ │ │ └── LocalProducer.java │ │ └── test │ │ └── java │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── integration │ │ └── consumer │ │ └── IntegrationConsumerTest.java ├── lib1 │ ├── build.gradle │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── integration │ │ │ └── lib1 │ │ │ ├── Lib1Enum.java │ │ │ ├── Lib1Model.java │ │ │ └── Lib1Producer.java │ │ └── test │ │ └── java │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── integration │ │ └── lib1 │ │ └── Lib1ProducerTest.java ├── lib2 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── integration │ │ └── lib2 │ │ ├── Lib2Enum.java │ │ ├── Lib2Model.java │ │ └── Lib2Producer.java └── lib3 │ ├── build.gradle │ └── src │ └── main │ └── java │ └── com │ └── uber │ └── crumb │ └── integration │ └── lib3 │ ├── Lib3Enum.java │ ├── Lib3Model.java │ └── Lib3Producer.java ├── sample ├── experiments-compiler │ ├── android │ │ ├── java │ │ │ ├── app │ │ │ │ ├── build.gradle │ │ │ │ └── src │ │ │ │ │ └── main │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── uber │ │ │ │ │ └── crumb │ │ │ │ │ └── sample │ │ │ │ │ └── ExperimentsHolder.java │ │ │ └── library │ │ │ │ ├── build.gradle │ │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── uber │ │ │ │ └── crumb │ │ │ │ └── sample │ │ │ │ └── LibraryExperiments.java │ │ └── kotlin │ │ │ ├── app │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── kotlin │ │ │ │ └── com │ │ │ │ └── uber │ │ │ │ └── crumb │ │ │ │ └── sample │ │ │ │ └── ExperimentsHolder.kt │ │ │ └── library │ │ │ ├── build.gradle │ │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ └── kotlin │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── LibraryExperiments.kt │ ├── experiment-enums-compiler │ │ ├── annotations │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── uber │ │ │ │ └── crumb │ │ │ │ └── sample │ │ │ │ └── experimentsenumscompiler │ │ │ │ └── annotations │ │ │ │ ├── Experiments.java │ │ │ │ └── ExperimentsCollector.java │ │ ├── java │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── uber │ │ │ │ └── crumb │ │ │ │ └── sample │ │ │ │ └── experimentenumscompiler │ │ │ │ ├── ExperimentsCompiler.java │ │ │ │ └── package-info.java │ │ └── kotlin │ │ │ ├── build.gradle │ │ │ └── src │ │ │ └── main │ │ │ └── kotlin │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── experimentenumscompiler │ │ │ └── ExperimentsCompiler.kt │ └── jvm │ │ ├── java │ │ ├── app │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── uber │ │ │ │ └── crumb │ │ │ │ └── sample │ │ │ │ └── ExperimentsHolder.java │ │ └── library │ │ │ ├── build.gradle │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── LibraryExperiments.java │ │ └── kotlin │ │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ └── kotlin │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── ExperimentsHolder.kt │ │ └── library │ │ ├── build.gradle │ │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── sample │ │ └── LibraryExperiments.kt └── plugins-compiler │ ├── PluginSampleDiagram.key │ ├── android │ ├── java │ │ ├── app │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── uber │ │ │ │ └── crumb │ │ │ │ └── sample │ │ │ │ ├── DefaultTranslations.java │ │ │ │ └── TranslationsPluginManager.java │ │ └── library │ │ │ ├── build.gradle │ │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── EnglishTranslations.java │ └── kotlin │ │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ └── kotlin │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ ├── DefaultTranslations.kt │ │ │ └── TranslationsPluginManager.kt │ │ └── library │ │ ├── build.gradle │ │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ └── kotlin │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── sample │ │ └── EnglishTranslations.kt │ ├── jvm │ ├── java │ │ ├── app │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── uber │ │ │ │ └── crumb │ │ │ │ └── sample │ │ │ │ ├── DefaultTranslations.java │ │ │ │ └── TranslationsPluginManager.java │ │ └── library │ │ │ ├── build.gradle │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── EnglishTranslations.java │ └── kotlin │ │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ └── kotlin │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ ├── DefaultTranslations.kt │ │ │ └── TranslationsPluginManager.kt │ │ └── library │ │ ├── build.gradle │ │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── sample │ │ └── EnglishTranslations.kt │ ├── plugins-compiler │ ├── annotations │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── pluginscompiler │ │ │ └── annotations │ │ │ ├── Plugin.java │ │ │ └── PluginPoint.java │ ├── java │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── uber │ │ │ └── crumb │ │ │ └── sample │ │ │ └── pluginscompiler │ │ │ ├── PluginsCompiler.java │ │ │ └── package-info.java │ └── kotlin │ │ ├── build.gradle │ │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── uber │ │ └── crumb │ │ └── sample │ │ └── pluginscompiler │ │ └── PluginsCompiler.kt │ └── translations-api │ ├── build.gradle │ └── src │ └── main │ └── java │ └── com │ └── uber │ └── crumb │ └── sample │ └── Translations.java ├── settings.gradle └── spotless ├── copyright.java └── copyright.kt /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*.{kt,kts}] 5 | indent_size=2 6 | continuation_indent_size=4 7 | insert_final_newline=true 8 | max_line_length=120 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | **Library version**: 9 | 10 | 11 | **Repro steps or stacktrace**: 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | **Description**: 9 | 10 | 11 | **Related issue(s)**: 12 | 13 | 14 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: JDK ${{ matrix.java_version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | # TODO Add 13 when Gradle 6.0 is out 12 | # TODO Add 9, 10, 11, and 12 after Kotlin 1.3.60 13 | java_version: [1.8] 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v1 17 | - name: Install JDK 18 | uses: actions/setup-java@v1 19 | with: 20 | java-version: ${{ matrix.java_version }} 21 | - name: Configure Gradle 22 | # Initial gradle configuration, install dependencies, etc 23 | run: ./gradlew help 24 | - name: Spot check 25 | # Run spotless first to fail fast on spotless issues 26 | run: ./gradlew spotlessCheck --stacktrace 27 | - name: Build project 28 | run: ./gradlew assemble --stacktrace 29 | - name: Run tests 30 | run: ./gradlew test --stacktrace 31 | - name: Final checks 32 | run: ./gradlew check --stacktrace 33 | - name: Upload snapshot (main only) 34 | run: ./gradlew uploadArchives -PSONATYPE_NEXUS_USERNAME="$SONATYPE_NEXUS_USERNAME" -PSONATYPE_NEXUS_PASSWORD="$SONATYPE_NEXUS_PASSWORD" 35 | env: 36 | SONATYPE_NEXUS_USERNAME: ${{ secrets.SonatypeUsername }} 37 | SONATYPE_NEXUS_PASSWORD: ${{ secrets.SonatypePassword }} 38 | if: success() && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && matrix.java_version == '1.8' 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###OSX### 2 | 3 | .DS_Store 4 | .AppleDouble 5 | .LSOverride 6 | 7 | # Icon must ends with two \r. 8 | Icon 9 | 10 | 11 | # Thumbnails 12 | ._* 13 | 14 | # Files that might appear on external disk 15 | .Spotlight-V100 16 | .Trashes 17 | 18 | 19 | ###Linux### 20 | 21 | *~ 22 | 23 | # KDE directory preferences 24 | .directory 25 | 26 | out/ 27 | 28 | ###Android### 29 | 30 | # Built application files 31 | *.apk 32 | *.ap_ 33 | 34 | # Files for ART and Dalvik VM 35 | *.dex 36 | 37 | # Java class files 38 | *.class 39 | 40 | # Generated files 41 | bin/ 42 | gen/ 43 | 44 | # Gradle files 45 | .gradle/ 46 | .gradletasknamecache 47 | build/ 48 | 49 | # Local configuration file (sdk path, etc) 50 | local.properties 51 | 52 | # Proguard folder generated by Eclipse 53 | proguard/ 54 | 55 | # Lint 56 | lint-report.html 57 | lint-report_files/ 58 | lint_result.txt 59 | 60 | # Mobile Tools for Java (J2ME) 61 | .mtj.tmp/ 62 | 63 | # Package Files # 64 | *.war 65 | *.ear 66 | 67 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 68 | hs_err_pid* 69 | 70 | 71 | ###IntelliJ### 72 | 73 | *.iml 74 | *.ipr 75 | *.iws 76 | .idea/ 77 | 78 | 79 | ###Eclipse### 80 | 81 | *.pydevproject 82 | .metadata 83 | tmp/ 84 | *.tmp 85 | *.bak 86 | *.swp 87 | *~.nib 88 | .settings/ 89 | .loadpath 90 | 91 | # External tool builders 92 | .externalToolBuilders/ 93 | 94 | # Locally stored "Eclipse launch configurations" 95 | *.launch 96 | 97 | # CDT-specific 98 | .cproject 99 | 100 | # PDT-specific 101 | .buildpath 102 | 103 | # sbteclipse plugin 104 | .target 105 | 106 | # TeXlipse plugin 107 | .texlipse 108 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | Version 0.1.0 5 | ------------- 6 | 7 | _2019-09-14_ 8 | 9 | ### Incremental annotation processing support ([#43](https://github.com/uber/crumb/pull/43)) 10 | 11 | Crumb is now fully compatible with incremental annotation processing, and extensions APIs have been 12 | updated to allow extensions to opt in and declare what kind of incrementalism they support. This 13 | system is similar to AutoValue's API for allowing extensions to declare their incremental support. 14 | Full documentation can be found in Javadocs. 15 | 16 | ### New element-based breadcrumbing mechanism ([#39](https://github.com/uber/crumb/pull/39)) 17 | 18 | Before, Crumb would breadcrumb metadata across compilation boundaries via writing files to 19 | resources. This had a few issues, but most importantly it would never be compatible with incremental 20 | annotation processing. This new system instead writes what we call "Crumb indexes", which are holder 21 | classes that are annotated with a `@CrumbIndex` annotation containing the metadata instead. Crumb 22 | consumers will just read all indexes in this known package now instead, and this has enabled us to 23 | support incremental annotation processing. 24 | 25 | ### Metadata wire format changes 26 | 27 | #### Raw bytes ([#42](https://github.com/uber/crumb/pull/42)) 28 | 29 | CrumbManager now stores metadata as raw bytes, with reads and writes exposed as 30 | [Okio](https://github.com/square/okio) `BufferedSource` and `BufferedSink` types ([#46](https://github.com/uber/crumb/pull/46)). 31 | 32 | #### Wire and Protos ([#44](https://github.com/uber/crumb/pull/44)) 33 | 34 | When using Crumb's annotation processor, it stores metadata as raw gzip'd protocol buffers via 35 | [Wire](https://github.com/square/wire). Note that Wire's runtime is temporarily shaded in for now 36 | due to a [known Kapt MPP bug](https://youtrack.jetbrains.com/issue/KT-31641). 37 | 38 | ### Consumers can now consumer local producer-generated models ([#49](https://github.com/uber/crumb/pull/49)) 39 | 40 | Before, consumers could not consumer metadata produced by producers in the same compilation/project. 41 | Now they can! 42 | 43 | ### Misc 44 | 45 | **Enhancement:** Extension interfaces now have sane defaults for applicability checks and also utilize 46 | `@JvmDefault` where appropriate. Note that this requires both targeting jdk8 and opting in to `@JvmDefault`. ([#44](https://github.com/uber/crumb/pull/44)) 47 | 48 | **Fix:** Check loaderForExtensions before loading extensions ([#34](https://github.com/uber/crumb/pull/34)) 49 | 50 | Dependency updates 51 | 52 | Kotlin: 1.3.50 53 | KotlinPoet: 1.3.0 54 | JavaPoet: 1.11.1 55 | 56 | Thanks contributors that helped with documentation, feedback, and reviews! [@vanniktech](https://github.com/vanniktech) [@drd](https://github.com/drd) 57 | 58 | Initial release! 59 | 60 | Version 0.0.1 61 | ------------- 62 | 63 | _2018-04-10_ 64 | 65 | Initial release! 66 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at mobile-open-source@uber.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to Crumb 2 | ======================= 3 | 4 | The Uber team welcomes contributions of all kinds, from simple bug reports through documentation, test cases, 5 | bugfixes, and features. 6 | 7 | Workflow 8 | -------- 9 | 10 | We love GitHub issues! 11 | 12 | For small feature requests, an issue first proposing it for discussion or demo implementation in a PR suffice. 13 | 14 | For big features, please open an issue so that we can agree on the direction, and hopefully avoid 15 | investing a lot of time on a feature that might need reworking. 16 | 17 | Small pull requests for things like typos, bugfixes, etc are always welcome. 18 | 19 | DOs and DON'Ts 20 | -------------- 21 | 22 | * DO include tests when adding new features. When fixing bugs, start with adding a test that highlights how the current behavior is broken. 23 | * DO keep the discussions focused. When a new or related topic comes up it's often better to create new issue than to side track the discussion. 24 | * DO run all Gradle verification tasks (`./gradlew check`) before submitting a pull request 25 | 26 | * DON'T submit PRs that alter licensing related files or headers. If you believe there's a problem with them, file an issue and we'll be happy to discuss it. 27 | 28 | ### Code style 29 | 30 | This project uses [GoogleJavaFormat](https://github.com/google/GoogleJavaFormat) and [ktlint](https://github.com/shyiko/ktlint), 31 | provided via the [spotless](https://github.com/diffplug/spotless) gradle plugin. 32 | 33 | If you find that one of your pull reviews does not pass the CI server check due to a code style conflict, you can 34 | easily fix it by running: `./gradlew spotlessApply`. 35 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | Releasing 2 | ========= 3 | 4 | 1. Change the version in `gradle.properties` to a non-SNAPSHOT version. 5 | 2. Update the `CHANGELOG.md` for the impending release. 6 | 3. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) 7 | 4. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version) 8 | 5. `./gradlew clean uploadArchives --no-parallel` 9 | 6. Update the `gradle.properties` to the next SNAPSHOT version. 10 | 7. `git commit -am "Prepare next development version."` 11 | 8. `git push && git push --tags` 12 | 9. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. 13 | - Select the artifact, click `close`, wait for it to close, then select again and click 14 | `release`. 15 | 10. After release propagates (wait ~1 hour), update Javadocs via [Osstrich](https://github.com/square/osstrich) 16 | - Make sure you have push access 17 | - `./gradlew publishDocs` 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | buildscript { 18 | apply from: 'gradle/dependencies.gradle' 19 | repositories { 20 | mavenCentral() 21 | google() 22 | jcenter() 23 | } 24 | dependencies { 25 | classpath deps.build.gradlePlugins.android 26 | classpath deps.build.gradlePlugins.kotlin 27 | } 28 | } 29 | 30 | plugins { 31 | id 'com.diffplug.gradle.spotless' 32 | } 33 | 34 | allprojects { 35 | buildscript { 36 | repositories { 37 | mavenCentral() 38 | google() 39 | jcenter() 40 | } 41 | } 42 | 43 | repositories { 44 | mavenCentral() 45 | google() 46 | jcenter() 47 | } 48 | } 49 | 50 | subprojects { 51 | afterEvaluate { 52 | if (project.getPlugins().hasPlugin('com.android.application') || 53 | project.getPlugins().hasPlugin('com.android.library')) { 54 | 55 | android.lintOptions { 56 | // The lint task fails on travis CI's machines, but isn't necessary for these samples either 57 | tasks.lint.enabled = false 58 | } 59 | } 60 | } 61 | 62 | apply from: rootProject.file('gradle/dependencies.gradle') 63 | apply plugin: 'com.diffplug.gradle.spotless' 64 | spotless { 65 | format 'misc', { 66 | target '**/*.md', '**/.gitignore' 67 | 68 | trimTrailingWhitespace() 69 | indentWithTabs() // or spaces. Takes an integer argument if you don't like 4 70 | endWithNewline() 71 | } 72 | // Not yet, pending https://github.com/diffplug/spotless/issues/142 73 | // kotlin { 74 | // target "**/*.kt" 75 | // ktlint(deps.versions.ktlint) 76 | // licenseHeaderFile rootProject.file('spotless/copyright.kt') 77 | // } 78 | java { 79 | target "**/src/main/**/com/uber/*.java" 80 | googleJavaFormat(deps.versions.gjf) 81 | licenseHeaderFile rootProject.file('spotless/copyright.java') 82 | removeUnusedImports() 83 | } 84 | groovyGradle { 85 | target '**/*.gradle' 86 | } 87 | } 88 | } 89 | 90 | apply from: 'gradle/dependencies.gradle' 91 | apply from: 'gradle/checkstyle.gradle' 92 | apply from: 'gradle/publish-docs.gradle' 93 | -------------------------------------------------------------------------------- /crumb-annotations/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | } 21 | 22 | sourceCompatibility = "1.7" 23 | targetCompatibility = "1.7" 24 | 25 | dependencies { 26 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 27 | //noinspection GradleDynamicVersion 28 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 29 | } 30 | 31 | tasks.withType(JavaCompile).configureEach { 32 | options.errorprone.disableWarningsInGeneratedCode = true 33 | } 34 | 35 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 36 | -------------------------------------------------------------------------------- /crumb-annotations/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018. Uber Technologies 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 | POM_NAME=Crumb Annotations 18 | POM_ARTIFACT_ID=crumb-annotations 19 | POM_PACKAGING=jar 20 | -------------------------------------------------------------------------------- /crumb-annotations/src/main/java/com/uber/crumb/annotations/CrumbConsumable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.annotations; 17 | 18 | import static java.lang.annotation.ElementType.TYPE; 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Inherited; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * A convenience annotation that can be used to indicate that this type should be available to the 28 | * Crumb processor and any of its extensions (since processors have to declare which annotations 29 | * they support). 30 | */ 31 | @Documented 32 | @Inherited 33 | @Target(TYPE) 34 | @Retention(RUNTIME) 35 | public @interface CrumbConsumable {} 36 | -------------------------------------------------------------------------------- /crumb-annotations/src/main/java/com/uber/crumb/annotations/CrumbConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.annotations; 17 | 18 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Annotation to indicate that a given class should consumer crumb metadata from the classpath 27 | * during processing. 28 | */ 29 | @Documented 30 | @Target(ANNOTATION_TYPE) 31 | @Retention(RUNTIME) 32 | public @interface CrumbConsumer {} 33 | -------------------------------------------------------------------------------- /crumb-annotations/src/main/java/com/uber/crumb/annotations/CrumbProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.annotations; 17 | 18 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Annotation to indicate that a given class should produce crumb metadata from the classpath during 27 | * processing. 28 | */ 29 | @Documented 30 | @Target(ANNOTATION_TYPE) 31 | @Retention(RUNTIME) 32 | public @interface CrumbProducer {} 33 | -------------------------------------------------------------------------------- /crumb-annotations/src/main/java/com/uber/crumb/annotations/CrumbQualifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.annotations; 17 | 18 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * This annotation can be used on custom other annotations to indicate that they are relevant for 27 | * Crumb and given to extensions in their APIs. 28 | */ 29 | @Documented 30 | @Target(ANNOTATION_TYPE) 31 | @Retention(RUNTIME) 32 | public @interface CrumbQualifier {} 33 | -------------------------------------------------------------------------------- /crumb-annotations/src/main/java/com/uber/crumb/annotations/internal/CrumbIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.annotations.internal; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.TYPE; 23 | 24 | /** 25 | * An annotation for recording information about a given index in crumb. Should be considered 26 | * private API. 27 | */ 28 | @Retention(RetentionPolicy.CLASS) 29 | @Target(TYPE) 30 | public @interface CrumbIndex { 31 | byte[] value(); 32 | } 33 | -------------------------------------------------------------------------------- /crumb-compiler-api/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'org.jetbrains.kotlin.jvm' 19 | id 'org.jetbrains.kotlin.kapt' 20 | id 'org.jetbrains.dokka' 21 | } 22 | 23 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 24 | kotlinOptions { 25 | jvmTarget = "1.8" 26 | freeCompilerArgs = ['-Xjsr305=strict', '-Xjvm-default=enable'] 27 | } 28 | } 29 | 30 | dependencies { 31 | kapt deps.apt.autoService 32 | compileOnly deps.apt.autoServiceAnnotations 33 | 34 | api deps.kotlin.stdLibJdk8 35 | api project(":crumb-annotations") 36 | } 37 | 38 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 39 | -------------------------------------------------------------------------------- /crumb-compiler-api/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018. Uber Technologies 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 | POM_NAME=Crumb Compiler API 18 | POM_ARTIFACT_ID=crumb-compiler-api 19 | POM_PACKAGING=jar 20 | -------------------------------------------------------------------------------- /crumb-compiler-api/src/main/kotlin/com/uber/crumb/compiler/api/CrumbConsumerExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.compiler.api 18 | 19 | import com.uber.crumb.annotations.CrumbConsumer 20 | import com.uber.crumb.annotations.CrumbQualifier 21 | import com.uber.crumb.compiler.api.CrumbExtension.IncrementalExtensionType 22 | import javax.annotation.processing.ProcessingEnvironment 23 | import javax.lang.model.element.AnnotationMirror 24 | import javax.lang.model.element.TypeElement 25 | 26 | /** 27 | * Interface for [CrumbConsumer] extensions. 28 | */ 29 | interface CrumbConsumerExtension : CrumbExtension { 30 | 31 | /** 32 | * Supported consumer annotations, if any, that the CrumbProcessor should collect on this 33 | * extension's behalf. Empty by default. 34 | */ 35 | @JvmDefault 36 | fun supportedConsumerAnnotations(): Set> { 37 | return emptySet() 38 | } 39 | 40 | /** 41 | * Determines whether or not a given type is applicable to this. 42 | * 43 | * @param context the [CrumbContext]. 44 | * @param type the type to check. 45 | * @param annotations collected [CrumbQualifier]-annotated annotations on [type]. 46 | * @return true if the type is applicable. 47 | */ 48 | @JvmDefault 49 | fun isConsumerApplicable(context: CrumbContext, 50 | type: TypeElement, 51 | annotations: Collection): Boolean { 52 | // Note: AutoCommon's MoreElements#isAnnotationPresent() is a safer option but not used here to avoid the dependency 53 | return supportedConsumerAnnotations().any { 54 | type.getAnnotation(it) != null 55 | } 56 | } 57 | 58 | /** 59 | * Invoked to tell this extension to consume the set of collected [ConsumerMetadata]. 60 | * 61 | * @param context the [CrumbContext]. 62 | * @param type the type this is consuming on. 63 | * @param annotations collected [CrumbQualifier]-annotated annotations on [type]. 64 | * @param metadata collected metadata associated with this extension. 65 | */ 66 | fun consume(context: CrumbContext, 67 | type: TypeElement, 68 | annotations: Collection, 69 | metadata: Set) 70 | 71 | /** 72 | * Determines the incremental type of this Extension. 73 | * 74 | * The [ProcessingEnvironment] can be used, among other things, to obtain the processor 75 | * options, using [ProcessingEnvironment.getOptions]. 76 | * 77 | * The actual incremental type of the Crumb processor as a whole will be the loosest 78 | * incremental types of the Extensions present in the annotation processor path. The default 79 | * returned value is [IncrementalExtensionType.UNKNOWN], which will disable incremental 80 | * annotation processing entirely. 81 | */ 82 | @JvmDefault 83 | fun consumerIncrementalType(processingEnvironment: ProcessingEnvironment): IncrementalExtensionType { 84 | return IncrementalExtensionType.UNKNOWN 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /crumb-compiler-api/src/main/kotlin/com/uber/crumb/compiler/api/CrumbContext.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.compiler.api 18 | 19 | import javax.annotation.processing.ProcessingEnvironment 20 | import javax.annotation.processing.RoundEnvironment 21 | 22 | /** 23 | * A holder class for the environment Crumb is running in. 24 | * 25 | * @param processingEnv The ProcessingEnvironment 26 | * @param roundEnv the RoundEnvironment 27 | */ 28 | class CrumbContext(val processingEnv: ProcessingEnvironment, 29 | val roundEnv: RoundEnvironment) 30 | -------------------------------------------------------------------------------- /crumb-compiler-api/src/main/kotlin/com/uber/crumb/compiler/api/CrumbExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.compiler.api 18 | 19 | import javax.annotation.processing.ProcessingEnvironment 20 | 21 | /** 22 | * Base extension for CrumbExtensions. This class isn't one you would implement directly. 23 | */ 24 | interface CrumbExtension { 25 | 26 | /** 27 | * Convenience init callback when extension processing is beginning. 28 | * 29 | * If you need anything from the processingEnv for later, it is recommended to save its instance here. 30 | */ 31 | @JvmDefault 32 | fun init(processingEnvironment: ProcessingEnvironment) { 33 | 34 | } 35 | 36 | /** 37 | * @return the [ExtensionKey] for this extension, used to indicate what key to use in storing/retrieving 38 | * metadata from the classpath. This is the key that [CrumbProducerExtension] data is written to 39 | * and [CrumbConsumerExtension] data is read from. By default, it's the name of the extension class. 40 | */ 41 | @JvmDefault 42 | val key: ExtensionKey get() = javaClass.name 43 | 44 | /** 45 | * Indicates to an annotation processor environment supporting incremental annotation processing 46 | * (currently a feature specific to Gradle starting with version 4.8) the incremental type of an 47 | * Extension. 48 | * 49 | * The constants for this enum are ordered by increasing performance (but also constraints). 50 | * 51 | * @see [Gradle documentation of its incremental annotation processing](https://docs.gradle.org/current/userguide/java_plugin.html.sec:incremental_annotation_processing) 52 | */ 53 | enum class IncrementalExtensionType { 54 | /** 55 | * The incrementality of this extension is unknown, or it is neither aggregating nor isolating. 56 | */ 57 | UNKNOWN, 58 | 59 | /** 60 | * This extension is *aggregating*, meaning that it may generate outputs based on several 61 | * annotated input classes and it respects the constraints imposed on aggregating processors. 62 | * It is common for Crumb producer extensions to be aggregating and unusual for consumer 63 | * extensions to be aggregating. 64 | * 65 | * @see [Gradle definition of aggregating processors](https://docs.gradle.org/current/userguide/java_plugin.html.aggregating_annotation_processors) 66 | */ 67 | AGGREGATING, 68 | 69 | /** 70 | * This extension is *isolating*, meaning roughly that its output depends on the 71 | * `@CrumbConsumer`/`@CrumbProducer` class and its dependencies, but not on other `@CrumbConsumer`/`@CrumbProducer` 72 | * classes that might be compiled at the same time. The constraints that an isolating extension must 73 | * respect are the same as those that Gradle imposes on an isolating annotation processor. 74 | * It is unusual for Crumb producer extensions to be isolating and common for consumer 75 | * extensions to be isolating. 76 | * 77 | * @see [Gradle definition of isolating processors](https://docs.gradle.org/current/userguide/java_plugin.html.isolating_annotation_processors) 78 | */ 79 | ISOLATING 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /crumb-compiler-api/src/main/kotlin/com/uber/crumb/compiler/api/CrumbProducerExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.compiler.api 18 | 19 | import com.uber.crumb.annotations.CrumbProducer 20 | import com.uber.crumb.annotations.CrumbQualifier 21 | import com.uber.crumb.compiler.api.CrumbExtension.IncrementalExtensionType 22 | import javax.annotation.processing.ProcessingEnvironment 23 | import javax.lang.model.element.AnnotationMirror 24 | import javax.lang.model.element.TypeElement 25 | 26 | /** 27 | * Interface for [CrumbProducer] extensions. 28 | */ 29 | interface CrumbProducerExtension : CrumbExtension { 30 | 31 | /** 32 | * Supported producer annotations, if any, that the CrumbProcessor should collect on this 33 | * extension's behalf. Empty by default. 34 | */ 35 | @JvmDefault 36 | fun supportedProducerAnnotations(): Set> { 37 | return emptySet() 38 | } 39 | 40 | /** 41 | * Determines whether or not a given type is applicable to this extension. 42 | * 43 | * @param context the [CrumbContext]. 44 | * @param type the type to check. 45 | * @param annotations collected [CrumbQualifier]-annotated annotations on [type]. 46 | * @return true if the type is applicable. 47 | */ 48 | @JvmDefault 49 | fun isProducerApplicable(context: CrumbContext, 50 | type: TypeElement, 51 | annotations: Collection): Boolean { 52 | // Note: AutoCommon's MoreElements#isAnnotationPresent() is a safer option but not used here to avoid the dependency 53 | return supportedProducerAnnotations().any { 54 | type.getAnnotation(it) != null 55 | } 56 | } 57 | 58 | /** 59 | * Invoked to request this extension's [ProducerMetadata]. 60 | * 61 | * @param context the [CrumbContext]. 62 | * @param type the type this is producing from. 63 | * @param annotations collected [CrumbQualifier]-annotated annotations on [type]. 64 | * @return the aggregated [ProducerMetadata]. 65 | */ 66 | fun produce(context: CrumbContext, 67 | type: TypeElement, 68 | annotations: Collection): ProducerMetadata 69 | 70 | /** 71 | * Determines the incremental type of this Extension. 72 | * 73 | * The [ProcessingEnvironment] can be used, among other things, to obtain the processor 74 | * options, using [ProcessingEnvironment.getOptions]. 75 | * 76 | * The actual incremental type of the Crumb processor as a whole will be the loosest 77 | * incremental types of the Extensions present in the annotation processor path. The default 78 | * returned value is [IncrementalExtensionType.UNKNOWN], which will disable incremental 79 | * annotation processing entirely. 80 | */ 81 | @JvmDefault 82 | fun producerIncrementalType(processingEnvironment: ProcessingEnvironment): IncrementalExtensionType { 83 | return IncrementalExtensionType.UNKNOWN 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /crumb-compiler-api/src/main/kotlin/com/uber/crumb/compiler/api/CrumbTypeAliases.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.compiler.api 18 | 19 | import javax.lang.model.element.Element 20 | 21 | typealias ExtensionKey = String 22 | typealias ConsumerMetadata = Map 23 | typealias ProducerMetadata = Pair, Set> 24 | -------------------------------------------------------------------------------- /crumb-compiler/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 17 | id 'org.jetbrains.kotlin.jvm' 18 | id 'org.jetbrains.kotlin.kapt' 19 | id 'org.jetbrains.dokka' 20 | // TODO Reenable once Kapt fixes MPP dependency resolution 21 | // https://youtrack.jetbrains.com/issue/KT-31641 22 | // https://youtrack.jetbrains.com/issue/KT-33206 23 | // id 'com.squareup.wire' 24 | } 25 | 26 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 27 | kotlinOptions { 28 | jvmTarget = "1.8" 29 | freeCompilerArgs = ['-Xjsr305=strict'] 30 | } 31 | } 32 | 33 | //sourceSets { 34 | // main { 35 | // java { 36 | // srcDir "${project.buildDir}/generated/src/main/java" 37 | // } 38 | // } 39 | //} 40 | 41 | //wire { 42 | // kotlin { 43 | // javaInterop = false 44 | // } 45 | //} 46 | 47 | dependencies { 48 | kapt deps.apt.autoService 49 | kapt deps.apt.incapProcessor 50 | compileOnly deps.apt.autoServiceAnnotations 51 | 52 | api project(":crumb-annotations") 53 | api project(":crumb-core") 54 | api project(':crumb-compiler-api') 55 | api deps.apt.incap 56 | implementation deps.misc.okio 57 | implementation deps.apt.autoCommon 58 | implementation deps.kotlin.stdLibJdk8 59 | } 60 | 61 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 62 | -------------------------------------------------------------------------------- /crumb-compiler/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018. Uber Technologies 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 | POM_NAME=Crumb Compiler 18 | POM_ARTIFACT_ID=crumb-compiler 19 | POM_PACKAGING=jar 20 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/TypeElementExt.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb 18 | 19 | import com.google.auto.common.AnnotationMirrors 20 | import com.google.auto.common.MoreElements 21 | import javax.lang.model.element.Element 22 | import javax.lang.model.element.TypeElement 23 | 24 | /* 25 | * Internal utils for Crumb. 26 | */ 27 | 28 | /** 29 | * Returns the name of the given type, including any enclosing types but not the package. 30 | * 31 | * @return the class name string. 32 | */ 33 | internal fun TypeElement.classNameOf(): String { 34 | val name = qualifiedName.toString() 35 | val pkgName = packageName() 36 | return if (pkgName.isEmpty()) name else name.substring(pkgName.length + 1) 37 | } 38 | 39 | /** 40 | * Returns the name of the package that the given type is in. If the type is in the default 41 | * (unnamed) package then the name is the empty string. 42 | * 43 | * @return the package name. 44 | */ 45 | internal fun Element.packageName(): String { 46 | return MoreElements.getPackage(this).qualifiedName.toString() 47 | } 48 | 49 | /** 50 | * @return annotations on this element that are annotated with type [T]. 51 | */ 52 | internal inline fun Element.annotatedAnnotations() 53 | = AnnotationMirrors.getAnnotatedAnnotations(this, T::class.java) 54 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/EnumAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | import java.io.IOException 19 | import kotlin.reflect.KClass 20 | 21 | /** 22 | * An abstract [ProtoAdapter] that converts values of an enum to and from integers. 23 | */ 24 | internal abstract class EnumAdapter protected constructor( 25 | type: KClass 26 | ) : ProtoAdapter(FieldEncoding.VARINT, type) { 27 | constructor(type: Class) : this(type.kotlin) 28 | 29 | override fun encodedSize(value: E): Int = commonEncodedSize(value) 30 | 31 | @Throws(IOException::class) 32 | override fun encode(writer: ProtoWriter, value: E) { 33 | commonEncode(writer, value) 34 | } 35 | 36 | @Throws(IOException::class) 37 | override fun decode(reader: ProtoReader): E = commonDecode(reader, this::fromValue) 38 | 39 | override fun redact(value: E): E = commonRedact(value) 40 | 41 | /** 42 | * Converts an integer to an enum. 43 | * Returns null if there is no corresponding enum. 44 | */ 45 | protected abstract fun fromValue(value: Int): E? 46 | } 47 | 48 | @Suppress("NOTHING_TO_INLINE") 49 | internal inline fun commonEncodedSize(value: E): Int { 50 | return ProtoWriter.varint32Size(value.value) 51 | } 52 | 53 | @Suppress("NOTHING_TO_INLINE") 54 | internal inline fun commonEncode(writer: ProtoWriter, value: E) { 55 | writer.writeVarint32(value.value) 56 | } 57 | 58 | @Suppress("NOTHING_TO_INLINE") 59 | internal inline fun EnumAdapter.commonDecode( 60 | reader: ProtoReader, 61 | fromValue: (Int) -> E? 62 | ): E { 63 | val value = reader.readVarint32() 64 | return fromValue(value) ?: throw ProtoAdapter.EnumConstantNotFoundException(value, type) 65 | } 66 | 67 | @Suppress("NOTHING_TO_INLINE", "UNUSED_PARAMETER") 68 | internal inline fun commonRedact(value: E): E { 69 | throw UnsupportedOperationException() 70 | } 71 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/FieldEncoding.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | import com.uber.crumb.internal.wire.internal.ProtocolException 19 | import java.io.IOException 20 | import kotlin.jvm.JvmStatic 21 | 22 | internal enum class FieldEncoding(internal val value: Int) { 23 | VARINT(0), FIXED64(1), LENGTH_DELIMITED(2), FIXED32(5); 24 | 25 | /** 26 | * Returns a Wire adapter that reads this field encoding without interpretation. For example, 27 | * messages are returned as byte strings and enums are returned as integers. 28 | */ 29 | fun rawProtoAdapter(): ProtoAdapter<*> = when (this) { 30 | VARINT -> ProtoAdapter.UINT64 31 | FIXED32 -> ProtoAdapter.FIXED32 32 | FIXED64 -> ProtoAdapter.FIXED64 33 | LENGTH_DELIMITED -> ProtoAdapter.BYTES 34 | } 35 | 36 | companion object { 37 | @JvmStatic 38 | @Throws(IOException::class) 39 | internal operator fun get(value: Int): FieldEncoding = when (value) { 40 | 0 -> VARINT 41 | 1 -> FIXED64 42 | 2 -> LENGTH_DELIMITED 43 | 5 -> FIXED32 44 | else -> throw ProtocolException("Unexpected FieldEncoding: $value") 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/MessageSerializedForm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | import java.io.IOException 19 | import java.io.ObjectStreamException 20 | import java.io.Serializable 21 | import java.io.StreamCorruptedException 22 | 23 | internal class MessageSerializedForm, B : Message.Builder>( 24 | private val bytes: ByteArray, 25 | private val messageClass: Class 26 | ) : Serializable { 27 | 28 | @Throws(ObjectStreamException::class) 29 | fun readResolve(): Any { 30 | val adapter = ProtoAdapter.get(messageClass) 31 | try { 32 | // Extensions will be decoded as unknown values. 33 | return adapter.decode(bytes) 34 | } catch (e: IOException) { 35 | throw StreamCorruptedException(e.message) 36 | } 37 | } 38 | 39 | companion object { 40 | private const val serialVersionUID = 0L 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/MessageSink.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | import java.io.Closeable 19 | import java.io.IOException 20 | 21 | internal interface MessageSink : Closeable { 22 | @Throws(IOException::class) 23 | fun write(message: T) 24 | 25 | @Throws(IOException::class) 26 | fun cancel() 27 | } 28 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/MessageSource.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | import java.io.Closeable 19 | import java.io.IOException 20 | 21 | internal interface MessageSource : Closeable { 22 | @Throws(IOException::class) 23 | fun read(): T? 24 | } 25 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/RuntimeEnumAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | import java.lang.reflect.Method 19 | 20 | /** 21 | * Converts values of an enum to and from integers using reflection. 22 | */ 23 | internal class RuntimeEnumAdapter( 24 | private val javaType: Class 25 | ) : EnumAdapter(javaType.kotlin) { 26 | private var fromValueMethod: Method? = null // Lazy to avoid reflection during class loading. 27 | 28 | private fun getFromValueMethod(): Method { 29 | return fromValueMethod ?: javaType.getMethod("fromValue", Int::class.javaPrimitiveType).also { 30 | fromValueMethod = it 31 | } 32 | } 33 | 34 | override fun fromValue(value: Int): E? = getFromValueMethod().invoke(null, value) as E 35 | 36 | override fun equals(other: Any?) = other is RuntimeEnumAdapter<*> && other.type == type 37 | 38 | override fun hashCode() = type.hashCode() 39 | } 40 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/Service.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | internal interface Service 19 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/Wire.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Square Inc. 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 | @file:JvmName("Wire") 17 | 18 | package com.uber.crumb.internal.wire 19 | 20 | import kotlin.jvm.JvmName 21 | 22 | /** 23 | * Returns `value` if it is not null; `defaultValue` otherwise. This is used to conveniently return 24 | * a default value when a value is null. For example, 25 | * 26 | * ``` 27 | * MyProto myProto = ... 28 | * MyField field = Wire.get(myProto.f, MyProto.f_default); 29 | * ``` 30 | * 31 | * will attempt to retrieve the value of the field 'f' defined by MyProto. If the field is null 32 | * (i.e., unset), `get` will return its second argument, which in this case is the default value for 33 | * the field 'f'. 34 | */ 35 | internal fun get(value: T?, defaultValue: T): T = value ?: defaultValue 36 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/WireEnum.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | /** 19 | * Interface for generated [Enum] values to help serialization and deserialization. 20 | */ 21 | internal interface WireEnum { 22 | /** 23 | * The tag value of an enum constant. 24 | */ 25 | val value: Int 26 | } 27 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/WireField.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | import kotlin.jvm.JvmName 19 | 20 | /** 21 | * Annotates generated [Message] fields with metadata for serialization and deserialization. 22 | */ 23 | @Target(AnnotationTarget.FIELD) 24 | @Retention(AnnotationRetention.RUNTIME) 25 | internal annotation class WireField( 26 | /** The tag number used to store the field's value. */ 27 | val tag: Int, 28 | /** 29 | * Reference to the static field that holds a [ProtoAdapter] that can encode and decode this 30 | * field's keys. This only applies to maps. See [.adapter] for a description of the value format. 31 | */ 32 | val keyAdapter: String = "", 33 | /** 34 | * Reference to the static field that holds a [ProtoAdapter] that can encode and decode this 35 | * field's values. The reference is a string like `com.uber.crumb.internal.wire.protos.person.Person#ADAPTER` 36 | * and contains a fully-qualified class name followed by a hash symbol and a field name. 37 | */ 38 | val adapter: String, 39 | /** 40 | * The field's protocol buffer label, one of [Label.OPTIONAL], [Label.REQUIRED], [Label.REPEATED], 41 | * or [Label.PACKED]. Defaults to [Label.OPTIONAL]. 42 | */ 43 | val label: Label = Label.OPTIONAL, 44 | /** 45 | * Redacted fields are omitted from toString() to protect sensitive data. Defaults to false. 46 | */ 47 | val redacted: Boolean = false 48 | ) { 49 | 50 | /** A protocol buffer label. */ 51 | enum class Label { 52 | REQUIRED, 53 | OPTIONAL, 54 | REPEATED, 55 | ONE_OF, 56 | /** Implies [REPEATED]. */ 57 | PACKED; 58 | 59 | val isRepeated: Boolean 60 | @JvmName("isRepeated") get() = this == REPEATED || this == PACKED 61 | 62 | val isPacked: Boolean 63 | @JvmName("isPacked") get() = this == PACKED 64 | 65 | val isOneOf: Boolean 66 | @JvmName("isOneOf") get() = this == ONE_OF 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/WireRpc.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Square Inc. 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 | package com.uber.crumb.internal.wire 17 | 18 | /** 19 | * For gRPC actions the path is formatted as `//`. The path of the proto 20 | * service below is `/squareup.helloworld.Greeter/SayHello`. 21 | * 22 | * ``` 23 | * package squareup.helloworld; 24 | * 25 | * service Greeter { 26 | * rpc SayHello (HelloRequest) returns (HelloReply) {} 27 | * } 28 | * ``` 29 | */ 30 | @Target(AnnotationTarget.FUNCTION) 31 | @Retention(AnnotationRetention.RUNTIME) 32 | internal annotation class WireRpc( 33 | val path: String, 34 | val requestAdapter: String, 35 | val responseAdapter: String 36 | ) 37 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/internal/-Platform.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Square Inc. 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 | package com.uber.crumb.internal.wire.internal 17 | 18 | import java.util.Collections 19 | 20 | internal typealias Serializable = java.io.Serializable 21 | 22 | internal typealias ObjectStreamException = java.io.ObjectStreamException 23 | 24 | internal typealias ProtocolException = java.net.ProtocolException 25 | 26 | @Suppress("NOTHING_TO_INLINE") // Syntactic sugar. 27 | internal inline fun MutableList.toUnmodifiableList(): List 28 | = Collections.unmodifiableList(this) 29 | 30 | @Suppress("NOTHING_TO_INLINE") // Syntactic sugar. 31 | internal inline fun MutableMap.toUnmodifiableMap(): Map = 32 | Collections.unmodifiableMap(this) 33 | 34 | @Suppress("NOTHING_TO_INLINE") // Syntactic sugar. 35 | internal inline fun String.format(vararg args: Any?): String = String.format(this, *args) 36 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/internal/ImmutableList.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Square Inc. 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 | package com.uber.crumb.internal.wire.internal 17 | 18 | import kotlin.jvm.JvmName 19 | 20 | internal class ImmutableList(list: List) : AbstractList(), RandomAccess, Serializable { 21 | private val list = ArrayList(list) 22 | 23 | override val size: Int 24 | @get:JvmName("size") get() = list.size 25 | 26 | override fun get(index: Int): T = list[index] 27 | 28 | override fun toArray(): Array { 29 | return list.toTypedArray() // Optimizing for mutable copy by MutableOnWriteList. 30 | } 31 | 32 | @Throws(ObjectStreamException::class) 33 | private fun writeReplace(): Any = list.toUnmodifiableList() 34 | } 35 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/internal/InternalJvm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Square Inc. 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 | @file:JvmName("Internal") 17 | @file:JvmMultifileClass 18 | 19 | package com.uber.crumb.internal.wire.internal 20 | 21 | import com.uber.crumb.internal.wire.ProtoAdapter 22 | 23 | // Methods for generated code use only. Not subject to public API rules. 24 | 25 | internal fun redactElements(list: java.util.List, adapter: ProtoAdapter) { 26 | for (i in 0 until list.size) { 27 | list[i] = adapter.redact(list[i]) 28 | } 29 | } 30 | 31 | internal fun redactElements(map: java.util.Map<*, T>, adapter: ProtoAdapter) { 32 | for (entry in map.entrySet()) { 33 | entry.setValue(adapter.redact(entry.value)) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/internal/MutableOnWriteList.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Square Inc. 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 | package com.uber.crumb.internal.wire.internal 17 | 18 | import kotlin.jvm.JvmName 19 | 20 | /** A wrapper around an empty/immutable list which only switches to mutable on first mutation. */ 21 | internal class MutableOnWriteList( 22 | private val immutableList: List 23 | ) : AbstractMutableList(), RandomAccess, Serializable { 24 | internal var mutableList: List = immutableList 25 | 26 | override fun get(index: Int): T = mutableList[index] 27 | 28 | override val size: Int 29 | @get:JvmName("size") get() = mutableList.size 30 | 31 | override fun set(index: Int, element: T): T { 32 | if (mutableList === immutableList) { 33 | mutableList = ArrayList(immutableList) 34 | } 35 | return (mutableList as ArrayList).set(index, element) 36 | } 37 | 38 | override fun add(index: Int, element: T) { 39 | if (mutableList === immutableList) { 40 | mutableList = ArrayList(immutableList) 41 | } 42 | (mutableList as ArrayList).add(index, element) 43 | } 44 | 45 | override fun removeAt(index: Int): T { 46 | if (mutableList === immutableList) { 47 | mutableList = ArrayList(immutableList) 48 | } 49 | return (mutableList as ArrayList).removeAt(index) 50 | } 51 | 52 | @Throws(ObjectStreamException::class) 53 | private fun writeReplace(): Any = ArrayList(mutableList) 54 | } 55 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/internal/Util.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Square, Inc. 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 | @file:JvmName("RuntimeUtils") 17 | 18 | package com.uber.crumb.internal.wire.internal 19 | 20 | import kotlin.jvm.JvmName 21 | 22 | @Suppress("NOTHING_TO_INLINE") // Syntactic sugar. 23 | internal inline infix fun Byte.and(other: Int): Int = toInt() and other 24 | 25 | @Suppress("NOTHING_TO_INLINE") // Syntactic sugar. 26 | internal inline infix fun Byte.shl(other: Int): Int = toInt() shl other 27 | -------------------------------------------------------------------------------- /crumb-compiler/src/main/proto/com/uber/crumb/internal/model/crumb_model.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package com.uber.crumb.internal.model; 4 | 5 | option java_package = "com.uber.crumb.internal.model"; 6 | 7 | message Crumb { 8 | // The name of the specific data model, usually defined by source producer's canonical name 9 | required string name = 1; 10 | 11 | repeated CrumbMetadata extras = 2; 12 | } 13 | 14 | message CrumbMetadata { 15 | required string extensionKey = 1; 16 | map producerMetadata = 2; 17 | } 18 | -------------------------------------------------------------------------------- /crumb-core/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 17 | id 'org.jetbrains.kotlin.jvm' 18 | id 'org.jetbrains.dokka' 19 | } 20 | 21 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 22 | kotlinOptions { 23 | jvmTarget = "1.8" 24 | freeCompilerArgs = ['-Xjsr305=strict'] 25 | } 26 | } 27 | 28 | dependencies { 29 | api project(":crumb-annotations") 30 | api deps.misc.okio 31 | api deps.kotlin.stdLibJdk8 32 | implementation deps.misc.javapoet 33 | implementation deps.misc.kotlinpoet 34 | } 35 | 36 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 37 | -------------------------------------------------------------------------------- /crumb-core/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018. Uber Technologies 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 | POM_NAME=Crumb Core 18 | POM_ARTIFACT_ID=crumb-core 19 | POM_PACKAGING=jar 20 | -------------------------------------------------------------------------------- /crumb-core/src/main/kotlin/com/uber/crumb/core/CrumbManager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | package com.uber.crumb.core 17 | 18 | import com.uber.crumb.annotations.internal.CrumbIndex 19 | import okio.Buffer 20 | import okio.BufferedSink 21 | import okio.BufferedSource 22 | import javax.annotation.processing.ProcessingEnvironment 23 | import javax.lang.model.element.Element 24 | import javax.lang.model.element.PackageElement 25 | 26 | /** 27 | * A utility class that helps with generating types to hold [CrumbIndexes][CrumbIndex] of metadata and reading them 28 | * later. 29 | * 30 | * @property env A given [ProcessingEnvironment] instance. 31 | * @property crumbLog A [CrumbLog] instance for logging information. 32 | */ 33 | class CrumbManager(private val env: ProcessingEnvironment, 34 | private val crumbLog: CrumbLog) { 35 | 36 | /** 37 | * This loads a given [Set] from the available [CrumbIndex] instances in the given [packageName]. 38 | * 39 | * @param packageName The target package to load types containing [CrumbIndex] annotations from. 40 | * @return the loaded [Set], or an empty set if none were found. 41 | */ 42 | fun load(packageName: String): Set { 43 | // If this package is null, it means there are no classes with this package name. One way this 44 | // could happen is if we process an annotation and reach this point without writing something 45 | // to the package. We do not error check here because that shouldn't happen with the 46 | // current implementation. 47 | val crumbGenPackage: PackageElement? = env.elementUtils.getPackageElement(packageName) 48 | 49 | if (crumbGenPackage == null) { 50 | crumbLog.e("No @CrumbIndex-annotated elements found in $packageName") 51 | return emptySet() 52 | } 53 | 54 | return crumbGenPackage.enclosedElements.mapNotNullTo(mutableSetOf()) { element -> 55 | element.getAnnotation(CrumbIndex::class.java)?.run { 56 | Buffer().apply { write(value) } 57 | } 58 | } 59 | } 60 | 61 | /** 62 | * This facilitates writing data to a [CrumbIndex] type in the given [packageName].[fileName] with the contents 63 | * written to the returned [BufferedSink]. 64 | * 65 | * @param packageName The package name to use for the file in writing. Note that this should be the package that all 66 | * metadata index-holder types are written to, and not necessarily the package name of the source 67 | * element. 68 | * @param fileName The file name to use in writing. 69 | * @param outputLanguage The target output language. 70 | * @param originatingElements Any originating elements for the metadata. 71 | * @return A [BufferedSink] to write metadata to. This will (only) be written to the eventual [CrumbIndex] once 72 | * [BufferedSink.close] is called. 73 | */ 74 | fun store( 75 | packageName: String, 76 | fileName: String, 77 | outputLanguage: CrumbOutputLanguage, 78 | originatingElements: Set = emptySet()): BufferedSink { 79 | return outputLanguage.writeTo(env.filer, packageName, fileName, originatingElements) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018. Uber Technologies 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 | GROUP=com.uber.crumb 18 | VERSION_NAME=0.2.0-SNAPSHOT 19 | POM_DESCRIPTION=An annotation processor for breadcrumbing metadata across compilation boundaries. 20 | POM_URL=https://github.com/uber/crumb/ 21 | POM_SCM_URL=https://github.com/uber/crumb/ 22 | POM_SCM_CONNECTION=scm:git:git://github.com/uber/crumb.git 23 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/uber/crumb.git 24 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 25 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 26 | POM_LICENCE_DIST=repo 27 | POM_DEVELOPER_ID=uber 28 | POM_DEVELOPER_NAME=Uber Technologies 29 | 30 | android.enableSeparateAnnotationProcessing=true 31 | android.suppressUnsupportedOptionWarnings=android.suppressUnsupportedOptionWarnings,android.enableSeparateAnnotationProcessing 32 | kapt.includeCompileClasspath=false 33 | -------------------------------------------------------------------------------- /gradle/checkstyle.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | subprojects { 18 | apply plugin: 'checkstyle' 19 | 20 | afterEvaluate { 21 | if (project.getPlugins().hasPlugin('com.android.application') || 22 | project.getPlugins().hasPlugin('com.android.library')) { 23 | 24 | task checkstyleMain(type: Checkstyle) { 25 | ignoreFailures = false 26 | showViolations = true 27 | source 'src/main', 'src/release' 28 | include '**/*.java' 29 | exclude '**/gen/**' 30 | exclude '**/R.java' 31 | exclude '**/BuildConfig.java' 32 | reports { 33 | xml.destination new File("$project.buildDir/reports/checkstyle/main.xml") 34 | } 35 | classpath = files() 36 | configFile = rootProject.file('checkstyle.xml') 37 | } 38 | 39 | task checkstyleTest(type: Checkstyle){ 40 | ignoreFailures = false 41 | showViolations = true 42 | source 'src/test', 'src/androidTest' 43 | include '**/*.java' 44 | exclude '**/gen/**' 45 | exclude '**/R.java' 46 | exclude '**/BuildConfig.java' 47 | reports { 48 | xml.destination new File("$project.buildDir/reports/checkstyle/test.xml") 49 | } 50 | classpath = files() 51 | configFile = rootProject.file('checkstyle.xml') 52 | } 53 | 54 | task checkstyle(dependsOn:['checkstyleMain', 'checkstyleTest']){ 55 | description 'Runs Checkstyle inspection against Android sourcesets.' 56 | group = 'Code Quality' 57 | } 58 | 59 | project.tasks.getByName("check").dependsOn "checkstyle" 60 | } else { 61 | checkstyle { 62 | ignoreFailures = false 63 | showViolations = true 64 | configFile rootProject.file('checkstyle.xml') 65 | } 66 | } 67 | 68 | tasks.withType(Checkstyle) { 69 | configProperties = ['proj.module.dir' : projectDir.absolutePath, 70 | 'checkstyle.cache.file': './build/cache/checkstyle-cache'] 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /gradle/config-kotlin-sources.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | if (project.plugins.hasPlugin("kotlin") 18 | || project.plugins.hasPlugin("org.jetbrains.kotlin.kapt") 19 | || project.plugins.hasPlugin("org.jetbrains.kotlin.android") 20 | || project.plugins.hasPlugin("org.jetbrains.kotlin.jvm") 21 | || project.plugins.hasPlugin("kotlin-android") 22 | || project.plugins.hasPlugin("kotlin-kapt")) { 23 | if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) { 24 | project.android.sourceSets { 25 | main.java.srcDirs += 'src/main/kotlin' 26 | debug.java.srcDirs += 'src/debug/kotlin' 27 | release.java.srcDirs += 'src/release/kotlin' 28 | test.java.srcDirs += 'src/test/kotlin' 29 | 30 | // For kapt stubs 31 | main.java.srcDirs += [file("$buildDir/generated/source/kapt/main")] 32 | debug.java.srcDirs += [file("$buildDir/generated/source/kapt/debug")] 33 | release.java.srcDirs += [file("$buildDir/generated/source/kapt/release")] 34 | test.java.srcDirs += [file("$buildDir/generated/source/kapt/test")] 35 | 36 | // For kotlin code gen during kapt 37 | main.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/main")] 38 | debug.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/debug")] 39 | release.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/release")] 40 | test.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/test")] 41 | } 42 | } else { 43 | apply plugin: 'idea' 44 | 45 | idea { 46 | module { 47 | sourceDirs += files( 48 | 'build/generated/source/kapt/main', 49 | 'build/generated/source/kaptKotlin/main', 50 | 'build/tmp/kapt/main/kotlinGenerated') 51 | generatedSourceDirs += files( 52 | 'build/generated/source/kapt/main', 53 | 'build/generated/source/kaptKotlin/main', 54 | 'build/tmp/kapt/main/kotlinGenerated') 55 | } 56 | } 57 | } 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /gradle/dependencies.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | def versions = [ 18 | autoService: '1.0-rc6', 19 | autoValue: '1.6.5', 20 | autoValueGson: '1.0.0', 21 | errorProne: '2.3.3', 22 | dokka: '0.9.18', 23 | errorPronePlugin: '0.7.1', 24 | incap: '0.2', 25 | gjf: '1.7', 26 | kotlin: '1.3.41', 27 | ktlint: '0.34.2', 28 | moshi: '1.8.0', 29 | spotless: '3.24.2', 30 | wire: "3.0.0-rc01" 31 | ] 32 | 33 | ext.deps = [ 34 | versions: versions, 35 | 36 | apt: [ 37 | autoCommon: "com.google.auto:auto-common:0.10", 38 | autoServiceAnnotations: "com.google.auto.service:auto-service-annotations:${versions.autoService}", 39 | autoService: "com.google.auto.service:auto-service:${versions.autoService}", 40 | autoValue: "com.google.auto.value:auto-value:${versions.autoValue}", 41 | autoValueAnnotations: "com.google.auto.value:auto-value-annotations:${versions.autoValue}", 42 | autoValueGson: "com.ryanharter.auto.value:auto-value-gson:${versions.autoValueGson}", 43 | autoValueGsonRuntime: "com.ryanharter.auto.value:auto-value-gson-runtime:${versions.autoValueGson}", 44 | autoValueMoshi: "com.ryanharter.auto.value:auto-value-moshi:0.4.7", 45 | incap: "net.ltgt.gradle.incap:incap:${versions.incap}", 46 | incapProcessor: "net.ltgt.gradle.incap:incap-processor:${versions.incap}" 47 | ], 48 | 49 | build: [ 50 | compileSdkVersion: 29, 51 | ci: 'true' == System.getenv('CI'), 52 | minSdkVersion: 14, 53 | targetSdkVersion: 29, 54 | errorProne: "com.google.errorprone:error_prone_core:${versions.errorProne}", 55 | 56 | gradlePlugins: [ 57 | android: 'com.android.tools.build:gradle:3.5.0', 58 | dokka: "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}", 59 | dokkaAndroid: "org.jetbrains.dokka:dokka-android-gradle-plugin:${versions.dokka}", 60 | kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 61 | ] 62 | ], 63 | 64 | kotlin: [ 65 | stdLib: "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}", 66 | stdLibJdk7: "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}", 67 | stdLibJdk8: "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}", 68 | ], 69 | 70 | misc: [ 71 | appCompat: 'androidx.appcompat:appcompat:1.0.2', 72 | errorProneAnnotations: "com.google.errorprone:error_prone_annotations:${versions.errorProne}", 73 | gson: "com.google.code.gson:gson:2.8.5", 74 | guava: "com.google.guava:guava:28.0-jre", 75 | javapoet: "com.squareup:javapoet:1.11.1", 76 | javaxExtras: 'com.uber.javaxextras:javax-extras:0.1.0', 77 | kotlinMetadata: 'me.eugeniomarletti.kotlin.metadata:kotlin-metadata:1.4.0', 78 | kotlinpoet: 'com.squareup:kotlinpoet:1.3.0', 79 | moshi: "com.squareup.moshi:moshi:${versions.moshi}", 80 | okio: "com.squareup.okio:okio:2.2.0", 81 | wire: "com.squareup.wire:wire-runtime:3.0.0-rc01" 82 | ], 83 | 84 | rx: [ 85 | android: 'io.reactivex.rxjava2:rxandroid:2.1.1', 86 | java: 'io.reactivex.rxjava2:rxjava:2.2.11' 87 | ], 88 | 89 | test: [ 90 | compileTesting: 'com.google.testing.compile:compile-testing:0.18', 91 | junit: 'junit:junit:4.12', 92 | truth: 'com.google.truth:truth:1.0' 93 | ] 94 | ] 95 | -------------------------------------------------------------------------------- /gradle/publish-docs.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018. Uber Technologies 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 | configurations { 18 | osstrich 19 | } 20 | 21 | dependencies { 22 | osstrich 'com.squareup.osstrich:osstrich:1.3.0' 23 | } 24 | 25 | task publishDocs(type: JavaExec) { 26 | classpath = configurations.osstrich 27 | main = 'com.squareup.osstrich.JavadocPublisher' 28 | args = [ 29 | 'build/javadoc', 30 | 'https://github.com/uber/crumb', 31 | 'com.uber.crumb' 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uber/crumb/550793f551862a2af369083bc12bfdcc110f9a0b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /integration-test/annotations/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | } 21 | 22 | sourceCompatibility = "1.7" 23 | targetCompatibility = "1.7" 24 | 25 | dependencies { 26 | api project(':crumb-annotations') 27 | 28 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 29 | //noinspection GradleDynamicVersion 30 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 31 | } 32 | 33 | tasks.withType(JavaCompile).configureEach { 34 | options.errorprone.disableWarningsInGeneratedCode = true 35 | } 36 | -------------------------------------------------------------------------------- /integration-test/annotations/src/main/java/com/uber/crumb/integration/annotations/GsonFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.annotations; 17 | 18 | import com.uber.crumb.annotations.CrumbConsumer; 19 | import com.uber.crumb.annotations.CrumbProducer; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | @CrumbProducer 26 | @CrumbConsumer 27 | @Target(ElementType.TYPE) 28 | @Retention(RetentionPolicy.CLASS) 29 | public @interface GsonFactory { 30 | 31 | Type value(); 32 | 33 | enum Type { 34 | PRODUCER, 35 | CONSUMER 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /integration-test/annotations/src/main/java/com/uber/crumb/integration/annotations/MoshiFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.annotations; 17 | 18 | import com.uber.crumb.annotations.CrumbConsumer; 19 | import com.uber.crumb.annotations.CrumbProducer; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | @CrumbProducer 26 | @CrumbConsumer 27 | @Target(ElementType.TYPE) 28 | @Retention(RetentionPolicy.CLASS) 29 | public @interface MoshiFactory { 30 | 31 | Type value(); 32 | 33 | enum Type { 34 | PRODUCER, 35 | CONSUMER 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /integration-test/compiler/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | import org.gradle.internal.jvm.Jvm 17 | 18 | plugins { 19 | id 'java-library' 20 | id 'org.jetbrains.kotlin.jvm' 21 | id 'org.jetbrains.kotlin.kapt' 22 | } 23 | 24 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 25 | kotlinOptions { 26 | jvmTarget = "1.8" 27 | freeCompilerArgs = ['-Xjsr305=strict', '-Xjvm-default=enable'] 28 | } 29 | } 30 | 31 | dependencies { 32 | kapt deps.apt.autoService 33 | 34 | implementation deps.apt.autoServiceAnnotations 35 | implementation deps.apt.autoCommon 36 | implementation deps.misc.guava 37 | implementation deps.misc.javapoet 38 | implementation deps.misc.gson 39 | implementation deps.misc.moshi 40 | implementation deps.kotlin.stdLibJdk8 41 | implementation project(":crumb-compiler-api") 42 | implementation project(":integration-test:annotations") 43 | 44 | testImplementation project(":crumb-compiler") 45 | testImplementation deps.test.compileTesting 46 | 47 | if (!Jvm.current().javaVersion.isJava9Compatible()) { 48 | testImplementation files(Jvm.current().getToolsJar()) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /integration-test/compiler/src/main/kotlin/com/uber/crumb/integration/compiler/CompilerExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.integration.compiler 18 | 19 | import com.google.auto.common.MoreElements 20 | import com.squareup.javapoet.ParameterizedTypeName 21 | import com.squareup.javapoet.TypeName 22 | import javax.annotation.processing.RoundEnvironment 23 | import javax.lang.model.element.Element 24 | import javax.lang.model.element.TypeElement 25 | 26 | internal typealias MoshiTypes = com.squareup.moshi.Types 27 | 28 | /** 29 | * Returns the name of the given type, including any enclosing types but not the package. 30 | * 31 | * @return the class name string. 32 | */ 33 | internal fun TypeElement.classNameOf(): String { 34 | val name = qualifiedName.toString() 35 | val pkgName = packageName() 36 | return if (pkgName.isEmpty()) name else name.substring(pkgName.length + 1) 37 | } 38 | 39 | /** 40 | * Returns the name of the package that the given type is in. If the type is in the default 41 | * (unnamed) package then the name is the empty string. 42 | * 43 | * @return the package name. 44 | */ 45 | internal fun Element.packageName(): String { 46 | return MoreElements.getPackage(this).qualifiedName.toString() 47 | } 48 | 49 | /** 50 | * @return the raw type. Useful if it's a parameterized type. 51 | */ 52 | internal fun Element.rawType(): TypeName { 53 | var type = TypeName.get(asType()) 54 | if (type is ParameterizedTypeName) { 55 | type = type.rawType 56 | } 57 | return type 58 | } 59 | 60 | /** Return a list of elements annotated with [T]. */ 61 | internal inline fun RoundEnvironment.findElementsAnnotatedWith(): Set = getElementsAnnotatedWith( 62 | T::class.java) 63 | 64 | internal fun String.asPackageAndName(): Pair { 65 | val lastIndex = lastIndexOf(".") 66 | val modelPackage = substring(0, lastIndex) 67 | val modelSimpleName = substring(lastIndex + 1) 68 | return Pair(modelPackage, modelSimpleName) 69 | } 70 | -------------------------------------------------------------------------------- /integration-test/compiler/src/test/kotlin/com/uber/crumb/integration/compiler/CrumbProcessorTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.integration.compiler 18 | 19 | import com.google.common.collect.ImmutableSet 20 | import com.google.common.truth.Truth.assertAbout 21 | import com.google.testing.compile.JavaFileObjects 22 | import com.google.testing.compile.JavaSourcesSubject 23 | import com.google.testing.compile.JavaSourcesSubjectFactory.javaSources 24 | import com.uber.crumb.CrumbProcessor 25 | import org.junit.Test 26 | import javax.tools.JavaFileObject 27 | 28 | class CrumbProcessorTest { 29 | 30 | @Test 31 | fun testNoMatchingModelsForFactoryShouldFail() { 32 | val modelName = "test.Foo" 33 | val model = JavaFileObjects.forSourceString(modelName, """ 34 | package test; 35 | import com.uber.crumb.annotations.CrumbConsumable; 36 | @CrumbConsumable public abstract class Foo { 37 | public abstract String getName(); 38 | public abstract boolean isAwesome(); 39 | }""") 40 | 41 | val factoryName = "test.MyAdapterFactory" 42 | val factory = JavaFileObjects.forSourceString(factoryName, """ 43 | package test; 44 | import com.google.gson.TypeAdapterFactory; 45 | import com.uber.crumb.integration.annotations.GsonFactory; 46 | @GsonFactory(GsonFactory.Type.PRODUCER) 47 | public abstract class MyAdapterFactory { 48 | public static TypeAdapterFactory create() { 49 | return new GsonProducer_MyAdapterFactory(); 50 | } 51 | }""") 52 | 53 | assertAbout>(javaSources()) 54 | .that(ImmutableSet.of(model, factory)) 55 | .processedWith(CrumbProcessor(listOf(GsonSupport(), MoshiSupport()))) 56 | .failsToCompile() 57 | .withErrorContaining(""" 58 | |No @CrumbConsumable-annotated elements applicable for the given @CrumbProducer-annotated element with the current crumb extensions 59 | | CrumbProducer: $factoryName 60 | | Extension: GsonSupport 61 | """.trimMargin()) 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /integration-test/compiler/src/test/kotlin/com/uber/crumb/integration/compiler/GsonSupportTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 com.uber.crumb.integration.compiler 18 | 19 | import com.google.common.collect.ImmutableSet 20 | import com.google.common.truth.Truth.assertAbout 21 | import com.google.testing.compile.JavaFileObjects 22 | import com.google.testing.compile.JavaSourcesSubject 23 | import com.google.testing.compile.JavaSourcesSubjectFactory.javaSources 24 | import com.uber.crumb.CrumbProcessor 25 | import org.junit.Test 26 | import javax.tools.JavaFileObject 27 | 28 | class GsonSupportTest { 29 | 30 | @Test 31 | fun generatesTypeAdapterFactory() { 32 | val source1 = JavaFileObjects.forSourceString("test.Foo", """ 33 | package test; 34 | import com.uber.crumb.annotations.CrumbConsumable; 35 | import com.google.gson.TypeAdapter; 36 | import com.google.gson.Gson; 37 | @CrumbConsumable public abstract class Foo { 38 | public static TypeAdapter typeAdapter(Gson gson) { 39 | return null; 40 | } 41 | public abstract String getName(); 42 | public abstract boolean isAwesome(); 43 | }""") 44 | 45 | val source2 = JavaFileObjects.forSourceString("test.Bar", """ 46 | package test; 47 | import com.uber.crumb.annotations.CrumbConsumable; 48 | import com.google.gson.TypeAdapter; 49 | import com.google.gson.Gson; 50 | @CrumbConsumable public abstract class Bar { 51 | public static TypeAdapter jsonAdapter(Gson gson) { 52 | return null; 53 | } 54 | public abstract String getName(); 55 | }""") 56 | 57 | val source3 = JavaFileObjects.forSourceString("test.MyAdapterFactory", """ 58 | package test; 59 | import com.google.gson.TypeAdapterFactory; 60 | import com.uber.crumb.integration.annotations.GsonFactory; 61 | @GsonFactory(GsonFactory.Type.PRODUCER) 62 | public abstract class MyAdapterFactory { 63 | public static TypeAdapterFactory create() { 64 | return new GsonProducer_MyAdapterFactory(); 65 | } 66 | }""") 67 | 68 | val expected = JavaFileObjects.forSourceString("test.GsonProducer_MyAdapterFactory", """ 69 | package test; 70 | 71 | import com.google.gson.Gson; 72 | import com.google.gson.TypeAdapter; 73 | import com.google.gson.TypeAdapterFactory; 74 | import com.google.gson.reflect.TypeToken; 75 | import java.lang.Override; 76 | import java.lang.SuppressWarnings; 77 | import javax.annotation.Nullable; 78 | 79 | final class GsonProducer_MyAdapterFactory implements TypeAdapterFactory { 80 | @Nullable 81 | @Override 82 | @SuppressWarnings("unchecked") 83 | public TypeAdapter create(Gson gson, TypeToken type) { 84 | Class rawType = (Class) type.getRawType(); 85 | if (Foo.class.isAssignableFrom(rawType)) { 86 | return (TypeAdapter) Foo.typeAdapter(gson); 87 | } else if (Bar.class.isAssignableFrom(rawType)) { 88 | return (TypeAdapter) Bar.jsonAdapter(gson); 89 | } else { 90 | return null; 91 | } 92 | } 93 | }""") 94 | 95 | assertAbout>(javaSources()) 96 | .that(ImmutableSet.of(source1, source2, source3)) 97 | .processedWith(CrumbProcessor(listOf(GsonSupport()))) 98 | .compilesWithoutError() 99 | .and() 100 | .generatesSources(expected) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /integration-test/integration/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | id 'net.ltgt.apt-idea' 21 | } 22 | 23 | sourceCompatibility = JavaVersion.VERSION_1_8 24 | targetCompatibility = JavaVersion.VERSION_1_8 25 | 26 | dependencies { 27 | api deps.misc.gson 28 | api deps.misc.moshi 29 | annotationProcessor project(":crumb-compiler") 30 | annotationProcessor project(":integration-test:compiler") 31 | annotationProcessor deps.apt.autoValue 32 | annotationProcessor deps.apt.autoValueAnnotations 33 | annotationProcessor deps.apt.autoValueGson 34 | annotationProcessor deps.apt.autoValueMoshi 35 | api project(":crumb-annotations") 36 | api project(":integration-test:lib1") 37 | api project(":integration-test:lib2") 38 | api project(":integration-test:lib3") 39 | api project(":integration-test:annotations") 40 | compileOnly deps.misc.javaxExtras 41 | compileOnly deps.apt.autoValueAnnotations 42 | implementation deps.apt.autoValueGsonRuntime 43 | 44 | testImplementation deps.test.truth 45 | 46 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 47 | //noinspection GradleDynamicVersion 48 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 49 | } 50 | 51 | tasks.withType(JavaCompile).configureEach { 52 | options.errorprone.disableWarningsInGeneratedCode = true 53 | } 54 | -------------------------------------------------------------------------------- /integration-test/integration/src/main/java/com/uber/crumb/integration/consumer/IntegrationConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.consumer; 17 | 18 | import com.google.gson.TypeAdapterFactory; 19 | import com.squareup.moshi.JsonAdapter; 20 | import com.uber.crumb.integration.annotations.GsonFactory; 21 | import com.uber.crumb.integration.annotations.MoshiFactory; 22 | 23 | @GsonFactory(GsonFactory.Type.CONSUMER) 24 | @MoshiFactory(MoshiFactory.Type.CONSUMER) 25 | public abstract class IntegrationConsumer { 26 | 27 | public static TypeAdapterFactory gson() { 28 | return new GsonConsumer_IntegrationConsumer(); 29 | } 30 | 31 | public static JsonAdapter.Factory moshi() { 32 | return new MoshiConsumer_IntegrationConsumer(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /integration-test/integration/src/main/java/com/uber/crumb/integration/localmodels/LocalEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.integration.localmodels; 17 | 18 | import com.google.gson.TypeAdapter; 19 | import com.google.gson.stream.JsonReader; 20 | import com.google.gson.stream.JsonWriter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.squareup.moshi.Types; 24 | import com.uber.crumb.annotations.CrumbConsumable; 25 | import java.io.IOException; 26 | import java.lang.annotation.Annotation; 27 | import java.lang.reflect.Type; 28 | import java.util.Set; 29 | import javax.annotation.Nullable; 30 | 31 | @CrumbConsumable 32 | public enum LocalEnum { 33 | FOO; 34 | 35 | public static TypeAdapter typeAdapter() { 36 | return new TypeAdapter() { 37 | @Override 38 | public void write(JsonWriter out, LocalEnum value) throws IOException { 39 | out.value(value.name().toLowerCase()); 40 | } 41 | 42 | @Override 43 | public LocalEnum read(JsonReader in) throws IOException { 44 | return LocalEnum.valueOf(in.nextString().toUpperCase()); 45 | } 46 | }; 47 | } 48 | 49 | public static JsonAdapter.Factory jsonAdapter() { 50 | return new JsonAdapter.Factory() { 51 | @Nullable 52 | @Override 53 | public JsonAdapter create(Type type, Set annotations, Moshi moshi) { 54 | Class rawType = Types.getRawType(type); 55 | if (rawType.isAssignableFrom(LocalEnum.class)) { 56 | return new JsonAdapter() { 57 | @Override 58 | public LocalEnum fromJson(com.squareup.moshi.JsonReader reader) throws IOException { 59 | return LocalEnum.valueOf(reader.nextString().toUpperCase()); 60 | } 61 | 62 | @Override 63 | public void toJson(com.squareup.moshi.JsonWriter writer, LocalEnum value) 64 | throws IOException { 65 | writer.value(value.name().toLowerCase()); 66 | } 67 | }; 68 | } 69 | return null; 70 | } 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /integration-test/integration/src/main/java/com/uber/crumb/integration/localmodels/LocalModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.integration.localmodels; 17 | 18 | import com.google.auto.value.AutoValue; 19 | import com.google.gson.Gson; 20 | import com.google.gson.TypeAdapter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.uber.crumb.annotations.CrumbConsumable; 24 | 25 | @AutoValue 26 | @CrumbConsumable 27 | public abstract class LocalModel { 28 | 29 | abstract String foo(); 30 | 31 | public static TypeAdapter typeAdapter(Gson gson) { 32 | return new AutoValue_LocalModel.GsonTypeAdapter(gson); 33 | } 34 | 35 | public static JsonAdapter jsonAdapter(Moshi moshi) { 36 | return new AutoValue_LocalModel.MoshiJsonAdapter(moshi); 37 | } 38 | 39 | public static LocalModel create(String foo) { 40 | return new AutoValue_LocalModel(foo); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /integration-test/integration/src/main/java/com/uber/crumb/integration/localmodels/LocalProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.integration.localmodels; 17 | 18 | import com.google.gson.TypeAdapterFactory; 19 | import com.squareup.moshi.JsonAdapter; 20 | import com.uber.crumb.integration.annotations.GsonFactory; 21 | import com.uber.crumb.integration.annotations.MoshiFactory; 22 | 23 | @GsonFactory(GsonFactory.Type.PRODUCER) 24 | @MoshiFactory(MoshiFactory.Type.PRODUCER) 25 | public abstract class LocalProducer { 26 | 27 | public static TypeAdapterFactory gson() { 28 | return new GsonProducer_LocalProducer(); 29 | } 30 | 31 | public static JsonAdapter.Factory moshi() { 32 | return new MoshiProducer_LocalProducer(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /integration-test/lib1/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | import net.ltgt.gradle.errorprone.CheckSeverity 17 | 18 | plugins { 19 | id 'java-library' 20 | id 'net.ltgt.errorprone' 21 | id 'net.ltgt.apt-idea' 22 | } 23 | 24 | sourceCompatibility = JavaVersion.VERSION_1_8 25 | targetCompatibility = JavaVersion.VERSION_1_8 26 | 27 | dependencies { 28 | annotationProcessor deps.apt.autoValue 29 | annotationProcessor deps.apt.autoValueAnnotations 30 | annotationProcessor deps.apt.autoValueGson 31 | annotationProcessor deps.apt.autoValueMoshi 32 | annotationProcessor project(":crumb-compiler") 33 | annotationProcessor project(":integration-test:compiler") 34 | compileOnly deps.misc.javaxExtras 35 | compileOnly deps.apt.autoValueAnnotations 36 | 37 | api deps.misc.gson 38 | api deps.misc.moshi 39 | implementation deps.apt.autoValueGsonRuntime 40 | 41 | api project(":crumb-annotations") 42 | api project(":integration-test:annotations") 43 | 44 | testImplementation deps.test.truth 45 | 46 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 47 | //noinspection GradleDynamicVersion 48 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 49 | } 50 | 51 | tasks.withType(JavaCompile).configureEach { 52 | options.errorprone { 53 | disableWarningsInGeneratedCode = true 54 | // Temporary until https://github.com/rharter/auto-value-moshi/issues/128 55 | check("CheckReturnValue", CheckSeverity.WARN) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /integration-test/lib1/src/main/java/com/uber/crumb/integration/lib1/Lib1Enum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib1; 17 | 18 | import com.google.gson.TypeAdapter; 19 | import com.google.gson.stream.JsonReader; 20 | import com.google.gson.stream.JsonWriter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.squareup.moshi.Types; 24 | import com.uber.crumb.annotations.CrumbConsumable; 25 | import java.io.IOException; 26 | import java.lang.annotation.Annotation; 27 | import java.lang.reflect.Type; 28 | import java.util.Set; 29 | import javax.annotation.Nullable; 30 | 31 | @CrumbConsumable 32 | public enum Lib1Enum { 33 | FOO; 34 | 35 | public static TypeAdapter typeAdapter() { 36 | return new TypeAdapter() { 37 | @Override 38 | public void write(JsonWriter out, Lib1Enum value) throws IOException { 39 | out.value(value.name().toLowerCase()); 40 | } 41 | 42 | @Override 43 | public Lib1Enum read(JsonReader in) throws IOException { 44 | return Lib1Enum.valueOf(in.nextString().toUpperCase()); 45 | } 46 | }; 47 | } 48 | 49 | public static JsonAdapter.Factory jsonAdapter() { 50 | return new JsonAdapter.Factory() { 51 | @Nullable 52 | @Override 53 | public JsonAdapter create(Type type, Set annotations, Moshi moshi) { 54 | Class rawType = Types.getRawType(type); 55 | if (rawType.isAssignableFrom(Lib1Enum.class)) { 56 | return new JsonAdapter() { 57 | @Override 58 | public Lib1Enum fromJson(com.squareup.moshi.JsonReader reader) throws IOException { 59 | return Lib1Enum.valueOf(reader.nextString().toUpperCase()); 60 | } 61 | 62 | @Override 63 | public void toJson(com.squareup.moshi.JsonWriter writer, Lib1Enum value) 64 | throws IOException { 65 | writer.value(value.name().toLowerCase()); 66 | } 67 | }; 68 | } 69 | return null; 70 | } 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /integration-test/lib1/src/main/java/com/uber/crumb/integration/lib1/Lib1Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib1; 17 | 18 | import com.google.auto.value.AutoValue; 19 | import com.google.gson.Gson; 20 | import com.google.gson.TypeAdapter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.uber.crumb.annotations.CrumbConsumable; 24 | 25 | @AutoValue 26 | @CrumbConsumable 27 | public abstract class Lib1Model { 28 | 29 | abstract String foo(); 30 | 31 | public static TypeAdapter typeAdapter(Gson gson) { 32 | return new AutoValue_Lib1Model.GsonTypeAdapter(gson); 33 | } 34 | 35 | public static JsonAdapter jsonAdapter(Moshi moshi) { 36 | return new AutoValue_Lib1Model.MoshiJsonAdapter(moshi); 37 | } 38 | 39 | public static Lib1Model create(String foo) { 40 | return new AutoValue_Lib1Model(foo); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /integration-test/lib1/src/main/java/com/uber/crumb/integration/lib1/Lib1Producer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib1; 17 | 18 | import com.google.gson.TypeAdapterFactory; 19 | import com.squareup.moshi.JsonAdapter; 20 | import com.uber.crumb.integration.annotations.GsonFactory; 21 | import com.uber.crumb.integration.annotations.MoshiFactory; 22 | 23 | @GsonFactory(GsonFactory.Type.PRODUCER) 24 | @MoshiFactory(MoshiFactory.Type.PRODUCER) 25 | public abstract class Lib1Producer { 26 | 27 | public static TypeAdapterFactory gson() { 28 | return new GsonProducer_Lib1Producer(); 29 | } 30 | 31 | public static JsonAdapter.Factory moshi() { 32 | return new MoshiProducer_Lib1Producer(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /integration-test/lib1/src/test/java/com/uber/crumb/integration/lib1/Lib1ProducerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib1; 17 | 18 | import static com.google.common.truth.Truth.assertThat; 19 | import static junit.framework.TestCase.fail; 20 | 21 | import com.google.gson.Gson; 22 | import com.google.gson.GsonBuilder; 23 | import com.squareup.moshi.Moshi; 24 | import java.io.IOException; 25 | import org.junit.Test; 26 | 27 | public final class Lib1ProducerTest { 28 | 29 | private static final String EXPECTED_MODEL_JSON = "{\"foo\":\"foo\"}"; 30 | private static final String EXPECTED_ENUM_JSON = "\"foo\""; 31 | private final Gson gson = 32 | new GsonBuilder().registerTypeAdapterFactory(Lib1Producer.gson()).create(); 33 | private final Moshi moshi = new Moshi.Builder().add(Lib1Producer.moshi()).build(); 34 | 35 | @Test 36 | public void verifyGson() { 37 | Lib1Model model = Lib1Model.create("foo"); 38 | String modelJson = gson.toJson(model); 39 | assertThat(modelJson).isEqualTo(EXPECTED_MODEL_JSON); 40 | Lib1Model returnedModel = gson.fromJson(modelJson, Lib1Model.class); 41 | assertThat(returnedModel).isEqualTo(model); 42 | 43 | Lib1Enum lib1Enum = Lib1Enum.FOO; 44 | String lib1EnumJson = gson.toJson(lib1Enum); 45 | assertThat(lib1EnumJson).isEqualTo(EXPECTED_ENUM_JSON); 46 | Lib1Enum returnedEnum = gson.fromJson(lib1EnumJson, Lib1Enum.class); 47 | assertThat(returnedEnum).isEqualTo(lib1Enum); 48 | } 49 | 50 | @Test 51 | public void verifyMoshi() { 52 | Lib1Model model = Lib1Model.create("foo"); 53 | String modelJson = moshi.adapter(Lib1Model.class).toJson(model); 54 | assertThat(modelJson).isEqualTo(EXPECTED_MODEL_JSON); 55 | Lib1Model returnedModel = null; 56 | try { 57 | returnedModel = moshi.adapter(Lib1Model.class).fromJson(modelJson); 58 | } catch (IOException e) { 59 | fail("Moshi model deserialization failed: " + e.getMessage()); 60 | } 61 | assertThat(returnedModel).isEqualTo(model); 62 | 63 | Lib1Enum lib1Enum = Lib1Enum.FOO; 64 | String lib1EnumJson = moshi.adapter(Lib1Enum.class).toJson(lib1Enum); 65 | assertThat(lib1EnumJson).isEqualTo(EXPECTED_ENUM_JSON); 66 | Lib1Enum returnedEnum = null; 67 | try { 68 | returnedEnum = moshi.adapter(Lib1Enum.class).fromJson(lib1EnumJson); 69 | } catch (IOException e) { 70 | fail("Moshi enum deserialization failed: " + e.getMessage()); 71 | } 72 | assertThat(returnedEnum).isEqualTo(lib1Enum); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /integration-test/lib2/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | import net.ltgt.gradle.errorprone.CheckSeverity 17 | 18 | plugins { 19 | id 'java-library' 20 | id 'net.ltgt.errorprone' 21 | id 'net.ltgt.apt-idea' 22 | } 23 | 24 | sourceCompatibility = JavaVersion.VERSION_1_8 25 | targetCompatibility = JavaVersion.VERSION_1_8 26 | 27 | dependencies { 28 | annotationProcessor deps.apt.autoValue 29 | annotationProcessor deps.apt.autoValueAnnotations 30 | annotationProcessor deps.apt.autoValueGson 31 | annotationProcessor deps.apt.autoValueMoshi 32 | annotationProcessor project(":crumb-compiler") 33 | annotationProcessor project(":integration-test:compiler") 34 | compileOnly deps.misc.javaxExtras 35 | compileOnly deps.apt.autoValueAnnotations 36 | 37 | api deps.misc.gson 38 | api deps.misc.moshi 39 | implementation deps.apt.autoValueGsonRuntime 40 | 41 | api project(":crumb-annotations") 42 | api project(":integration-test:annotations") 43 | 44 | testImplementation deps.test.truth 45 | 46 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 47 | //noinspection GradleDynamicVersion 48 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 49 | } 50 | 51 | tasks.withType(JavaCompile).configureEach { 52 | options.errorprone { 53 | disableWarningsInGeneratedCode = true 54 | // Temporary until https://github.com/rharter/auto-value-moshi/issues/128 55 | check("CheckReturnValue", CheckSeverity.WARN) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /integration-test/lib2/src/main/java/com/uber/crumb/integration/lib2/Lib2Enum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib2; 17 | 18 | import com.google.gson.TypeAdapter; 19 | import com.google.gson.stream.JsonReader; 20 | import com.google.gson.stream.JsonWriter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.squareup.moshi.Types; 24 | import com.uber.crumb.annotations.CrumbConsumable; 25 | import java.io.IOException; 26 | import java.lang.annotation.Annotation; 27 | import java.lang.reflect.Type; 28 | import java.util.Set; 29 | import javax.annotation.Nullable; 30 | 31 | @CrumbConsumable 32 | public enum Lib2Enum { 33 | FOO; 34 | 35 | public static TypeAdapter typeAdapter() { 36 | return new TypeAdapter() { 37 | @Override 38 | public void write(JsonWriter out, Lib2Enum value) throws IOException { 39 | out.value(value.name().toLowerCase()); 40 | } 41 | 42 | @Override 43 | public Lib2Enum read(JsonReader in) throws IOException { 44 | return Lib2Enum.valueOf(in.nextString().toUpperCase()); 45 | } 46 | }; 47 | } 48 | 49 | public static JsonAdapter.Factory jsonAdapter() { 50 | return new JsonAdapter.Factory() { 51 | @Nullable 52 | @Override 53 | public JsonAdapter create(Type type, Set annotations, Moshi moshi) { 54 | Class rawType = Types.getRawType(type); 55 | if (rawType.isAssignableFrom(Lib2Enum.class)) { 56 | return new JsonAdapter() { 57 | @Override 58 | public Lib2Enum fromJson(com.squareup.moshi.JsonReader reader) throws IOException { 59 | return Lib2Enum.valueOf(reader.nextString().toUpperCase()); 60 | } 61 | 62 | @Override 63 | public void toJson(com.squareup.moshi.JsonWriter writer, Lib2Enum value) 64 | throws IOException { 65 | writer.value(value.name().toLowerCase()); 66 | } 67 | }; 68 | } 69 | return null; 70 | } 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /integration-test/lib2/src/main/java/com/uber/crumb/integration/lib2/Lib2Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib2; 17 | 18 | import com.google.auto.value.AutoValue; 19 | import com.google.gson.Gson; 20 | import com.google.gson.TypeAdapter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.uber.crumb.annotations.CrumbConsumable; 24 | 25 | @AutoValue 26 | @CrumbConsumable 27 | public abstract class Lib2Model { 28 | 29 | abstract String foo(); 30 | 31 | public static JsonAdapter jsonAdapter(Moshi moshi) { 32 | return new AutoValue_Lib2Model.MoshiJsonAdapter(moshi); 33 | } 34 | 35 | public static TypeAdapter typeAdapter(Gson gson) { 36 | return new AutoValue_Lib2Model.GsonTypeAdapter(gson); 37 | } 38 | 39 | public static Lib2Model create(String foo) { 40 | return new AutoValue_Lib2Model(foo); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /integration-test/lib2/src/main/java/com/uber/crumb/integration/lib2/Lib2Producer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib2; 17 | 18 | import com.google.gson.TypeAdapterFactory; 19 | import com.squareup.moshi.JsonAdapter; 20 | import com.uber.crumb.integration.annotations.GsonFactory; 21 | import com.uber.crumb.integration.annotations.MoshiFactory; 22 | 23 | @GsonFactory(GsonFactory.Type.PRODUCER) 24 | @MoshiFactory(MoshiFactory.Type.PRODUCER) 25 | public abstract class Lib2Producer { 26 | 27 | public static TypeAdapterFactory gson() { 28 | return new GsonProducer_Lib2Producer(); 29 | } 30 | 31 | public static JsonAdapter.Factory moshi() { 32 | return new MoshiProducer_Lib2Producer(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /integration-test/lib3/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | import net.ltgt.gradle.errorprone.CheckSeverity 17 | 18 | plugins { 19 | id 'java-library' 20 | id 'net.ltgt.errorprone' 21 | id 'net.ltgt.apt-idea' 22 | } 23 | 24 | sourceCompatibility = JavaVersion.VERSION_1_8 25 | targetCompatibility = JavaVersion.VERSION_1_8 26 | 27 | dependencies { 28 | annotationProcessor deps.apt.autoValue 29 | annotationProcessor deps.apt.autoValueAnnotations 30 | annotationProcessor deps.apt.autoValueGson 31 | annotationProcessor deps.apt.autoValueMoshi 32 | annotationProcessor project(":crumb-compiler") 33 | annotationProcessor project(":integration-test:compiler") 34 | compileOnly deps.misc.javaxExtras 35 | compileOnly deps.apt.autoValueAnnotations 36 | 37 | api deps.misc.gson 38 | api deps.misc.moshi 39 | implementation deps.apt.autoValueGsonRuntime 40 | 41 | api project(":crumb-annotations") 42 | api project(":integration-test:annotations") 43 | 44 | testImplementation deps.test.truth 45 | 46 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 47 | //noinspection GradleDynamicVersion 48 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 49 | } 50 | 51 | tasks.withType(JavaCompile).configureEach { 52 | options.errorprone { 53 | disableWarningsInGeneratedCode = true 54 | // Temporary until https://github.com/rharter/auto-value-moshi/issues/128 55 | check("CheckReturnValue", CheckSeverity.WARN) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /integration-test/lib3/src/main/java/com/uber/crumb/integration/lib3/Lib3Enum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib3; 17 | 18 | import com.google.gson.TypeAdapter; 19 | import com.google.gson.stream.JsonReader; 20 | import com.google.gson.stream.JsonWriter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.squareup.moshi.Types; 24 | import com.uber.crumb.annotations.CrumbConsumable; 25 | import java.io.IOException; 26 | import java.lang.annotation.Annotation; 27 | import java.lang.reflect.Type; 28 | import java.util.Set; 29 | import javax.annotation.Nullable; 30 | 31 | @CrumbConsumable 32 | public enum Lib3Enum { 33 | FOO; 34 | 35 | public static TypeAdapter typeAdapter() { 36 | return new TypeAdapter() { 37 | @Override 38 | public void write(JsonWriter out, Lib3Enum value) throws IOException { 39 | out.value(value.name().toLowerCase()); 40 | } 41 | 42 | @Override 43 | public Lib3Enum read(JsonReader in) throws IOException { 44 | return Lib3Enum.valueOf(in.nextString().toUpperCase()); 45 | } 46 | }; 47 | } 48 | 49 | public static JsonAdapter.Factory jsonAdapter() { 50 | return new JsonAdapter.Factory() { 51 | @Nullable 52 | @Override 53 | public JsonAdapter create(Type type, Set annotations, Moshi moshi) { 54 | Class rawType = Types.getRawType(type); 55 | if (rawType.isAssignableFrom(Lib3Enum.class)) { 56 | return new JsonAdapter() { 57 | @Override 58 | public Lib3Enum fromJson(com.squareup.moshi.JsonReader reader) throws IOException { 59 | return Lib3Enum.valueOf(reader.nextString().toUpperCase()); 60 | } 61 | 62 | @Override 63 | public void toJson(com.squareup.moshi.JsonWriter writer, Lib3Enum value) 64 | throws IOException { 65 | writer.value(value.name().toLowerCase()); 66 | } 67 | }; 68 | } 69 | return null; 70 | } 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /integration-test/lib3/src/main/java/com/uber/crumb/integration/lib3/Lib3Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib3; 17 | 18 | import com.google.auto.value.AutoValue; 19 | import com.google.gson.Gson; 20 | import com.google.gson.TypeAdapter; 21 | import com.squareup.moshi.JsonAdapter; 22 | import com.squareup.moshi.Moshi; 23 | import com.uber.crumb.annotations.CrumbConsumable; 24 | 25 | @AutoValue 26 | @CrumbConsumable 27 | public abstract class Lib3Model { 28 | 29 | abstract String foo(); 30 | 31 | public static JsonAdapter jsonAdapter(Moshi moshi) { 32 | return new AutoValue_Lib3Model.MoshiJsonAdapter(moshi); 33 | } 34 | 35 | public static TypeAdapter typeAdapter(Gson gson) { 36 | return new AutoValue_Lib3Model.GsonTypeAdapter(gson); 37 | } 38 | 39 | public static Lib3Model create(String foo) { 40 | return new AutoValue_Lib3Model(foo); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /integration-test/lib3/src/main/java/com/uber/crumb/integration/lib3/Lib3Producer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.integration.lib3; 17 | 18 | import com.google.gson.TypeAdapterFactory; 19 | import com.squareup.moshi.JsonAdapter; 20 | import com.uber.crumb.integration.annotations.GsonFactory; 21 | import com.uber.crumb.integration.annotations.MoshiFactory; 22 | 23 | @GsonFactory(GsonFactory.Type.PRODUCER) 24 | @MoshiFactory(MoshiFactory.Type.PRODUCER) 25 | public abstract class Lib3Producer { 26 | 27 | public static TypeAdapterFactory gson() { 28 | return new GsonProducer_Lib3Producer(); 29 | } 30 | 31 | public static JsonAdapter.Factory moshi() { 32 | return new MoshiProducer_Lib3Producer(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/java/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.application' 19 | } 20 | 21 | android { 22 | compileSdkVersion deps.build.compileSdkVersion 23 | 24 | defaultConfig { 25 | applicationId "com.uber.crumb.sample.app" 26 | minSdkVersion deps.build.minSdkVersion 27 | targetSdkVersion deps.build.targetSdkVersion 28 | } 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_1_8 31 | targetCompatibility JavaVersion.VERSION_1_8 32 | } 33 | lintOptions { 34 | disable 'MissingApplicationIcon' 35 | } 36 | } 37 | 38 | repositories { 39 | google() 40 | } 41 | 42 | dependencies { 43 | annotationProcessor project(":crumb-compiler") 44 | annotationProcessor project(":sample:experiments-compiler:experiment-enums-compiler:java") 45 | implementation project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 46 | implementation project(":crumb-annotations") 47 | implementation project(":sample:experiments-compiler:android:java:library") 48 | implementation deps.misc.appCompat 49 | } 50 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/java/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/java/app/src/main/java/com/uber/crumb/sample/ExperimentsHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.ExperimentsCollector; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | @ExperimentsCollector 23 | public abstract class ExperimentsHolder { 24 | 25 | public static Map> experiments() { 26 | return Experiments_ExperimentsHolder.EXPERIMENTS; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/java/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.library' 19 | } 20 | 21 | android { 22 | compileSdkVersion deps.build.compileSdkVersion 23 | 24 | defaultConfig { 25 | minSdkVersion deps.build.minSdkVersion 26 | targetSdkVersion deps.build.targetSdkVersion 27 | } 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | } 33 | 34 | dependencies { 35 | annotationProcessor project(":crumb-compiler") 36 | annotationProcessor project(":sample:experiments-compiler:experiment-enums-compiler:java") 37 | implementation project(":crumb-annotations") 38 | implementation project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 39 | } 40 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/java/library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/java/library/src/main/java/com/uber/crumb/sample/LibraryExperiments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.Experiments; 19 | 20 | @Experiments 21 | public enum LibraryExperiments { 22 | XP_A, 23 | XP_C, 24 | XP_D, 25 | XP_E, 26 | XP_F, 27 | XP_G, 28 | } 29 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/kotlin/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.application' 19 | id 'org.jetbrains.kotlin.android' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | apply from: rootProject.file('gradle/config-kotlin-sources.gradle') 23 | 24 | android { 25 | compileSdkVersion deps.build.compileSdkVersion 26 | 27 | defaultConfig { 28 | applicationId "com.uber.crumb.sample.app" 29 | minSdkVersion deps.build.minSdkVersion 30 | targetSdkVersion deps.build.targetSdkVersion 31 | } 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | lintOptions { 37 | disable 'MissingApplicationIcon' 38 | } 39 | } 40 | 41 | repositories { 42 | google() 43 | } 44 | 45 | dependencies { 46 | kapt project(":crumb-compiler") 47 | kapt project(":sample:experiments-compiler:experiment-enums-compiler:kotlin") 48 | implementation project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 49 | implementation project(":crumb-annotations") 50 | implementation project(":sample:experiments-compiler:android:kotlin:library") 51 | implementation deps.kotlin.stdLibJdk7 52 | implementation deps.misc.appCompat 53 | implementation deps.kotlin.stdLib 54 | } 55 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/kotlin/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/kotlin/app/src/main/kotlin/com/uber/crumb/sample/ExperimentsHolder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.ExperimentsCollector 19 | 20 | @ExperimentsCollector 21 | object ExperimentsHolder 22 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/kotlin/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.library' 19 | id 'org.jetbrains.kotlin.android' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | apply from: rootProject.file('gradle/config-kotlin-sources.gradle') 23 | 24 | android { 25 | compileSdkVersion deps.build.compileSdkVersion 26 | 27 | defaultConfig { 28 | minSdkVersion deps.build.minSdkVersion 29 | targetSdkVersion deps.build.targetSdkVersion 30 | } 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_1_8 33 | targetCompatibility JavaVersion.VERSION_1_8 34 | } 35 | } 36 | 37 | dependencies { 38 | kapt project(":crumb-compiler") 39 | kapt project(":sample:experiments-compiler:experiment-enums-compiler:kotlin") 40 | api deps.kotlin.stdLibJdk7 41 | implementation project(":crumb-annotations") 42 | implementation project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 43 | } 44 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/kotlin/library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/experiments-compiler/android/kotlin/library/src/main/kotlin/com/uber/crumb/sample/LibraryExperiments.kt: -------------------------------------------------------------------------------- 1 | package com.uber.crumb.sample 2 | 3 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.Experiments 4 | 5 | @Experiments 6 | enum class LibraryExperiments { 7 | XP_A, 8 | XP_C, 9 | XP_D, 10 | XP_E, 11 | XP_F, 12 | XP_G 13 | } 14 | -------------------------------------------------------------------------------- /sample/experiments-compiler/experiment-enums-compiler/annotations/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | } 21 | 22 | sourceCompatibility = JavaVersion.VERSION_1_8 23 | targetCompatibility = JavaVersion.VERSION_1_8 24 | 25 | dependencies { 26 | api project(':crumb-annotations') 27 | 28 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 29 | //noinspection GradleDynamicVersion 30 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 31 | } 32 | 33 | tasks.withType(JavaCompile).configureEach { 34 | options.errorprone.disableWarningsInGeneratedCode = true 35 | } 36 | -------------------------------------------------------------------------------- /sample/experiments-compiler/experiment-enums-compiler/annotations/src/main/java/com/uber/crumb/sample/experimentsenumscompiler/annotations/Experiments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample.experimentsenumscompiler.annotations; 17 | 18 | import static java.lang.annotation.ElementType.TYPE; 19 | import static java.lang.annotation.RetentionPolicy.CLASS; 20 | 21 | import com.uber.crumb.annotations.CrumbProducer; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | @CrumbProducer 26 | @Retention(CLASS) 27 | @Target(TYPE) 28 | public @interface Experiments {} 29 | -------------------------------------------------------------------------------- /sample/experiments-compiler/experiment-enums-compiler/annotations/src/main/java/com/uber/crumb/sample/experimentsenumscompiler/annotations/ExperimentsCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample.experimentsenumscompiler.annotations; 17 | 18 | import static java.lang.annotation.ElementType.TYPE; 19 | import static java.lang.annotation.RetentionPolicy.CLASS; 20 | 21 | import com.uber.crumb.annotations.CrumbConsumer; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | @CrumbConsumer 26 | @Retention(CLASS) 27 | @Target(TYPE) 28 | public @interface ExperimentsCollector {} 29 | -------------------------------------------------------------------------------- /sample/experiments-compiler/experiment-enums-compiler/java/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | } 21 | 22 | sourceCompatibility = JavaVersion.VERSION_1_8 23 | targetCompatibility = JavaVersion.VERSION_1_8 24 | 25 | dependencies { 26 | annotationProcessor deps.apt.autoService 27 | compileOnly deps.misc.javaxExtras 28 | 29 | implementation deps.apt.autoServiceAnnotations 30 | implementation deps.apt.autoCommon 31 | implementation deps.misc.guava 32 | implementation deps.misc.javapoet 33 | implementation deps.kotlin.stdLibJdk8 34 | implementation project(path: ":crumb-compiler-api", configuration: "default") 35 | api project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 36 | 37 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 38 | //noinspection GradleDynamicVersion 39 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 40 | } 41 | 42 | tasks.withType(JavaCompile).configureEach { 43 | options.errorprone.disableWarningsInGeneratedCode = true 44 | } 45 | -------------------------------------------------------------------------------- /sample/experiments-compiler/experiment-enums-compiler/java/src/main/java/com/uber/crumb/sample/experimentenumscompiler/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | /** Enum experiments compiler demo. */ 18 | @com.uber.javaxextras.EverythingIsNonNullByDefault 19 | package com.uber.crumb.sample.experimentenumscompiler; 20 | -------------------------------------------------------------------------------- /sample/experiments-compiler/experiment-enums-compiler/kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'org.jetbrains.kotlin.jvm' 19 | id 'org.jetbrains.kotlin.kapt' 20 | } 21 | 22 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 23 | kotlinOptions { 24 | jvmTarget = "1.8" 25 | freeCompilerArgs = ['-Xjsr305=strict', '-Xjvm-default=enable'] 26 | } 27 | } 28 | 29 | dependencies { 30 | kapt deps.apt.autoService 31 | 32 | implementation deps.apt.autoServiceAnnotations 33 | implementation deps.apt.autoCommon 34 | implementation deps.misc.guava 35 | implementation deps.misc.kotlinMetadata 36 | implementation deps.misc.kotlinpoet 37 | implementation deps.kotlin.stdLibJdk8 38 | implementation project(":crumb-compiler") 39 | implementation project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 40 | } 41 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/java/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | id 'net.ltgt.apt-idea' 21 | } 22 | 23 | sourceCompatibility = JavaVersion.VERSION_1_8 24 | targetCompatibility = JavaVersion.VERSION_1_8 25 | 26 | dependencies { 27 | annotationProcessor project(":crumb-compiler") 28 | annotationProcessor project(":sample:experiments-compiler:experiment-enums-compiler:java") 29 | implementation project(":crumb-annotations") 30 | implementation project(":sample:experiments-compiler:jvm:java:library") 31 | 32 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 33 | //noinspection GradleDynamicVersion 34 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 35 | } 36 | 37 | tasks.withType(JavaCompile).configureEach { 38 | options.errorprone.disableWarningsInGeneratedCode = true 39 | } 40 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/java/app/src/main/java/com/uber/crumb/sample/ExperimentsHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.ExperimentsCollector; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | @ExperimentsCollector 23 | public abstract class ExperimentsHolder { 24 | 25 | public static Map> experiments() { 26 | return Experiments_ExperimentsHolder.EXPERIMENTS; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/java/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | id 'net.ltgt.apt-idea' 21 | } 22 | 23 | sourceCompatibility = JavaVersion.VERSION_1_8 24 | targetCompatibility = JavaVersion.VERSION_1_8 25 | 26 | dependencies { 27 | annotationProcessor project(":crumb-compiler") 28 | annotationProcessor project(":sample:experiments-compiler:experiment-enums-compiler:java") 29 | api project(":crumb-annotations") 30 | api project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 31 | 32 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 33 | //noinspection GradleDynamicVersion 34 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 35 | } 36 | 37 | tasks.withType(JavaCompile).configureEach { 38 | options.errorprone.disableWarningsInGeneratedCode = true 39 | } 40 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/java/library/src/main/java/com/uber/crumb/sample/LibraryExperiments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.Experiments; 19 | 20 | @Experiments 21 | public enum LibraryExperiments { 22 | XP_A, 23 | XP_C, 24 | XP_D, 25 | XP_E, 26 | XP_F, 27 | XP_G, 28 | } 29 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/kotlin/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'org.jetbrains.kotlin.jvm' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | 23 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 24 | kotlinOptions { 25 | jvmTarget = "1.8" 26 | freeCompilerArgs = ['-Xjsr305=strict'] 27 | } 28 | } 29 | 30 | dependencies { 31 | kapt project(":crumb-compiler") 32 | kapt project(":sample:experiments-compiler:experiment-enums-compiler:kotlin") 33 | implementation project(":crumb-annotations") 34 | implementation project(":sample:experiments-compiler:jvm:kotlin:library") 35 | implementation deps.kotlin.stdLibJdk7 36 | } 37 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/kotlin/app/src/main/kotlin/com/uber/crumb/sample/ExperimentsHolder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.ExperimentsCollector 19 | 20 | @ExperimentsCollector 21 | object ExperimentsHolder 22 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/kotlin/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'org.jetbrains.kotlin.jvm' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | 23 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 24 | kotlinOptions { 25 | jvmTarget = "1.8" 26 | freeCompilerArgs = ['-Xjsr305=strict'] 27 | } 28 | } 29 | 30 | dependencies { 31 | kapt project(":crumb-compiler") 32 | kapt project(":sample:experiments-compiler:experiment-enums-compiler:kotlin") 33 | api project(":crumb-annotations") 34 | api project(":sample:experiments-compiler:experiment-enums-compiler:annotations") 35 | api deps.kotlin.stdLibJdk7 36 | } 37 | -------------------------------------------------------------------------------- /sample/experiments-compiler/jvm/kotlin/library/src/main/kotlin/com/uber/crumb/sample/LibraryExperiments.kt: -------------------------------------------------------------------------------- 1 | package com.uber.crumb.sample 2 | 3 | import com.uber.crumb.sample.experimentsenumscompiler.annotations.Experiments 4 | 5 | @Experiments 6 | enum class LibraryExperiments { 7 | XP_A, 8 | XP_C, 9 | XP_D, 10 | XP_E, 11 | XP_F, 12 | XP_G 13 | } 14 | -------------------------------------------------------------------------------- /sample/plugins-compiler/PluginSampleDiagram.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uber/crumb/550793f551862a2af369083bc12bfdcc110f9a0b/sample/plugins-compiler/PluginSampleDiagram.key -------------------------------------------------------------------------------- /sample/plugins-compiler/android/java/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.application' 19 | } 20 | 21 | android { 22 | compileSdkVersion deps.build.compileSdkVersion 23 | 24 | defaultConfig { 25 | applicationId "com.uber.crumb.sample.app" 26 | minSdkVersion deps.build.minSdkVersion 27 | targetSdkVersion deps.build.targetSdkVersion 28 | } 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_1_8 31 | targetCompatibility JavaVersion.VERSION_1_8 32 | } 33 | lintOptions { 34 | disable 'MissingApplicationIcon' 35 | } 36 | } 37 | 38 | repositories { 39 | google() 40 | } 41 | 42 | dependencies { 43 | annotationProcessor project(":crumb-compiler") 44 | annotationProcessor project(":sample:plugins-compiler:plugins-compiler:java") 45 | implementation project(":sample:plugins-compiler:plugins-compiler:annotations") 46 | implementation project(":crumb-annotations") 47 | implementation project(":sample:plugins-compiler:android:java:library") 48 | implementation deps.misc.appCompat 49 | implementation project(":sample:plugins-compiler:translations-api") 50 | } 51 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/java/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/java/app/src/main/java/com/uber/crumb/sample/DefaultTranslations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin; 19 | 20 | @Plugin 21 | public class DefaultTranslations implements Translations { 22 | 23 | @Override 24 | public String translationForKey(String key) { 25 | return "foo"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/java/app/src/main/java/com/uber/crumb/sample/TranslationsPluginManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.PluginPoint; 19 | import java.util.Set; 20 | 21 | @PluginPoint(Translations.class) 22 | public abstract class TranslationsPluginManager { 23 | 24 | public static Set obtain() { 25 | return Plugins_TranslationsPluginManager.PLUGINS; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/java/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.library' 19 | } 20 | 21 | android { 22 | compileSdkVersion deps.build.compileSdkVersion 23 | 24 | defaultConfig { 25 | minSdkVersion deps.build.minSdkVersion 26 | targetSdkVersion deps.build.targetSdkVersion 27 | } 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | } 33 | 34 | dependencies { 35 | annotationProcessor project(":crumb-compiler") 36 | annotationProcessor project(":sample:plugins-compiler:plugins-compiler:java") 37 | implementation project(":crumb-annotations") 38 | implementation project(":sample:plugins-compiler:plugins-compiler:annotations") 39 | implementation project(":sample:plugins-compiler:translations-api") 40 | } 41 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/java/library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/java/library/src/main/java/com/uber/crumb/sample/EnglishTranslations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin; 19 | 20 | @Plugin 21 | public class EnglishTranslations implements Translations { 22 | 23 | @Override 24 | public String translationForKey(String key) { 25 | return "foo"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/kotlin/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.application' 19 | id 'org.jetbrains.kotlin.android' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | apply from: rootProject.file('gradle/config-kotlin-sources.gradle') 23 | 24 | android { 25 | compileSdkVersion deps.build.compileSdkVersion 26 | 27 | defaultConfig { 28 | applicationId "com.uber.crumb.sample.app" 29 | minSdkVersion deps.build.minSdkVersion 30 | targetSdkVersion deps.build.targetSdkVersion 31 | } 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | lintOptions { 37 | disable 'MissingApplicationIcon' 38 | } 39 | } 40 | 41 | repositories { 42 | google() 43 | } 44 | 45 | dependencies { 46 | kapt project(":crumb-compiler") 47 | kapt project(":sample:plugins-compiler:plugins-compiler:kotlin") 48 | implementation project(":sample:plugins-compiler:plugins-compiler:annotations") 49 | implementation project(":crumb-annotations") 50 | implementation project(":sample:plugins-compiler:android:kotlin:library") 51 | implementation deps.misc.appCompat 52 | implementation deps.kotlin.stdLib 53 | implementation project(":sample:plugins-compiler:translations-api") 54 | } 55 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/kotlin/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/kotlin/app/src/main/kotlin/com/uber/crumb/sample/DefaultTranslations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin 19 | 20 | @Plugin 21 | class DefaultTranslations : Translations { 22 | 23 | override fun translationForKey(key: String): String { 24 | return "foo" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/kotlin/app/src/main/kotlin/com/uber/crumb/sample/TranslationsPluginManager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.PluginPoint 19 | 20 | @PluginPoint(Translations::class) 21 | object TranslationsPluginManager 22 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/kotlin/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'com.android.library' 19 | id 'org.jetbrains.kotlin.android' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | apply from: rootProject.file('gradle/config-kotlin-sources.gradle') 23 | 24 | android { 25 | compileSdkVersion deps.build.compileSdkVersion 26 | 27 | defaultConfig { 28 | minSdkVersion deps.build.minSdkVersion 29 | targetSdkVersion deps.build.targetSdkVersion 30 | } 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_1_8 33 | targetCompatibility JavaVersion.VERSION_1_8 34 | } 35 | } 36 | 37 | dependencies { 38 | kapt project(":crumb-compiler") 39 | kapt project(":sample:plugins-compiler:plugins-compiler:kotlin") 40 | implementation deps.kotlin.stdLib 41 | implementation project(":crumb-annotations") 42 | implementation project(":sample:plugins-compiler:plugins-compiler:annotations") 43 | implementation project(":sample:plugins-compiler:translations-api") 44 | } 45 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/kotlin/library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/plugins-compiler/android/kotlin/library/src/main/kotlin/com/uber/crumb/sample/EnglishTranslations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin 19 | 20 | @Plugin 21 | class EnglishTranslations : Translations { 22 | 23 | override fun translationForKey(key: String?): String { 24 | return "foo" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/java/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | id 'net.ltgt.apt-idea' 21 | } 22 | 23 | sourceCompatibility = JavaVersion.VERSION_1_8 24 | targetCompatibility = JavaVersion.VERSION_1_8 25 | 26 | dependencies { 27 | annotationProcessor project(":crumb-compiler") 28 | annotationProcessor project(":sample:plugins-compiler:plugins-compiler:java") 29 | implementation project(":crumb-annotations") 30 | implementation project(":sample:plugins-compiler:jvm:java:library") 31 | implementation project(":sample:plugins-compiler:translations-api") 32 | 33 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 34 | //noinspection GradleDynamicVersion 35 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 36 | } 37 | 38 | tasks.withType(JavaCompile).configureEach { 39 | options.errorprone.disableWarningsInGeneratedCode = true 40 | } 41 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/java/app/src/main/java/com/uber/crumb/sample/DefaultTranslations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin; 19 | 20 | @Plugin 21 | public class DefaultTranslations implements Translations { 22 | 23 | @Override 24 | public String translationForKey(String key) { 25 | return "foo"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/java/app/src/main/java/com/uber/crumb/sample/TranslationsPluginManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.PluginPoint; 19 | import java.util.Set; 20 | 21 | @PluginPoint(Translations.class) 22 | public abstract class TranslationsPluginManager { 23 | 24 | public static Set obtain() { 25 | return Plugins_TranslationsPluginManager.PLUGINS; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/java/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | id 'net.ltgt.apt-idea' 21 | } 22 | 23 | sourceCompatibility = JavaVersion.VERSION_1_8 24 | targetCompatibility = JavaVersion.VERSION_1_8 25 | 26 | dependencies { 27 | annotationProcessor project(":crumb-compiler") 28 | annotationProcessor project(":sample:plugins-compiler:plugins-compiler:java") 29 | api project(":crumb-annotations") 30 | api project(":sample:plugins-compiler:plugins-compiler:annotations") 31 | api project(":sample:plugins-compiler:translations-api") 32 | 33 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 34 | //noinspection GradleDynamicVersion 35 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 36 | } 37 | 38 | tasks.withType(JavaCompile).configureEach { 39 | options.errorprone.disableWarningsInGeneratedCode = true 40 | } 41 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/java/library/src/main/java/com/uber/crumb/sample/EnglishTranslations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin; 19 | 20 | @Plugin 21 | public class EnglishTranslations implements Translations { 22 | 23 | @Override 24 | public String translationForKey(String key) { 25 | return "foo"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/kotlin/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'org.jetbrains.kotlin.jvm' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | 23 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 24 | kotlinOptions { 25 | jvmTarget = "1.8" 26 | freeCompilerArgs = ['-Xjsr305=strict'] 27 | } 28 | } 29 | 30 | dependencies { 31 | kapt project(":crumb-compiler") 32 | kapt project(":sample:plugins-compiler:plugins-compiler:kotlin") 33 | implementation project(":crumb-annotations") 34 | implementation project(":sample:plugins-compiler:jvm:kotlin:library") 35 | implementation project(":sample:plugins-compiler:translations-api") 36 | implementation deps.kotlin.stdLib 37 | } 38 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/kotlin/app/src/main/kotlin/com/uber/crumb/sample/DefaultTranslations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin 19 | 20 | @Plugin 21 | class DefaultTranslations : Translations { 22 | 23 | override fun translationForKey(key: String): String { 24 | return "foo" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/kotlin/app/src/main/kotlin/com/uber/crumb/sample/TranslationsPluginManager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.PluginPoint 19 | 20 | @PluginPoint(Translations::class) 21 | object TranslationsPluginManager 22 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/kotlin/library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'org.jetbrains.kotlin.jvm' 20 | id 'org.jetbrains.kotlin.kapt' 21 | } 22 | 23 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 24 | kotlinOptions { 25 | jvmTarget = "1.8" 26 | freeCompilerArgs = ['-Xjsr305=strict'] 27 | } 28 | } 29 | 30 | dependencies { 31 | kapt project(":crumb-compiler") 32 | kapt project(":sample:plugins-compiler:plugins-compiler:kotlin") 33 | implementation deps.kotlin.stdLib 34 | api project(":crumb-annotations") 35 | api project(":sample:plugins-compiler:plugins-compiler:annotations") 36 | api project(":sample:plugins-compiler:translations-api") 37 | } 38 | -------------------------------------------------------------------------------- /sample/plugins-compiler/jvm/kotlin/library/src/main/kotlin/com/uber/crumb/sample/EnglishTranslations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample 17 | 18 | import com.uber.crumb.sample.pluginscompiler.annotations.Plugin 19 | 20 | @Plugin 21 | class EnglishTranslations : Translations { 22 | 23 | override fun translationForKey(key: String?): String { 24 | return "foo" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/plugins-compiler/plugins-compiler/annotations/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | } 21 | 22 | sourceCompatibility = JavaVersion.VERSION_1_8 23 | targetCompatibility = JavaVersion.VERSION_1_8 24 | 25 | dependencies { 26 | api project(':crumb-annotations') 27 | 28 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 29 | //noinspection GradleDynamicVersion 30 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 31 | } 32 | 33 | tasks.withType(JavaCompile).configureEach { 34 | options.errorprone.disableWarningsInGeneratedCode = true 35 | } 36 | -------------------------------------------------------------------------------- /sample/plugins-compiler/plugins-compiler/annotations/src/main/java/com/uber/crumb/sample/pluginscompiler/annotations/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample.pluginscompiler.annotations; 17 | 18 | import static java.lang.annotation.ElementType.TYPE; 19 | import static java.lang.annotation.RetentionPolicy.CLASS; 20 | 21 | import com.uber.crumb.annotations.CrumbProducer; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | @CrumbProducer 26 | @Retention(CLASS) 27 | @Target(TYPE) 28 | public @interface Plugin {} 29 | -------------------------------------------------------------------------------- /sample/plugins-compiler/plugins-compiler/annotations/src/main/java/com/uber/crumb/sample/pluginscompiler/annotations/PluginPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample.pluginscompiler.annotations; 17 | 18 | import static java.lang.annotation.ElementType.TYPE; 19 | import static java.lang.annotation.RetentionPolicy.CLASS; 20 | 21 | import com.uber.crumb.annotations.CrumbConsumer; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | @CrumbConsumer 26 | @Retention(CLASS) 27 | @Target(TYPE) 28 | public @interface PluginPoint { 29 | /** @return the target class plugin implementations. */ 30 | Class value(); 31 | } 32 | -------------------------------------------------------------------------------- /sample/plugins-compiler/plugins-compiler/java/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | } 21 | 22 | sourceCompatibility = JavaVersion.VERSION_1_8 23 | targetCompatibility = JavaVersion.VERSION_1_8 24 | 25 | dependencies { 26 | annotationProcessor deps.apt.autoService 27 | compileOnly deps.misc.javaxExtras 28 | 29 | implementation deps.apt.autoServiceAnnotations 30 | implementation deps.apt.autoCommon 31 | implementation deps.misc.guava 32 | implementation deps.misc.javapoet 33 | implementation deps.kotlin.stdLibJdk8 34 | implementation project(path: ":crumb-compiler-api", configuration: "default") 35 | api project(":sample:plugins-compiler:plugins-compiler:annotations") 36 | 37 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 38 | //noinspection GradleDynamicVersion 39 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 40 | } 41 | 42 | tasks.withType(JavaCompile).configureEach { 43 | options.errorprone.disableWarningsInGeneratedCode = true 44 | } 45 | -------------------------------------------------------------------------------- /sample/plugins-compiler/plugins-compiler/java/src/main/java/com/uber/crumb/sample/pluginscompiler/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | /** Plugins compiler demo. */ 18 | @com.uber.javaxextras.EverythingIsNonNullByDefault 19 | package com.uber.crumb.sample.pluginscompiler; 20 | -------------------------------------------------------------------------------- /sample/plugins-compiler/plugins-compiler/kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'org.jetbrains.kotlin.jvm' 19 | id 'org.jetbrains.kotlin.kapt' 20 | } 21 | 22 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 23 | kotlinOptions { 24 | jvmTarget = "1.8" 25 | freeCompilerArgs = ['-Xjsr305=strict', '-Xjvm-default=enable'] 26 | } 27 | } 28 | 29 | dependencies { 30 | kapt deps.apt.autoService 31 | 32 | implementation deps.apt.autoServiceAnnotations 33 | implementation deps.apt.autoCommon 34 | implementation deps.misc.guava 35 | implementation deps.misc.kotlinMetadata 36 | implementation deps.misc.kotlinpoet 37 | implementation deps.kotlin.stdLibJdk8 38 | implementation project(":crumb-compiler") 39 | implementation project(":sample:plugins-compiler:plugins-compiler:annotations") 40 | } 41 | -------------------------------------------------------------------------------- /sample/plugins-compiler/translations-api/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018. Uber Technologies 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 | plugins { 18 | id 'java-library' 19 | id 'net.ltgt.errorprone' 20 | id 'net.ltgt.apt-idea' 21 | } 22 | 23 | sourceCompatibility = JavaVersion.VERSION_1_8 24 | targetCompatibility = JavaVersion.VERSION_1_8 25 | 26 | dependencies { 27 | errorprone "com.google.errorprone:error_prone_core:${deps.versions.errorProne}" 28 | //noinspection GradleDynamicVersion 29 | errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" 30 | } 31 | 32 | tasks.withType(JavaCompile).configureEach { 33 | options.errorprone.disableWarningsInGeneratedCode = true 34 | } 35 | -------------------------------------------------------------------------------- /sample/plugins-compiler/translations-api/src/main/java/com/uber/crumb/sample/Translations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018. Uber Technologies 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 | package com.uber.crumb.sample; 17 | 18 | /** An example "Translations" plugin interface that implementers could implement. */ 19 | public interface Translations { 20 | String translationForKey(String key); 21 | } 22 | -------------------------------------------------------------------------------- /spotless/copyright.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright $YEAR. Uber Technologies 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 | -------------------------------------------------------------------------------- /spotless/copyright.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright $YEAR. Uber Technologies 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 | --------------------------------------------------------------------------------