├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── VERSION ├── bin └── sync-version.sh ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts └── src │ └── main │ └── kotlin │ ├── smithy-gradle-plugin.java-conventions.gradle.kts │ └── smithy-gradle-plugin.plugin-conventions.gradle.kts ├── config ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml └── spotbugs │ └── filter.xml ├── examples ├── base-plugin │ ├── failure-cases │ │ ├── conflicting-output-dir-configs │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ ├── settings.gradle.kts │ │ │ ├── smithy-build-conflicting.json │ │ │ └── smithy-build.json │ │ ├── forbid-dependency-resolution-fork │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ ├── settings.gradle.kts │ │ │ └── smithy-build.json │ │ ├── forbid-dependency-resolution-no-fork │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ ├── settings.gradle.kts │ │ │ └── smithy-build.json │ │ ├── forbid-implicit-no-build-config │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ └── settings.gradle.kts │ │ └── syntax-error │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ └── main.smithy │ │ │ ├── settings.gradle.kts │ │ │ └── smithy-build.json │ ├── includes-in-sourceset │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── includes │ │ │ ├── also-included.smithy │ │ │ └── included.smithy │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── output-directory-config │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── output-directory-with-projection │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── output-directory │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── scans-for-cli-version │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── smithy-build-task │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ └── uses-explicitly-set-cli-version │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json ├── jar-plugin │ ├── adds-tags │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── build-dependencies │ │ ├── README.md │ │ ├── internal-model │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── internal.smithy │ │ │ └── smithy-build.json │ │ ├── service │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ └── smithy-build.json │ │ └── settings.gradle.kts │ ├── custom-trait │ │ ├── README.md │ │ ├── consumer │ │ │ ├── build.gradle.kts │ │ │ └── model │ │ │ │ └── main.smithy │ │ ├── custom-string-trait │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── custom-trait.smithy │ │ │ ├── smithy-build.json │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── io │ │ │ │ │ └── smithy │ │ │ │ │ └── examples │ │ │ │ │ └── traits │ │ │ │ │ └── JsonNameTrait.java │ │ │ │ └── resources │ │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── software.amazon.smithy.model.traits.TraitService │ │ └── settings.gradle.kts │ ├── disable-jar │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── failure-cases │ │ ├── invalid-projection │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ ├── settings.gradle.kts │ │ │ └── smithy-build.json │ │ ├── missing-runtime-dependency │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ ├── settings.gradle.kts │ │ │ └── smithy-build.json │ │ └── require-prerequisite-plugin │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ └── main.smithy │ │ │ └── settings.gradle.kts │ ├── kotlin-jvm-project │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ ├── smithy-build.json │ │ └── src │ │ │ └── main │ │ │ └── kotlin │ │ │ └── Main.kt │ ├── multi-project │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── consumer │ │ │ ├── build.gradle.kts │ │ │ ├── model │ │ │ │ └── main.smithy │ │ │ └── smithy-build.json │ │ ├── gradle.properties │ │ ├── producer1 │ │ │ ├── build.gradle.kts │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── software │ │ │ │ │ └── amazon │ │ │ │ │ └── smithy │ │ │ │ │ └── producer1 │ │ │ │ │ └── Producer1Trait.java │ │ │ │ └── resources │ │ │ │ └── META-INF │ │ │ │ ├── services │ │ │ │ └── software.amazon.smithy.model.traits.TraitService │ │ │ │ └── smithy │ │ │ │ ├── main.smithy │ │ │ │ └── manifest │ │ ├── producer2 │ │ │ ├── build.gradle.kts │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── software │ │ │ │ │ └── amazon │ │ │ │ │ └── smithy │ │ │ │ │ └── producer2 │ │ │ │ │ └── Producer2Trait.java │ │ │ │ └── resources │ │ │ │ └── META-INF │ │ │ │ ├── services │ │ │ │ └── software.amazon.smithy.model.traits.TraitService │ │ │ │ └── smithy │ │ │ │ ├── main.smithy │ │ │ │ └── manifest │ │ └── settings.gradle.kts │ ├── multiple-jars │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── multiple-sources │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ ├── a.smithy │ │ │ └── nested │ │ │ │ ├── foo.smithy │ │ │ │ └── more │ │ │ │ └── baz.smithy │ │ ├── settings.gradle.kts │ │ ├── smithy-build.json │ │ └── src │ │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── smithy │ │ │ │ └── c.smithy │ │ │ └── smithy │ │ │ └── b.smithy │ ├── no-models │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── projection │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── projects-with-tags │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── jars │ │ │ ├── a │ │ │ │ ├── META-INF │ │ │ │ │ ├── MANIFEST.MF │ │ │ │ │ └── smithy │ │ │ │ │ │ ├── a.smithy │ │ │ │ │ │ └── manifest │ │ │ │ └── a.jar │ │ │ ├── b │ │ │ │ ├── META-INF │ │ │ │ │ ├── MANIFEST.MF │ │ │ │ │ └── smithy │ │ │ │ │ │ ├── b.smithy │ │ │ │ │ │ └── manifest │ │ │ │ └── b.jar │ │ │ └── c │ │ │ │ ├── META-INF │ │ │ │ ├── MANIFEST.MF │ │ │ │ └── smithy │ │ │ │ │ ├── c.smithy │ │ │ │ │ └── manifest │ │ │ │ └── c.jar │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json │ ├── scala-project │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ ├── smithy-build.json │ │ └── src │ │ │ └── main │ │ │ └── scala │ │ │ └── example │ │ │ └── Main.scala │ └── source-projection │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── model │ │ └── main.smithy │ │ ├── settings.gradle.kts │ │ └── smithy-build.json └── trait-package-plugin │ ├── create-simple-trait │ ├── README.md │ ├── build.gradle.kts │ ├── model │ │ └── custom-trait.smithy │ ├── settings.gradle.kts │ └── smithy-build.json │ └── use-with-existing-trait │ ├── README.md │ ├── build.gradle.kts │ ├── model │ └── custom-trait.smithy │ ├── settings.gradle.kts │ ├── smithy-build.json │ └── src │ └── main │ ├── java │ └── io │ │ └── smithy │ │ └── gradle │ │ └── examples │ │ └── traits │ │ └── JsonNameTrait.java │ └── resources │ └── META-INF │ └── services │ └── software.amazon.smithy.model.traits.TraitService ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── integ-test-utils ├── build.gradle.kts └── src │ └── main │ └── java │ └── software │ └── amazon │ └── smithy │ └── gradle │ └── Utils.java ├── settings.gradle.kts ├── smithy-base ├── build.gradle.kts └── src │ ├── it │ └── java │ │ └── software │ │ └── amazon │ │ └── smithy │ │ └── gradle │ │ ├── ConflictingOutputDirectoriesTest.java │ │ ├── ForbidDependencyResolutionTest.java │ │ ├── ForbidImplicitNoBuildConfigTest.java │ │ ├── IncludesInSourceSetTest.java │ │ ├── OutputDirectoryConfigTest.java │ │ ├── OutputDirectoryTest.java │ │ ├── OutputDirectoryWithProjectionTest.java │ │ ├── ScansForCliVersionTest.java │ │ ├── SelectTaskTest.java │ │ ├── SmithyBuildTaskTest.java │ │ ├── SyntaxErrorTest.java │ │ └── UsesExplicitlySetCLIVersionTest.java │ ├── main │ ├── java │ │ └── software │ │ │ └── amazon │ │ │ └── smithy │ │ │ └── gradle │ │ │ ├── SmithyBasePlugin.java │ │ │ ├── SmithyExtension.java │ │ │ ├── SmithyGradleVersion.java │ │ │ ├── SmithySourceDirectorySet.java │ │ │ ├── SmithyUtils.java │ │ │ ├── internal │ │ │ ├── CliDependencyResolver.java │ │ │ └── DefaultSmithySourceDirectorySet.java │ │ │ └── tasks │ │ │ ├── AbstractSmithyCliTask.java │ │ │ ├── SmithyBuildTask.java │ │ │ ├── SmithyFormatTask.java │ │ │ ├── SmithySelectTask.java │ │ │ └── SmithyValidateTask.java │ └── resources │ │ └── software │ │ └── amazon │ │ └── smithy │ │ └── gradle │ │ ├── empty │ │ └── version.properties │ └── test │ └── java │ └── software │ └── amazon │ └── smithy │ └── gradle │ ├── SmithyExtensionTest.java │ ├── SmithyGradleVersionTest.java │ └── tasks │ ├── SmithyBuildTaskTest.java │ └── SmithyFormatTaskTest.java ├── smithy-jar ├── build.gradle.kts └── src │ ├── it │ └── java │ │ └── software │ │ └── amazon │ │ └── smithy │ │ └── gradle │ │ ├── AddsTagsTest.java │ │ ├── BuildDependenciesTest.java │ │ ├── CustomTraitTest.java │ │ ├── DisableJarTest.java │ │ ├── InvalidProjectionTest.java │ │ ├── KotlinJvmProjectTest.java │ │ ├── MissingRuntimeDependencyTest.java │ │ ├── MultiProjectTest.java │ │ ├── MultipleJarsTest.java │ │ ├── MultipleSourcesTest.java │ │ ├── NoModelsTest.java │ │ ├── ProjectionTest.java │ │ ├── ProjectsWithTagsTest.java │ │ ├── ScalaProjectTest.java │ │ └── SourceProjectionTest.java │ ├── main │ └── java │ │ └── software │ │ └── amazon │ │ └── smithy │ │ └── gradle │ │ ├── SmithyJarPlugin.java │ │ ├── actions │ │ └── SmithyManifestUpdateAction.java │ │ └── tasks │ │ └── SmithyJarStagingTask.java │ └── test │ └── java │ └── software │ └── amazon │ └── smithy │ └── gradle │ └── tasks │ ├── SmithyJarStagingTaskTest.java │ └── SmithyValidateTaskTest.java ├── smithy-templates.json └── smithy-trait-package ├── build.gradle.kts └── src ├── it └── java │ └── software │ └── amazon │ └── smithy │ └── gradle │ ├── CreatesCustomTraitTest.java │ └── RespectsManualTraitTest.java └── main └── java └── software └── amazon └── smithy └── gradle ├── SmithyTraitPackagePlugin.java └── tasks └── MergeSpiFilesTask.java /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Add core contributors to all prs by default 2 | * @smithy-lang/smithy 3 | 4 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | #### Background 2 | * What do these changes do? 3 | * Why are they important? 4 | 5 | #### Testing 6 | * How did you test these changes? 7 | 8 | #### Links 9 | * Links to additional context, if necessary 10 | * Issue #, if applicable (see [here](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) for a list of keywords to use for linking issues) 11 | 12 | --- 13 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 14 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | build: 11 | runs-on: ${{ matrix.os }} 12 | name: Java ${{ matrix.java }} ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | java: [17] 16 | os: [ubuntu-latest, windows-latest] 17 | 18 | steps: 19 | - name: Checkout smithy-gradle-plugin 20 | uses: actions/checkout@v2 21 | with: 22 | path: smithy-gradle-plugin 23 | 24 | # We checkout smithy main here since we will often require changes that 25 | # have not yet been released but have been merged. 26 | - name: Checkout smithy main branch 27 | uses: actions/checkout@v2 28 | with: 29 | repository: awslabs/smithy 30 | path: smithy 31 | 32 | - name: Set up JDK ${{ matrix.java }} 33 | uses: actions/setup-java@v1 34 | with: 35 | java-version: ${{ matrix.java }} 36 | 37 | - name: Publish smithy main to maven local 38 | run: | 39 | cd smithy 40 | ./gradlew clean publishToMavenLocal 41 | 42 | - name: Clean and build smithy-gradle-plugin 43 | run: | 44 | cd smithy-gradle-plugin 45 | ./gradlew clean publishToMavenLocal 46 | ./gradlew -g $PWD build -Plog-tests 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse 2 | .classpath 3 | .project 4 | .settings/ 5 | 6 | # Intellij 7 | .idea/ 8 | *.iml 9 | *.iws 10 | 11 | # Mac 12 | .DS_Store 13 | 14 | # Ignore Gradle project-specific cache directory 15 | .gradle 16 | 17 | # Ignore Gradle build output directory 18 | build 19 | out/ 20 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/awslabs/smithy-gradle-plugin/issues), or [recently closed](https://github.com/awslabs/smithy-gradle-plugin/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/smithy-gradle-plugin/labels/help%20wanted) issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](https://github.com/awslabs/smithy-gradle-plugin/blob/main/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Smithy Gradle Plugin 2 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.2.0 2 | -------------------------------------------------------------------------------- /bin/sync-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | EXPECTED_VERSION=$(cat VERSION) 4 | 5 | # find all gradle build files and replace the existing version with the expected 6 | find . -type f -name 'build.gradle.kts' \ 7 | -exec sed -i '' "s/\(id(\"software\.amazon\.smithy\.gradle\.smithy\([[:graph:]]*\)\")\.version(\"\)\([[:digit:]\.]*\)\")/\\1${EXPECTED_VERSION}\")/" {} \; 8 | 9 | # update all references to the version in READMEs 10 | find . -type f -name 'README.md' \ 11 | -exec sed -i '' "s/\(id(\"software\.amazon\.smithy\.gradle\.smithy\([[:graph:]]*\)\")\.version(\"\)\([[:digit:]\.]*\)\")/\\1${EXPECTED_VERSION}\")/" {} \; 12 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 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 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | import org.jreleaser.model.Active 17 | 18 | plugins { 19 | base 20 | id("org.jreleaser") version "1.17.0" 21 | } 22 | 23 | val pluginVersion = project.file("VERSION").readText().replace(System.lineSeparator(), "") 24 | allprojects { 25 | group = "software.amazon.smithy.gradle" 26 | version = pluginVersion 27 | } 28 | println("Smithy Gradle version: '${pluginVersion}'") 29 | 30 | /* 31 | * Jreleaser (https://jreleaser.org) config. 32 | */ 33 | jreleaser { 34 | dryrun = false 35 | 36 | // Used for creating a tagged release, uploading files and generating changelog. 37 | // In the future we can set this up to push release tags to GitHub, but for now it's 38 | // set up to do nothing. 39 | // https://jreleaser.org/guide/latest/reference/release/index.html 40 | release { 41 | generic { 42 | enabled = true 43 | skipRelease = true 44 | } 45 | } 46 | 47 | // Used to announce a release to configured announcers. 48 | // https://jreleaser.org/guide/latest/reference/announce/index.html 49 | announce { 50 | active = Active.NEVER 51 | } 52 | 53 | // Signing configuration. 54 | // https://jreleaser.org/guide/latest/reference/signing.html 55 | signing { 56 | active = Active.ALWAYS 57 | armored = true 58 | } 59 | 60 | // Configuration for deploying to Maven Central. 61 | // https://jreleaser.org/guide/latest/examples/maven/maven-central.html#_gradle 62 | deploy { 63 | maven { 64 | mavenCentral { 65 | create("maven-central") { 66 | active = Active.ALWAYS 67 | url = "https://central.sonatype.com/api/v1/publisher" 68 | stagingRepositories.add("${rootProject.buildDir}/staging") 69 | } 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | // Support convention plugins written in Kotlin. Convention plugins are 3 | // build scripts in 'src/main' that automatically become available as 4 | // plugins in the main build. 5 | `kotlin-dsl` 6 | } 7 | 8 | repositories { 9 | // Use the plugin portal to apply community plugins in convention plugins. 10 | gradlePluginPortal() 11 | } 12 | 13 | dependencies { 14 | // Java convention dependencies 15 | implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.6") 16 | implementation("com.adarshr:gradle-test-logger-plugin:4.0.0") 17 | 18 | // Plugin convention dependencies 19 | implementation("com.gradle.publish:plugin-publish-plugin:1.3.1") 20 | } 21 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/smithy-gradle-plugin.java-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | 2 | plugins { 3 | `java-library` 4 | checkstyle 5 | } 6 | 7 | java { 8 | sourceCompatibility = JavaVersion.VERSION_1_8 9 | targetCompatibility = JavaVersion.VERSION_1_8 10 | } 11 | 12 | dependencies { 13 | implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") 14 | implementation("software.amazon.smithy:smithy-build:[1.0, 2.0[") 15 | implementation("software.amazon.smithy:smithy-cli:[1.0, 2.0[") 16 | } 17 | 18 | //// ==== Licensing ===== 19 | // Reusable license copySpec 20 | val licenseSpec = copySpec { 21 | from("${project.rootDir}/LICENSE") 22 | from("${project.rootDir}/NOTICE") 23 | } 24 | 25 | // Configure all jars to include license info 26 | tasks.withType() { 27 | metaInf.with(licenseSpec) 28 | } 29 | 30 | 31 | 32 | // Suppress warnings in javadocs 33 | tasks.withType { 34 | (options as StandardJavadocDocletOptions).addStringOption("Xdoclint:-html", "-quiet") 35 | } 36 | 37 | /* 38 | * CheckStyle 39 | * ==================================================== 40 | * 41 | * Apply CheckStyle to source files but not tests. 42 | */ 43 | tasks["checkstyleTest"].enabled = false 44 | 45 | /* 46 | * Repositories 47 | * ==================================================== 48 | */ 49 | repositories { 50 | mavenLocal() 51 | mavenCentral() 52 | } 53 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/smithy-gradle-plugin.plugin-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.spotbugs.snom.Effort 2 | 3 | plugins { 4 | id("smithy-gradle-plugin.java-conventions") 5 | `java-gradle-plugin` 6 | id("com.gradle.plugin-publish") 7 | jacoco 8 | id("com.adarshr.test-logger") 9 | id("com.github.spotbugs") 10 | } 11 | 12 | /* 13 | * Common plugin settings 14 | * ==================================================== 15 | */ 16 | gradlePlugin { 17 | website.set("https://smithy.io") 18 | vcsUrl.set("https://github.com/smithy-lang/smithy-gradle-plugin") 19 | } 20 | 21 | /* 22 | * Staging repository 23 | * ==================================================== 24 | * 25 | * Configure publication to staging repo for jreleaser 26 | */ 27 | publishing { 28 | repositories { 29 | maven { 30 | name = "stagingRepository" 31 | url = uri("${rootProject.buildDir}/staging") 32 | } 33 | } 34 | // Add license spec to all maven publications 35 | publications.withType() { 36 | project.afterEvaluate { 37 | pom { 38 | name.set(project.name) 39 | description.set(project.description) 40 | url.set("https://github.com/smithy-lang/smithy-gradle-plugin") 41 | licenses { 42 | license { 43 | name.set("Apache License 2.0") 44 | url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") 45 | distribution.set("repo") 46 | } 47 | } 48 | developers { 49 | developer { 50 | id.set("smithy") 51 | name.set("Smithy") 52 | organization.set("Amazon Web Services") 53 | organizationUrl.set("https://aws.amazon.com") 54 | roles.add("developer") 55 | } 56 | } 57 | scm { 58 | url.set("https://github.com/smithy-lang/smithy-gradle-plugin.git") 59 | } 60 | } 61 | } 62 | } 63 | } 64 | 65 | /* 66 | * Unit tests 67 | * ==================================================== 68 | */ 69 | dependencies { 70 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.0") 71 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.0") 72 | testImplementation("org.junit.jupiter:junit-jupiter-params:5.4.0") 73 | testImplementation("org.hamcrest:hamcrest:2.1") 74 | testImplementation(project(":integ-test-utils")) 75 | } 76 | 77 | // Use Junit5's test runner. 78 | tasks.withType { 79 | useJUnitPlatform() 80 | } 81 | 82 | testlogger { 83 | showExceptions = true 84 | showStackTraces = true 85 | showFullStackTraces = false 86 | showCauses = true 87 | showSummary = true 88 | showPassed = true 89 | showSkipped = true 90 | showFailed = true 91 | showOnlySlow = false 92 | showStandardStreams = true 93 | showPassedStandardStreams = false 94 | showSkippedStandardStreams = false 95 | showFailedStandardStreams = true 96 | logLevel = LogLevel.LIFECYCLE 97 | } 98 | 99 | /* 100 | * Configure integration tests 101 | * ==================================================== 102 | */ 103 | sourceSets { 104 | create("it") { 105 | compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"] 106 | runtimeClasspath += output + compileClasspath + sourceSets["test"].runtimeClasspath 107 | } 108 | } 109 | // Disable spotbugs and checkstyle for integration tests 110 | tasks["spotbugsIt"].enabled = false 111 | tasks["checkstyleIt"].enabled = false 112 | 113 | 114 | tasks.register("integTest") { 115 | useJUnitPlatform() 116 | testClassesDirs = sourceSets["it"].output.classesDirs 117 | classpath = sourceSets["it"].runtimeClasspath 118 | maxParallelForks = Runtime.getRuntime().availableProcessors() / 2 119 | } 120 | 121 | afterEvaluate { 122 | tasks["integTest"].dependsOn("publishToMavenLocal") 123 | 124 | // Always run javadoc and integration tests after build. 125 | tasks["assemble"].dependsOn("javadoc") 126 | tasks["build"].finalizedBy(tasks["integTest"]) 127 | } 128 | 129 | /* 130 | * Code coverage 131 | * ==================================================== 132 | * 133 | * Create code coverage reports after running tests. 134 | */ 135 | // Always run the jacoco test report after testing. 136 | tasks["test"].finalizedBy(tasks["jacocoTestReport"]) 137 | // Configure jacoco to generate an HTML report. 138 | tasks.jacocoTestReport { 139 | reports { 140 | xml.required.set(false) 141 | csv.required.set(false) 142 | html.outputLocation.set(file("$buildDir/reports/jacoco")) 143 | } 144 | } 145 | 146 | /* 147 | * Spotbugs 148 | * ==================================================== 149 | * 150 | * Run spotbugs against source files and configure suppressions. 151 | */ 152 | // Configure the spotbugs extension. 153 | spotbugs { 154 | effort = Effort.MAX 155 | excludeFilter = file("${project.rootDir}/config/spotbugs/filter.xml") 156 | } 157 | 158 | // We don't need to lint tests. 159 | tasks["spotbugsTest"].enabled = false 160 | 161 | -------------------------------------------------------------------------------- /config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /config/spotbugs/filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/conflicting-output-dir-configs/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example attempts to set the output directory multiple times 2 | // in different smithy-build.json files. The build will fail. 3 | 4 | plugins { 5 | `java-library` 6 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 7 | } 8 | 9 | repositories { 10 | mavenLocal() 11 | mavenCentral() 12 | } 13 | 14 | dependencies { 15 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 16 | } 17 | 18 | smithy { 19 | smithyBuildConfigs.set(files("smithy-build.json", "smithy-build-conflicting.json")) 20 | format.set(false) 21 | } 22 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/conflicting-output-dir-configs/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Bar {} 9 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/conflicting-output-dir-configs/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "conflicting-output-dirs" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/conflicting-output-dir-configs/smithy-build-conflicting.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "outputDirectory": "build/nested-output-directory-other", 4 | "projections": { 5 | "foo": {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/conflicting-output-dir-configs/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "outputDirectory": "build/nested-output-directory", 4 | "projections": { 5 | "foo": {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-fork/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example tries to use dependencies within the smithy-build.json file. 2 | // The fork setting is also set to true which will spawn a new process to execute 3 | // the smithy cli commands. The build will fail. 4 | 5 | plugins { 6 | `java-library` 7 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 17 | } 18 | 19 | smithy { 20 | fork.set(true) 21 | format.set(false) 22 | } -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-fork/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Bar { 9 | } 10 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-fork/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "forbid-dependency-resolution" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-fork/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "maven": { 4 | "dependencies": [ 5 | "software.amazon.smithy:smithy-aws-traits:[1.0,2.0)" 6 | ] 7 | }, 8 | "projections": { 9 | "foo": {} 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-no-fork/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example tries to use dependencies within the smithy-build.json file. 2 | // The build will fail. 3 | 4 | plugins { 5 | `java-library` 6 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 7 | } 8 | 9 | repositories { 10 | mavenLocal() 11 | mavenCentral() 12 | } 13 | 14 | dependencies { 15 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 16 | } 17 | 18 | smithy { 19 | format.set(false) 20 | } 21 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-no-fork/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Bar { 9 | } 10 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-no-fork/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "forbid-dependency-resolution" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-dependency-resolution-no-fork/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "maven": { 4 | "dependencies": [ 5 | "software.amazon.smithy:smithy-aws-traits:[1.0,2.0)" 6 | ] 7 | }, 8 | "projections": { 9 | "foo": {} 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-implicit-no-build-config/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 4 | } 5 | 6 | repositories { 7 | mavenLocal() 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 13 | } 14 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-implicit-no-build-config/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Bar { 9 | } 10 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/forbid-implicit-no-build-config/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "forbid-dependency-resolution" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/syntax-error/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example fails to build due to a syntax error. 2 | 3 | plugins { 4 | id("java-library") 5 | id("smith-base").version("0.7.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | smithy { 14 | format.set(false) 15 | } -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/syntax-error/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | error!!!! 4 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/syntax-error/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "syntax-error" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/base-plugin/failure-cases/syntax-error/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/base-plugin/includes-in-sourceset/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Include Additional Sources In SourceSet 2 | This is an example Gradle Smithy project. In addition to serving as documentation, 3 | this project is run as an integration test for the plugin. 4 | 5 | This project demonstrates the inclusion of additional source directories in the 6 | `smithy` [sourceSet](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSet.html). 7 | Smithy files within the sourceSet will be used as model sources for the `smithyBuild` task. 8 | 9 | ## Using the example as a starting point 10 | 11 | Since this sample is run as an integration test, by default it is only configured 12 | to use a locally published version of the plugin. To use this as a starting point 13 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 14 | Gradle to use public sources. 15 | 16 | -------------------------------------------------------------------------------- /examples/base-plugin/includes-in-sourceset/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example adds additional files to the main smithy source set. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 6 | } 7 | 8 | sourceSets { 9 | main { 10 | smithy { 11 | srcDir("includes/") 12 | } 13 | } 14 | } 15 | 16 | repositories { 17 | mavenLocal() 18 | mavenCentral() 19 | } 20 | -------------------------------------------------------------------------------- /examples/base-plugin/includes-in-sourceset/includes/also-included.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace com.example.included 4 | 5 | string IncludedStringShape 6 | -------------------------------------------------------------------------------- /examples/base-plugin/includes-in-sourceset/includes/included.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace com.example.included 4 | 5 | structure MyIncludedStructure { 6 | fieldA: IncludedStringShape 7 | fieldB: FieldB 8 | } 9 | 10 | string FieldB 11 | -------------------------------------------------------------------------------- /examples/base-plugin/includes-in-sourceset/model/main.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace smithy.example 4 | 5 | use com.example.included#MyIncludedStructure 6 | 7 | structure Example { 8 | foo: String 9 | bar: MyIncludedStructure 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/includes-in-sourceset/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "includes-in-sourceset" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/includes-in-sourceset/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-config/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Custom Output Directory 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates how to write the built Smithy models to a custom output 7 | directory using the `outputDirectory` property of the `smithy-build` config 8 | 9 | **Note**: Setting the output directory via the `smithy` gradle plugin extension will 10 | override any output Directory settings in provided smithy-build configs. 11 | 12 | ## Using the example as a starting point 13 | 14 | Since this sample is run as an integration test, by default it is only configured 15 | to use a locally published version of the plugin. To use this as a starting point 16 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 17 | Gradle to use public sources. 18 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-config/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example writes Smithy build artifacts to a specified directory. The 2 | // directory is specified in the smithy-build.json file rather than in the 3 | // gradle build files. 4 | 5 | plugins { 6 | id("java-library") 7 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 17 | } 18 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-config/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Foo {} 9 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-config/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "output-directory-config" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-config/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "outputDirectory": "build/nested-output-directory", 4 | "projections": {} 5 | } 6 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-with-projection/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Output Directory with Projection 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates setting a custom output directory and a custom projection. 7 | 8 | ## Using the example as a starting point 9 | 10 | Since this sample is run as an integration test, by default it is only configured 11 | to use a locally published version of the plugin. To use this as a starting point 12 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 13 | Gradle to use public sources. 14 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-with-projection/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example writes Smithy build artifacts to a specified directory and 2 | // generates a projected version of the model. 3 | 4 | plugins { 5 | id("java-library") 6 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 7 | } 8 | 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | // This dependency is used in the projected model, so it's requird here too. 17 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 18 | } 19 | 20 | smithy { 21 | sourceProjection.set("foo") 22 | 23 | // This could also be set to another directory outside the project's buildDir entirely. 24 | outputDirectory.set(file(project.getBuildDir().toPath().resolve("nested-output-directory").toFile())) 25 | } 26 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-with-projection/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Foo {} 9 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-with-projection/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "projection" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory-with-projection/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Custom Output Directory 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates how to write the built Smithy models to a custom output 7 | directory. 8 | 9 | ## Using the example as a starting point 10 | 11 | Since this sample is run as an integration test, by default it is only configured 12 | to use a locally published version of the plugin. To use this as a starting point 13 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 14 | Gradle to use public sources. 15 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example writes Smithy build artifacts to a specified directory. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | // This dependency is used in the projected model, so it's required here too. 15 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 16 | } 17 | 18 | smithy { 19 | // This could also be set to another directory outside the project's buildDir entirely. 20 | outputDirectory.set(file(project.getBuildDir().toPath().resolve("nested-output-directory").toFile())) 21 | } 22 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Foo {} 9 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "projection" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/output-directory/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": {} 4 | } 5 | -------------------------------------------------------------------------------- /examples/base-plugin/scans-for-cli-version/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Build Script Dependency 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates using the version of Smithy found in the build script 7 | dependencies to build the project. 8 | 9 | ## Using the example as a starting point 10 | 11 | Since this sample is run as an integration test, by default it is only configured 12 | to use a locally published version of the plugin. To use this as a starting point 13 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 14 | Gradle to use public sources. 15 | -------------------------------------------------------------------------------- /examples/base-plugin/scans-for-cli-version/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example is an integration test to ensure that the smithy-cli version can be 2 | // found by scanning buildScript dependencies. 3 | 4 | plugins { 5 | id("java-library") 6 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 7 | } 8 | 9 | repositories { 10 | mavenLocal() 11 | mavenCentral() 12 | } 13 | -------------------------------------------------------------------------------- /examples/base-plugin/scans-for-cli-version/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | bar: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/base-plugin/scans-for-cli-version/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "scans-for-cli-version" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/scans-for-cli-version/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/base-plugin/smithy-build-task/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Custom Smithy Build Task 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example builds Smithy models using a custom build task and disables the default 7 | `smithyBuild` task. This allows for a more granular level of control of when the 8 | build runs, as well as the classpath used when building. 9 | 10 | ## Using the example as a starting point 11 | 12 | Since this sample is run as an integration test, by default it is only configured 13 | to use a locally published version of the plugin. To use this as a starting point 14 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 15 | Gradle to use public sources. 16 | -------------------------------------------------------------------------------- /examples/base-plugin/smithy-build-task/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import software.amazon.smithy.gradle.tasks.SmithyBuildTask 2 | 3 | // This example builds Smithy models using a custom build task 4 | // and disables the default "smithyBuildJar" task. This allows 5 | // for a more granular level of control in when the build runs 6 | // and the classpath used when building. 7 | 8 | plugins { 9 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 10 | } 11 | 12 | val doIt = tasks.register("doit") { 13 | models.set(files("model/")) 14 | smithyBuildConfigs.set(files("smithy-build.json")) 15 | } 16 | 17 | tasks["build"].finalizedBy(doIt) 18 | 19 | tasks.register("copyOutput") { 20 | into(layout.buildDirectory.dir("model")) 21 | from(doIt.map { it.getPluginProjectionDirectory("source", "model") }) 22 | } 23 | 24 | repositories { 25 | mavenLocal() 26 | mavenCentral() 27 | } 28 | -------------------------------------------------------------------------------- /examples/base-plugin/smithy-build-task/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Example { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/base-plugin/smithy-build-task/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "smithy-build-task" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/smithy-build-task/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | // A comment. 3 | "version": "1.0" 4 | } 5 | -------------------------------------------------------------------------------- /examples/base-plugin/uses-explicitly-set-cli-version/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Explicit CLI Dependency 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates setting a specific version of the smithy CLI 7 | to use when executing the CLI for other tasks. 8 | 9 | ## Using the example as a starting point 10 | 11 | Since this sample is run as an integration test, by default it is only configured 12 | to use a locally published version of the plugin. To use this as a starting point 13 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 14 | Gradle to use public sources. 15 | -------------------------------------------------------------------------------- /examples/base-plugin/uses-explicitly-set-cli-version/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example is an integration test to ensure that the smithy-cli version can be 2 | // found by scanning buildScript dependencies. 3 | 4 | plugins { 5 | id("java-library") 6 | id("software.amazon.smithy.gradle.smithy-base").version("1.2.0") 7 | } 8 | 9 | dependencies { 10 | smithyCli("software.amazon.smithy:smithy-cli:1.45.0") 11 | } 12 | 13 | repositories { 14 | mavenLocal() 15 | mavenCentral() 16 | } 17 | -------------------------------------------------------------------------------- /examples/base-plugin/uses-explicitly-set-cli-version/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | /// a string member 5 | bar: String 6 | } 7 | -------------------------------------------------------------------------------- /examples/base-plugin/uses-explicitly-set-cli-version/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "scans-for-cli-version" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/base-plugin/uses-explicitly-set-cli-version/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/adds-tags/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Adding Tags 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates how you can add custom tags to your JAR that allow 7 | projections to search for the JAR by tag and include it as a projection source. 8 | 9 | ## Using the example as a starting point 10 | 11 | Since this sample is run as an integration test, by default it is only configured 12 | to use a locally published version of the plugin. To use this as a starting point 13 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 14 | Gradle to use public sources. 15 | 16 | ## See Also 17 | 18 | [Projection tags](https://smithy.io/2.0/guides/building-models/gradle-plugin.html#projection-tags) 19 | -------------------------------------------------------------------------------- /examples/jar-plugin/adds-tags/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example adds a Smithy tag to the built JAR. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | group = "software.amazon.smithy" 9 | version = "9.9.9" 10 | 11 | repositories { 12 | mavenLocal() 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") 18 | } 19 | 20 | smithy { 21 | // You can add custom tags to your JAR that allow projections to search 22 | // for this JAR by tag and include this JAR as a projection source. 23 | tags.addAll("Foo", "Baz") 24 | } 25 | -------------------------------------------------------------------------------- /examples/jar-plugin/adds-tags/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/adds-tags/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "adds-tags" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/adds-tags/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Build Dependencies 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This project demonstrates the use of smithy build dependencies to specify dependencies 7 | that will only be used for calling smithy build but will not be included in any generated 8 | jars. 9 | 10 | ## Using the example as a starting point 11 | 12 | Since this sample is run as an integration test, by default it is only configured 13 | to use a locally published version of the plugin. To use this as a starting point 14 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 15 | Gradle to use public sources. 16 | 17 | ## See Also 18 | 19 | [Generating a projection](https://smithy.io/2.0/guides/building-models/gradle-plugin.html#generating-a-projection) 20 | 21 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/internal-model/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example builds the model and places it in the JAR. 2 | 3 | plugins { 4 | `java-library` 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | smithy { 14 | tags.addAll("Foo", "com.baz:bar") 15 | } 16 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/internal-model/model/internal.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace smithy.example.internal 4 | 5 | @internal 6 | structure InternalStructure { 7 | field: String 8 | } 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/internal-model/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/service/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example builds the model and places it in the JAR. 2 | 3 | plugins { 4 | `java-library` 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | smithyBuild(project(":internal-model")) 15 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 16 | } 17 | 18 | smithy { 19 | sourceProjection.set("external") 20 | projectionSourceTags.addAll("Foo", "com.baz:bar") 21 | } 22 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/service/model/main.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace smithy.example 4 | 5 | use smithy.example.internal#InternalStructure 6 | 7 | structure Baz { 8 | foo: String 9 | bar: InternalStructure 10 | } 11 | 12 | @aws.auth#unsignedPayload 13 | operation Foo {} 14 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/service/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "external": { 5 | "transforms": [ 6 | { 7 | "name": "excludeShapesByTrait", 8 | "args": { 9 | "traits": [ 10 | "internal" 11 | ] 12 | } 13 | } 14 | ] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/jar-plugin/build-dependencies/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "build-dependencies" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | 12 | include(":service") 13 | include(":internal-model") 14 | -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Custom traits 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This project demonstrates the use of the `smithy-jar` gradle plugin for packaging 7 | Smithy trait definitions in a JAR alongside the Java definitions of those same custom 8 | traits. 9 | 10 | ## Using the example as a starting point 11 | 12 | Since this sample is run as an integration test, by default it is only configured 13 | to use a locally published version of the plugin. To use this as a starting point 14 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 15 | Gradle to use public sources. 16 | 17 | -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/consumer/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 4 | } 5 | 6 | 7 | // This test project doesn't produce a JAR. 8 | tasks["jar"].enabled = false 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation(project(":custom-string-trait")) 17 | } 18 | 19 | smithy { 20 | smithyBuildConfigs.set(project.files()) 21 | } 22 | -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/consumer/model/main.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace example 4 | 5 | use io.smithy.example#jsonName 6 | 7 | structure MyStructure { 8 | @jsonName("TESTING") 9 | myMember: String 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/custom-string-trait/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This package defines a custom trait for use in other models 2 | plugins { 3 | id("java-library") 4 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 5 | } 6 | 7 | repositories { 8 | mavenLocal() 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") 14 | } 15 | -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/custom-string-trait/model/custom-trait.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace io.smithy.example 4 | 5 | @trait(selector: "member") 6 | string jsonName 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/custom-string-trait/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/custom-string-trait/src/main/java/io/smithy/examples/traits/JsonNameTrait.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: MIT-0 4 | */ 5 | 6 | package io.smithy.examples.traits; 7 | 8 | import software.amazon.smithy.model.FromSourceLocation; 9 | import software.amazon.smithy.model.SourceLocation; 10 | import software.amazon.smithy.model.shapes.ShapeId; 11 | import software.amazon.smithy.model.traits.StringTrait; 12 | 13 | public final class JsonNameTrait extends StringTrait { 14 | 15 | public static final ShapeId ID = ShapeId.from("io.smithy.example#jsonName"); 16 | 17 | private JsonNameTrait(String name) { 18 | super(ID, name, SourceLocation.NONE); 19 | } 20 | 21 | private JsonNameTrait(String name, FromSourceLocation sourceLocation) { 22 | super(ID, name, sourceLocation); 23 | } 24 | 25 | public static final class Provider extends StringTrait.Provider { 26 | public Provider() { 27 | super(ID, JsonNameTrait::new); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/custom-string-trait/src/main/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService: -------------------------------------------------------------------------------- 1 | io.smithy.examples.traits.JsonNameTrait$Provider -------------------------------------------------------------------------------- /examples/jar-plugin/custom-trait/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "custom-string-trait" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | 12 | include("custom-string-trait") 13 | include("consumer") 14 | -------------------------------------------------------------------------------- /examples/jar-plugin/disable-jar/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Disable JAR 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates how you can build a project that does not create a JAR. 7 | 8 | ## Using the example as a starting point 9 | 10 | Since this sample is run as an integration test, by default it is only configured 11 | to use a locally published version of the plugin. To use this as a starting point 12 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 13 | Gradle to use public sources. 14 | -------------------------------------------------------------------------------- /examples/jar-plugin/disable-jar/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example builds Smithy models but does not create a JAR. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") 15 | } 16 | 17 | tasks["jar"].enabled = false 18 | -------------------------------------------------------------------------------- /examples/jar-plugin/disable-jar/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Example { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/disable-jar/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "disable-jar" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/disable-jar/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/invalid-projection/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example attempts to use an invalid projection. The build will fail. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") 15 | } 16 | 17 | smithy { 18 | sourceProjection.set("invalid") 19 | format.set(false) 20 | } 21 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/invalid-projection/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/invalid-projection/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "projection" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/invalid-projection/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/missing-runtime-dependency/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example creates a projected version of the model, but because the 2 | // projected model references traits from another package and that package 3 | // is not part of the runtime dependencies, the build will fail when the 4 | // plugin validates the JAR with Smithy model discovery. 5 | 6 | plugins { 7 | id("java-library") 8 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 9 | } 10 | 11 | repositories { 12 | mavenLocal() 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | smithyBuild("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 18 | 19 | // This dependency is used in the projected model, so it's required here too. 20 | // This should fail to build since this is missing. 21 | //implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 22 | } 23 | 24 | smithy { 25 | sourceProjection.set("foo") 26 | format.set(false) 27 | } 28 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/missing-runtime-dependency/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Foo {} 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/missing-runtime-dependency/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "projection" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/missing-runtime-dependency/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/require-prerequisite-plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example attempts to use the smithy-jar plugin without a required 2 | // prerequisite plugin. The build will fail. 3 | 4 | plugins { 5 | id("software.amazon.smithy-jar").version("0.8.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/require-prerequisite-plugin/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Foo { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Bar { 9 | } 10 | -------------------------------------------------------------------------------- /examples/jar-plugin/failure-cases/require-prerequisite-plugin/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "require-prerequisite-pluing" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/kotlin-jvm-project/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Kotlin JVM Project 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This project demonstrates using the Smithy Gradle Plugin with a Kotlin project. 7 | The Jar created by the Kotlin JVM plugin will include the Smithy models built by the 8 | `smithyBuild` task. 9 | 10 | ## Using the example as a starting point 11 | 12 | Since this sample is run as an integration test, by default it is only configured 13 | to use a locally published version of the plugin. To use this as a starting point 14 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 15 | Gradle to use public sources. 16 | 17 | -------------------------------------------------------------------------------- /examples/jar-plugin/kotlin-jvm-project/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This project adds smithy models to a JAR created by a Kotlin project 2 | 3 | plugins { 4 | kotlin("jvm") version "1.9.23" 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | -------------------------------------------------------------------------------- /examples/jar-plugin/kotlin-jvm-project/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/kotlin-jvm-project/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "kotlin-jvm-project" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | gradlePluginPortal() 7 | mavenCentral() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/jar-plugin/kotlin-jvm-project/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/kotlin-jvm-project/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | fun main(args: Array) { 2 | println("Hello World!") 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Trait Dependencies 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates how you can use dependencies in your model. In particular, 7 | it demonstrates the definition and usage of two custom traits in separate packages. 8 | It also showcases the usage of the plugin with sub-projects. 9 | 10 | ## Using the example as a starting point 11 | 12 | Since this sample is run as an integration test, by default it is only configured 13 | to use a locally published version of the plugin. To use this as a starting point 14 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 15 | Gradle to use public sources. 16 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example demonstrates the use of the smithy-jar Gradle plugin 2 | // with a project that has multiple subprojects that depend on each other. 3 | 4 | plugins { 5 | `java-library` 6 | } 7 | 8 | allprojects { 9 | group = "software.amazon.smithy.it" 10 | version = "999.999.999" 11 | } 12 | 13 | tasks["jar"].enabled = false 14 | 15 | subprojects { 16 | apply(plugin = "java-library") 17 | 18 | java { 19 | sourceCompatibility = JavaVersion.VERSION_1_8 20 | targetCompatibility = JavaVersion.VERSION_1_8 21 | } 22 | 23 | repositories { 24 | mavenLocal() 25 | mavenCentral() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/consumer/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 3 | } 4 | 5 | dependencies { 6 | implementation(project(":producer1")) 7 | implementation(project(":producer2")) 8 | } 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/consumer/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.consumer 2 | 3 | use smithy.producer#producer1 4 | use smithy.producer#producer2 5 | 6 | @producer1 7 | @producer2 8 | structure Foo {} 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/consumer/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.parallel=true 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer1/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | } 4 | 5 | dependencies { 6 | api("software.amazon.smithy:smithy-model:[1.0, 2.0[") 7 | } 8 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer1/src/main/java/software/amazon/smithy/producer1/Producer1Trait.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.producer1; 2 | 3 | import software.amazon.smithy.model.node.Node; 4 | import software.amazon.smithy.model.node.ObjectNode; 5 | import software.amazon.smithy.model.shapes.ShapeId; 6 | import software.amazon.smithy.model.traits.AnnotationTrait; 7 | 8 | public final class Producer1Trait extends AnnotationTrait { 9 | public static final ShapeId ID = ShapeId.from("smithy.producer#producer1"); 10 | 11 | public Producer1Trait(ObjectNode objectNode) { 12 | super(ID, objectNode); 13 | } 14 | 15 | public Producer1Trait() { 16 | this(Node.objectNode()); 17 | } 18 | 19 | public static final class Provider extends AnnotationTrait.Provider { 20 | public Provider() { 21 | super(ID, Producer1Trait::new); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer1/src/main/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService: -------------------------------------------------------------------------------- 1 | software.amazon.smithy.producer1.Producer1Trait$Provider 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer1/src/main/resources/META-INF/smithy/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.producer 2 | 3 | @trait(selector: "*") 4 | structure producer1 {} 5 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer1/src/main/resources/META-INF/smithy/manifest: -------------------------------------------------------------------------------- 1 | main.smithy 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer2/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | } 4 | 5 | dependencies { 6 | api("software.amazon.smithy:smithy-model:[1.0, 2.0[") 7 | } 8 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer2/src/main/java/software/amazon/smithy/producer2/Producer2Trait.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.producer2; 2 | 3 | import software.amazon.smithy.model.node.Node; 4 | import software.amazon.smithy.model.node.ObjectNode; 5 | import software.amazon.smithy.model.shapes.ShapeId; 6 | import software.amazon.smithy.model.traits.AnnotationTrait; 7 | 8 | public final class Producer2Trait extends AnnotationTrait { 9 | public static final ShapeId ID = ShapeId.from("smithy.producer#producer2"); 10 | 11 | public Producer2Trait(ObjectNode objectNode) { 12 | super(ID, objectNode); 13 | } 14 | 15 | public Producer2Trait() { 16 | this(Node.objectNode()); 17 | } 18 | 19 | public static final class Provider extends AnnotationTrait.Provider { 20 | public Provider() { 21 | super(ID, Producer2Trait::new); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer2/src/main/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService: -------------------------------------------------------------------------------- 1 | software.amazon.smithy.producer2.Producer2Trait$Provider 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer2/src/main/resources/META-INF/smithy/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.producer 2 | 3 | @trait(selector: "*") 4 | structure producer2 {} 5 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/producer2/src/main/resources/META-INF/smithy/manifest: -------------------------------------------------------------------------------- 1 | main.smithy 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/multi-project/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "multi-project" 2 | 3 | include(":producer1") 4 | include(":producer2") 5 | include(":consumer") 6 | 7 | pluginManagement { 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | // Uncomment these to use the published version of the plugin from your preferred source. 12 | // gradlePluginPortal() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-jars/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Include Additional Sources In SourceSet 2 | This is an example Gradle Smithy project. In addition to serving as documentation, 3 | this project is run as an integration test for the plugin. 4 | 5 | This project demonstrates creating a second JAR task that includes build smithy models 6 | in addition to the base Jar task created by the `java-library` plugin. 7 | 8 | ## Using the example as a starting point 9 | Since this sample is run as an integration test, by default it is only configured 10 | to use a locally published version of the plugin. To use this as a starting point 11 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 12 | Gradle to use public sources. 13 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-jars/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example demonstrates building a JAR using the `smithy-jar` plugin and the 2 | // java-library "jar" task as well as a second JAR using manually defined tasks 3 | 4 | import software.amazon.smithy.gradle.actions.SmithyManifestUpdateAction 5 | import software.amazon.smithy.gradle.tasks.SmithyBuildTask 6 | import software.amazon.smithy.gradle.tasks.SmithyJarStagingTask 7 | 8 | plugins { 9 | `java-library` 10 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 11 | } 12 | 13 | val buildTask: SmithyBuildTask = tasks.getByName("smithyBuild") 14 | 15 | // Stage smithy files for adding to jar 16 | val stagingTask = tasks.create("stageSmithySources") { 17 | inputDirectory.set(buildTask.outputDir) 18 | projection.set("sourceJar") 19 | } 20 | 21 | // Set up tasks that build source and javadoc jars. 22 | tasks.register("sourcesJar") { 23 | from(sourceSets.main.get().allJava) 24 | metaInf.from(stagingTask.smithyStagingDir.get()) 25 | archiveClassifier.set("sources") 26 | } 27 | 28 | // Update the task with the smithy action 29 | tasks["sourcesJar"].doFirst(SmithyManifestUpdateAction(project, setOf("a", "b", "c"))) 30 | tasks["sourcesJar"].dependsOn("stageSmithySources") 31 | 32 | // Make sure the build task executes the sources Jar build 33 | tasks["build"].dependsOn("sourcesJar") 34 | 35 | 36 | repositories { 37 | mavenLocal() 38 | mavenCentral() 39 | } 40 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-jars/model/main.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace smithy.example 4 | 5 | structure Example { 6 | foo: String 7 | } 8 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-jars/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "multiple-jars" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-jars/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "sourceJar": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Multiple Sources 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This project demonstrates the three default locations where Smithy models are pulled 7 | from in a given Gradle project: 8 | 9 | - `model/` 10 | - `src/main/smithy/` 11 | - `src/main/resources/META-INF/smithy` 12 | 13 | ## Using the example as a starting point 14 | 15 | Since this sample is run as an integration test, by default it is only configured 16 | to use a locally published version of the plugin. To use this as a starting point 17 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 18 | Gradle to use public sources. 19 | 20 | ## See Also 21 | 22 | [Smithy model sources](https://smithy.io/2.0/guides/building-models/gradle-plugin.html#smithy-model-sources) 23 | 24 | [`smithy-build.json`'s `imports`](https://smithy.io/2.0/guides/building-models/build-config.html?highlight=imports) 25 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example pulls Smithy models from the following locations: 2 | // - model/ 3 | // - src/main/smithy/ 4 | // - src/main/resources/META-INF/smithy 5 | 6 | plugins { 7 | id("java-library") 8 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 9 | } 10 | 11 | repositories { 12 | mavenLocal() 13 | mavenCentral() 14 | } 15 | 16 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/model/a.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure A {} 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/model/nested/foo.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example.nested 2 | 3 | structure Foo { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/model/nested/more/baz.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example.nested.baz 2 | 3 | structure Baz {} 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "multiple-sources" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/src/main/resources/META-INF/smithy/c.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure C { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/multiple-sources/src/main/smithy/b.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure B { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/no-models/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - No Models 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates a project with no defined models. 7 | 8 | ## Using the example as a starting point 9 | 10 | Since this sample is run as an integration test, by default it is only configured 11 | to use a locally published version of the plugin. To use this as a starting point 12 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 13 | Gradle to use public sources. 14 | 15 | Since this example has no models, you will need to add them yourself. To do this, 16 | create a directory called `model` and add your new model files there. See the 17 | `Multiple Sources` project or the documentation [here](https://smithy.io/2.0/guides/building-models/gradle-plugin.html#smithy-model-sources) 18 | for other locations models are read from by default. Models may also be placed in 19 | custom locations using [`imports` in your `smithy-build.json`](https://smithy.io/2.0/guides/building-models/build-config.html) 20 | -------------------------------------------------------------------------------- /examples/jar-plugin/no-models/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example is an integration test to ensure that projects with no models do not fail. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | group = "software.amazon.smithy" 9 | version = "9.9.9" 10 | 11 | repositories { 12 | mavenLocal() 13 | mavenCentral() 14 | } 15 | -------------------------------------------------------------------------------- /examples/jar-plugin/no-models/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "no-models" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/no-models/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0" 3 | } 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/projection/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Projection 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates how to set which projection is built into the JAR. 7 | 8 | ## Using the example as a starting point 9 | 10 | Since this sample is run as an integration test, by default it is only configured 11 | to use a locally published version of the plugin. To use this as a starting point 12 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 13 | Gradle to use public sources. 14 | 15 | ## See Also 16 | 17 | [Generating a projection](https://smithy.io/2.0/guides/building-models/gradle-plugin.html#generating-a-projection) 18 | -------------------------------------------------------------------------------- /examples/jar-plugin/projection/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example places a projected version of the model into the JAR. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 15 | } 16 | 17 | smithy { 18 | sourceProjection.set("foo") 19 | } 20 | -------------------------------------------------------------------------------- /examples/jar-plugin/projection/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Foo {} 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/projection/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "projection" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/projection/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Projection Sources with Tags 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates how to use the tags set on Smithy model JARs to control 7 | which sources are used for a projection. See the `Adding Tags` example to see how 8 | to add those tags to the JAR. 9 | 10 | ## Using the example as a starting point 11 | 12 | Since this sample is run as an integration test, by default it is only configured 13 | to use a locally published version of the plugin. To use this as a starting point 14 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 15 | Gradle to use public sources. 16 | 17 | ## See Also 18 | 19 | [Projection tags](https://smithy.io/2.0/guides/building-models/gradle-plugin.html#projection-tags) 20 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example places a projected version of the model into the JAR. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | smithyBuild(files("jars/a/a.jar", "jars/b/b.jar")) 15 | implementation(files("jars/c/c.jar")) 16 | } 17 | 18 | smithy { 19 | sourceProjection.set("foo") 20 | projectionSourceTags.addAll("X", "Foo") 21 | } 22 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/a/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Smithy-Tags: X, Y, Z 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/a/META-INF/smithy/a.smithy: -------------------------------------------------------------------------------- 1 | namespace foo.baz 2 | 3 | integer Integer 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/a/META-INF/smithy/manifest: -------------------------------------------------------------------------------- 1 | a.smithy 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/a/a.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithy-lang/smithy-gradle-plugin/55262820d6a4ad7b87fbbbac185b593c652ebcde/examples/jar-plugin/projects-with-tags/jars/a/a.jar -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/b/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Smithy-Tags: Foo, Baz 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/b/META-INF/smithy/b.smithy: -------------------------------------------------------------------------------- 1 | namespace foo.baz 2 | 3 | float Float 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/b/META-INF/smithy/manifest: -------------------------------------------------------------------------------- 1 | b.smithy 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/b/b.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithy-lang/smithy-gradle-plugin/55262820d6a4ad7b87fbbbac185b593c652ebcde/examples/jar-plugin/projects-with-tags/jars/b/b.jar -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/c/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithy-lang/smithy-gradle-plugin/55262820d6a4ad7b87fbbbac185b593c652ebcde/examples/jar-plugin/projects-with-tags/jars/c/META-INF/MANIFEST.MF -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/c/META-INF/smithy/c.smithy: -------------------------------------------------------------------------------- 1 | namespace foo.baz 2 | 3 | long Long 4 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/c/META-INF/smithy/manifest: -------------------------------------------------------------------------------- 1 | c.smithy 2 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/jars/c/c.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithy-lang/smithy-gradle-plugin/55262820d6a4ad7b87fbbbac185b593c652ebcde/examples/jar-plugin/projects-with-tags/jars/c/c.jar -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "projects-with-tags" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/projects-with-tags/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/scala-project/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Scala Project 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This project demonstrates using the Smithy Gradle Plugin with a Scala project. 7 | The Jar created by the Scala plugin will include the Smithy models built by the 8 | `smithyBuild` task. 9 | 10 | ## Using the example as a starting point 11 | 12 | Since this sample is run as an integration test, by default it is only configured 13 | to use a locally published version of the plugin. To use this as a starting point 14 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 15 | Gradle to use public sources. 16 | 17 | -------------------------------------------------------------------------------- /examples/jar-plugin/scala-project/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This project adds smithy models to a JAR created by a Kotlin project 2 | 3 | plugins { 4 | scala 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | dependencies { 9 | implementation("org.scala-lang:scala-library:2.13.11") 10 | } 11 | 12 | repositories { 13 | mavenLocal() 14 | mavenCentral() 15 | } 16 | -------------------------------------------------------------------------------- /examples/jar-plugin/scala-project/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | -------------------------------------------------------------------------------- /examples/jar-plugin/scala-project/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "scala-project" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | gradlePluginPortal() 7 | mavenCentral() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/jar-plugin/scala-project/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/jar-plugin/scala-project/src/main/scala/example/Main.scala: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | object Main { 4 | def main(args: Array[String]): Unit = { 5 | println(greeting()) 6 | } 7 | 8 | def greeting(): String = "Hello, world!" 9 | } 10 | -------------------------------------------------------------------------------- /examples/jar-plugin/source-projection/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Source Projection 2 | 3 | This is an example Gradle Smithy project. In addition to serving as documentation, 4 | this project is run as an integration test for the plugin. 5 | 6 | This example demonstrates a simple Gradle Smithy project that places the default 7 | source projection into the built jar. 8 | 9 | ## Using the example as a starting point 10 | 11 | Since this sample is run as an integration test, by default it is only configured 12 | to use a locally published version of the plugin. To use this as a starting point 13 | for your own project, uncomment the lines in `settings.gradle.kts` that configure 14 | Gradle to use public sources. 15 | 16 | ## See Also 17 | 18 | [Building a source model](https://smithy.io/2.0/guides/building-models/gradle-plugin.html#building-a-source-model) 19 | -------------------------------------------------------------------------------- /examples/jar-plugin/source-projection/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // This example builds the model and places it in the JAR. 2 | 3 | plugins { 4 | id("java-library") 5 | id("software.amazon.smithy.gradle.smithy-jar").version("1.2.0") 6 | } 7 | 8 | repositories { 9 | mavenLocal() 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[") 15 | } 16 | 17 | smithy { 18 | // Uncomment this to use a custom projection when building the JAR. 19 | // projection = "foo" 20 | } 21 | -------------------------------------------------------------------------------- /examples/jar-plugin/source-projection/model/main.smithy: -------------------------------------------------------------------------------- 1 | namespace smithy.example 2 | 3 | structure Baz { 4 | foo: String 5 | } 6 | 7 | @aws.auth#unsignedPayload 8 | operation Foo {} 9 | -------------------------------------------------------------------------------- /examples/jar-plugin/source-projection/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "source-projection" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/jar-plugin/source-projection/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "projections": { 4 | "foo": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/create-simple-trait/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Custom Trait Module 2 | 3 | TODO 4 | 5 | ## Using the example as a starting point 6 | 7 | TODO 8 | 9 | ## See Also 10 | 11 | TODO: Add plugin documentation when available 12 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/create-simple-trait/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Custom Smithy structure trait with multiple inputs" 2 | 3 | plugins { 4 | id("software.amazon.smithy.gradle.smithy-trait-package").version("1.2.0") 5 | } 6 | 7 | group = "software.amazon.smithy" 8 | version = "9.9.9" 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") 17 | } 18 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/create-simple-trait/model/custom-trait.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace io.smithy.gradle.example 4 | 5 | @trait( 6 | selector: "resource" 7 | breakingChanges: [ 8 | { 9 | change: "presence" 10 | } 11 | ] 12 | ) 13 | structure resourceMetadata { 14 | /// Provides a custom name for your resource. 15 | @required 16 | description: String 17 | 18 | /// A type for the resource 19 | @required 20 | type: ResourceType 21 | 22 | /// A list of associated structures 23 | associated: Associated 24 | } 25 | 26 | @private 27 | @idRef(failWhenMissing: true, selector: "structure") 28 | string Associated 29 | 30 | @private 31 | enum ResourceType { 32 | NORMAL 33 | SPECIAL 34 | OTHER 35 | NONE 36 | } 37 | 38 | @trait(selector: "member") 39 | string jsonName 40 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/create-simple-trait/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "create-simple-trait" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/create-simple-trait/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "sources": ["model"], 4 | "plugins": { 5 | "trait-codegen": { 6 | "package": "io.smithy.gradle.examples.traits", 7 | "namespace": "io.smithy.gradle.example", 8 | "header": ["Header line one", "Header line two"] 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/use-with-existing-trait/README.md: -------------------------------------------------------------------------------- 1 | # Example Project - Trait Module with both generated and manual traits 2 | 3 | TODO 4 | 5 | ## Using the example as a starting point 6 | 7 | TODO 8 | 9 | ## See Also 10 | 11 | TODO: Add plugin documentation when available 12 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/use-with-existing-trait/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Use existing, hand-written Java trait definition alongside generated trait definitions." 2 | 3 | plugins { 4 | id("software.amazon.smithy.gradle.smithy-trait-package").version("1.2.0") 5 | } 6 | 7 | group = "software.amazon.smithy" 8 | version = "9.9.9" 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") 17 | } 18 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/use-with-existing-trait/model/custom-trait.smithy: -------------------------------------------------------------------------------- 1 | $version: "2.0" 2 | 3 | namespace io.smithy.gradle.example 4 | 5 | @trait( 6 | selector: "resource" 7 | breakingChanges: [ 8 | { 9 | change: "presence" 10 | } 11 | ] 12 | ) 13 | structure resourceMetadata { 14 | /// Provides a custom name for your resource. 15 | @required 16 | description: String 17 | 18 | /// A type for the resource 19 | @required 20 | type: ResourceType 21 | 22 | /// A list of associated structures 23 | associated: Associated 24 | } 25 | 26 | @private 27 | @idRef(failWhenMissing: true, selector: "structure") 28 | string Associated 29 | 30 | @private 31 | enum ResourceType { 32 | NORMAL 33 | SPECIAL 34 | OTHER 35 | NONE 36 | } 37 | 38 | @tags(["no-generate"]) 39 | @trait(selector: "member") 40 | string jsonName 41 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/use-with-existing-trait/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "use-with-existing-trait" 2 | 3 | pluginManagement { 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | // Uncomment these to use the published version of the plugin from your preferred source. 8 | // gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/use-with-existing-trait/smithy-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "sources": ["model"], 4 | "plugins": { 5 | "trait-codegen": { 6 | "package": "io.smithy.gradle.examples.traits", 7 | "namespace": "io.smithy.gradle.example", 8 | "excludeTags": ["no-generate"], 9 | "header": ["Header line one", "Header line two"] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/use-with-existing-trait/src/main/java/io/smithy/gradle/examples/traits/JsonNameTrait.java: -------------------------------------------------------------------------------- 1 | package io.smithy.gradle.examples.traits; 2 | 3 | import software.amazon.smithy.model.FromSourceLocation; 4 | import software.amazon.smithy.model.SourceLocation; 5 | import software.amazon.smithy.model.shapes.ShapeId; 6 | import software.amazon.smithy.model.traits.StringTrait; 7 | public final class JsonNameTrait extends StringTrait { 8 | 9 | public static final ShapeId ID = ShapeId.from("io.smithy.gradle.example#jsonName"); 10 | 11 | private JsonNameTrait(String name) { 12 | super(ID, name, SourceLocation.NONE); 13 | } 14 | 15 | private JsonNameTrait(String name, FromSourceLocation sourceLocation) { 16 | super(ID, name, sourceLocation); 17 | } 18 | 19 | public static final class Provider extends StringTrait.Provider { 20 | public Provider() { 21 | super(ID, JsonNameTrait::new); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/trait-package-plugin/use-with-existing-trait/src/main/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService: -------------------------------------------------------------------------------- 1 | io.smithy.gradle.examples.traits.JsonNameTrait$Provider 2 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.parallel=true 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithy-lang/smithy-gradle-plugin/55262820d6a4ad7b87fbbbac185b593c652ebcde/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-8.14.2-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /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 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /integ-test-utils/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Integration test utilities used across multiple plugins." 2 | 3 | plugins { 4 | id("smithy-gradle-plugin.java-conventions") 5 | } 6 | 7 | dependencies { 8 | implementation(gradleTestKit()) 9 | implementation("org.junit.jupiter:junit-jupiter-api:5.4.0") 10 | implementation("org.junit.jupiter:junit-jupiter-engine:5.4.0") 11 | implementation("org.junit.jupiter:junit-jupiter-params:5.4.0") 12 | implementation("org.hamcrest:hamcrest:2.1") 13 | } 14 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "smithy-gradle" 2 | 3 | include("smithy-base") 4 | include("smithy-jar") 5 | include("smithy-trait-package") 6 | include("integ-test-utils") 7 | -------------------------------------------------------------------------------- /smithy-base/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.filters.ReplaceTokens 2 | 3 | description = "This plugin sets up the basic capabilities necessary for building Smithy models. " + 4 | "Applying this plugin will create the basic source sets and configurations needed for Smithy " + 5 | "projects. It will also create a smithy build task that will build and validate all the " + 6 | "Smithy models in the project." 7 | 8 | plugins { 9 | id("smithy-gradle-plugin.plugin-conventions") 10 | } 11 | 12 | gradlePlugin { 13 | plugins { 14 | create("smithy-base-plugin") { 15 | id = "${group}.smithy-base" 16 | displayName = "Smithy Gradle Base Plugin" 17 | description = project.description 18 | implementationClass = "software.amazon.smithy.gradle.SmithyBasePlugin" 19 | tags.addAll("smithy", "api", "building") 20 | } 21 | } 22 | } 23 | 24 | // Update the version.properties file to reflect current version of project 25 | tasks.withType { 26 | include("**/*") 27 | filter("tokens" to mapOf("SmithyGradleVersion" to version)) 28 | } 29 | 30 | // Use Junit5's test runner. 31 | tasks.withType { 32 | // Override version in tests 33 | environment( "smithygradle.version.override", "0.0.Alpha-Test"); 34 | } -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/ConflictingOutputDirectoriesTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class ConflictingOutputDirectoriesTest { 9 | @Test 10 | public void testConflictingConfigs() { 11 | Utils.withCopy("base-plugin/failure-cases/conflicting-output-dir-configs", buildDir -> { 12 | BuildResult result = GradleRunner.create() 13 | .forwardOutput() 14 | .withProjectDir(buildDir) 15 | .withArguments("clean", "build", "--stacktrace") 16 | .buildAndFail(); 17 | 18 | Assertions.assertTrue(result.getOutput() 19 | .contains("Conflicting output directories defined in provided smithy build configs:")); 20 | 21 | Utils.assertArtifactsNotCreated(buildDir, 22 | "build/smithyprojections/conflicting-output-dirs/source/build-info/smithy-build-info.json"); 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/ForbidDependencyResolutionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class ForbidDependencyResolutionTest { 9 | @Test 10 | public void testNoFork() { 11 | Utils.withCopy("base-plugin/failure-cases/forbid-dependency-resolution-no-fork", buildDir -> { 12 | BuildResult result = GradleRunner.create() 13 | .forwardOutput() 14 | .withProjectDir(buildDir) 15 | .withArguments("clean", "build", "--stacktrace") 16 | .buildAndFail(); 17 | 18 | Assertions.assertTrue(result.getOutput() 19 | .contains("SMITHY_DEPENDENCY_MODE is set to 'forbid', but the following Maven dependencies are defined in smithy-build.json")); 20 | Utils.assertArtifactsNotCreated(buildDir, 21 | "build/smithyprojections/forbid-dependency-resolution/source/build-info/smithy-build-info.json"); 22 | }); 23 | } 24 | 25 | @Test 26 | public void testFork() { 27 | Utils.withCopy("base-plugin/failure-cases/forbid-dependency-resolution-fork", buildDir -> { 28 | BuildResult result = GradleRunner.create() 29 | .forwardOutput() 30 | .withProjectDir(buildDir) 31 | .withArguments("clean", "build", "--stacktrace") 32 | .buildAndFail(); 33 | 34 | Assertions.assertTrue(result.getOutput() 35 | .contains("SMITHY_DEPENDENCY_MODE is set to 'forbid', but the following Maven dependencies are defined in smithy-build.json")); 36 | Utils.assertArtifactsNotCreated(buildDir, 37 | "build/smithyprojections/forbid-dependency-resolution/source/build-info/smithy-build-info.json"); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/ForbidImplicitNoBuildConfigTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class ForbidImplicitNoBuildConfigTest { 9 | @Test 10 | public void testExceptionThrows() { 11 | Utils.withCopy("base-plugin/failure-cases/forbid-implicit-no-build-config", buildDir -> { 12 | BuildResult result = GradleRunner.create() 13 | .forwardOutput() 14 | .withProjectDir(buildDir) 15 | .withArguments("clean", "build", "--stacktrace") 16 | .buildAndFail(); 17 | 18 | Assertions.assertTrue(result.getOutput() 19 | .contains("No smithy-build configs found. If this was intentional, set the `smithyBuildConfigs` property to an empty list.")); 20 | Utils.assertArtifactsNotCreated(buildDir, 21 | "build/smithyprojections/forbid-implicit-no-build-config/source/build-info/smithy-build-info.json"); 22 | }); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/IncludesInSourceSetTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class IncludesInSourceSetTest { 8 | @Test 9 | public void testSourceProjection() { 10 | Utils.withCopy("base-plugin/includes-in-sourceset", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertArtifactsCreated(buildDir, 19 | "build/smithyprojections/includes-in-sourceset/source/build-info/smithy-build-info.json", 20 | "build/smithyprojections/includes-in-sourceset/source/model/model.json", 21 | "build/smithyprojections/includes-in-sourceset/source/sources/also-included.smithy", 22 | "build/smithyprojections/includes-in-sourceset/source/sources/included.smithy", 23 | "build/smithyprojections/includes-in-sourceset/source/sources/main.smithy", 24 | "build/smithyprojections/includes-in-sourceset/source/sources/manifest"); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/OutputDirectoryConfigTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.File; 8 | 9 | public class OutputDirectoryConfigTest { 10 | @Test 11 | public void testOutputDirectoryBuild() { 12 | Utils.withCopy("base-plugin/output-directory-config", buildDir -> { 13 | BuildResult result = GradleRunner.create() 14 | .forwardOutput() 15 | .withProjectDir(buildDir) 16 | .withArguments("clean", "build", "--stacktrace") 17 | .build(); 18 | File outputDir = buildDir.toPath().resolve("build") 19 | .resolve("nested-output-directory").toFile(); 20 | 21 | Utils.assertSmithyBuildTaskRan(result); 22 | Utils.assertValidationRan(result); 23 | 24 | Utils.assertArtifactsCreated(outputDir, 25 | "source/build-info/smithy-build-info.json", 26 | "source/model/model.json", 27 | "source/sources/main.smithy", 28 | "source/sources/manifest"); 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/OutputDirectoryTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.File; 8 | import java.io.UncheckedIOException; 9 | import java.nio.file.Path; 10 | 11 | public class OutputDirectoryTest { 12 | @Test 13 | public void testOutputDirectory() { 14 | String projectName = "base-plugin/output-directory"; 15 | Path buildDirPath = Utils.createTempDir(projectName); 16 | File buildDir = buildDirPath.toFile(); 17 | File outputDir = buildDirPath.resolve("build").resolve("nested-output-directory").toFile(); 18 | try { 19 | Utils.copyProject(projectName, buildDir); 20 | BuildResult result = GradleRunner.create() 21 | .forwardOutput() 22 | .withProjectDir(buildDir) 23 | .withArguments("clean", "build", "--stacktrace") 24 | .build(); 25 | Utils.assertSmithyBuildTaskRan(result); 26 | Utils.assertValidationRan(result); 27 | Utils.assertArtifactsCreated(outputDir, 28 | "source/build-info/smithy-build-info.json", 29 | "source/model/model.json", 30 | "source/sources/main.smithy", 31 | "source/sources/manifest"); 32 | } catch (UncheckedIOException e) { 33 | throw e; 34 | } finally { 35 | Utils.deleteTempDir(buildDir); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/OutputDirectoryWithProjectionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.File; 8 | import java.io.UncheckedIOException; 9 | import java.nio.file.Path; 10 | 11 | public class OutputDirectoryWithProjectionTest { 12 | @Test 13 | public void testOutputDirectory() { 14 | String projectName = "base-plugin/output-directory-with-projection"; 15 | Path buildDirPath = Utils.createTempDir(projectName); 16 | File buildDir = buildDirPath.toFile(); 17 | File outputDir = buildDirPath.resolve("build").resolve("nested-output-directory").toFile(); 18 | try { 19 | Utils.copyProject(projectName, buildDir); 20 | BuildResult result = GradleRunner.create() 21 | .forwardOutput() 22 | .withProjectDir(buildDir) 23 | .withArguments("clean", "build", "--stacktrace") 24 | .build(); 25 | Utils.assertSmithyBuildTaskRan(result); 26 | Utils.assertValidationRan(result); 27 | Utils.assertArtifactsCreated(outputDir, 28 | "source/build-info/smithy-build-info.json", 29 | "source/model/model.json", 30 | "source/sources/main.smithy", 31 | "source/sources/manifest", 32 | "foo/build-info/smithy-build-info.json", 33 | "foo/model/model.json", 34 | "foo/sources/manifest", 35 | "foo/sources/model.json"); 36 | } catch (UncheckedIOException e) { 37 | throw e; 38 | } finally { 39 | Utils.deleteTempDir(buildDir); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/ScansForCliVersionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class ScansForCliVersionTest { 8 | @Test 9 | public void scansForCliVersion() { 10 | Utils.withCopy("base-plugin/scans-for-cli-version", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertValidationRan(result); 19 | }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/SelectTaskTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | import software.amazon.smithy.model.node.Node; 8 | 9 | public class SelectTaskTest { 10 | @Test 11 | public void selectsString() { 12 | Utils.withCopy("base-plugin/uses-explicitly-set-cli-version", buildDir -> { 13 | BuildResult result = GradleRunner.create() 14 | .forwardOutput() 15 | .withProjectDir(buildDir) 16 | .withArguments("select", "--selector", "member") 17 | .build(); 18 | 19 | Utils.assertSmithyBuildDidNotRun(result); 20 | 21 | Utils.assertArtifactsNotCreated(buildDir, 22 | "build/smithyprojections/uses-explicitly-set-cli-version/source/build-info/smithy-build-info.json"); 23 | 24 | Assertions.assertTrue(result.getOutput().contains("smithy.example#Foo$bar")); 25 | }); 26 | } 27 | 28 | @Test 29 | public void selectsWithShowString() { 30 | Utils.withCopy("base-plugin/uses-explicitly-set-cli-version", buildDir -> { 31 | BuildResult result = GradleRunner.create() 32 | .forwardOutput() 33 | .withProjectDir(buildDir) 34 | .withArguments("select", "--selector", "member", "--show", "type,vars") 35 | .build(); 36 | 37 | Utils.assertSmithyBuildDidNotRun(result); 38 | 39 | Utils.assertArtifactsNotCreated(buildDir, 40 | "build/smithyprojections/uses-explicitly-set-cli-version/source/build-info/smithy-build-info.json"); 41 | 42 | Assertions.assertTrue(result.getOutput().contains("\"shape\": \"smithy.example#Foo$bar\"")); 43 | }); 44 | } 45 | 46 | @Test 47 | public void selectsWithShowTraitsString() { 48 | Utils.withCopy("base-plugin/uses-explicitly-set-cli-version", buildDir -> { 49 | BuildResult result = GradleRunner.create() 50 | .forwardOutput() 51 | .withProjectDir(buildDir) 52 | .withArguments("select", "--selector", "structure > member", "--show-traits", "documentation", "--stacktrace") 53 | .build(); 54 | 55 | Utils.assertSmithyBuildDidNotRun(result); 56 | 57 | Utils.assertArtifactsNotCreated(buildDir, 58 | "build/smithyprojections/uses-explicitly-set-cli-version/source/build-info/smithy-build-info.json"); 59 | 60 | Assertions.assertTrue(result.getOutput().contains("\"smithy.api#documentation\": \"a string member\"")); 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/SmithyBuildTaskTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 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 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package software.amazon.smithy.gradle; 17 | 18 | import org.gradle.testkit.runner.BuildResult; 19 | import org.gradle.testkit.runner.GradleRunner; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import java.io.File; 23 | 24 | public class SmithyBuildTaskTest { 25 | @Test 26 | public void testCustomBuild() { 27 | Utils.withCopy("base-plugin/smithy-build-task", buildDir -> { 28 | BuildResult result = GradleRunner.create() 29 | .forwardOutput() 30 | .withProjectDir(buildDir) 31 | .withArguments("build", "--stacktrace") 32 | .build(); 33 | Utils.assertSmithyBuildDidNotRun(result); 34 | Utils.assertArtifactsCreated( 35 | buildDir, 36 | "build/smithyprojections/smithy-build-task/source/build-info/smithy-build-info.json", 37 | "build/smithyprojections/smithy-build-task/source/model/model.json", 38 | "build/smithyprojections/smithy-build-task/source/sources/main.smithy", 39 | "build/smithyprojections/smithy-build-task/source/sources/manifest"); 40 | }); 41 | } 42 | 43 | @Test 44 | public void pluginProjectionDirectoryExpressesTaskDependency() { 45 | Utils.withCopy("base-plugin/smithy-build-task", buildDir -> { 46 | BuildResult result = GradleRunner.create() 47 | .forwardOutput() 48 | .withProjectDir(buildDir) 49 | .withArguments("copyOutput", "--stacktrace") 50 | .build(); 51 | Utils.assertSmithyBuildDidNotRun(result); 52 | Utils.assertArtifactsCreated( 53 | buildDir, 54 | "build/model/model.json"); 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/SyntaxErrorTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.GradleRunner; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class SyntaxErrorTest { 7 | @Test 8 | public void testFailsWithSyntaxError() { 9 | Utils.withCopy("base-plugin/failure-cases/syntax-error", buildDir -> { 10 | GradleRunner.create() 11 | .forwardOutput() 12 | .withProjectDir(buildDir) 13 | .withArguments("clean", "build", "--stacktrace") 14 | .buildAndFail(); 15 | 16 | Utils.assertArtifactsNotCreated(buildDir, 17 | "build/smithyprojections/syntax-error/source/build-info/smithy-build-info.json"); 18 | }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /smithy-base/src/it/java/software/amazon/smithy/gradle/UsesExplicitlySetCLIVersionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class UsesExplicitlySetCLIVersionTest { 9 | @Test 10 | public void usesExplicitCliVersion() { 11 | Utils.withCopy("base-plugin/uses-explicitly-set-cli-version", buildDir -> { 12 | BuildResult result = GradleRunner.create() 13 | .forwardOutput() 14 | .withProjectDir(buildDir) 15 | .withArguments("clean", "build", "-i", "--stacktrace") 16 | .build(); 17 | 18 | Utils.assertSmithyBuildTaskRan(result); 19 | Utils.assertValidationRan(result); 20 | Assertions.assertTrue(result.getOutput().contains("(using explicitly configured Smithy CLI: 1.45.0)")); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /smithy-base/src/main/java/software/amazon/smithy/gradle/SmithyGradleVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle; 7 | 8 | import static java.lang.String.format; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.util.Properties; 13 | import org.gradle.api.GradleException; 14 | 15 | 16 | /** 17 | * Represents a Smithy-Gradle-Plugin version. 18 | */ 19 | public final class SmithyGradleVersion { 20 | public static final String VERSION_OVERRIDE_VAR = "smithygradle.version.override"; 21 | public static final String VERSION = resolveVersion(); 22 | private static final String VERSION_RESOURCE_NAME = "version.properties"; 23 | private static final String VERSION_NUMBER_PROPERTY = "version"; 24 | 25 | private SmithyGradleVersion() {} 26 | 27 | private static String resolveVersion() { 28 | // Check for resources file with Version info 29 | try (InputStream inputStream = SmithyGradleVersion.class.getResourceAsStream(VERSION_RESOURCE_NAME)) { 30 | if (inputStream == null) { 31 | throw new GradleException(format("Version file '%s' not found.", VERSION_RESOURCE_NAME)); 32 | } 33 | Properties properties = new Properties(); 34 | properties.load(inputStream); 35 | String version = properties.get(VERSION_NUMBER_PROPERTY).toString(); 36 | 37 | // Allow version to be overridden if needed for tests 38 | String overrideVersion = System.getenv(VERSION_OVERRIDE_VAR); 39 | if (overrideVersion != null) { 40 | return overrideVersion; 41 | } 42 | return version; 43 | 44 | } catch (IOException e) { 45 | throw new GradleException(format("Failed to read Version file %S", VERSION_RESOURCE_NAME), e); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /smithy-base/src/main/java/software/amazon/smithy/gradle/SmithySourceDirectorySet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle; 7 | 8 | import java.util.List; 9 | import org.gradle.api.file.SourceDirectorySet; 10 | import software.amazon.smithy.utils.ListUtils; 11 | 12 | 13 | /** 14 | * A {@code SmithySourceDirectorySet} defines the properties and methods added to a 15 | * {@link org.gradle.api.tasks.SourceSet} by the {@link SmithyBasePlugin}. 16 | */ 17 | public interface SmithySourceDirectorySet extends SourceDirectorySet { 18 | /** 19 | * Name of the source set extension contributed by the Smithy plugin. 20 | */ 21 | String NAME = "smithy"; 22 | 23 | /** 24 | * Source Directories this Source set will search for Smithy model files in. 25 | */ 26 | List SOURCE_DIRS = ListUtils.of( 27 | "model", "src/$name/smithy", "src/$name/resources/META-INF/smithy"); 28 | } 29 | -------------------------------------------------------------------------------- /smithy-base/src/main/java/software/amazon/smithy/gradle/internal/DefaultSmithySourceDirectorySet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle.internal; 7 | 8 | import javax.inject.Inject; 9 | import org.gradle.api.file.SourceDirectorySet; 10 | import org.gradle.api.internal.file.DefaultSourceDirectorySet; 11 | import org.gradle.api.internal.tasks.TaskDependencyFactory; 12 | import software.amazon.smithy.gradle.SmithySourceDirectorySet; 13 | import software.amazon.smithy.utils.SmithyInternalApi; 14 | 15 | 16 | /** 17 | * Default implementation of the {@link SmithySourceDirectorySet}. 18 | */ 19 | @SmithyInternalApi 20 | public class DefaultSmithySourceDirectorySet extends DefaultSourceDirectorySet implements SmithySourceDirectorySet { 21 | @Inject 22 | public DefaultSmithySourceDirectorySet(SourceDirectorySet sourceSet, TaskDependencyFactory taskDependencyFactory) { 23 | super(sourceSet, taskDependencyFactory); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithyFormatTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle.tasks; 7 | 8 | import java.io.File; 9 | import javax.inject.Inject; 10 | import org.gradle.StartParameter; 11 | import org.gradle.api.model.ObjectFactory; 12 | import org.gradle.api.tasks.TaskAction; 13 | import software.amazon.smithy.utils.ListUtils; 14 | 15 | 16 | /** 17 | * Executes the Smithy CLI {@code format} tool on a set of source files. 18 | * 19 | *

The smithy format tool is an opinionated formatter that can be used to maintain 20 | * a consistent, readable style for your smithy files. This task can be used to quickly 21 | * reformat smithy files as part of your gradle build process. 22 | * 23 | *

WARNING: This task will mutate input source files and change their formatting in-place. 24 | * 25 | *

Note: Smithy format was introduced to the CLI in version 1.33.0 so earlier 26 | * versions will be unable to use this tool. 27 | */ 28 | public abstract class SmithyFormatTask extends AbstractSmithyCliTask { 29 | private static final String DESCRIPTION = "Formats smithy models."; 30 | 31 | @Inject 32 | public SmithyFormatTask(ObjectFactory objectFactory, StartParameter startParameter) { 33 | super(objectFactory, startParameter); 34 | setDescription(DESCRIPTION); 35 | } 36 | 37 | @TaskAction 38 | public void execute() { 39 | writeHeading("Running smithy format"); 40 | for (final File file : getModels().get()) { 41 | if (file.exists() && file.isDirectory()) { 42 | executeCliProcess("format", 43 | ListUtils.of(), 44 | objectFactory.fileCollection().from(file), 45 | true 46 | ); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithySelectTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle.tasks; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import javax.inject.Inject; 11 | import org.gradle.StartParameter; 12 | import org.gradle.api.GradleException; 13 | import org.gradle.api.model.ObjectFactory; 14 | import org.gradle.api.provider.Property; 15 | import org.gradle.api.tasks.Input; 16 | import org.gradle.api.tasks.Optional; 17 | import org.gradle.api.tasks.TaskAction; 18 | import org.gradle.api.tasks.options.Option; 19 | import org.gradle.work.DisableCachingByDefault; 20 | 21 | 22 | /** 23 | * Executes the Smithy CLI {@code select} command on a set of source files. 24 | * 25 | *

This task queries a set of models from the provided sources using a selector. 26 | * 27 | *

NOTE: this task must be executed with the command line option `--selector` set. 28 | * 29 | * @see Smithy Selectors 30 | */ 31 | @DisableCachingByDefault(because = "Select task should only be called manually.") 32 | public abstract class SmithySelectTask extends AbstractSmithyCliTask { 33 | private static final String DESCRIPTION = "Queries Smithy models with a selector."; 34 | 35 | @Inject 36 | public SmithySelectTask(ObjectFactory objectFactory, StartParameter startParameter) { 37 | super(objectFactory, startParameter); 38 | setDescription(DESCRIPTION); 39 | } 40 | 41 | @Input 42 | @Option(option = "selector", description = "The Smithy selector to execute") 43 | abstract Property getSelector(); 44 | 45 | 46 | @Input 47 | @Optional 48 | @Option(option = "show", description = "The Smithy selector to execute") 49 | abstract Property getShow(); 50 | 51 | @Input 52 | @Optional 53 | @Option(option = "show-traits", description = "The Smithy selector to execute") 54 | abstract Property getShowTraits(); 55 | 56 | @TaskAction 57 | public void execute() { 58 | if (!getSelector().isPresent()) { 59 | throw new GradleException("Select task requires that the command line option `--select` be set."); 60 | } 61 | List extraArgs = new ArrayList<>(); 62 | extraArgs.add("--selector"); 63 | extraArgs.add(getSelector().get()); 64 | 65 | if (getShow().isPresent()) { 66 | extraArgs.add("--show"); 67 | extraArgs.add(getShow().get()); 68 | } 69 | 70 | if (getShowTraits().isPresent()) { 71 | extraArgs.add("--show-traits"); 72 | extraArgs.add(getShowTraits().get()); 73 | } 74 | 75 | executeCliProcess("select", 76 | extraArgs, 77 | getModels().get(), 78 | true 79 | ); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithyValidateTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle.tasks; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import javax.inject.Inject; 11 | import org.gradle.StartParameter; 12 | import org.gradle.api.file.FileCollection; 13 | import org.gradle.api.model.ObjectFactory; 14 | import org.gradle.api.provider.Property; 15 | import org.gradle.api.provider.Provider; 16 | import org.gradle.api.tasks.Input; 17 | import org.gradle.api.tasks.InputFiles; 18 | import org.gradle.api.tasks.Internal; 19 | import org.gradle.api.tasks.Optional; 20 | import org.gradle.api.tasks.TaskAction; 21 | import software.amazon.smithy.model.validation.Severity; 22 | 23 | 24 | /** 25 | * Validates the Smithy models. 26 | * 27 | *

The validation task will execute the Smithy CLI in a new process 28 | * to ensure that it uses an explicit classpath. Doing so will ensure that the 29 | * generated JAR works correctly when used alongside its dependencies. 30 | * 31 | */ 32 | public abstract class SmithyValidateTask extends AbstractSmithyCliTask { 33 | private static final String DESCRIPTION = "Validates smithy models."; 34 | 35 | @Inject 36 | public SmithyValidateTask(ObjectFactory objectFactory, StartParameter startParameter) { 37 | super(objectFactory, startParameter); 38 | getAllowUnknownTraits().convention(false); 39 | getDisableModelDiscovery().convention(false); 40 | getSeverity().convention(Severity.DANGER.toString()); 41 | setDescription(DESCRIPTION); 42 | getOutputs().upToDateWhen(t -> true); 43 | } 44 | 45 | /** 46 | * Files to use as a sources for the Smithy CLI {@code validate} command. 47 | * 48 | *

This is a required input of the SmithyValidate task. 49 | * 50 | * @return file collection to use as sources for the validate task. 51 | */ 52 | @InputFiles 53 | public abstract Property getSources(); 54 | 55 | /** 56 | * Disable model discovery. 57 | * 58 | *

Defaults to false. This option is ignored if an explicit model discovery classpath is provided 59 | * in the {@code getModelDiscoveryClasspath()} property. 60 | * 61 | * @return flag indicating whether to disable model discovery 62 | */ 63 | @Input 64 | @Optional 65 | public abstract Property getDisableModelDiscovery(); 66 | 67 | /** 68 | * Set the minimum reported validation severity. 69 | * 70 | *

This value should be one of: NOTE, WARNING, DANGER, ERROR [default]. 71 | * 72 | * @return minimum validator severity 73 | */ 74 | @Input 75 | @Optional 76 | public abstract Property getSeverity(); 77 | 78 | /** 79 | * Gets the classpath to use when executing the Smithy CLI. 80 | * 81 | *

The cli execution classpath for this task is different from other build 82 | * tasks because we do NOT want to include the discovery classpath for this 83 | * task. 84 | * 85 | * @return classpath to use for cli execution 86 | */ 87 | @Internal 88 | @Override 89 | Provider getCliExecutionClasspath() { 90 | return getCliClasspath(); 91 | } 92 | 93 | @TaskAction 94 | public void execute() { 95 | writeHeading("Running smithy validate"); 96 | 97 | // Add validator severity settings 98 | List extraArgs = new ArrayList<>(); 99 | extraArgs.add("--severity"); 100 | extraArgs.add(getSeverity().get()); 101 | 102 | // Set models to an empty collection so source models are not included in validation path. 103 | executeCliProcess("validate", extraArgs, 104 | getSources().get(), 105 | getDisableModelDiscovery().get() 106 | ); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /smithy-base/src/main/resources/software/amazon/smithy/gradle/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithy-lang/smithy-gradle-plugin/55262820d6a4ad7b87fbbbac185b593c652ebcde/smithy-base/src/main/resources/software/amazon/smithy/gradle/empty -------------------------------------------------------------------------------- /smithy-base/src/main/resources/software/amazon/smithy/gradle/version.properties: -------------------------------------------------------------------------------- 1 | # Do NOT update this here. It is updated to the correct 2 | # version as part of the gradle build process 3 | version=@SmithyGradleVersion@ 4 | -------------------------------------------------------------------------------- /smithy-base/src/test/java/software/amazon/smithy/gradle/SmithyExtensionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.api.Project; 4 | import org.gradle.testfixtures.ProjectBuilder; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.contains; 11 | import static org.hamcrest.Matchers.emptyIterable; 12 | import static org.hamcrest.Matchers.equalTo; 13 | import static org.junit.jupiter.api.Assertions.assertFalse; 14 | import static org.junit.jupiter.api.Assertions.assertTrue; 15 | 16 | public class SmithyExtensionTest { 17 | private Project testProject; 18 | 19 | @BeforeEach 20 | public void init() { 21 | testProject = ProjectBuilder.builder().build(); 22 | } 23 | 24 | 25 | @Test 26 | public void validateDefaults() { 27 | 28 | SmithyExtension extension = testProject.getExtensions().create("smithyTest", SmithyExtension.class); 29 | 30 | assertThat(extension.getProjectionSourceTags().get(), emptyIterable()); 31 | assertThat(extension.getSmithyBuildConfigs().get(), contains(testProject.file("smithy-build.json"))); 32 | assertTrue(extension.getFormat().get()); 33 | assertFalse(extension.getFork().get()); 34 | assertFalse(extension.getAllowUnknownTraits().get()); 35 | 36 | assertThat(extension.getSourceProjection().get(), equalTo("source")); 37 | extension.getSourceProjection().set("foo"); 38 | assertThat(extension.getSourceProjection().get(), equalTo("foo")); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /smithy-base/src/test/java/software/amazon/smithy/gradle/SmithyGradleVersionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import software.amazon.smithy.gradle.SmithyGradleVersion; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | 9 | public class SmithyGradleVersionTest { 10 | private static final String TEST_OVERRIDE_VERSION = "0.0.Alpha-Test"; 11 | 12 | @Test 13 | public void versionOverrideWorks() { 14 | assertEquals(SmithyGradleVersion.VERSION, TEST_OVERRIDE_VERSION); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /smithy-base/src/test/java/software/amazon/smithy/gradle/tasks/SmithyBuildTaskTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle.tasks; 2 | 3 | import org.gradle.api.Project; 4 | import org.gradle.api.logging.configuration.ShowStacktrace; 5 | import org.gradle.testfixtures.ProjectBuilder; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | import software.amazon.smithy.gradle.SmithyUtils; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | import static org.junit.jupiter.api.Assertions.assertFalse; 12 | 13 | public class SmithyBuildTaskTest { 14 | private Project testProject; 15 | 16 | @BeforeEach 17 | public void init() { 18 | testProject = ProjectBuilder.builder().build(); 19 | testProject.getConfigurations().create(SmithyUtils.SMITHY_CLI_CONFIGURATION_NAME); 20 | testProject.getConfigurations().create("smithyBuild"); 21 | testProject.getConfigurations().create("runtimeClasspath"); 22 | } 23 | 24 | @Test 25 | public void validateDefaults() { 26 | SmithyBuildTask buildTask = testProject.getTasks().create("smithyUnitTestBuild", SmithyBuildTask.class); 27 | 28 | assertFalse(buildTask.getFork().get()); 29 | assertEquals(buildTask.getShowStackTrace().get(), ShowStacktrace.INTERNAL_EXCEPTIONS); 30 | assertEquals(buildTask.getSourceProjection().get(), "source"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /smithy-base/src/test/java/software/amazon/smithy/gradle/tasks/SmithyFormatTaskTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle.tasks; 2 | 3 | import org.gradle.api.Project; 4 | import org.gradle.api.logging.configuration.ShowStacktrace; 5 | import org.gradle.testfixtures.ProjectBuilder; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | import software.amazon.smithy.gradle.SmithyUtils; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | import static org.junit.jupiter.api.Assertions.assertFalse; 12 | 13 | public class SmithyFormatTaskTest { 14 | private Project testProject; 15 | 16 | @BeforeEach 17 | public void init() { 18 | testProject = ProjectBuilder.builder().build(); 19 | testProject.getConfigurations().create(SmithyUtils.SMITHY_CLI_CONFIGURATION_NAME); 20 | 21 | testProject.getConfigurations().create("smithyBuild"); 22 | testProject.getConfigurations().create("runtimeClasspath"); 23 | } 24 | 25 | @Test 26 | public void validateDefaults() { 27 | 28 | 29 | SmithyFormatTask formatTask = testProject.getTasks().create("smithyUnitTestFormat", 30 | SmithyFormatTask.class); 31 | 32 | assertEquals(formatTask.getShowStackTrace().get(), ShowStacktrace.INTERNAL_EXCEPTIONS); 33 | assertFalse(formatTask.getFork().get()); 34 | assertFalse(formatTask.getAllowUnknownTraits().get()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /smithy-jar/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Adds built Smithy files to an existing jar task such as that created " + 2 | "by the Java or Kotlin plugins. The smithy-jar plugin also adds build metadata " + 3 | "and tags to the JAR's MANIFEST. The smithy-jar plugin applies the smithy-base " + 4 | "plugin when it is applied." 5 | 6 | plugins { 7 | id("smithy-gradle-plugin.plugin-conventions") 8 | } 9 | 10 | gradlePlugin { 11 | plugins { 12 | create("smithy-jar-plugin") { 13 | id = "${group}.smithy-jar" 14 | displayName = "Smithy Gradle Jar Packaging Plugin" 15 | description = project.description 16 | implementationClass = "software.amazon.smithy.gradle.SmithyJarPlugin" 17 | tags.addAll("smithy", "api", "building") 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation(project(":smithy-base")) 24 | } -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/AddsTagsTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.File; 8 | import java.util.Arrays; 9 | import java.util.jar.Attributes; 10 | import java.util.jar.JarFile; 11 | import java.util.jar.Manifest; 12 | 13 | import static org.hamcrest.MatcherAssert.assertThat; 14 | import static org.hamcrest.Matchers.containsInAnyOrder; 15 | 16 | public class AddsTagsTest { 17 | @Test 18 | public void addsSmithyTagsToJars() { 19 | Utils.withCopy("jar-plugin/adds-tags", buildDir -> { 20 | BuildResult result = GradleRunner.create() 21 | .forwardOutput() 22 | .withProjectDir(buildDir) 23 | .withArguments("clean", "build", "--stacktrace") 24 | .build(); 25 | 26 | Utils.assertSmithyBuildTaskRan(result); 27 | Utils.assertValidationRan(result); 28 | Utils.assertJarContains(buildDir, "build/libs/adds-tags-9.9.9.jar", 29 | "META-INF/MANIFEST.MF", 30 | "META-INF/smithy/manifest", 31 | "META-INF/smithy/main.smithy"); 32 | 33 | JarFile jar = new JarFile(new File(buildDir, "build/libs/adds-tags-9.9.9.jar")); 34 | Manifest manifest = jar.getManifest(); 35 | String tags = (String) manifest.getMainAttributes().get(new Attributes.Name("Smithy-Tags")); 36 | jar.close(); 37 | String[] tagValues = tags.split(", "); 38 | 39 | assertThat(Arrays.asList(tagValues), containsInAnyOrder( 40 | "software.amazon.smithy", "software.amazon.smithy:adds-tags", 41 | "software.amazon.smithy:adds-tags:9.9.9", "Foo", "Baz")); 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/BuildDependenciesTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.gradle.testkit.runner.TaskOutcome; 6 | import org.junit.jupiter.api.Test; 7 | import software.amazon.smithy.model.Model; 8 | import software.amazon.smithy.model.loader.ModelAssembler; 9 | import software.amazon.smithy.model.shapes.ShapeId; 10 | 11 | import java.io.File; 12 | 13 | import static java.util.Objects.requireNonNull; 14 | import static org.junit.jupiter.api.Assertions.assertFalse; 15 | import static org.junit.jupiter.api.Assertions.assertSame; 16 | import static org.junit.jupiter.api.Assertions.assertTrue; 17 | 18 | public class BuildDependenciesTest { 19 | @Test 20 | public void buildsCorrectlyWithSmithyBuildDependencies() { 21 | Utils.withCopy("jar-plugin/build-dependencies", buildDir -> { 22 | BuildResult result = GradleRunner.create() 23 | .forwardOutput() 24 | .withProjectDir(buildDir) 25 | .withArguments("clean", "build", "--stacktrace") 26 | .build(); 27 | 28 | // Check that nested build and validation tasks succeeded 29 | assertSame(requireNonNull(result.task(":internal-model:smithyBuild")).getOutcome(), TaskOutcome.SUCCESS); 30 | assertSame(requireNonNull(result.task(":internal-model:smithyJarValidate")).getOutcome(), TaskOutcome.SUCCESS); 31 | assertSame(requireNonNull(result.task(":internal-model:jar")).getOutcome(), TaskOutcome.SUCCESS); 32 | assertSame(requireNonNull(result.task(":service:smithyBuild")).getOutcome(), TaskOutcome.SUCCESS); 33 | assertSame(requireNonNull(result.task(":service:smithyJarValidate")).getOutcome(), TaskOutcome.SUCCESS); 34 | assertSame(requireNonNull(result.task(":service:jar")).getOutcome(), TaskOutcome.SUCCESS); 35 | 36 | // Check that internal model artifacts were generated 37 | Utils.assertArtifactsCreated(buildDir, 38 | "internal-model/build/smithyprojections/internal-model/source/build-info/smithy-build-info.json", 39 | "internal-model/build/smithyprojections/internal-model/source/sources/internal.smithy", 40 | "internal-model/build/smithyprojections/internal-model/source/sources/manifest", 41 | "internal-model/build/libs/internal-model.jar"); 42 | 43 | Utils.assertArtifactsCreated(buildDir, 44 | "service/build/smithyprojections/service/external/build-info/smithy-build-info.json", 45 | "service/build/smithyprojections/service/external/sources/model.json", 46 | "service/build/smithyprojections/service/external/sources/manifest", 47 | "service/build/libs/service.jar"); 48 | 49 | // Check that the service jar contains expected files 50 | Utils.assertJarContains(buildDir, "service/build/libs/service.jar", 51 | "META-INF/MANIFEST.MF", 52 | "META-INF/smithy/manifest", 53 | "META-INF/smithy/model.json"); 54 | 55 | // Get smithy model stored in constructed jar file 56 | File jarFile = new File(buildDir, "service/build/libs/service.jar"); 57 | Model model = Model.assembler() 58 | .addImport(jarFile.getPath()) 59 | .putProperty(ModelAssembler.ALLOW_UNKNOWN_TRAITS, true) 60 | .assemble().unwrap(); 61 | 62 | // Check that the model does have at least the basic shapes we expect 63 | assertTrue(model.getShape(ShapeId.from("smithy.example#Foo")).isPresent()); 64 | assertTrue(model.getShape(ShapeId.from("smithy.example#Baz")).isPresent()); 65 | 66 | // Validate that model does **not** contain build dep shapes 67 | assertFalse(model.getShape(ShapeId.from("smithy.example.internal#InternalStructure")).isPresent()); 68 | assertFalse(model.getShape(ShapeId.from("aws.auth#unsignedPayload")).isPresent()); 69 | }); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/CustomTraitTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.gradle.testkit.runner.TaskOutcome; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static java.util.Objects.requireNonNull; 9 | import static org.junit.jupiter.api.Assertions.assertSame; 10 | 11 | public class CustomTraitTest { 12 | @Test 13 | public void testCustomTrait() { 14 | Utils.withCopy("jar-plugin/custom-trait", buildDir -> { 15 | BuildResult result = GradleRunner.create() 16 | .forwardOutput() 17 | .withProjectDir(buildDir) 18 | .withArguments("clean", "build", "--stacktrace") 19 | .build(); 20 | 21 | // Check that nested build and validation tasks succeeded 22 | assertSame(requireNonNull(result.task(":custom-string-trait:smithyBuild")).getOutcome(), TaskOutcome.SUCCESS); 23 | assertSame(requireNonNull(result.task(":custom-string-trait:smithyJarValidate")).getOutcome(), TaskOutcome.SUCCESS); 24 | assertSame(requireNonNull(result.task(":custom-string-trait:jar")).getOutcome(), TaskOutcome.SUCCESS); 25 | assertSame(requireNonNull(result.task(":custom-string-trait:smithyBuild")).getOutcome(), TaskOutcome.SUCCESS); 26 | 27 | 28 | // Check that custom trait artifacts were generated 29 | Utils.assertArtifactsCreated(buildDir, 30 | "custom-string-trait/build/smithyprojections/custom-string-trait/source/build-info/smithy-build-info.json", 31 | "custom-string-trait/build/smithyprojections/custom-string-trait/source/sources/custom-trait.smithy", 32 | "custom-string-trait/build/smithyprojections/custom-string-trait/source/sources/manifest", 33 | "custom-string-trait/build/libs/custom-string-trait.jar"); 34 | 35 | // Check that the trait library jar contains expected files 36 | Utils.assertJarContains(buildDir, "custom-string-trait/build/libs/custom-string-trait.jar", 37 | "META-INF/MANIFEST.MF", 38 | "META-INF/smithy/manifest", 39 | "META-INF/smithy/custom-trait.smithy", 40 | "META-INF/services/software.amazon.smithy.model.traits.TraitService", 41 | "io/smithy/examples/traits/JsonNameTrait.class", 42 | "io/smithy/examples/traits/JsonNameTrait$Provider.class"); 43 | 44 | Utils.assertArtifactsCreated(buildDir, 45 | "consumer/build/smithyprojections/consumer/source/build-info/smithy-build-info.json", 46 | "consumer/build/smithyprojections/consumer/source/sources/main.smithy", 47 | "consumer/build/smithyprojections/consumer/source/sources/manifest"); 48 | }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/DisableJarTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class DisableJarTest { 8 | @Test 9 | public void testProjection() { 10 | Utils.withCopy("jar-plugin/disable-jar", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertArtifactsCreated(buildDir, 19 | "build/smithyprojections/disable-jar/source/build-info/smithy-build-info.json", 20 | "build/smithyprojections/disable-jar/source/model/model.json", 21 | "build/smithyprojections/disable-jar/source/sources/main.smithy", 22 | "build/smithyprojections/disable-jar/source/sources/manifest"); 23 | Utils.assertArtifactsNotCreated(buildDir, "build/libs/disable-jar.jar"); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/InvalidProjectionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class InvalidProjectionTest { 9 | @Test 10 | public void testProjection() { 11 | Utils.withCopy("jar-plugin/failure-cases/invalid-projection", buildDir -> { 12 | BuildResult result = GradleRunner.create() 13 | .forwardOutput() 14 | .withProjectDir(buildDir) 15 | .withArguments("clean", "build", "--stacktrace") 16 | .buildAndFail(); 17 | 18 | Assertions.assertTrue(result.getOutput().contains("Smithy projection `invalid` not found")); 19 | }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/KotlinJvmProjectTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class KotlinJvmProjectTest { 8 | @Test 9 | public void testSourceProjection() { 10 | Utils.withCopy("jar-plugin/kotlin-jvm-project", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertValidationRan(result); 19 | Utils.assertArtifactsCreated(buildDir, 20 | "build/smithyprojections/kotlin-jvm-project/source/build-info/smithy-build-info.json", 21 | "build/smithyprojections/kotlin-jvm-project/source/model/model.json", 22 | "build/smithyprojections/kotlin-jvm-project/source/sources/main.smithy", 23 | "build/smithyprojections/kotlin-jvm-project/source/sources/manifest", 24 | "build/libs/kotlin-jvm-project.jar"); 25 | Utils.assertJarContains(buildDir, 26 | "build/libs/kotlin-jvm-project.jar", 27 | "META-INF/smithy/manifest", 28 | "META-INF/smithy/main.smithy", 29 | "META-INF/kotlin-jvm-project.kotlin_module", 30 | "MainKt.class" 31 | ); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/MissingRuntimeDependencyTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class MissingRuntimeDependencyTest { 9 | @Test 10 | public void testProjection() { 11 | Utils.withCopy("jar-plugin/failure-cases/missing-runtime-dependency", buildDir -> { 12 | BuildResult result = GradleRunner.create() 13 | .forwardOutput() 14 | .withProjectDir(buildDir) 15 | .withArguments("clean", "build", "--stacktrace") 16 | .buildAndFail(); 17 | 18 | Assertions.assertTrue(result.getOutput().contains("Unable to resolve trait")); 19 | }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/MultiProjectTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.gradle.testkit.runner.TaskOutcome; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.io.File; 9 | import java.util.Arrays; 10 | import java.util.jar.Attributes; 11 | import java.util.jar.JarFile; 12 | import java.util.jar.Manifest; 13 | 14 | import static java.util.Objects.requireNonNull; 15 | import static org.hamcrest.MatcherAssert.assertThat; 16 | import static org.hamcrest.Matchers.containsInAnyOrder; 17 | import static org.junit.jupiter.api.Assertions.assertSame; 18 | 19 | public class MultiProjectTest { 20 | @Test 21 | public void testProjection() { 22 | Utils.withCopy("jar-plugin/multi-project", buildDir -> { 23 | BuildResult result = GradleRunner.create() 24 | .forwardOutput() 25 | .withProjectDir(buildDir) 26 | .withArguments("clean", "build", "--stacktrace") 27 | .build(); 28 | 29 | // Check that expected smithy task executed for consumer 30 | assertSame(requireNonNull(result.task(":consumer:smithyBuild")).getOutcome(), TaskOutcome.SUCCESS); 31 | assertSame(requireNonNull(result.task(":consumer:smithyJarValidate")).getOutcome(), TaskOutcome.SUCCESS); 32 | 33 | // Check that producer jars created 34 | Utils.assertArtifactsCreated(buildDir, 35 | "producer1/build/libs/producer1-999.999.999.jar", 36 | "producer2/build/libs/producer2-999.999.999.jar"); 37 | 38 | // Check that all smithy and jar artifacts for consumer created 39 | Utils.assertArtifactsCreated(buildDir, 40 | "consumer/build/smithyprojections/consumer/source/build-info/smithy-build-info.json", 41 | "consumer/build/smithyprojections/consumer/source/sources/main.smithy", 42 | "consumer/build/smithyprojections/consumer/source/sources/manifest", 43 | "consumer/build/libs/consumer-999.999.999.jar"); 44 | 45 | // Check that that jar contains correct objects 46 | Utils.assertJarContains(buildDir, "consumer/build/libs/consumer-999.999.999.jar", 47 | "META-INF/MANIFEST.MF", 48 | "META-INF/smithy/manifest", 49 | "META-INF/smithy/main.smithy"); 50 | 51 | // Check that correct tags were added to jar manifest 52 | JarFile jar = new JarFile(new File(buildDir, "consumer/build/libs/consumer-999.999.999.jar")); 53 | Manifest manifest = jar.getManifest(); 54 | String tags = (String) manifest.getMainAttributes().get(new Attributes.Name("Smithy-Tags")); 55 | jar.close(); 56 | String[] tagValues = tags.split(", "); 57 | 58 | assertThat(Arrays.asList(tagValues), containsInAnyOrder( 59 | "software.amazon.smithy.it:consumer", "software.amazon.smithy.it:consumer:999.999.999", 60 | "software.amazon.smithy.it")); 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/MultipleJarsTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.File; 8 | import java.util.Arrays; 9 | import java.util.jar.Attributes; 10 | import java.util.jar.JarFile; 11 | import java.util.jar.Manifest; 12 | 13 | import static org.hamcrest.MatcherAssert.assertThat; 14 | import static org.hamcrest.Matchers.containsInAnyOrder; 15 | 16 | public class MultipleJarsTest { 17 | @Test 18 | public void addsSmithyTagsToJars() { 19 | Utils.withCopy("jar-plugin/multiple-jars", buildDir -> { 20 | BuildResult result = GradleRunner.create() 21 | .forwardOutput() 22 | .withProjectDir(buildDir) 23 | .withArguments("clean", "build", "--stacktrace") 24 | .build(); 25 | 26 | Utils.assertSmithyBuildTaskRan(result); 27 | Utils.assertValidationRan(result); 28 | 29 | // Check that all projections and expected jars exist 30 | Utils.assertArtifactsCreated(buildDir, 31 | "build/smithyprojections/multiple-jars/source/build-info/smithy-build-info.json", 32 | "build/smithyprojections/multiple-jars/source/model/model.json", 33 | "build/smithyprojections/multiple-jars/source/sources/main.smithy", 34 | "build/smithyprojections/multiple-jars/source/sources/manifest", 35 | "build/smithyprojections/multiple-jars/sourceJar/build-info/smithy-build-info.json", 36 | "build/smithyprojections/multiple-jars/sourceJar/model/model.json", 37 | "build/smithyprojections/multiple-jars/sourceJar/sources/model.json", 38 | "build/smithyprojections/multiple-jars/sourceJar/sources/manifest", 39 | "build/libs/multiple-jars.jar", 40 | "build/libs/multiple-jars-sources.jar"); 41 | 42 | // Check that models were correctly staged for both staging tasks 43 | Utils.assertArtifactsCreated(buildDir, 44 | "build/tmp/staging-smithyJarStaging/META-INF/smithy/main.smithy", 45 | "build/tmp/staging-smithyJarStaging/META-INF/smithy/manifest", 46 | "build/tmp/staging-stageSmithySources/META-INF/smithy/model.json", 47 | "build/tmp/staging-stageSmithySources/META-INF/smithy/manifest" 48 | ); 49 | 50 | Utils.assertJarContains(buildDir, "build/libs/multiple-jars-sources.jar", 51 | "META-INF/MANIFEST.MF", 52 | "META-INF/smithy/manifest", 53 | "META-INF/smithy/model.json"); 54 | 55 | JarFile jar = new JarFile(new File(buildDir, "build/libs/multiple-jars-sources.jar")); 56 | Manifest manifest = jar.getManifest(); 57 | String tags = (String) manifest.getMainAttributes().get(new Attributes.Name("Smithy-Tags")); 58 | jar.close(); 59 | String[] tagValues = tags.split(", "); 60 | 61 | assertThat(Arrays.asList(tagValues), containsInAnyOrder("a", "b", "c")); 62 | }); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/MultipleSourcesTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class MultipleSourcesTest { 8 | @Test 9 | public void testProjection() { 10 | Utils.withCopy("jar-plugin/multiple-sources", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertValidationRan(result); 19 | Utils.assertArtifactsCreated(buildDir, 20 | "build/smithyprojections/multiple-sources/source/build-info/smithy-build-info.json", 21 | "build/smithyprojections/multiple-sources/source/model/model.json", 22 | "build/smithyprojections/multiple-sources/source/sources/a.smithy", 23 | "build/smithyprojections/multiple-sources/source/sources/b.smithy", 24 | "build/smithyprojections/multiple-sources/source/sources/c.smithy", 25 | "build/smithyprojections/multiple-sources/source/sources/nested/foo.smithy", 26 | "build/smithyprojections/multiple-sources/source/sources/nested/more/baz.smithy", 27 | "build/smithyprojections/multiple-sources/source/sources/manifest", 28 | "build/libs/multiple-sources.jar"); 29 | Utils.assertJarContains(buildDir, 30 | "build/libs/multiple-sources.jar", 31 | "META-INF/smithy/manifest", 32 | "META-INF/smithy/a.smithy", 33 | "META-INF/smithy/b.smithy", 34 | "META-INF/smithy/c.smithy", 35 | "META-INF/smithy/nested/foo.smithy", 36 | "META-INF/smithy/nested/more/baz.smithy"); 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/NoModelsTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class NoModelsTest { 8 | @Test 9 | public void createsJarWithNoModels() { 10 | Utils.withCopy("jar-plugin/no-models", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertValidationRan(result); 19 | Utils.assertArtifactsCreated(buildDir, "build/libs/no-models-9.9.9.jar"); 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/ProjectionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.containsString; 9 | import static org.hamcrest.Matchers.not; 10 | 11 | public class ProjectionTest { 12 | @Test 13 | public void testProjection() { 14 | Utils.withCopy("jar-plugin/projection", buildDir -> { 15 | BuildResult result = GradleRunner.create() 16 | .forwardOutput() 17 | .withProjectDir(buildDir) 18 | .withArguments("clean", "build", "--stacktrace") 19 | .build(); 20 | 21 | Utils.assertSmithyBuildTaskRan(result); 22 | Utils.assertValidationRan(result); 23 | Utils.assertArtifactsCreated(buildDir, 24 | "build/smithyprojections/projection/source/build-info/smithy-build-info.json", 25 | "build/smithyprojections/projection/source/model/model.json", 26 | "build/smithyprojections/projection/source/sources/main.smithy", 27 | "build/smithyprojections/projection/source/sources/manifest", 28 | "build/smithyprojections/projection/foo/build-info/smithy-build-info.json", 29 | "build/smithyprojections/projection/foo/model/model.json", 30 | "build/smithyprojections/projection/foo/sources/manifest", 31 | "build/smithyprojections/projection/foo/sources/model.json", 32 | "build/libs/projection.jar"); 33 | Utils.assertJarContains(buildDir, 34 | "build/libs/projection.jar", 35 | "META-INF/smithy/manifest", 36 | "META-INF/smithy/model.json"); 37 | }); 38 | } 39 | 40 | @Test 41 | public void usesWarningLoggingByDefault() { 42 | Utils.withCopy("jar-plugin/projection", buildDir -> { 43 | BuildResult result = GradleRunner.create() 44 | .forwardOutput() 45 | .withProjectDir(buildDir) 46 | .withArguments("clean", "build") 47 | .build(); 48 | 49 | // This string appears only when logging INFO or higher. 50 | assertThat(result.getOutput(), not(containsString("[INFO] Validating"))); 51 | }); 52 | } 53 | 54 | @Test 55 | public void modifiesLogging() { 56 | Utils.withCopy("jar-plugin/projection", buildDir -> { 57 | BuildResult result = GradleRunner.create() 58 | .forwardOutput() 59 | .withProjectDir(buildDir) 60 | .withArguments("clean", "build", "--info") 61 | .build(); 62 | assertThat(result.getOutput(), containsString("[INFO] Smithy validation complete")); 63 | }); 64 | } 65 | 66 | @Test 67 | public void usesDebugMode() { 68 | Utils.withCopy("jar-plugin/projection", buildDir -> { 69 | BuildResult result = GradleRunner.create() 70 | .forwardOutput() 71 | .withProjectDir(buildDir) 72 | .withArguments("clean", "build", "--debug") 73 | .build(); 74 | 75 | // This string only appears with debug logging. 76 | assertThat(result.getOutput(), containsString("Found Smithy model")); 77 | }); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/ProjectsWithTagsTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | import software.amazon.smithy.model.Model; 8 | import software.amazon.smithy.model.shapes.ShapeId; 9 | 10 | public class ProjectsWithTagsTest { 11 | @Test 12 | public void testProjectionWithSourceTags() { 13 | Utils.withCopy("jar-plugin/projects-with-tags", buildDir -> { 14 | BuildResult result = GradleRunner.create() 15 | .forwardOutput() 16 | .withProjectDir(buildDir) 17 | .withArguments("clean", "build", "--stacktrace") 18 | .build(); 19 | 20 | Utils.assertSmithyBuildTaskRan(result); 21 | Utils.assertValidationRan(result); 22 | Utils.assertJarContains(buildDir, 23 | "build/libs/projects-with-tags.jar", 24 | "META-INF/smithy/manifest", 25 | "META-INF/smithy/model.json"); 26 | 27 | Model model = Model.assembler() 28 | .addImport(buildDir.toPath().resolve("build").resolve("libs").resolve("projects-with-tags.jar")) 29 | .assemble() 30 | .unwrap(); 31 | 32 | Assertions.assertTrue(model.getShape(ShapeId.from("foo.baz#Integer")).isPresent()); 33 | Assertions.assertTrue(model.getShape(ShapeId.from("foo.baz#Float")).isPresent()); 34 | Assertions.assertTrue(model.getShape(ShapeId.from("smithy.example#Baz")).isPresent()); 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/ScalaProjectTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class ScalaProjectTest { 8 | @Test 9 | public void testScalaProject() { 10 | Utils.withCopy("jar-plugin/scala-project", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertValidationRan(result); 19 | Utils.assertArtifactsCreated(buildDir, 20 | "build/smithyprojections/scala-project/source/build-info/smithy-build-info.json", 21 | "build/smithyprojections/scala-project/source/model/model.json", 22 | "build/smithyprojections/scala-project/source/sources/main.smithy", 23 | "build/smithyprojections/scala-project/source/sources/manifest", 24 | "build/libs/scala-project.jar"); 25 | Utils.assertJarContains(buildDir, 26 | "build/libs/scala-project.jar", 27 | "META-INF/smithy/manifest", 28 | "META-INF/smithy/main.smithy", 29 | "example/Main.class" 30 | ); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /smithy-jar/src/it/java/software/amazon/smithy/gradle/SourceProjectionTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import org.gradle.testkit.runner.BuildResult; 4 | import org.gradle.testkit.runner.GradleRunner; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class SourceProjectionTest { 8 | @Test 9 | public void testSourceProjection() { 10 | Utils.withCopy("jar-plugin/source-projection", buildDir -> { 11 | BuildResult result = GradleRunner.create() 12 | .forwardOutput() 13 | .withProjectDir(buildDir) 14 | .withArguments("clean", "build", "--stacktrace") 15 | .build(); 16 | 17 | Utils.assertSmithyBuildTaskRan(result); 18 | Utils.assertValidationRan(result); 19 | Utils.assertArtifactsCreated(buildDir, 20 | "build/smithyprojections/source-projection/source/build-info/smithy-build-info.json", 21 | "build/smithyprojections/source-projection/source/model/model.json", 22 | "build/smithyprojections/source-projection/source/sources/main.smithy", 23 | "build/smithyprojections/source-projection/source/sources/manifest", 24 | "build/smithyprojections/source-projection/foo/build-info/smithy-build-info.json", 25 | "build/smithyprojections/source-projection/foo/model/model.json", 26 | "build/smithyprojections/source-projection/foo/sources/manifest", 27 | "build/smithyprojections/source-projection/foo/sources/model.json", 28 | "build/libs/source-projection.jar"); 29 | Utils.assertJarContains(buildDir, "build/libs/source-projection.jar", 30 | "META-INF/smithy/manifest", 31 | "META-INF/smithy/main.smithy"); 32 | }); 33 | } 34 | 35 | @Test 36 | public void testSourceProjectionWithConfigurationCaching() { 37 | Utils.withCopy("jar-plugin/source-projection", buildDir -> { 38 | BuildResult result = GradleRunner.create() 39 | .forwardOutput() 40 | .withProjectDir(buildDir) 41 | .withArguments("clean", "build", "--stacktrace", "--configuration-cache") 42 | .build(); 43 | 44 | Utils.assertSmithyBuildTaskRan(result); 45 | Utils.assertValidationRan(result); 46 | Utils.assertArtifactsCreated(buildDir, 47 | "build/smithyprojections/source-projection/source/build-info/smithy-build-info.json", 48 | "build/smithyprojections/source-projection/source/model/model.json", 49 | "build/smithyprojections/source-projection/source/sources/main.smithy", 50 | "build/smithyprojections/source-projection/source/sources/manifest", 51 | "build/smithyprojections/source-projection/foo/build-info/smithy-build-info.json", 52 | "build/smithyprojections/source-projection/foo/model/model.json", 53 | "build/smithyprojections/source-projection/foo/sources/manifest", 54 | "build/smithyprojections/source-projection/foo/sources/model.json", 55 | "build/libs/source-projection.jar"); 56 | Utils.assertJarContains(buildDir, "build/libs/source-projection.jar", 57 | "META-INF/smithy/manifest", 58 | "META-INF/smithy/main.smithy"); 59 | }); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /smithy-jar/src/main/java/software/amazon/smithy/gradle/actions/SmithyManifestUpdateAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle.actions; 7 | 8 | import java.util.Date; 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | import javax.annotation.Nonnull; 12 | import org.gradle.api.Action; 13 | import org.gradle.api.GradleException; 14 | import org.gradle.api.Project; 15 | import org.gradle.api.Task; 16 | import org.gradle.api.java.archives.Attributes; 17 | import org.gradle.jvm.tasks.Jar; 18 | import org.gradle.util.GradleVersion; 19 | import software.amazon.smithy.gradle.SmithyGradleVersion; 20 | 21 | 22 | /** 23 | * Action that updates a JAR's manifest with Smithy-specific attributes. 24 | * 25 | *

This action adds projection tags to JAR manifest via the {@code SmithyTags} property. 26 | * A number of headers are also included in the manifest to add basic build info such as 27 | * JDK version used for the build and the build timestamp. 28 | */ 29 | public final class SmithyManifestUpdateAction implements Action { 30 | private static final String BUILD_TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; 31 | 32 | private final Set tags = new HashSet<>(); 33 | 34 | public SmithyManifestUpdateAction(Project project, Set tags) { 35 | addDefaultTags(project); 36 | this.tags.addAll(tags); 37 | } 38 | 39 | @Override 40 | public void execute(@Nonnull Task task) { 41 | // Note: this is necessary because "doFirst" only allows actions with Task inputs 42 | if (!(task instanceof Jar)) { 43 | throw new GradleException("SmithyManifestUpdateAction expected task of type Jar but found " 44 | + task.getClass()); 45 | } 46 | Jar jar = (Jar) task; 47 | Attributes attributes = jar.getManifest().getAttributes(); 48 | addBuildInfo(attributes); 49 | addTagsToManifest(attributes); 50 | } 51 | 52 | private void addBuildInfo(Attributes manifestAttributes) { 53 | manifestAttributes.put("Build-Timestamp", 54 | new java.text.SimpleDateFormat(BUILD_TIMESTAMP_FORMAT).format(new Date())); 55 | manifestAttributes.put("Created-With", "Smithy-Gradle-Plugin (" + SmithyGradleVersion.VERSION 56 | + "), Gradle (" + GradleVersion.current().getVersion() + ")"); 57 | manifestAttributes.put("Build-Jdk", System.getProperty("java.version")); 58 | manifestAttributes.put("Build-OS", System.getProperty("os.name") 59 | + " " + System.getProperty("os.arch") + " " 60 | + System.getProperty("os.version")); 61 | } 62 | 63 | private void addDefaultTags(Project project) { 64 | // Always add the group, the group + ":" + name, and the group + ":" + name + ":" + version as tags. 65 | if (!project.getGroup().toString().isEmpty()) { 66 | tags.add(project.getGroup().toString()); 67 | tags.add(project.getGroup() + ":" + project.getName()); 68 | tags.add(project.getGroup() + ":" + project.getName() + ":" + project.getVersion()); 69 | project.getLogger().info("Adding built-in Smithy JAR tags: {}", tags); 70 | } 71 | } 72 | 73 | private void addTagsToManifest(Attributes manifestAttributes) { 74 | manifestAttributes.put("Smithy-Tags", String.join(", ", tags)); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /smithy-jar/src/main/java/software/amazon/smithy/gradle/tasks/SmithyJarStagingTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle.tasks; 7 | 8 | 9 | import java.io.File; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | import javax.inject.Inject; 13 | import org.gradle.api.DefaultTask; 14 | import org.gradle.api.GradleException; 15 | import org.gradle.api.file.DirectoryProperty; 16 | import org.gradle.api.file.FileSystemOperations; 17 | import org.gradle.api.file.ProjectLayout; 18 | import org.gradle.api.provider.Property; 19 | import org.gradle.api.provider.Provider; 20 | import org.gradle.api.tasks.Input; 21 | import org.gradle.api.tasks.InputDirectory; 22 | import org.gradle.api.tasks.Internal; 23 | import org.gradle.api.tasks.OutputDirectory; 24 | import org.gradle.api.tasks.TaskAction; 25 | import software.amazon.smithy.gradle.SmithyUtils; 26 | 27 | 28 | /** 29 | * Stages Smithy source files and manifest generated by the {@code sources} plugin into the 30 | * correct file structure for inclusion in a JAR as resources. 31 | * 32 | *

The smithy source files and smithy {@code manifest} file are expected to exist at 33 | * {@code META-INF/smithy/*} within a JAR in order to be discoverable by the Smithy CLI. 34 | * 35 | *

The temporary staging directory created by this task is named {@code staging-$TaskName} 36 | * in order to ensure that multiple staging tasks can be run without naming collisions. 37 | */ 38 | public abstract class SmithyJarStagingTask extends DefaultTask { 39 | private static final String DESCRIPTION = "Stages smithy models for addition to a jar file."; 40 | private static final String SOURCES_PLUGIN_NAME = "sources"; 41 | private static final String SOURCE_PROJECTION = "source"; 42 | 43 | private final FileSystemOperations fileSystemOperations; 44 | 45 | @Inject 46 | public SmithyJarStagingTask(FileSystemOperations fileSystemOperations, 47 | ProjectLayout projectLayout) { 48 | this.fileSystemOperations = fileSystemOperations; 49 | getProjection().convention(SOURCE_PROJECTION); 50 | getOutputDir().set(projectLayout.getBuildDirectory().getLocationOnly()); 51 | setDescription(DESCRIPTION); 52 | } 53 | 54 | /** 55 | * Input directory containing the smithy build artifacts to use for staging. 56 | * 57 | *

This should almost always be the output directory of a {@link SmithyBuildTask}. 58 | * 59 | */ 60 | @InputDirectory 61 | public abstract DirectoryProperty getInputDirectory(); 62 | 63 | /** 64 | * Projection to stage sources for. 65 | * 66 | *

Defaults to "source". 67 | * 68 | *

Note: The projection must exist in one of the smithy-build configs used to generate 69 | * the input directory. 70 | */ 71 | @Input 72 | public abstract Property getProjection(); 73 | 74 | /** 75 | * Output Directory of the task. 76 | * 77 | *

Note: Marked as internal so that it is not checked for caching, although it can be used as 78 | * an input property. 79 | */ 80 | @Internal 81 | public abstract DirectoryProperty getOutputDir(); 82 | 83 | @Internal 84 | Provider getSourcesPluginPath() { 85 | return getInputDirectory().getAsFile().zip(getProjection(), (input, projection) -> 86 | SmithyUtils.getProjectionPluginPath(input, projection, SOURCES_PLUGIN_NAME)); 87 | } 88 | 89 | @Internal 90 | Provider getSmithyResourceTempDir() { 91 | return getOutputDir().getAsFile().map(file -> 92 | SmithyUtils.getSmithyResourceTempDir(getName(), file)); 93 | } 94 | 95 | /** 96 | * Get the smithy staging directory path without the wrapping {@code META-INF} directory. 97 | * 98 | *

This output should be used when including staging directory as a {@code metaInf} file 99 | * for a jar task. For example: 100 | *

101 |      *  tasks.register("MyJarTask") {
102 |      *     // Include the staged files as a metaInf resource
103 |      *     metaInf.from(stagingTask.smithyStagingDir.get())
104 |      *     // Other inputs for the jar task
105 |      *  }
106 |      * 
107 | */ 108 | @OutputDirectory 109 | public Provider getSmithyStagingDir() { 110 | return getSmithyResourceTempDir() 111 | .map(File::getParentFile); 112 | } 113 | 114 | /** 115 | * Get the staged source directory. 116 | * 117 | *

This output should be used when including the staging directory in the resource sourceSet 118 | * for a project. 119 | */ 120 | @OutputDirectory 121 | public Provider getSmithyMetaInfDir() { 122 | return getSmithyStagingDir().map(File::getParentFile); 123 | } 124 | 125 | @TaskAction 126 | public void copyModelsToStaging() { 127 | getLogger().info("Copying smithy models to staging"); 128 | Path sources = getSourcesPluginPath().get(); 129 | validateSources(sources); 130 | 131 | fileSystemOperations.copy(c -> { 132 | c.from(sources.toFile()); 133 | c.into(getSmithyResourceTempDir().get()); 134 | }); 135 | } 136 | 137 | private void validateSources(final Path sources) { 138 | if (!Files.isDirectory(sources)) { 139 | if (getProjection().get().equals("source")) { 140 | getLogger().warn("No Smithy model files were found"); 141 | } else { 142 | // This means the projection was explicitly set, so fail if no models were found. 143 | throw new GradleException("Smithy projection `" + getProjection().get() + "` not found or does not " 144 | + "contain any models. Is this projection defined in your " 145 | + "smithy-build.json file?"); 146 | } 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /smithy-jar/src/test/java/software/amazon/smithy/gradle/tasks/SmithyJarStagingTaskTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle.tasks; 2 | 3 | import org.gradle.api.Project; 4 | import org.gradle.testfixtures.ProjectBuilder; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | public class SmithyJarStagingTaskTest { 11 | private Project testProject; 12 | 13 | @BeforeEach 14 | public void init() { 15 | testProject = ProjectBuilder.builder().build(); 16 | } 17 | 18 | @Test 19 | public void validateDefaults() { 20 | SmithyJarStagingTask stagingTask = testProject.getTasks().create("smithyUnitTestJarStaging", 21 | SmithyJarStagingTask.class); 22 | 23 | assertEquals(stagingTask.getProjection().get(), "source"); 24 | assertEquals(stagingTask.getOutputDir().get(), testProject.getLayout().getBuildDirectory().get()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /smithy-jar/src/test/java/software/amazon/smithy/gradle/tasks/SmithyValidateTaskTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle.tasks; 2 | 3 | import org.gradle.api.Project; 4 | import org.gradle.api.logging.configuration.ShowStacktrace; 5 | import org.gradle.testfixtures.ProjectBuilder; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | import software.amazon.smithy.gradle.SmithyUtils; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | import static org.junit.jupiter.api.Assertions.assertFalse; 12 | import static org.junit.jupiter.api.Assertions.assertTrue; 13 | 14 | public class SmithyValidateTaskTest { 15 | private Project testProject; 16 | 17 | @BeforeEach 18 | public void init() { 19 | testProject = ProjectBuilder.builder().build(); 20 | testProject.getConfigurations().create(SmithyUtils.SMITHY_CLI_CONFIGURATION_NAME); 21 | testProject.getConfigurations().create("smithyBuild"); 22 | testProject.getConfigurations().create("runtimeClasspath"); 23 | } 24 | 25 | @Test 26 | public void validateDefaults() { 27 | SmithyValidateTask validateTask = testProject.getTasks().create("smithyUnitTestValidate", 28 | SmithyValidateTask.class); 29 | 30 | assertEquals(validateTask.getShowStackTrace().get(), ShowStacktrace.INTERNAL_EXCEPTIONS); 31 | assertFalse(validateTask.getFork().get()); 32 | assertFalse(validateTask.getAllowUnknownTraits().get()); 33 | assertFalse(validateTask.getDisableModelDiscovery().get()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /smithy-templates.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "smithy-gradle-plugin", 3 | "templates": { 4 | "includes-in-sourceset": { 5 | "documentation": "Add additional files to the main smithy source set.", 6 | "path": "examples/base-plugin/includes-in-sourceset", 7 | "include": [ 8 | "gradle/", 9 | "gradlew", 10 | "gradlew.bat", 11 | ".gitignore" 12 | ] 13 | }, 14 | "output-directory": { 15 | "documentation": "Write Smithy build artifacts to a specified directory.", 16 | "path": "examples/base-plugin/output-directory", 17 | "include": [ 18 | "gradle/", 19 | "gradlew", 20 | "gradlew.bat", 21 | ".gitignore" 22 | ] 23 | }, 24 | "output-directory-with-config": { 25 | "documentation": "Write Smithy build artifacts to a specified directory based on smithy-build settings.", 26 | "path": "examples/base-plugin/output-directory-config", 27 | "include": [ 28 | "gradle/", 29 | "gradlew", 30 | "gradlew.bat", 31 | ".gitignore" 32 | ] 33 | }, 34 | "output-directory-with-projection": { 35 | "documentation": "Write Smithy build artifacts to a specified directory and generate a projected version of the model.", 36 | "path": "examples/base-plugin/output-directory-with-projection", 37 | "include": [ 38 | "gradle/", 39 | "gradlew", 40 | "gradlew.bat", 41 | ".gitignore" 42 | ] 43 | }, 44 | "smithy-build-task": { 45 | "documentation": "Build Smithy models using a custom build task.", 46 | "path": "examples/base-plugin/smithy-build-task", 47 | "include": [ 48 | "gradle/", 49 | "gradlew", 50 | "gradlew.bat", 51 | ".gitignore" 52 | ] 53 | }, 54 | "add-tags": { 55 | "documentation": "Add a Smithy tag to the built JAR.", 56 | "path": "examples/jar-plugin/adds-tags", 57 | "include": [ 58 | "gradle/", 59 | "gradlew", 60 | "gradlew.bat", 61 | ".gitignore" 62 | ] 63 | }, 64 | "build-dependencies": { 65 | "documentation": "Add build-only dependencies.", 66 | "path": "examples/jar-plugin/build-dependencies", 67 | "include": [ 68 | "gradle/", 69 | "gradlew", 70 | "gradlew.bat", 71 | ".gitignore" 72 | ] 73 | }, 74 | "custom-trait": { 75 | "documentation": "Add Smithy files for a trait alongside the Java definition of that trait.", 76 | "path": "examples/jar-plugin/custom-trait", 77 | "include": [ 78 | "gradle/", 79 | "gradlew", 80 | "gradlew.bat", 81 | ".gitignore" 82 | ] 83 | }, 84 | "kotlin-jvm-project": { 85 | "documentation": "Add Smithy models to a JAR created by a Kotlin project.", 86 | "path": "examples/jar-plugin/kotlin-jvm-project", 87 | "include": [ 88 | "gradle/", 89 | "gradlew", 90 | "gradlew.bat", 91 | ".gitignore" 92 | ] 93 | }, 94 | "scala-project": { 95 | "documentation": "Add Smithy models to a JAR created by a Scala project.", 96 | "path": "examples/jar-plugin/scala-project", 97 | "include": [ 98 | "gradle/", 99 | "gradlew", 100 | "gradlew.bat", 101 | ".gitignore" 102 | ] 103 | }, 104 | "multiple-jars": { 105 | "documentation": "Build a Smithy JAR using both the java-library plugin and manually defined tasks.", 106 | "path": "examples/jar-plugin/multiple-jars", 107 | "include": [ 108 | "gradle/", 109 | "gradlew", 110 | "gradlew.bat", 111 | ".gitignore" 112 | ] 113 | }, 114 | "projection": { 115 | "documentation": "Place a projected version of the model into the JAR.", 116 | "path": "examples/jar-plugin/projection", 117 | "include": [ 118 | "gradle/", 119 | "gradlew", 120 | "gradlew.bat", 121 | ".gitignore" 122 | ] 123 | }, 124 | "source-projection": { 125 | "documentation": "Build a Smithy model and place it in a JAR.", 126 | "path": "examples/jar-plugin/source-projection", 127 | "include": [ 128 | "gradle/", 129 | "gradlew", 130 | "gradlew.bat", 131 | ".gitignore" 132 | ] 133 | }, 134 | "simple-trait": { 135 | "documentation": "Trait package for simple Smithy structure trait with multiple inputs.", 136 | "path": "examples/trait-package-plugin/create-simple-trait", 137 | "include": [ 138 | "gradle/", 139 | "gradlew", 140 | "gradlew.bat", 141 | ".gitignore" 142 | ] 143 | }, 144 | "existing-trait": { 145 | "documentation": "Use existing, hand-written Java trait definition alongside generated trait definitions.", 146 | "path": "examples/trait-package-plugin/use-with-existing-trait", 147 | "include": [ 148 | "gradle/", 149 | "gradlew", 150 | "gradlew.bat", 151 | ".gitignore" 152 | ] 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /smithy-trait-package/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Configures a Java library package for Smithy traits, using " + 2 | "Smithy's trait-codegen plugin to generate Java implementation of traits." 3 | 4 | plugins { 5 | id("smithy-gradle-plugin.plugin-conventions") 6 | } 7 | 8 | gradlePlugin { 9 | plugins { 10 | create("smithy-trait-package-plugin") { 11 | id = "${group}.smithy-trait-package" 12 | displayName = "Smithy Gradle Trait Package plugin." 13 | description = project.description 14 | implementationClass = "software.amazon.smithy.gradle.SmithyTraitPackagePlugin" 15 | tags.addAll("smithy", "api", "building") 16 | } 17 | } 18 | } 19 | 20 | dependencies { 21 | implementation(project(":smithy-jar")) 22 | implementation(project(":smithy-base")) 23 | } 24 | -------------------------------------------------------------------------------- /smithy-trait-package/src/it/java/software/amazon/smithy/gradle/CreatesCustomTraitTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue; 4 | 5 | import java.io.File; 6 | import org.gradle.testkit.runner.BuildResult; 7 | import org.gradle.testkit.runner.GradleRunner; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class CreatesCustomTraitTest { 11 | 12 | @Test 13 | public void createsTraitsAndAddsToJar() { 14 | Utils.withCopy("trait-package-plugin/create-simple-trait", buildDir -> { 15 | BuildResult result = GradleRunner.create() 16 | .forwardOutput() 17 | .withProjectDir(buildDir) 18 | .withArguments("clean", "build", "--stacktrace") 19 | .build(); 20 | 21 | Utils.assertSmithyBuildTaskRan(result); 22 | Utils.assertValidationRan(result); 23 | Utils.assertJarContains(buildDir, "build/libs/create-simple-trait-9.9.9.jar", 24 | "META-INF/MANIFEST.MF", 25 | "META-INF/smithy/manifest", 26 | "META-INF/smithy/custom-trait.smithy", 27 | "META-INF/services/software.amazon.smithy.model.traits.TraitService", 28 | "io/smithy/gradle/examples/traits/ResourceMetadataTrait.class", 29 | "io/smithy/gradle/examples/traits/ResourceType.class", 30 | "io/smithy/gradle/examples/traits/JsonNameTrait.class" 31 | ); 32 | 33 | String spiContents = Utils.getJarEntryContents(new File(buildDir, "build/libs/create-simple-trait-9.9.9.jar"), 34 | "META-INF/services/software.amazon.smithy.model.traits.TraitService"); 35 | 36 | assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.ResourceMetadataTrait$Provider")); 37 | assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.JsonNameTrait$Provider")); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /smithy-trait-package/src/it/java/software/amazon/smithy/gradle/RespectsManualTraitTest.java: -------------------------------------------------------------------------------- 1 | package software.amazon.smithy.gradle; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue; 4 | 5 | import java.io.File; 6 | import org.gradle.testkit.runner.BuildResult; 7 | import org.gradle.testkit.runner.GradleRunner; 8 | import org.gradle.testkit.runner.TaskOutcome; 9 | import org.junit.jupiter.api.Assertions; 10 | import org.junit.jupiter.api.Test; 11 | 12 | public class RespectsManualTraitTest { 13 | 14 | @Test 15 | public void respectsExistingTraitAndMergesSpiFiles() { 16 | Utils.withCopy("trait-package-plugin/use-with-existing-trait", buildDir -> { 17 | BuildResult result = GradleRunner.create() 18 | .forwardOutput() 19 | .withProjectDir(buildDir) 20 | .withArguments("clean", "build", "--stacktrace") 21 | .build(); 22 | 23 | Utils.assertSmithyBuildTaskRan(result); 24 | Utils.assertValidationRan(result); 25 | 26 | // Check that the merge task was executed successfully 27 | Assertions.assertTrue(result.task(":mergeSpiFiles").getOutcome() == TaskOutcome.SUCCESS); 28 | 29 | Utils.assertJarContains(buildDir, "build/libs/use-with-existing-trait-9.9.9.jar", 30 | "META-INF/MANIFEST.MF", 31 | "META-INF/smithy/manifest", 32 | "META-INF/smithy/custom-trait.smithy", 33 | "META-INF/services/software.amazon.smithy.model.traits.TraitService", 34 | "io/smithy/gradle/examples/traits/ResourceMetadataTrait.class", 35 | "io/smithy/gradle/examples/traits/ResourceType.class", 36 | "io/smithy/gradle/examples/traits/JsonNameTrait.class" 37 | ); 38 | 39 | String spiContents = Utils.getJarEntryContents(new File(buildDir, "build/libs/use-with-existing-trait-9.9.9.jar"), 40 | "META-INF/services/software.amazon.smithy.model.traits.TraitService"); 41 | 42 | assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.ResourceMetadataTrait$Provider")); 43 | assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.JsonNameTrait$Provider")); 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /smithy-trait-package/src/main/java/software/amazon/smithy/gradle/SmithyTraitPackagePlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle; 7 | 8 | import java.io.File; 9 | import java.nio.file.Path; 10 | import java.util.Optional; 11 | import javax.inject.Inject; 12 | import org.gradle.api.Plugin; 13 | import org.gradle.api.Project; 14 | import org.gradle.api.Task; 15 | import org.gradle.api.artifacts.Configuration; 16 | import org.gradle.api.artifacts.Dependency; 17 | import org.gradle.api.plugins.JavaLibraryPlugin; 18 | import org.gradle.api.tasks.SourceSet; 19 | import org.gradle.api.tasks.SourceSetContainer; 20 | import org.gradle.api.tasks.TaskProvider; 21 | import org.gradle.language.jvm.tasks.ProcessResources; 22 | import software.amazon.smithy.gradle.internal.CliDependencyResolver; 23 | import software.amazon.smithy.gradle.tasks.MergeSpiFilesTask; 24 | import software.amazon.smithy.gradle.tasks.SmithyBuildTask; 25 | 26 | /** 27 | * A {@link org.gradle.api.Plugin} that sets up a package for a custom trait. 28 | */ 29 | public class SmithyTraitPackagePlugin implements Plugin { 30 | private static final String SMITHY_TRAIT_CODEGEN_DEP_NAME = "smithy-trait-codegen"; 31 | private static final String TRAIT_CODEGEN_PLUGIN_NAME = "trait-codegen"; 32 | private static final String TRAIT_SPI_FILE_NAME = "software.amazon.smithy.model.traits.TraitService"; 33 | private static final String TRAIT_SPI_FILE_PATH = "META-INF/services/" + TRAIT_SPI_FILE_NAME; 34 | private static final String DEPENDENCY_NOTATION = "software.amazon.smithy:%s:%s"; 35 | private static final String MERGE_TASK_NAME = "mergeSpiFiles"; 36 | private static final String SOURCE = "source"; 37 | 38 | private SmithyExtension extension; 39 | private final Project project; 40 | 41 | @Inject 42 | public SmithyTraitPackagePlugin(Project project) { 43 | this.project = project; 44 | } 45 | 46 | @Override 47 | public void apply(Project project) { 48 | project.getPlugins().apply(JavaLibraryPlugin.class); 49 | project.getPlugins().apply(SmithyJarPlugin.class); 50 | 51 | extension = project.getExtensions().getByType(SmithyExtension.class); 52 | 53 | // Only configure trait codegen dependency for main sourceSet 54 | project.getExtensions().getByType(SourceSetContainer.class).all(sourceSet -> { 55 | if (SourceSet.isMain(sourceSet)) { 56 | project.afterEvaluate(p -> configureDependencies(sourceSet)); 57 | 58 | // Add Trait codegen outputs to source set 59 | Path pluginOutput = extension.getPluginProjectionPath(SOURCE, TRAIT_CODEGEN_PLUGIN_NAME).get(); 60 | sourceSet.getJava().srcDir(pluginOutput); 61 | 62 | // Merge generated file with the existing SPI file if found 63 | Optional existingOptional = existingSpiFile(sourceSet); 64 | if (existingOptional.isPresent()) { 65 | project.getLogger().info("Found existing SPI file. Merging with generated..."); 66 | TaskProvider mergeTaskProvider = addMergeTask(sourceSet, pluginOutput, 67 | existingOptional.get()); 68 | sourceSet.getResources().srcDir(mergeTaskProvider.get().getOutputDir()); 69 | 70 | // remove existing from resources to prevent conflicts 71 | sourceSet.getResources().exclude(e -> e.getFile().equals(existingOptional.get())); 72 | } else { 73 | // Add the generated SPI file as a resource 74 | sourceSet.getResources().srcDir(pluginOutput).exclude("**/*.java"); 75 | } 76 | } 77 | }); 78 | } 79 | 80 | private Optional existingSpiFile(SourceSet sourceSet) { 81 | return sourceSet.getResources().getFiles().stream() 82 | .filter(f -> f.getName().equals(TRAIT_SPI_FILE_NAME)) 83 | .findFirst(); 84 | } 85 | 86 | private void configureDependencies(SourceSet sourceSet) { 87 | Configuration smithyBuild = project.getConfigurations() 88 | .getByName(SmithyUtils.getSmithyBuildConfigurationName(sourceSet)); 89 | 90 | // Prefer explicit dependency 91 | Optional explicitDepOptional = smithyBuild.getAllDependencies().stream() 92 | .filter(d -> SmithyUtils.isMatchingDependency(d, SMITHY_TRAIT_CODEGEN_DEP_NAME)) 93 | .findFirst(); 94 | if (explicitDepOptional.isPresent()) { 95 | project.getLogger().info(String.format("(using explicitly configured Dependency for %s: %s)", 96 | SMITHY_TRAIT_CODEGEN_DEP_NAME, explicitDepOptional.get().getVersion())); 97 | return; 98 | } 99 | 100 | // If trait codegen does not exist, add the dependency with the same version as the resolved CLI version 101 | String cliVersion = CliDependencyResolver.resolve(project); 102 | project.getDependencies().add(smithyBuild.getName(), 103 | String.format(DEPENDENCY_NOTATION, SMITHY_TRAIT_CODEGEN_DEP_NAME, cliVersion)); 104 | } 105 | 106 | private TaskProvider addMergeTask(SourceSet sourceSet, Path pluginPath, File existing) { 107 | String mergeTaskName = SmithyUtils.getRelativeSourceSetName(sourceSet, MERGE_TASK_NAME); 108 | SmithyBuildTask buildTask = project.getTasks().withType(SmithyBuildTask.class) 109 | .getByName(SmithyBasePlugin.SMITHY_BUILD_TASK_NAME); 110 | ProcessResources process = project.getTasks().withType(ProcessResources.class).getByName("processResources"); 111 | Task compileTask = project.getTasks().getByName(sourceSet.getCompileJavaTaskName()); 112 | return project.getTasks().register(mergeTaskName, MergeSpiFilesTask.class, 113 | mergeTask -> { 114 | mergeTask.mustRunAfter(buildTask); 115 | process.dependsOn(mergeTask); 116 | compileTask.dependsOn(mergeTask); 117 | mergeTask.getGeneratedFile().set(pluginPath.resolve(TRAIT_SPI_FILE_PATH).toFile()); 118 | mergeTask.getExistingFile().set(existing); 119 | }); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /smithy-trait-package/src/main/java/software/amazon/smithy/gradle/tasks/MergeSpiFilesTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package software.amazon.smithy.gradle.tasks; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.BufferedWriter; 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.nio.file.Files; 13 | import javax.inject.Inject; 14 | import org.gradle.api.DefaultTask; 15 | import org.gradle.api.GradleException; 16 | import org.gradle.api.file.DirectoryProperty; 17 | import org.gradle.api.file.ProjectLayout; 18 | import org.gradle.api.file.RegularFile; 19 | import org.gradle.api.file.RegularFileProperty; 20 | import org.gradle.api.provider.Provider; 21 | import org.gradle.api.tasks.InputFile; 22 | import org.gradle.api.tasks.Internal; 23 | import org.gradle.api.tasks.OutputDirectory; 24 | import org.gradle.api.tasks.TaskAction; 25 | 26 | 27 | /** 28 | * Merges two Service Provider files into a new provider file. 29 | * 30 | *

The generated, merged provider file is written to {@code build/generated-resources/} by default. 31 | * 32 | * @see Java Service Provider Interface Introduction 33 | */ 34 | public abstract class MergeSpiFilesTask extends DefaultTask { 35 | private static final String DESCRIPTION = "Merges two Java Service Provider Files."; 36 | 37 | @Inject 38 | public MergeSpiFilesTask(ProjectLayout projectLayout) { 39 | getMetaInfDir().convention(projectLayout.getBuildDirectory().dir("generated-resources/META-INF/services")); 40 | setDescription(DESCRIPTION); 41 | } 42 | 43 | /** 44 | * Generated Service Provider file to merge with existing file. 45 | */ 46 | @InputFile 47 | public abstract RegularFileProperty getGeneratedFile(); 48 | 49 | /** 50 | * Existing Service Provider file to merge with generated file. 51 | */ 52 | @InputFile 53 | public abstract RegularFileProperty getExistingFile(); 54 | 55 | /** 56 | * Output Directory of the task. 57 | * 58 | *

Note: Marked as internal so that it is not checked for caching, although it can be used as 59 | * an input property. 60 | */ 61 | @Internal 62 | public abstract DirectoryProperty getMetaInfDir(); 63 | 64 | /** 65 | * Read-only property 66 | * 67 | *

Provides the service provider file name to use based on the provided input files. 68 | */ 69 | @Internal 70 | Provider getServiceFileName() { 71 | return getGeneratedFile().getAsFile().map(File::getName); 72 | } 73 | 74 | /** 75 | * Read-only property 76 | * 77 | *

Gets the output service provider file as a {@link File}. 78 | */ 79 | @Internal 80 | Provider getServiceProviderFile() { 81 | return getMetaInfDir().file(getServiceFileName().get()).map(RegularFile::getAsFile); 82 | } 83 | 84 | @OutputDirectory 85 | public Provider getOutputDir() { 86 | return getMetaInfDir().map(file -> file.getAsFile().getParentFile().getParentFile()); 87 | } 88 | 89 | @TaskAction 90 | public void mergeFiles() { 91 | getLogger().info("Merging Service provider files..."); 92 | validate(); 93 | createRequiredFiles(); 94 | 95 | try (BufferedReader generated = Files.newBufferedReader(getGeneratedFile().getAsFile().get().toPath()); 96 | BufferedReader existing = Files.newBufferedReader(getExistingFile().getAsFile().get().toPath()); 97 | BufferedWriter output = Files.newBufferedWriter(getServiceProviderFile().get().toPath()) 98 | ) { 99 | appendInputToOutput(generated, output); 100 | appendInputToOutput(existing, output); 101 | } catch (IOException e) { 102 | throw new GradleException("Failed to merge service provider files.", e); 103 | } 104 | } 105 | 106 | private void validate() { 107 | File generated = getGeneratedFile().getAsFile().get(); 108 | if (!generated.exists()) { 109 | throw new GradleException("Input file does not exist."); 110 | } 111 | File existing = getExistingFile().getAsFile().get(); 112 | if (!existing.exists()) { 113 | throw new GradleException("Input file does not exist."); 114 | } 115 | if (!generated.getName().equals(existing.getName())) { 116 | throw new GradleException("Could not merge SPI files with differing names"); 117 | } 118 | } 119 | 120 | private void createRequiredFiles() { 121 | try { 122 | Files.createDirectories(getMetaInfDir().get().getAsFile().toPath()); 123 | Files.createFile(getServiceProviderFile().get().toPath()); 124 | } catch (IOException e) { 125 | throw new GradleException("Could not create service provider file: " + getServiceProviderFile().get(), e); 126 | } 127 | } 128 | 129 | private void appendInputToOutput(BufferedReader source, BufferedWriter sink) throws IOException { 130 | String str; 131 | while ((str = source.readLine()) != null) { 132 | sink.write(str + System.lineSeparator()); 133 | } 134 | } 135 | } 136 | --------------------------------------------------------------------------------