Skip to content

Commit

Permalink
Merge pull request #216 from ascopes/bugfix/missing-directories
Browse files Browse the repository at this point in the history
Warn ahead of time if directories are missing and omit them from compilation
  • Loading branch information
ascopes authored May 12, 2024
2 parents 777ce58 + 4c2dc78 commit 275b715
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.github.ascopes.protobufmavenplugin.plugins.UrlProtocPluginBean;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -673,6 +674,13 @@ private Collection<Path> sourceDirectories() {
.stream()
.flatMap(Collection::stream)
.map(File::toPath)
.filter(path -> {
if (Files.notExists(path)) {
log.warn("Ignoring source directory {} as it does not appear to exist", path);
return false;
}
return true;
})
.collect(Collectors.toList());

return transformedSourceDirectories.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.github.ascopes.protobufmavenplugin.plugins.UrlProtocPluginBean;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -747,9 +748,9 @@ void whenSourceDirectoriesProvidedExpectPathsInRequest(
@TempDir Path someTempDir
) throws Throwable {
// Given
var path1 = someTempDir.resolve("foo").resolve("bar");
var path2 = someTempDir.resolve("do").resolve("ray");
var path3 = someTempDir.resolve("aaa").resolve("bbb");
var path1 = Files.createDirectories(someTempDir.resolve("foo").resolve("bar"));
var path2 = Files.createDirectories(someTempDir.resolve("do").resolve("ray"));
var path3 = Files.createDirectories(someTempDir.resolve("aaa").resolve("bbb"));

mojo.sourceDirectories = List.of(path1.toFile(), path2.toFile(), path3.toFile());

Expand All @@ -762,6 +763,29 @@ void whenSourceDirectoriesProvidedExpectPathsInRequest(
var actualRequest = captor.getValue();
assertThat(actualRequest.getSourceRoots()).containsExactly(path1, path2, path3);
}

@DisplayName("missing sourceDirectories are not provided to the generator")
@Test
void missingSourceDirectoriesAreNotProvidedToTheGenerator(
@TempDir Path someTempDir
) throws Throwable {
// Given
var path1 = Files.createDirectories(someTempDir.resolve("foo").resolve("bar"));
var path2 = someTempDir.resolve("do").resolve("ray");
var path3 = Files.createDirectories(someTempDir.resolve("aaa").resolve("bbb"));
assertThat(path2).doesNotExist();

mojo.sourceDirectories = List.of(path1.toFile(), path2.toFile(), path3.toFile());

// When
mojo.execute();

// Then
var captor = ArgumentCaptor.forClass(GenerationRequest.class);
verify(mojo.sourceCodeGenerator).generate(captor.capture());
var actualRequest = captor.getValue();
assertThat(actualRequest.getSourceRoots()).containsExactly(path1, path3);
}
}

@DisplayName("languages are enabled and disabled as expected")
Expand Down

0 comments on commit 275b715

Please sign in to comment.