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

Patch-in generated resources during testing #228

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ private Stream<Path> buildPatchModulePathStream() {
.map(File::toPath)
.filter(Files::isDirectory);

return Stream.concat(classesFileStream, resourceFileStream);
Stream<Path> additionalResourceFileStream = sourceSets.stream()
.flatMap(sourceSet -> sourceSet.getOutput().getDirs().getFiles().stream())
.map(File::toPath)
.filter(Files::isDirectory);

return Stream.concat(Stream.concat(classesFileStream, resourceFileStream), additionalResourceFileStream);
}

private TaskOption buildAddReadsOption(TestEngine testEngine) {
Expand Down
24 changes: 24 additions & 0 deletions test-project-kotlin/greeter.provider.test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@ modularity {
val compileTestJava: JavaCompile by tasks.named("compileTestJava")
val moduleOptions: org.javamodularity.moduleplugin.extensions.ModuleOptions by compileTestJava.extensions
moduleOptions.addModules = listOf("jdk.unsupported")

val generatedResourcesDir = "generated/resources/test";

sourceSets {
test {
// Add additional output directory for generated resources.
// See org.gradle.api.tasks.SourceSetOutput for more info.
output.dir(layout.buildDirectory.dir(generatedResourcesDir))
}
}

val generateResources = tasks.register("generateResources") {
doLast {
val outputFile = layout.buildDirectory.file("$generatedResourcesDir/generated-resource.txt")
outputFile.get().asFile.parentFile.mkdirs()
outputFile.get().asFile.writeText("some content")

println("Resource file generated at: ${outputFile.get().asFile.absolutePath}")
}
}

tasks.test {
dependsOn(generateResources)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ class GreeterTest {
val greeter = GreeterLocator().findGreeter()
assertFalse(greeter.hello().isBlank())
}

@Test
fun testGeneratedResource() {
val resource = object: Any() {}.javaClass.getResourceAsStream("/generated-resource.txt")
if (resource == null) {
throw RuntimeException("Couldn't load generated resource")
}
}
}
Loading