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

Let ClassFinder work in Gradle #32

Closed
misty000 opened this issue May 20, 2015 · 2 comments
Closed

Let ClassFinder work in Gradle #32

misty000 opened this issue May 20, 2015 · 2 comments

Comments

@misty000
Copy link

gradle compile Class to "projectRoot/build/classes/main", that ClassFinder can't find Perspectives and Components in "classes".
I rewrite ClassFinder#exctractClasses.

private List<Class> exctractClasses(final String packageDir, List<String> files) {
    return files.stream()
            .map(Paths::get)
            .map(path -> binDirs.stream()        // find the right classpath of file
                    .filter(path::startsWith)
                    .findFirst()
                    .map(p -> p.relativize(path)))
            .filter(Optional::isPresent)
            .map(Optional::get)
            .filter(path -> path.startsWith(packageDir))
            .map(path -> path.toString().replace(File.separator, CLASS_DOT))
            .map(className -> className.substring(0, className.lastIndexOf(CLASS_FILE)))
            .filter(classFile -> !classFile.contains(CLASS_DOLLAR))
            .map(this::loadClass)
            .filter(clazz -> clazz != null)
            .collect(Collectors.toList());
}

I don't know if it can work in maven.
This is my sample project: http://git.oschina.net/ellipse/JacpFXSample

@amoAHCP
Copy link
Collaborator

amoAHCP commented May 20, 2015

Hi,
I have tested it with maven on OSX and it works... have you tested it with Windows? I have to test it on a Windows VM later. THX Andy

@misty000
Copy link
Author

Do you think empty string ("") is allowed to "getBasePackages" to find all classes?

    @Override
    protected String[] getBasePackages() {
        return new String[]{"quickstart"};
    }

If it allowed, I make some changes in "exctractClasses".

private List<Class> exctractClasses(final String packageDir, List<String> files) {
    return files.parallelStream()
            .filter(s -> !s.contains(CLASS_DOLLAR)) // exclude "$" at start
            .map(Paths::get)                        // Path is better than String
            .map(path -> binDirs.stream()           // find the right classpath of file
                    .filter(path::startsWith)
                    .findFirst()
                    .map(p -> p.relativize(path)))
            .filter(Optional::isPresent)
            .map(op -> op.get().toString())
            .filter(path -> path.startsWith(packageDir))
                    // use startsWith instead contains
                    // because package "misty" may match "misty.Perspective" but not "org.misty.Perspective"
            .map(path -> path.replace(File.separator, CLASS_DOT))
            .map(className -> className.substring(0, className.lastIndexOf(CLASS_FILE)))
            .map(this::loadClass)
            .filter(clazz -> clazz != null)
            .collect(Collectors.toList());
}

And it works on quickstart project with gradle on Windows

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

2 participants