Skip to content

Commit

Permalink
Fix building models in subdirs (smithy-lang#1860)
Browse files Browse the repository at this point in the history
Fixes smithy-lang#1859

Modifies the changes in smithy-lang#1851,
specifically `SmithyBuild::addSources`, to not check subdirectories for
Smithy files. The previous behavior was to just add whatever path was
given to the method, *not* everything in subdirectories. However, the
change didn't recursively search subdirectores, so you could get build
errors due to missing shapes when running the sources plugin.

This change reverts the behavior of `SmithyBuild::addSource` to only
add whichever path it was given, but still checks to see if the path
is a valid Smithy model.
  • Loading branch information
milesziemer authored and Steven Yuan committed Aug 11, 2023
1 parent 61908e0 commit 6e444f5
Showing 1 changed file with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

package software.amazon.smithy.build;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -199,23 +197,10 @@ public SmithyBuild config(SmithyBuildConfig config) {
//
// Ignores and logs when an unsupported model file is encountered.
private void addSource(Path path) {
try {
if (Files.isDirectory(path)) {
// Pre-emptively crawl the given models to filter them up front into a flat, file-only, list.
Files.list(path).filter(Files::isRegularFile).forEach(this::addSourceFile);
} else {
addSourceFile(path);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private void addSourceFile(Path file) {
if (!VALID_MODELS.matches(file.getFileName())) {
LOGGER.warning("Omitting unsupported Smithy model file from model sources: " + file);
if (Files.isRegularFile(path) && !VALID_MODELS.matches(path.getFileName())) {
LOGGER.warning("Omitting unsupported Smithy model file from model sources: " + path);
} else {
sources.add(file.toAbsolutePath());
sources.add(path.toAbsolutePath());
}
}

Expand Down

0 comments on commit 6e444f5

Please sign in to comment.