summaryrefslogtreecommitdiff
path: root/src/test/java/org/javacs/FindResource.java
blob: 55b519fde2cfc5e54bbf34942692ee4e898e51bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package org.javacs;

import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;

/** Find java sources in test-project/workspace/src */
public class FindResource {
    public static URI uri(String resourcePath) {
        if (resourcePath.startsWith("/")) resourcePath = resourcePath.substring(1);

        Path path = Paths.get("./src/test/test-project/workspace/src").resolve(resourcePath).normalize();
        File file = path.toFile();

        if (!file.exists()) throw new RuntimeException(file + " does not exist");

        return file.toURI();
    }
}