Skip to content

Commit

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

Modifies the changes in #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 Jul 18, 2023
1 parent 7cf1b57 commit e76d3a0
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 e76d3a0

Please sign in to comment.