summaryrefslogtreecommitdiff
path: root/src/test/java/org/javacs/FindResource.java
blob: 6e6860ef44f7bcb0438f8d6510981cd87da480fb (plain)
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
package org.javacs;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/** Find java sources in test-project/workspace/src */
public class FindResource {
    public static URI uri(String resourcePath) {
        var path = path(resourcePath);

        return path.toUri();
    }

    public static String contents(String resourcePath) {
        var path = path(resourcePath);
        List<String> lines;
        try {
            lines = Files.readAllLines(path);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return String.join("\n", lines);
    }

    public static Path path(String resourcePath) {
        if (resourcePath.startsWith("/")) resourcePath = resourcePath.substring(1);

        return Paths.get("./src/test/test-project/workspace/src").resolve(resourcePath).normalize();
    }
}