Skip to content

Commit

Permalink
Update to use empty list instead of new property
Browse files Browse the repository at this point in the history
  • Loading branch information
hpmellema committed Feb 19, 2024
1 parent 3604392 commit 07455d6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 44 deletions.
2 changes: 1 addition & 1 deletion examples/jar-plugin/custom-trait/consumer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ dependencies {
}

smithy {
noBuildConfig.set(true)
smithyBuildConfigs.set(project.files())
}
4 changes: 0 additions & 4 deletions examples/jar-plugin/multi-project/consumer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ dependencies {
implementation(project(":producer1"))
implementation(project(":producer2"))
}

smithy {
noBuildConfig.set(true)
}
3 changes: 3 additions & 0 deletions examples/jar-plugin/multi-project/consumer/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void testExceptionThrows() {
.buildAndFail();

Assertions.assertTrue(result.getOutput()
.contains("No smithy-build configs found. If this was intentional, set the `noBuildConfigs` flag to `true`."));
.contains("No smithy-build configs found. If this was intentional, set the `smithyBuildConfigs` property to an empty list."));
Utils.assertArtifactsNotCreated(buildDir,
"build/smithyprojections/forbid-implicit-no-build-config/source/build-info/smithy-build-info.json");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ private TaskProvider<SmithyBuildTask> addBuildTaskForSourceSet(SourceSet sourceS
build.getSmithyBuildConfigs().set(extension.getSmithyBuildConfigs());
build.getSourceProjection().set(extension.getSourceProjection());
build.getProjectionSourceTags().set(extension.getProjectionSourceTags());
build.getNoBuildConfig().set(extension.getNoBuildConfig());
build.getOutputDir().set(extension.getOutputDirectory());

// Add smithy configurations as classpaths for build task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ private void configureDefaults(Project project) {
getSourceProjection().convention(SMITHY_SOURCE_PROJECTION_DEFAULT);
getFork().convention(false);
getFormat().convention(true);
getNoBuildConfig().convention(false);
getAllowUnknownTraits().convention(false);
getOutputDirectory().convention(getDefaultOutputDirectory(project));

}

/**
Expand Down Expand Up @@ -144,17 +142,6 @@ public NamedDomainObjectContainer<SmithySourceDirectorySet> getSourceSets() {
*/
public abstract Property<Boolean> getFork();

/**
* Gets whether unknown traits in the model should be ignored.
*
* <p>By default, the build will fail if no config is provided.
* This can be set to true to allow the build task to execute
* with an empty config when no smithy-build config is provided.
*
* @return Returns true if no config should be provided.
*/
public abstract Property<Boolean> getNoBuildConfig();

/**
* Gets the output directory for running Smithy build.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public SmithyBuildTask(ObjectFactory objectFactory) {
super(objectFactory);

getSourceProjection().convention("source");
getNoBuildConfig().convention(false);
getOutputDir().convention(SmithyUtils.getProjectionOutputDirProperty(getProject()));
}

Expand Down Expand Up @@ -68,17 +67,6 @@ public SmithyBuildTask(ObjectFactory objectFactory) {
@InputFiles
public abstract Property<FileCollection> getSmithyBuildConfigs();

/**
* Sets whether to allow the build to continue if no build config is set.
*
* <p> Defaults to false.
*
* @return flag indicating if build should continue if no build configs are found.
*/
@Input
@Optional
public abstract Property<Boolean> getNoBuildConfig();

/**
* Sets whether to fail a {@link SmithyBuildTask} if an unknown trait is encountered.
*
Expand Down Expand Up @@ -124,14 +112,20 @@ List<String> getModelAbsolutePaths() {
* @return Returns true if at least one of the specified build configs exists.
*/
@Internal
Provider<Boolean> getSmithyBuildConfigsExist() {
return getSmithyBuildConfigs().map(files -> !files.filter(File::exists).isEmpty());
Provider<Boolean> getSmithyBuildConfigsMissing() {
return getSmithyBuildConfigs().map(
files -> !files.isEmpty() && files.filter(File::exists).isEmpty()
);
}

@TaskAction
public void execute() {
writeHeading("Running smithy build");
validateBuildConfigs();

if (getSmithyBuildConfigsMissing().get()) {
throw new GradleException("No smithy-build configs found. "
+ "If this was intentional, set the `smithyBuildConfigs` property to an empty list.");
}

BuildParameterBuilder builder = new BuildParameterBuilder();

Expand Down Expand Up @@ -164,13 +158,4 @@ public void execute() {
getFork().get()
);
}

private void validateBuildConfigs() {
// If none of the specified Smithy build configs exist and
// the `noBuildConfigs` flag is false then throw an error
if (!getSmithyBuildConfigsExist().get() && !getNoBuildConfig().get()) {
throw new GradleException("No smithy-build configs found. "
+ "If this was intentional, set the `noBuildConfigs` flag to `true`.");
}
}
}

0 comments on commit 07455d6

Please sign in to comment.