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

Create empty manifest when no source models #607

Merged
merged 1 commit into from
Oct 20, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ subprojects {
test {
testLogging {
events = ["passed", "skipped", "failed"]
exceptionFormat = "full"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will print exception messages in Travis :D

}
}
}
Expand Down
3 changes: 2 additions & 1 deletion docs/source/1.0/guides/building-models/build-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,8 @@ The ``sources`` plugin copies the source models and creates a manifest.
When building the ``source`` projection, the models that were used to build the
model are copied over literally. When a JAR is used as a source model, the
Smithy models contained within the JAR are copied as a source model while the
JAR itself is not copied.
JAR itself is not copied. If there are no source models, an empty manifest is
created.

When applying a projection, a new model file is created that contains only
the shapes, trait definitions, and metadata that were defined in a source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ public void execute(PluginContext context) {
projectSources(context);
}

String manifest = "";
if (names.isEmpty()) {
LOGGER.info(String.format("Skipping `%s` manifest because no Smithy sources found", projectionName));
LOGGER.info(String.format("Writing empty `%s` manifest because no Smithy sources found", projectionName));
} else {
LOGGER.fine(() -> String.format("Writing `%s` manifest", projectionName));
// Normalize filenames to Unix style.
String manifest = names.stream().map(name -> name.replace("\\", "/")).collect(Collectors.joining("\n"));
context.getFileManifest().writeFile("manifest", manifest + "\n");
manifest = names.stream().map(name -> name.replace("\\", "/")).collect(Collectors.joining("\n"));
}
context.getFileManifest().writeFile("manifest", manifest + "\n");
}

private static List<String> copySources(PluginContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -133,6 +134,26 @@ public void buildsModels() throws Exception {
assertThat(Files.isRegularFile(outputDirectory.resolve("b/model/model.json")), is(true));
}

@Test
public void createsEmptyManifest() throws Exception {
SmithyBuildConfig config = SmithyBuildConfig.builder()
.load(Paths.get(getClass().getResource("empty-config.json").toURI()))
.outputDirectory(outputDirectory.toString())
.build();
Model model = Model.assembler()
.assemble()
.unwrap();
SmithyBuild builder = new SmithyBuild().config(config).model(model);
SmithyBuildResult results = builder.build();
List<Path> files = results.allArtifacts().collect(Collectors.toList());

assertThat(files, hasItem(outputDirectory.resolve("source/sources/manifest")));
assertThat("\n", equalTo(IoUtils.readUtf8File(results.allArtifacts()
.filter(path -> path.toString().endsWith("/manifest"))
.findFirst()
.get())));
}

@Test
public void doesNotCopyErroneousModelsToBuildOutput() throws Exception {
SmithyBuildConfig config = SmithyBuildConfig.builder()
Expand Down Expand Up @@ -377,6 +398,7 @@ public void buildCanOverrideConfigOutputDirectory() throws Exception {
List<Path> files = results.allArtifacts().collect(Collectors.toList());

assertThat(files, containsInAnyOrder(
outputDirectory.resolve("source/sources/manifest"),
outputDirectory.resolve("source/model/model.json"),
outputDirectory.resolve("source/build-info/smithy-build-info.json"),
outputDirectory.resolve("a/sources/manifest"),
Expand Down