Repository: commons-crypto Updated Branches: refs/heads/master 55910b7b2 -> 7274287f3
CRYPTO-90 Utils loads system properties during class loading Fix up NativeCodeLoader so it still sees properties from the local file. These are no longer copied into the System props, so need to use the defaultProperties from Utils Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/7274287f Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/7274287f Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/7274287f Branch: refs/heads/master Commit: 7274287f3277a3e62bac8c2270ded0d82e32fef5 Parents: 55910b7 Author: Sebb <s...@apache.org> Authored: Tue Jul 5 10:49:44 2016 +0100 Committer: Sebb <s...@apache.org> Committed: Tue Jul 5 10:49:44 2016 +0100 ---------------------------------------------------------------------- .../apache/commons/crypto/NativeCodeLoader.java | 40 +++++--------------- 1 file changed, 9 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/7274287f/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java index 255d2f6..1a4725e 100644 --- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java +++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java @@ -29,6 +29,7 @@ import java.util.UUID; import org.apache.commons.crypto.conf.ConfigurationKeys; import org.apache.commons.crypto.utils.IoUtils; +import org.apache.commons.crypto.utils.Utils; /** * A helper to load the native code i.e. libcommons-crypto.so. This handles the @@ -38,6 +39,7 @@ import org.apache.commons.crypto.utils.IoUtils; final class NativeCodeLoader { private final static boolean nativeCodeLoaded; + /** * The private constructor of {@link NativeCodeLoader}. */ @@ -72,9 +74,12 @@ final class NativeCodeLoader { * @return the jar file. */ private static File findNativeLibrary() { + // Get the properties once + final Properties props = Utils.getDefaultProperties(); + // Try to load the library in commons-crypto.lib.path */ - String nativeLibraryPath = NativeCodeLoader.getLibPath(); - String nativeLibraryName = NativeCodeLoader.getLibName(); + String nativeLibraryPath = props.getProperty(ConfigurationKeys.LIB_PATH_KEY); + String nativeLibraryName = props.getProperty(ConfigurationKeys.LIB_NAME_KEY); // Resolve the library file name with a suffix (e.g., dll, .so, etc.) if (nativeLibraryName == null) { @@ -110,7 +115,8 @@ final class NativeCodeLoader { // Temporary folder for the native lib. Use the value of // commons-crypto.tempdir or java.io.tmpdir - String tempFolder = new File(NativeCodeLoader.getTmpDir()).getAbsolutePath(); + String tempFolder = new File(props.getProperty(ConfigurationKeys.LIB_TEMPDIR_KEY, + System.getProperty("java.io.tmpdir"))).getAbsolutePath(); // Extract and load a native library inside the jar file return extractLibraryFile(nativeLibraryPath, nativeLibraryName, @@ -272,32 +278,4 @@ final class NativeCodeLoader { static boolean isNativeCodeLoaded() { return nativeCodeLoaded; } - - /** - * Gets the temp directory for extracting crypto library. - * - * @return the temp directory. - */ - private static String getTmpDir() { - return System.getProperty(ConfigurationKeys.LIB_TEMPDIR_KEY, - System.getProperty("java.io.tmpdir")); - } - - /** - * Gets the file name of native library. - * - * @return the file name of native library. - */ - private static String getLibName() { - return System.getProperty(ConfigurationKeys.LIB_NAME_KEY); - } - - /** - * Gets path of native library. - * - * @return the path of native library. - */ - private static String getLibPath() { - return System.getProperty(ConfigurationKeys.LIB_PATH_KEY); - } }