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

import java.net.URI;
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);

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

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

        return URI.create("file://" + file);
    }
}