private static boolean verifyLoading(Throwable[] failureReason, String logname) { logInfo(Internal.class, "loaded " + logname); LinkageError linkError = checkLoaded(); if (linkError == null) { return true; } logFine(Internal.class, "cannot use " + logname + ": " + linkError); updateLoadFailureReason(failureReason, linkError); return false; }
private static String getDefaultLibPath(String classUrl) { return getDefaultLibPath(System.getProperty("java.library.path"), classUrl); }
private static LinkageError checkLoaded() { try { getLibraryVersionMessage(); return null; } catch (LinkageError e) { return e; } }
static Throwable loadLibraryX() { if (checkLoaded() == null) return null; if ("true".equalsIgnoreCase(System.getProperty("sqlite4java.debug"))) { logger.setLevel(Level.FINE); String classUrl = getClassUrl(); String defaultPath = getDefaultLibPath(classUrl); String versionSuffix = getVersionSuffix(classUrl); String forcedPath = getForcedPath(); if (Internal.isFineLogging()) { logFine(Internal.class, "loading library"); logFine(Internal.class, "java.library.path=" + System.getProperty("java.library.path")); logFine(Internal.class, "sqlite4java.library.path=" + System.getProperty("sqlite4java.library.path")); logFine(Internal.class, "cwd=" + new File(".").getAbsolutePath()); logFine(Internal.class, "default path=" + (defaultPath == null ? "null " : new File(defaultPath).getAbsolutePath())); logFine(Internal.class, "forced path=" + (forcedPath == null ? "null " : new File(forcedPath).getAbsolutePath())); String os = getOs(); String arch = getArch(os); List<String> names = collectLibraryNames(versionSuffix, os, arch); Throwable[] failureReason = {null}; boolean loaded = false; loaded = tryLoadFromPath(name, os, forcedPath, failureReason); if (loaded) break; loaded = tryLoadFromPath(name, os, defaultPath, failureReason); if (loaded) break;
static String getVersionSuffix(String classUrl) { File jar = getJarFileFromClassUrl(classUrl); if (jar == null) return null; String name = jar.getName(); String lower = name.toLowerCase(Locale.US); if (!lower.startsWith(BASE_LIBRARY_NAME)) return null; if (!lower.endsWith(".jar")) return null; int f = BASE_LIBRARY_NAME.length(); int t = name.length() - 4; // ".jar".length() return f + 1 < t && name.charAt(f) == '-' ? name.substring(f, t) : null; }
private static List<String> collectLibraryNames(String versionSuffix, String os, String arch) { List<String> baseSuffixes = collectBaseLibraryNames(os, arch); ArrayList<String> r = new ArrayList<String>(24); String[] configurationSuffixes = SQLite.isDebugBinaryPreferred() ? DEBUG_SUFFIXES : RELEASE_SUFFIXES; if (versionSuffix != null) { for (String configurationSuffix : configurationSuffixes) { for (String baseSuffix : baseSuffixes) { r.add(baseSuffix + configurationSuffix + versionSuffix); } } } for (String configurationSuffix : configurationSuffixes) { for (String baseSuffix : baseSuffixes) { r.add(baseSuffix + configurationSuffix); } } return r; }
File jar = getJarFileFromClassUrl(classUrl); if (jar == null) return null;