Skip to content

Commit

Permalink
Correclty bind extension to tasks (#72) (#75)
Browse files Browse the repository at this point in the history
Configures the tasks to have their first configuration action
to be copying the value from the extension to the task.

Co-authored-by: Brandon Dahler <bnd@amazon.com>
  • Loading branch information
brandondahler and Brandon Dahler committed Apr 12, 2023
1 parent 11f3655 commit 69ef55f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 34 deletions.
9 changes: 9 additions & 0 deletions src/main/java/software/amazon/smithy/gradle/SmithyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.language.jvm.tasks.ProcessResources;
import software.amazon.smithy.gradle.tasks.SmithyBuild;
import software.amazon.smithy.gradle.tasks.SmithyBuildJar;
import software.amazon.smithy.gradle.tasks.SmithyTagsTask;
import software.amazon.smithy.gradle.tasks.Validate;
Expand Down Expand Up @@ -84,12 +85,19 @@ public void apply(Project project) {
registerSourceSets(project);
addCliDependencies(project);
buildJarTask.setAllowUnknownTraits(extension.getAllowUnknownTraits());
buildJarTask.setSmithyBuildConfigs(extension.getSmithyBuildConfigs());
buildJarTask.setProjection(extension.getProjection());
buildJarTask.getProjectionSourceTags().addAll(extension.getProjectionSourceTags());
// We need to manually add these files as a dependency because we
// dynamically inject the Smithy CLI JARs into the classpath.
Configuration smithyCliFiles = project.getConfigurations().getByName("smithyCli");
buildJarTask.getInputs().files(smithyCliFiles);
});

project.getTasks().withType(SmithyBuild.class).configureEach(smithyBuild -> {
smithyBuild.setSmithyBuildConfigs(extension.getSmithyBuildConfigs());
});

// This plugin supports loading Smithy models from various locations, including
// META-INF/smithy. It also creates a staging directory for all of the merged
// resources that were found in each search location. This can cause conflicts
Expand All @@ -103,6 +111,7 @@ public void apply(Project project) {
Task jarTask = project.getTasks().getByName("jar");
// Only run the smithyTags task if the jar task is enabled.
smithyTagsTask.setEnabled(jarTask.getEnabled());
smithyTagsTask.getTags().addAll(extension.getTags());
});

project.getTasks().getByName("jar").dependsOn(smithyTagsProvider);
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/software/amazon/smithy/gradle/tasks/SmithyBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;
import software.amazon.smithy.gradle.SmithyExtension;
import software.amazon.smithy.gradle.SmithyUtils;

/**
Expand Down Expand Up @@ -101,15 +100,6 @@ public final void setSmithyBuildConfigs(FileCollection smithyBuildConfigs) {

@TaskAction
public void execute() {
// Configure the task from the extension if things aren't already setup.
SmithyExtension extension = SmithyUtils.getSmithyExtension(getProject());

if (smithyBuildConfigs == null) {
getLogger().debug("Setting smithyBuildConfigs of {} to {} from SmithyExtension",
getClass().getName(), extension.getSmithyBuildConfigs());
setSmithyBuildConfigs(extension.getSmithyBuildConfigs());
}

// Clear out the build directory when rebuilding.
getProject().delete(getOutputDir());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.gradle.api.tasks.TaskAction;
import org.gradle.workers.WorkerExecutor;
import software.amazon.smithy.cli.BuildParameterBuilder;
import software.amazon.smithy.gradle.SmithyExtension;
import software.amazon.smithy.gradle.SmithyUtils;

/**
Expand Down Expand Up @@ -177,23 +176,6 @@ public File getSmithyResourceStagingDir() {

@TaskAction
public void execute() {
// Configure the task from the extension if things aren't already setup.
SmithyExtension extension = SmithyUtils.getSmithyExtension(getProject());

if (projection == null) {
getLogger().debug("Setting SmithyBuildJar projection from extension: {}", extension.getProjection());
setProjection(extension.getProjection());
}

// Merge tags from the extension into the task.
projectionSourceTags.addAll(extension.getProjectionSourceTags());

// Merge or overwrite?
if (smithyBuildConfigs == null) {
setSmithyBuildConfigs(extension.getSmithyBuildConfigs());
getLogger().debug("Setting SmithyBuildJar smithyBuildConfigs from extension: {}", smithyBuildConfigs);
}

writeHeading("Running smithy build");

// Clear out the directories when rebuilding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.gradle.internal.logging.text.StyledTextOutput;
import org.gradle.internal.logging.text.StyledTextOutputFactory;
import org.gradle.jvm.tasks.Jar;
import software.amazon.smithy.gradle.SmithyExtension;
import software.amazon.smithy.gradle.SmithyUtils;

/**
* Adds Smithy-Tags to the JAR built by the {@link Jar} Task.
Expand Down Expand Up @@ -69,10 +67,6 @@ public void execute() {
return;
}

// Configure the task from the extension if things aren't already setup.
SmithyExtension extension = SmithyUtils.getSmithyExtension(getProject());
tags.addAll(extension.getTags());

// Always add the group, the group + ":" + name, and the group + ":" + name + ":" + version as tags.
if (!getProject().getGroup().toString().isEmpty()) {
tags.add(getProject().getGroup().toString());
Expand Down

0 comments on commit 69ef55f

Please sign in to comment.