2
0

Harmonize standardized platform naming between Native class and gradle.

This commit is contained in:
Maarten Billemont 2018-06-25 12:25:38 -04:00
parent b1698ee339
commit b5040a7786
6 changed files with 73 additions and 19 deletions

View File

@ -1,5 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="javax.annotation.Nullable" />
<option name="myDefaultNotNull" value="javax.annotation.Nonnull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>

View File

@ -1,6 +1,5 @@
#Fri Jun 22 01:12:28 EDT 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip

View File

@ -79,18 +79,28 @@ library {
static String standardOperatingSystem(NativePlatform platform) { static String standardOperatingSystem(NativePlatform platform) {
OperatingSystem os = platform.getOperatingSystem() OperatingSystem os = platform.getOperatingSystem()
if (os.isWindows()) { if (os.isWindows())
return OperatingSystemFamily.WINDOWS return OperatingSystemFamily.WINDOWS
} else if (os.isLinux()) { else if (os.isMacOsX())
return OperatingSystemFamily.LINUX
} else if (os.isMacOsX()) {
return OperatingSystemFamily.MAC_OS 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) { static String standardArchitecture(NativePlatform platform) {
Architecture arch = platform.getArchitecture() 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"
} }

View File

@ -18,12 +18,16 @@
package com.lyndir.masterpassword.impl; package com.lyndir.masterpassword.impl;
import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import java.io.*; import java.io.*;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** /**
@ -45,7 +49,8 @@ public final class Native {
try { try {
System.loadLibrary( name ); System.loadLibrary( name );
return; 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. // Try to find and open a stream to the packaged library resource.
@ -82,10 +87,26 @@ public final class Native {
@Nonnull @Nonnull
private static String getLibraryResource(final String library) { private static String getLibraryResource(final String library) {
String system = System.getProperty( "os.name" ).toLowerCase( Locale.ROOT ); String system = ifNotNullElse( System.getProperty( "os.name" ), "linux" ).toLowerCase( Locale.ROOT );
String architecture = System.getProperty( "os.arch" ).toLowerCase( Locale.ROOT ); String architecture = ifNotNullElse( System.getProperty( "os.arch" ), "x86" ).toLowerCase( Locale.ROOT );
if ("Mac OS X".equalsIgnoreCase( system ))
// 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"; 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 ); return Joiner.on( RESOURCE_SEPARATOR ).join( "", NATIVES_PATH, system, architecture, library );
} }

View File

@ -18,7 +18,7 @@ dependencies {
compileOnly group: 'com.google.auto.value', name: 'auto-value', version: '1.2' compileOnly group: 'com.google.auto.value', name: 'auto-value', version: '1.2'
apt 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' testImplementation group: 'org.testng', name: 'testng', version: '6.8.5'
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2' testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2'
} }
test.useTestNG() test.useTestNG()

View File

@ -7,11 +7,11 @@ description = 'Master Password Test Suite'
dependencies { dependencies {
implementation group: 'com.lyndir.lhunath.opal', name: 'opal-system', version: '1.7-p2' implementation group: 'com.lyndir.lhunath.opal', name: 'opal-system', version: '1.7-p2'
compile project( ':masterpassword-algorithm' ) implementation project( ':masterpassword-algorithm' )
compile project( ':masterpassword-model' ) implementation project( ':masterpassword-model' )
testCompile group: 'org.testng', name: 'testng', version: '6.8.5' testImplementation group: 'org.testng', name: 'testng', version: '6.8.5'
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2' testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2'
} }
//tasks.withType(Test) { //tasks.withType(Test) {
// systemProperty "java.library.path", "/Users/lhunath/Documents/workspace/lyndir/MasterPassword/core/java/algorithm/build/libs/mpw/shared" // systemProperty "java.library.path", "/Users/lhunath/Documents/workspace/lyndir/MasterPassword/core/java/algorithm/build/libs/mpw/shared"