Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convinence method which allows resolving plugin projection directories from SmithyBuild task instances #140

Merged

Conversation

brandondahler
Copy link
Contributor

Background

Currently, the standardized method to resolve a given projection + plugin's path is via the SmithyExtension method getPluginProjectionPath. This method will return a Provider<Path> based on the outputDirectory property defined in the extension.

This pull request adds a similar convenience method on the SmithBuildTask implementation itself. The referenced location is functionally the same in most normal setups. In Gradle, utilizing a provider that is based off of the task implementation's DirectoryProperty instead of the extension's DirectoryProperty, even if the task's instance is bound to the extension's instance, will express the implicit dependency between task definitions.

That is, running ./gradlew copyOutput on this task implementation will not execute the smithyBuild task:

tasks.register<Sync>("copyOutput") {
    into(layout.buildDirectory.dir("model"))
    from(smithy.getPluginProjectionPath("source", "model"))
}

Correct behavior requires an explicit dependency:

tasks.register<Sync>("copyOutput") {
    dependsOn(smithyBuild)

    into(layout.buildDirectory.dir("model"))
    from(smithy.getPluginProjectionPath("source", "model"))
}

With this update, this will work as expected and express the dependency upon smithyBuild correctly:

tasks.register<Sync>("copyOutput") {
    into(layout.buildDirectory.dir("model"))
    from(smithyBuild.map { it.getPluginProjectionDirectory("source", "model") })
}

In the implementaiton, I chose to express it as a Provider<Directory> instead of Provider<Path> because utilizing the Gradle-provided Directory and similar api definitions aid in further idiomatic resolution of child directories and files over the Path class.

Testing

  • Implemented integration test built on the smithy-build-task example that shows usage and verifies behavior

Links

N/A


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@brandondahler brandondahler requested a review from a team as a code owner July 10, 2024 16:39
@brandondahler brandondahler requested a review from hpmellema July 10, 2024 16:39
Copy link
Contributor

@hpmellema hpmellema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea for simplifying usage. Thank you for the contribution!

@hpmellema hpmellema merged commit a626b97 into smithy-lang:main Jul 10, 2024
4 checks passed
@brandondahler brandondahler deleted the features/SmithyBuildPluginProjection branch July 10, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants