Skip to content

Commit

Permalink
Re-add "Add exception on implicit empty config (#123)"
Browse files Browse the repository at this point in the history
This reverts commit 590302c.
  • Loading branch information
hpmellema committed Mar 14, 2024
1 parent 1f62788 commit 8379033
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace smithy.example

structure Foo {
foo: String
}

@aws.auth#unsignedPayload
operation Bar {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rootProject.name = "forbid-dependency-resolution"

pluginManagement {
repositories {
mavenLocal()
mavenCentral()
}
}
6 changes: 5 additions & 1 deletion examples/jar-plugin/custom-trait/consumer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ repositories {

dependencies {
implementation(project(":custom-string-trait"))
}
}

smithy {
smithyBuildConfigs.set(project.files())
}
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"
}
3 changes: 3 additions & 0 deletions examples/jar-plugin/multiple-sources/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
@@ -0,0 +1,24 @@
package software.amazon.smithy.gradle;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ForbidImplicitNoBuildConfigTest {
@Test
public void testExceptionThrows() {
Utils.withCopy("base-plugin/failure-cases/forbid-implicit-no-build-config", buildDir -> {
BuildResult result = GradleRunner.create()
.forwardOutput()
.withProjectDir(buildDir)
.withArguments("clean", "build", "--stacktrace")
.buildAndFail();

Assertions.assertTrue(result.getOutput()
.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");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ private void configureDefaults(Project project) {
getFormat().convention(true);
getAllowUnknownTraits().convention(false);
getOutputDirectory().convention(getDefaultOutputDirectory(project));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
Expand Down Expand Up @@ -57,14 +59,14 @@ public SmithyBuildTask(ObjectFactory objectFactory) {
public abstract SetProperty<String> getProjectionSourceTags();


/** Smithy build configs to use for building models.
/**
* Smithy build configs to use for building models.
*
* @return list of smithy-build config json files
*/
@InputFiles
public abstract Property<FileCollection> getSmithyBuildConfigs();


/**
* Sets whether to fail a {@link SmithyBuildTask} if an unknown trait is encountered.
*
Expand Down Expand Up @@ -104,10 +106,27 @@ List<String> getModelAbsolutePaths() {
.collect(Collectors.toList());
}

/**
* Read-only property.
*
* @return Returns true if at least one of the specified build configs exists.
*/
@Internal
Provider<Boolean> getSmithyBuildConfigsMissing() {
return getSmithyBuildConfigs().map(
files -> !files.isEmpty() && files.filter(File::exists).isEmpty()
);
}

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

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();

// Model discovery classpath
Expand Down

0 comments on commit 8379033

Please sign in to comment.