Skip to content

Commit

Permalink
Add convenience method to resolve plugin projection directories from …
Browse files Browse the repository at this point in the history
…SmithyBuild task instances (#140)

Co-authored-by: Brandon Dahler <bnd@amazon.com>
  • Loading branch information
brandondahler and Brandon Dahler authored Jul 10, 2024
1 parent 4650d02 commit a626b97
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/base-plugin/smithy-build-task/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ plugins {
id("software.amazon.smithy.gradle.smithy-base").version("1.0.0")
}

tasks.create<SmithyBuildTask>("doit") {
val doIt = tasks.register<SmithyBuildTask>("doit") {
models.set(files("model/"))
smithyBuildConfigs.set(files("smithy-build.json"))
}

tasks["build"].finalizedBy(tasks["doit"])
tasks["build"].finalizedBy(doIt)

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

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,19 @@ public void testCustomBuild() {
"build/smithyprojections/smithy-build-task/source/sources/manifest");
});
}

@Test
public void pluginProjectionDirectoryExpressesTaskDependency() {
Utils.withCopy("base-plugin/smithy-build-task", buildDir -> {
BuildResult result = GradleRunner.create()
.forwardOutput()
.withProjectDir(buildDir)
.withArguments("copyOutput", "--stacktrace")
.build();
Utils.assertSmithyBuildDidNotRun(result);
Utils.assertArtifactsCreated(
buildDir,
"build/model/model.json");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.inject.Inject;
import org.gradle.StartParameter;
import org.gradle.api.GradleException;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ObjectFactory;
Expand Down Expand Up @@ -165,4 +166,19 @@ public void execute() {
getFork().get()
);
}

/**
* Convenience method to get the directory containing plugin artifacts.
*
* @param projection projection name
* @param plugin name of plugin to get artifact directory for
*
* @return provider for the plugin artifact directory
*/
public Provider<Directory> getPluginProjectionDirectory(String projection, String plugin) {
return getProject().getLayout().dir(
getOutputDir().getAsFile()
.map(file -> SmithyUtils.getProjectionPluginPath(file, projection, plugin).toFile()));
}

}

0 comments on commit a626b97

Please sign in to comment.