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

Why not provide map package recursively? #924

Closed
lantaozi opened this issue Apr 20, 2016 · 3 comments
Closed

Why not provide map package recursively? #924

lantaozi opened this issue Apr 20, 2016 · 3 comments
Labels
Milestone

Comments

@lantaozi
Copy link

lantaozi commented Apr 20, 2016

I set the map-sub-package option as true as follows:

        MapperOptions mapperOptions = new MapperOptions();
        mapperOptions.setMapSubPackages(true);
        final Morphia morphia = new Morphia(new Mapper(mapperOptions));
        morphia.mapPackage("com.package.name");

But it could only find classes in one package layer.
And i find the reason is the getFielNames in ReflectionUtils:

private static Set<String> getFileNames(final File directory, final String packageName, final boolean mapSubPackages) {
        Set<String> fileNames = new HashSet<String>();
        for (File file: directory.listFiles()) {
            if (file.isFile()) {
                fileNames.add(packageName + '.' + file.getName());
            } else if (mapSubPackages){
                fileNames.addAll(getFileNames(file, packageName + '.' + file.getName(), false));
            }
        }
        return fileNames;
    }

it seems a bug appeared. or for some other considerations?

@ulrichcech
Copy link
Contributor

Hi Tony,

I think, you hit the following issue:
#898

Could you test with the 1.2.0-SNAPSHOT-Version of morphia, if your
problem still exists?

Am 20.04.16 um 12:07 schrieb Tony Yang:

I set the map-sub-package option as true as follows:
|MapperOptions mapperOptions = new MapperOptions();
mapperOptions.setMapSubPackages(true);
final Morphia morphia = new Morphia(new Mapper(mapperOptions));
morphia.mapPackage("com.package.name");|
But it could only reflect one package layer.
And i find the reason is the getFielNames in ReflectionUtils:
|private static Set getFileNames(final File directory, final
String packageName, final boolean mapSubPackages) {
Set fileNames = new HashSet();
for (File file: directory.listFiles()) {
if (file.isFile()) {
fileNames.add(packageName + '.' + file.getName());
} else if (mapSubPackages){
fileNames.addAll(getFileNames(file, packageName + '.' +
file.getName(), false));
}
}
return fileNames;
}|
it seems a bug appeared. or for some other considerations?


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#924

@lantaozi
Copy link
Author

Not exactly.
fileNames.addAll(getFileNames(file, packageName + '.' + file.getName(), false));
I think the 'false' should be 'mapSubPackages' instead. the recursive invocation is not exact.

@ulrichcech
Copy link
Contributor

Yes, you are absolutely right, this must be 'true' instead of 'false'...at this point, mapSubPackage is always true, so you can provide 'true' here.

@evanchooly evanchooly added the bug label May 25, 2016
@evanchooly evanchooly added this to the 1.2.0 milestone May 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants