From b5040a7786456ee85e8322b7f81ca9325fa353f6 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Mon, 25 Jun 2018 12:25:38 -0400 Subject: [PATCH] Harmonize standardized platform naming between Native class and gradle. --- gradle/.idea/misc.xml | 24 +++++++++++++++ .../gradle/wrapper/gradle-wrapper.properties | 3 +- platform-independent/c/core/build.gradle | 24 ++++++++++----- .../lyndir/masterpassword/impl/Native.java | 29 ++++++++++++++++--- platform-independent/java/model/build.gradle | 4 +-- platform-independent/java/tests/build.gradle | 8 ++--- 6 files changed, 73 insertions(+), 19 deletions(-) diff --git a/gradle/.idea/misc.xml b/gradle/.idea/misc.xml index fdae1d0d..88b86d0a 100644 --- a/gradle/.idea/misc.xml +++ b/gradle/.idea/misc.xml @@ -1,5 +1,29 @@ + + + + diff --git a/gradle/gradle/wrapper/gradle-wrapper.properties b/gradle/gradle/wrapper/gradle-wrapper.properties index 49df2ab4..16d28051 100644 --- a/gradle/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 22 01:12:28 EDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip diff --git a/platform-independent/c/core/build.gradle b/platform-independent/c/core/build.gradle index 4de67c83..5b97e0dd 100644 --- a/platform-independent/c/core/build.gradle +++ b/platform-independent/c/core/build.gradle @@ -79,18 +79,28 @@ library { static String standardOperatingSystem(NativePlatform platform) { OperatingSystem os = platform.getOperatingSystem() - if (os.isWindows()) { + if (os.isWindows()) return OperatingSystemFamily.WINDOWS - } else if (os.isLinux()) { - return OperatingSystemFamily.LINUX - } else if (os.isMacOsX()) { + else if (os.isMacOsX()) return OperatingSystemFamily.MAC_OS - } + else if (os.isLinux()) + return OperatingSystemFamily.LINUX - return os.name.toLowerCase() + // Other systems will need to use a Linux compatibility layer for now. + return OperatingSystemFamily.LINUX } static String standardArchitecture(NativePlatform platform) { Architecture arch = platform.getArchitecture() - return arch.name.toLowerCase().replaceAll( "-", "_" ) + if (arch.isArm()) + return "arm" + else if (arch.name.toLowerCase( Locale.ROOT ).startsWith( "arm" )) + return "arm64" + else if (arch.isAmd64()) + return "x86_64" + else if (arch.isI386()) + return "x86" + + // Other systems will need to be compatible with the x86 architecture. + return "x86" } diff --git a/platform-independent/java/algorithm/src/main/java/com/lyndir/masterpassword/impl/Native.java b/platform-independent/java/algorithm/src/main/java/com/lyndir/masterpassword/impl/Native.java index 1d69f4c8..63c036ea 100644 --- a/platform-independent/java/algorithm/src/main/java/com/lyndir/masterpassword/impl/Native.java +++ b/platform-independent/java/algorithm/src/main/java/com/lyndir/masterpassword/impl/Native.java @@ -18,12 +18,16 @@ package com.lyndir.masterpassword.impl; +import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; + import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; import com.google.common.io.ByteStreams; import com.lyndir.lhunath.opal.system.logging.Logger; import java.io.*; import java.util.Locale; import javax.annotation.Nonnull; +import javax.annotation.Nullable; /** @@ -45,7 +49,8 @@ public final class Native { try { System.loadLibrary( name ); return; - } catch (@SuppressWarnings("ErrorNotRethrown") final UnsatisfiedLinkError ignored) { + } + catch (@SuppressWarnings("ErrorNotRethrown") final UnsatisfiedLinkError ignored) { } // Try to find and open a stream to the packaged library resource. @@ -82,10 +87,26 @@ public final class Native { @Nonnull private static String getLibraryResource(final String library) { - String system = System.getProperty( "os.name" ).toLowerCase( Locale.ROOT ); - String architecture = System.getProperty( "os.arch" ).toLowerCase( Locale.ROOT ); - if ("Mac OS X".equalsIgnoreCase( system )) + String system = ifNotNullElse( System.getProperty( "os.name" ), "linux" ).toLowerCase( Locale.ROOT ); + String architecture = ifNotNullElse( System.getProperty( "os.arch" ), "x86" ).toLowerCase( Locale.ROOT ); + + // Standardize system naming in accordance with masterpassword-core. + if (system.contains( "windows" )) + system = "windows"; + else if (system.contains( "mac os x" ) || system.contains( "darwin" ) || system.contains( "osx" )) system = "macos"; + else + system = "linux"; + + // Standardize architecture naming in accordance with masterpassword-core. + if (ImmutableList.of( "arm", "arm-v7", "armv7", "arm32" ).contains( architecture )) + architecture = "arm"; + else if (architecture.startsWith( "arm" )) + architecture = "arm64"; + else if (ImmutableList.of( "x86_64", "amd64", "x64", "x86-64" ).contains( architecture )) + architecture = "x86_64"; + else + architecture = "x86"; return Joiner.on( RESOURCE_SEPARATOR ).join( "", NATIVES_PATH, system, architecture, library ); } diff --git a/platform-independent/java/model/build.gradle b/platform-independent/java/model/build.gradle index 8e1584bc..a2b00d23 100644 --- a/platform-independent/java/model/build.gradle +++ b/platform-independent/java/model/build.gradle @@ -18,7 +18,7 @@ dependencies { compileOnly group: 'com.google.auto.value', name: 'auto-value', version: '1.2' apt group: 'com.google.auto.value', name: 'auto-value', version: '1.2' - testCompile group: 'org.testng', name: 'testng', version: '6.8.5' - testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2' + testImplementation group: 'org.testng', name: 'testng', version: '6.8.5' + testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2' } test.useTestNG() diff --git a/platform-independent/java/tests/build.gradle b/platform-independent/java/tests/build.gradle index 9737d6a9..3f26e7b1 100644 --- a/platform-independent/java/tests/build.gradle +++ b/platform-independent/java/tests/build.gradle @@ -7,11 +7,11 @@ description = 'Master Password Test Suite' dependencies { implementation group: 'com.lyndir.lhunath.opal', name: 'opal-system', version: '1.7-p2' - compile project( ':masterpassword-algorithm' ) - compile project( ':masterpassword-model' ) + implementation project( ':masterpassword-algorithm' ) + implementation project( ':masterpassword-model' ) - testCompile group: 'org.testng', name: 'testng', version: '6.8.5' - testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2' + testImplementation group: 'org.testng', name: 'testng', version: '6.8.5' + testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2' } //tasks.withType(Test) { // systemProperty "java.library.path", "/Users/lhunath/Documents/workspace/lyndir/MasterPassword/core/java/algorithm/build/libs/mpw/shared"