From efed076de49b5a115cd5f437a0a7d07bd594b165 Mon Sep 17 00:00:00 2001 From: Secret Date: Wed, 9 Oct 2024 11:39:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +- src/main/java/org/gmssl/NativeLoader.java | 79 ++++++++++++----------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/pom.xml b/pom.xml index 184d92d..4393002 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,8 @@ UTF-8 - 11 - 11 + 8 + 8 false Debug @@ -33,7 +33,7 @@ com.googlecode.cmake-maven-project cmake-maven-plugin - 3.23.2-b1 + 3.27.7-b1 cmake-generate diff --git a/src/main/java/org/gmssl/NativeLoader.java b/src/main/java/org/gmssl/NativeLoader.java index dc119b8..0e28827 100644 --- a/src/main/java/org/gmssl/NativeLoader.java +++ b/src/main/java/org/gmssl/NativeLoader.java @@ -8,7 +8,9 @@ */ package org.gmssl; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -17,17 +19,15 @@ /** * @author yongfei.li - * @email 290836576@qq.com + * @email 290836576@qq.com * @date 2023/09/07 * @description Native lib load util */ public class NativeLoader { + static final String GMSSLJNILIB_NAME = "libgmssljni"; /* custom jni library prefix path relative to project resources */ private static final String RESOURCELIB_PREFIXPATH = "lib"; - - static final String GMSSLJNILIB_NAME="libgmssljni"; - private static final Properties PROPERTIES = new Properties(); static { @@ -44,64 +44,66 @@ public class NativeLoader { /** * load jni lib from resources path,the parameter does not contain the path and suffix. - * @param libaray libarayName * + * @param libaray libarayName */ - public synchronized static void load (String libaray){ + public synchronized static void load(String libaray) { String resourceLibPath = RESOURCELIB_PREFIXPATH + "/" + libaray + "." + libExtension(); try (InputStream inputStream = NativeLoader.class.getClassLoader().getResourceAsStream(resourceLibPath)) { if (null == inputStream) { throw new GmSSLException("lib file not found in JAR: " + resourceLibPath); } - Path tempFile = Files.createTempFile(libaray, "."+libExtension()); + Path tempFile = Files.createTempFile(libaray, "." + libExtension()); tempFile.toFile().deleteOnExit(); Files.copy(inputStream, tempFile, StandardCopyOption.REPLACE_EXISTING); checkReferencedLib(); System.load(tempFile.toAbsolutePath().toString()); } catch (Exception e) { - throw new GmSSLException("Unable to load lib from JAR"); + throw new GmSSLException("Unable to load lib from JAR,resourceLibPath:" + resourceLibPath); } } /** * Get the operating system type. + * * @return operating system name */ - static String osType(){ - String os="unknown"; + static String osType() { + String os = "unknown"; String osName = System.getProperty("os.name").toLowerCase(); - if(osName.startsWith("windows")){ - os="win"; + if (osName.startsWith("windows")) { + os = "win"; } - if(osName.startsWith("linux")){ + if (osName.startsWith("linux")) { if ("dalvik".equalsIgnoreCase(System.getProperty("java.vm.name"))) { os = "android"; System.setProperty("jna.nounpack", "true"); } else { - os="linux"; + os = "linux"; } } - if(osName.startsWith("mac os x") || osName.startsWith("darwin")){ - os="osx"; + if (osName.startsWith("mac os x") || osName.startsWith("darwin")) { + os = "osx"; } return os; } /** * Get the library extension name based on the operating system type. + * * @return extension name */ - static String libExtension(){ - String osType=osType(); - String libExtension=null; - if("win".equals(osType)){ - libExtension="dll"; + static String libExtension() { + String osType = osType(); + String libExtension = null; + if ("win".equals(osType)) { + libExtension = "dll"; } - if("osx".equals(osType)){ - libExtension="dylib"; + if ("osx".equals(osType)) { + libExtension = "dylib"; } - if("linux".equals(osType)){ - libExtension="so"; + if ("linux".equals(osType)) { + libExtension = "so"; } return libExtension; } @@ -112,20 +114,19 @@ static String libExtension(){ * in order to correct the @rpath path issue. Alternatively, you can manually execute the command * "install_name_tool -change @rpath/libgmssl.3.dylib /usr/local/lib/libgmssl.3.dylib xxx/lib/libgmssljni.dylib" to fix the library reference path issue. * This has already been loaded and manual execution is unnecessary. - * */ - private static void checkReferencedLib(){ - if("osx".equals(osType())){ - String macReferencedLib=PROPERTIES.getProperty("macReferencedLib"); - Optional optionalStr = Optional.ofNullable(macReferencedLib); - if(optionalStr.isPresent() && !optionalStr.get().isEmpty()){ - File libFile = new File(macReferencedLib); - if(libFile.exists()){ - System.load(macReferencedLib); - } - } + private static void checkReferencedLib() { + if ("osx".equals(osType())) { + String macReferencedLib = PROPERTIES.getProperty("macReferencedLib"); + Optional optionalStr = Optional.ofNullable(macReferencedLib); + if (optionalStr.isPresent() && !optionalStr.get().isEmpty()) { + File libFile = new File(macReferencedLib); + if (libFile.exists()) { + System.load(macReferencedLib); + } + } - } - } + } + } } From 7a34ab71bd66da843dfe90577a56f6bb15051445 Mon Sep 17 00:00:00 2001 From: Secret Date: Wed, 9 Oct 2024 11:50:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4393002..43d2a22 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 org.gmssl - GmSSLJNI + GmSSLJNI-Windows 3.1.1 GmSSL-Java jar @@ -181,4 +181,16 @@ + + + junpzx-custom-nexus + junpzx-custom-nexus-snapshots + https://repository.junpzx.cn/repository/maven-local-snapshot/ + + + junpzx-custom-nexus + junpzx-custom-nexus-releases + https://repository.junpzx.cn/repository/maven-local/ + + \ No newline at end of file From ac50da5005b48de7c96cba01387e6f6d18bb7d78 Mon Sep 17 00:00:00 2001 From: Secret Date: Wed, 9 Oct 2024 11:51:26 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 43d2a22..3aec72e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 org.gmssl - GmSSLJNI-Windows + GmSSLJNI 3.1.1 GmSSL-Java jar