nebula-test
nebula-test copied to clipboard
Default classpath filtering from #49 unintentionally filters user (cwd) class path due to 2 little bugs (on Windows)
This leads to the fact that the gradle plug-in under test (not being in gradle cache yet, because it is just being built and tested) is not in the classpath of the nebula test of the plug-in...
Current code in GradleRunner:
static final Predicate<URL> CLASSPATH_USER_DIR = new Predicate<URL>() {
@Override
boolean apply(URL url) {
File userDir = new File(StandardSystemProperty.USER_DIR.value())
return url.path.startsWith(userDir.path)
}
}
Debug logs show the problem right away:
url: file:/D:/workspaces/testautomation/buildsystem/gradle/???/plugins/artifactory/build/classes/test/
userDir: D:\workspaces\testautomation\buildsystem\gradle\???\plugins\artifactory
userDir.path: D:\workspaces\testautomation\buildsystem\gradle\???\plugins\artifactory
url.path: /D:/workspaces/testautomation/buildsystem/gradle/???/plugins/artifactory/build/classes/test/
Thus, it does not work on Windows, because of:
- the leading '/' in
url.path
- '/' vs. ''
(It seems to be okay on Mac.)
The solution seems to be changing the return statement check of the GradleRunner.CLASSPATH_USER_DIR
predicate like this for example:
static final Predicate<URL> CLASSPATH_USER_DIR = new Predicate<URL>() {
@Override
boolean apply(URL url) {
File userDir = new File(StandardSystemProperty.USER_DIR.value())
return url.path.substring(1).startsWith(userDir.path.replace('\\', '/'))
// Or:
//return url.path.contains(userDir.path.replace('\\', '/'))
}
}
A more elegant approach was suggested by my colleague @epeee
return url.path.startsWith(userDir.toURI().toURL().path)