private void findLibraryArtifact() { try { if (!tryProviderClass("org.newsclub.lib.junixsocket.common.NarMetadata", "junixsocket-native-common") && // !tryProviderClass("org.newsclub.lib.junixsocket.custom.NarMetadata", "junixsocket-native-custom") // ) { String cp = System.getProperty("java.class.path", ""); if (cp.contains("junixsocket-native-custom/target-eclipse") || cp.contains( "junixsocket-native-common/target-eclipse")) { throw new UnsatisfiedLinkError("Could not load native library.\n\n*** ECLIPSE USERS ***\n" + "If you're running from within Eclipse, please close the \"junixsocket-native-*\" projects\n"); } if (artifactName != null) { throw new UnsatisfiedLinkError("Artifact " + artifactName + " does not contain library for " + architectureAndOS); } else { throw new ClassNotFoundException( "You need to add a dependency to either junixsocket-native-common or junixsocket-native-custom"); } } } catch (Exception e) { throw new RuntimeException(e); } }
if (!libraryOverride.isEmpty()) { System.loadLibrary(libraryOverride); setLoaded(libraryOverride); return; findLibraryArtifact(); try { System.loadLibrary(libraryNameAndVersion); setLoaded(artifactName + "/" + libraryNameAndVersion); return; } catch (LinkageError e) { libFile = createTempFile("libtmp", System.mapLibraryName(libraryNameAndVersion)); try (OutputStream out = new FileOutputStream(libFile)) { byte[] buf = new byte[4096]; setLoaded(artifactName + "/" + libraryNameAndVersion); if (!libFile.delete()) { libFile.deleteOnExit(); close();
private boolean tryProviderClass(String providerClassname, String artifactCandidate) throws IOException { try { this.providerClass = Class.forName(providerClassname); } catch (ClassNotFoundException e) { return false; } this.artifactName = artifactCandidate; Properties p = new Properties(); try (InputStream in = providerClass.getResourceAsStream( "/META-INF/maven/com.kohlschutter.junixsocket/" + artifactCandidate + "/pom.properties")) { p.load(in); this.version = p.getProperty("version"); if (version == null) { throw new NullPointerException("Could not read version from pom.properties"); } this.libraryNameAndVersion = libraryName + "-" + version; } this.libraryIn = findLibrary(); if (libraryIn != null) { return true; } else { return false; } }