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

Remove check for CLI version before executing format #125

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public final class SmithyBasePlugin implements Plugin<Project> {
public static final String SMITHY_CLI_CONFIG = "smithyCli";

private static final GradleVersion MINIMUM_GRADLE_VERSION = GradleVersion.version("8.2.0");
private static final GradleVersion MIN_SMITHY_FORMAT_VERSION = GradleVersion.version("1.33.0");

private final Project project;

Expand Down Expand Up @@ -90,37 +89,19 @@ private void configureSourceSetDefaults(Project project, SmithyExtension extensi
});

project.afterEvaluate(p -> {
// Resolve the Smithy CLI artifact to use
String cliVersion = CliDependencyResolver.resolve(project);
// Resolve the Smithy CLI artifact
CliDependencyResolver.resolve(project);

project.getExtensions().getByType(SourceSetContainer.class).all(sourceSet -> {
// Add format task for source set if enabled and the CLI version supports it
if (extension.getFormat().get() && cliVersionSupportsFormat(cliVersion, sourceSet)) {
p.getExtensions().getByType(SourceSetContainer.class).all(sourceSet -> {
// Add format task for source set if enabled
if (extension.getFormat().get()) {
SmithySourceDirectorySet sds = sourceSet.getExtensions().getByType(SmithySourceDirectorySet.class);
addFormatTaskForSourceSet(sourceSet, sds, extension);
}
});
});
}


/**
* Smithy-format was added in version 1.33.0. It is not supported in earlier CLI versions.
*/
private boolean cliVersionSupportsFormat(String cliVersion, SourceSet sourceSet) {
boolean supported = GradleVersion.version(cliVersion).compareTo(MIN_SMITHY_FORMAT_VERSION) >= 0;

if (!supported && SourceSet.isMain(sourceSet)) {
project.getLogger().warn("Formatting task is not supported Smithy CLI version: "
+ "(" + cliVersion + "). Skipping."
+ "Minimum supported Smithy CLI version for formatting is "
+ MIN_SMITHY_FORMAT_VERSION);
}

return supported;
}


/**
* Creates and configures smithy-specific configurations if they do not already exist.
*
Expand Down
Loading