nebula-plugins / nebula-test

Test harness for Gradle plugins
Apache License 2.0
45 stars 18 forks source link

Default classpath filtering from #49 unintentionally filters user (cwd) class path due to 2 little bugs (on Windows) #57

Open reinholdfuereder opened 9 years ago

reinholdfuereder commented 9 years ago

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:

(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('\\', '/'))
        }
    }
reinholdfuereder commented 9 years ago

A more elegant approach was suggested by my colleague @epeee

return url.path.startsWith(userDir.toURI().toURL().path)