Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add "org.bytedeco.javacpp.findLibraries" system property to disable search for libraries ([pull #565](https://github.com/bytedeco/javacpp/pull/565))
* Fix `Generator` causing memory leaks for `String` parameters on callback ([issue bytedeco/javacpp-presets#1141](https://github.com/bytedeco/javacpp-presets/issues/1141))
* Add `Loader.new/access/deleteGlobalRef()` methods to store JNI `Object` references in `Pointer` ([issue bytedeco/javacpp-presets#1141](https://github.com/bytedeco/javacpp-presets/issues/1141))
* Make `Loader.findLibrary()` also search in "sun.boot.library.path" for jlink ([pull #565](https://github.com/bytedeco/javacpp/pull/565))
Expand Down
38 changes: 24 additions & 14 deletions src/main/java/org/bytedeco/javacpp/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,9 @@ public static URL[] findResources(Class cls, String name, int maxLength) throws
static boolean pathsFirst = false;
/** Whether to extract libraries to {@link #cacheDir}, set via "org.bytedeco.javacpp.cacheLibraries" system property. */
static boolean cacheLibraries = true;
/** Whether to search libraries in class, module, and library paths, set via "org.bytedeco.javacpp.findLibraries" system property. */
static boolean findLibraries = true;

static {
String s = System.getProperty("org.bytedeco.javacpp.pathsfirst", "false").toLowerCase();
s = System.getProperty("org.bytedeco.javacpp.pathsFirst", s).toLowerCase();
Expand All @@ -961,6 +964,10 @@ public static URL[] findResources(Class cls, String name, int maxLength) throws
s = System.getProperty("org.bytedeco.javacpp.cachelibraries", "true").toLowerCase();
s = System.getProperty("org.bytedeco.javacpp.cacheLibraries", s).toLowerCase();
cacheLibraries = s.equals("true") || s.equals("t") || s.equals("");

s = System.getProperty("org.bytedeco.javacpp.findlibraries", "true").toLowerCase();
s = System.getProperty("org.bytedeco.javacpp.findLibraries", s).toLowerCase();
findLibraries = s.equals("true") || s.equals("t") || s.equals("");
}

/** Deletes the directory and all the files in it. */
Expand Down Expand Up @@ -1285,7 +1292,8 @@ public static String load(Class cls, Properties properties, boolean pathsFirst,

String cacheDir = null;
try {
cacheDir = cacheLibraries ? getCacheDir().toString() : null;
// Checking for findLibraries prevents the creation of an empty useless cache dir
cacheDir = cacheLibraries && findLibraries ? getCacheDir().toString() : null;
} catch (IOException e) {
// no cache dir, no worries
}
Expand All @@ -1306,7 +1314,7 @@ public static String load(Class cls, Properties properties, boolean pathsFirst,
preload = preload.substring(0, preload.length() - 1);
}
URL[] urls = foundLibraries.get(preload), oldUrls = urls;
if (urls == null) {
if (urls == null && findLibraries) {
foundLibraries.put(preload, urls = findLibrary(cls, p, preload, pathsFirst));
}
String filename = null;
Expand Down Expand Up @@ -1400,7 +1408,7 @@ public static String load(Class cls, Properties properties, boolean pathsFirst,
library += "#" + library + librarySuffix;
}
URL[] urls = foundLibraries.get(library), oldUrls = urls;
if (urls == null) {
if (urls == null && findLibraries) {
foundLibraries.put(library, urls = findLibrary(cls, p, library, pathsFirst));
}
String filename = null;
Expand Down Expand Up @@ -1487,20 +1495,22 @@ public static URL[] findLibrary(Class cls, ClassProperties properties, String li
String[] extensions = properties.get("platform.extension").toArray(new String[0]);
String prefix = properties.getProperty("platform.library.prefix", "");
String suffix = properties.getProperty("platform.library.suffix", "");
String[] styles = {
prefix + libname + suffix + version, // Linux style
prefix + libname + version + suffix, // Mac OS X style
prefix + libname + suffix // without version
};
String[] styles2 = {
prefix + libname2 + suffix + version2, // Linux style
prefix + libname2 + version2 + suffix, // Mac OS X style
prefix + libname2 + suffix // without version
};
String[] styles, styles2;
if (version.length() == 0 && version2.length() == 0) {
// optimize a bit for this case in particular on Windows
styles = new String[] { prefix + libname + suffix };
styles2 = new String[] { prefix + libname2 + suffix };
} else {
styles = new String[] {
prefix + libname + suffix + version, // Linux style
prefix + libname + version + suffix, // Mac OS X style
prefix + libname + suffix // without version
};
styles2 = new String[] {
prefix + libname2 + suffix + version2, // Linux style
prefix + libname2 + version2 + suffix, // Mac OS X style
prefix + libname2 + suffix // without version
};
}

String[] suffixes = properties.get("platform.library.suffix").toArray(new String[0]);
Expand Down Expand Up @@ -1663,7 +1673,7 @@ public static synchronized String loadLibrary(Class<?> cls, URL[] urls, String l
UnsatisfiedLinkError loadError = null;
classStack.get().push(cls);
try {
for (URL url : urls) {
for (URL url : urls != null ? urls : new URL[0]) {
URI uri = url.toURI();
File file = null;
try {
Expand Down