aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/glavo/javah/ModulePath.java
blob: b355b24c204266ac01f4fb0c60aabde1735cfb79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package org.glavo.javah;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;

public class ModulePath implements SearchPath {
    private final Path path;
    private final List<Path> paths;

    public ModulePath(Path path) {
        Objects.requireNonNull(path);

        this.path = path;
        try {
            paths = Files.list(path)
                    .filter(Files::isRegularFile)
                    .flatMap(p -> Utils.getPathsFrom(p).stream())
                    .collect(Collectors.toList());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    @Override
    public Path searchClass(String className) {
        return Utils.searchFrom(paths, className);
    }

    @Override
    public String toString() {
        return "ModulePath[" + path + "]";
    }
}