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

Correclty bind extension to tasks (#72) #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 -> {
hpmellema marked this conversation as resolved.
Show resolved Hide resolved
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
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