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

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

Open
reinholdfuereder opened this issue Aug 5, 2015 · 1 comment

Comments

@reinholdfuereder
Copy link

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('\\', '/'))
        }
    }
@reinholdfuereder reinholdfuereder changed the title Default classpath filtering from #49 unintentionally filters user (cwd) class path due to 2 little bugs Default classpath filtering from #49 unintentionally filters user (cwd) class path due to 2 little bugs (on Windows) Aug 6, 2015
@reinholdfuereder
Copy link
Author

A more elegant approach was suggested by my colleague @epeee

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant