| 37 | import java.util.concurrent.TimeUnit; |
| 38 | |
| 39 | public class TestOs { |
| 40 | public static void init() { |
| 41 | } |
| 42 | |
| 43 | private static FileTime getLastModifiedTime(Path absoluteDevReleasePath) { |
| 44 | try { |
| 45 | return Files.getLastModifiedTime(absoluteDevReleasePath); |
| 46 | } catch (IOException e) { |
| 47 | return FileTime.from(0, TimeUnit.MILLISECONDS); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // This is copy of main Os class to load test jni library |
| 52 | static { |
| 53 | String outputLibExt; |
| 54 | if (Os.type == Os.LINUX || Os.type == Os.FREEBSD) { |
| 55 | outputLibExt = ".so"; |
| 56 | } else if (Os.type == Os.DARWIN) { |
| 57 | outputLibExt = ".dylib"; |
| 58 | } else if (Os.type == Os.WINDOWS) { |
| 59 | outputLibExt = ".dll"; |
| 60 | } else { |
| 61 | throw new Error("Unsupported OS: " + Os.name); |
| 62 | } |
| 63 | |
| 64 | final String rustLibName; |
| 65 | if (Os.type == Os.WINDOWS) { |
| 66 | rustLibName = "qdbsqllogictest" + outputLibExt; |
| 67 | } else { |
| 68 | rustLibName = "libqdbsqllogictest" + outputLibExt; |
| 69 | } |
| 70 | |
| 71 | URL resource = TestOs.class.getResource("/io/questdb/bin/" + Os.name + '-' + Os.archName + '/' + rustLibName); |
| 72 | if (resource != null) { |
| 73 | String absolutePathPreCompiled; |
| 74 | try { |
| 75 | absolutePathPreCompiled = resource.toURI().getPath(); |
| 76 | } catch (URISyntaxException e) { |
| 77 | throw new RuntimeException(e); |
| 78 | } |
| 79 | if (Os.isWindows() && absolutePathPreCompiled.charAt(0) == '/') { |
| 80 | // Remove forward / |
| 81 | absolutePathPreCompiled = absolutePathPreCompiled.substring(1); |
| 82 | } |
| 83 | String sourcesPath = absolutePathPreCompiled.substring(0, absolutePathPreCompiled.indexOf("/target/")); |
| 84 | Path absoluteDevReleasePath = Paths.get(sourcesPath + "/rust/qdb-sqllogictest/target/release/" + rustLibName).toAbsolutePath(); |
| 85 | Path absoluteDevDebugPath = Paths.get(sourcesPath + "/rust/qdb-sqllogictest/target/debug/" + rustLibName).toAbsolutePath(); |
| 86 | Path absolutePrdPath = Paths.get(absolutePathPreCompiled); |
| 87 | |
| 88 | FileTime tsDevRel = getLastModifiedTime(absoluteDevReleasePath); |
| 89 | FileTime tsDevDeb = getLastModifiedTime(absoluteDevDebugPath); |
| 90 | FileTime tsPrd = getLastModifiedTime(absolutePrdPath); |
| 91 | |
| 92 | Path rustLibPath; |
| 93 | if (tsDevRel.compareTo(tsPrd) > 0 && tsDevRel.compareTo(tsDevDeb) > 0) { |
| 94 | System.err.println("Loading DEV release sqllogictest library: " + absoluteDevReleasePath); |
| 95 | rustLibPath = absoluteDevReleasePath; |
| 96 | } else if (tsDevDeb.compareTo(tsPrd) > 0) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…