aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/glavo/javah/ModulePath.java
blob: fdb7499072fa61bc5ac1431205d6afd8cb3dd2d3 (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
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);
        if (!Files.isDirectory(path)) {
            throw new IllegalArgumentException(path + "is not a dir");
        }

        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);
    }
}