Skip to content

Commit

Permalink
fix class path directroy analyzer (#590)
Browse files Browse the repository at this point in the history
* fix class path directroy analyzer

* add resources-config.json for test

* add resources-config.json for test

* fix tests

* fix tests

* fix tests

* fix tests

* fix tests

* fix test
  • Loading branch information
n0tl3ss committed Apr 11, 2024
1 parent 08d4a02 commit d4b5ce3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Expand Up @@ -102,7 +102,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (inNativeImageDir && relativePathOf(file).endsWith("resource-config.json")) {
if (!ignoreExistingResourcesConfig && inNativeImageDir && relativePathOf(file).endsWith("resource-config.json")) {
hasNativeImageResourceFile = true;
return FileVisitResult.TERMINATE;
}
Expand Down
Expand Up @@ -59,9 +59,9 @@ abstract class AbstractFunctionalTest extends Specification {
boolean debug
boolean hasConfigurationCache = Boolean.getBoolean("config.cache")

boolean IS_WINDOWS = System.getProperty("os.name", "unknown").contains("Windows");
boolean IS_LINUX = System.getProperty("os.name", "unknown").contains("Linux");
boolean IS_MAC = System.getProperty("os.name", "unknown").contains("Mac");
boolean IS_WINDOWS = System.getProperty("os.name", "unknown").contains("Windows")
boolean IS_LINUX = System.getProperty("os.name", "unknown").contains("Linux")
boolean IS_MAC = System.getProperty("os.name", "unknown").contains("Mac")

private StringWriter outputWriter
private StringWriter errorOutputWriter
Expand Down
Expand Up @@ -20,19 +20,35 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun
if (!restrictToModules) {
options << '-Dresources.autodetection.restrictToModuleDependencies=false'
}
if (ignoreExistingResourcesConfig) {
options << '-Dresources.autodetection.ignoreExistingResourcesConfig=true'
}
if (detectionExclusionPatterns) {
options << "-Dresources.autodetection.detectionExclusionPatterns=${joinForCliArg(detectionExclusionPatterns)}".toString()
}

when:
def resourcesFile = file("src/main/resources/META-INF/native-image/app/resource-config.json")
resourcesFile.parentFile.mkdirs()
resourcesFile << """
{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
},
"bundles" : [ ]
}
"""

mvn(['-Pnative', '-DquickBuild', '-DskipTests', *options, 'package', 'exec:exec@native'])

then:
buildSucceeded
outputContains "Hello, native!"

and:
matches(file("target/native/generated/generateResourceConfig/resource-config.json").text, '''{
if (ignoreExistingResourcesConfig) {
matches(file("target/native/generated/generateResourceConfig/resource-config.json").text, '''{
"resources" : {
"includes" : [ {
"pattern" : "\\\\Qmessage.txt\\\\E"
Expand All @@ -41,12 +57,22 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun
},
"bundles" : [ ]
}''')
} else {
matches(file("target/native/generated/generateResourceConfig/resource-config.json").text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
},
"bundles" : [ ]
}''')
}

where:
detection | includedPatterns | restrictToModules | detectionExclusionPatterns
false | [Pattern.quote("message.txt")] | false | []
true | [] | false | ["META-INF/.*"]
true | [] | true | ["META-INF/.*"]
detection | includedPatterns | restrictToModules | detectionExclusionPatterns | ignoreExistingResourcesConfig
false | [Pattern.quote("message.txt")] | false | [] | true
true | [] | false | ["META-INF/.*"] | true
true | [] | true | ["META-INF/.*"] | true
true | [] | true | [] | false
}

def "can test an application which uses test resources"() {
Expand Down

0 comments on commit d4b5ce3

Please sign in to comment.