Skip to content

Commit

Permalink
Revert replacement of "/" by File.separator
Browse files Browse the repository at this point in the history
Resources use "/" on all systems
  • Loading branch information
sebbASF committed Nov 30, 2023
1 parent 1d2759b commit 1ae8893
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
*/
final class NativeCodeLoader {

/** The separator to be used in constructing a resource path */
private static final String RESOURCE_PATH_SEPARATOR = "/";

private static final String SIMPLE_NAME = NativeCodeLoader.class.getSimpleName();

private static final String NATIVE_LIBNAME = "commons-crypto";
Expand Down Expand Up @@ -82,7 +85,7 @@ private static void debug(final String format, final Object... args) {
*/
private static File extractLibraryFile(final String libFolderForCurrentOS, final String libraryFileName,
final String targetFolder) {
final String nativeLibraryFilePath = libFolderForCurrentOS + File.separator + libraryFileName;
final String nativeLibraryFilePath = libFolderForCurrentOS + RESOURCE_PATH_SEPARATOR + libraryFileName;

// Attach UUID to the native library file to ensure multiple class loaders
// can read the libcommons-crypto multiple times.
Expand Down Expand Up @@ -171,12 +174,12 @@ private static File findNativeLibrary() {
// Load an OS-dependent native library inside a jar file
nativeLibraryPath = "/org/apache/commons/crypto/native/" + OsInfo.getNativeLibFolderPathForCurrentOS();
debug("%s nativeLibraryPath = %s", SIMPLE_NAME, nativeLibraryPath);
final String resource = nativeLibraryPath + File.separator + nativeLibraryName;
final String resource = nativeLibraryPath + RESOURCE_PATH_SEPARATOR + nativeLibraryName;
boolean hasNativeLib = hasResource(resource);
debug("%s resource %s exists = %s", SIMPLE_NAME, resource, hasNativeLib);
if (!hasNativeLib) {
final String altName = NATIVE_LIBNAME_ALT;
if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + File.separator + altName)) {
if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + RESOURCE_PATH_SEPARATOR + altName)) {
// Fix for openjdk7 for Mac
nativeLibraryName = altName;
hasNativeLib = true;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/apache/commons/crypto/OsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.commons.crypto;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
Expand All @@ -28,6 +27,9 @@
*/
final class OsInfo {

/** The separator to be used in constructing a resource path */
private static final String RESOURCE_PATH_SEPARATOR = "/";

private final static HashMap<String, String> archMapping = new HashMap<>();

/**
Expand Down Expand Up @@ -140,7 +142,7 @@ static String getArchName() {
* @return the current OS's native lib folder.
*/
static String getNativeLibFolderPathForCurrentOS() {
return getOSName() + File.separator + getArchName();
return getOSName() + RESOURCE_PATH_SEPARATOR + getArchName();
}

/**
Expand Down

0 comments on commit 1ae8893

Please sign in to comment.