Skip to content

Commit

Permalink
Prevent builds from failing if no test list is present
Browse files Browse the repository at this point in the history
Fixes #188
  • Loading branch information
lazar-mitrovic committed May 23, 2022
1 parent 464f126 commit 92869df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Expand Up @@ -410,7 +410,7 @@ private void configureNativeConfigurationRepo(ExtensionAware graalvmNative) {
configurationRepository.getEnabled().convention(false);
configurationRepository.getUri().convention(configurationRepository.getVersion().map(v -> {
try {
return new URI("https://github.com/graalvm/jvm-reachability-metadata/releases/download/" + v + "/jvm-reachability-metadata-" + v + ".zip");
return new URI("https://github.com/graalvm/graalvm-reachability-metadata/releases/download/" + v + "/graalvm-reachability-metadata-" + v + ".zip");
} catch (URISyntaxException e) {
return null;
}
Expand Down Expand Up @@ -471,7 +471,7 @@ public void registerTestBinary(Project project,
injectTestPluginDependencies(project, graalExtension.getTestSupport());

TaskProvider<BuildNativeImageTask> testImageBuilder = tasks.named(deriveTaskName(name, "native", "Compile"), BuildNativeImageTask.class, task -> {
task.setOnlyIf(t -> graalExtension.getTestSupport().get());
task.setOnlyIf(t -> graalExtension.getTestSupport().get() && testListDirectory.getAsFile().get().exists());
task.getTestListDirectory().set(testListDirectory);
testTask.get();
ConfigurableFileCollection testList = project.getObjects().fileCollection();
Expand All @@ -488,7 +488,7 @@ public void registerTestBinary(Project project,

tasks.named(isPrimaryTest ? NATIVE_TEST_TASK_NAME : "native" + capitalize(name), NativeRunTask.class, task -> {
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
task.setOnlyIf(t -> graalExtension.getTestSupport().get());
task.setOnlyIf(t -> graalExtension.getTestSupport().get() && testListDirectory.getAsFile().get().exists());
});
}

Expand Down
Expand Up @@ -60,7 +60,6 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URISyntaxException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -109,6 +108,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
configureEnvironment();
if (!hasTests()) {
logger.info("Skipped native-image tests since there are no test classes.");
return;
}

Expand Down Expand Up @@ -169,8 +169,8 @@ private void configureEnvironment() {
private boolean hasTests() {
Path testOutputPath = Paths.get(project.getBuild().getTestOutputDirectory());
if (Files.exists(testOutputPath) && Files.isDirectory(testOutputPath)) {
try (DirectoryStream<Path> directory = Files.newDirectoryStream(testOutputPath)) {
return directory.iterator().hasNext();
try (Stream<Path> testClasses = Files.walk(testOutputPath)) {
return testClasses.anyMatch(p -> p.getFileName().toString().endsWith(".class"));
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
Expand Down

0 comments on commit 92869df

Please sign in to comment.