Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add directory layout according to os-maven-plugin and osdetector-gradle-plugin #32

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,26 @@ following directory & file structure:

```
/natives
/linux_32
/linux-x86_32-32
libxxx[-vvv].so
/linux_64
/linux-x86_64-64
libxxx[-vvv].so
/osx_32
/osx-x86_32-32
libxxx[-vvv].dylib
/osx_64
/osx-x86_64-64
libxxx[-vvv].dylib
/osx_arm64
/osx-aarch_64-64
libxxx[-vvv].dylib
/windows_32
/windows_x86_32-32
xxx[-vvv].dll
/windows_64
/windows-x86_64-64
xxx[-vvv].dll
/aix_32
/windows-itanium_64-64
xxx[-vvv].dll
/aix_ppc_32-32
libxxx[-vvv].so
libxxx[-vvv].a
/aix_64
/aix_ppc_64-64
libxxx[-vvv].so
libxxx[-vvv].a
```
Expand Down
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ Wisconsin-Madison and Glencoe Software, Inc.</license.copyrightOwners>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!--Logback for test as implementaiton.-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -158,6 +167,19 @@ Wisconsin-Madison and Glencoe Software, Inc.</license.copyrightOwners>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>
${project.build.directory}/test-classes/dummy.jar
</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
</project>
77 changes: 77 additions & 0 deletions src/main/java/org/scijava/nativelib/DefaultOsInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.scijava.nativelib;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.scijava.nativelib.NativeOsArchUtil.*;

import java.util.Collections;
import java.util.List;

public enum DefaultOsInfo {
/* 32 bit */
AIX_PPC_32(OS_FAMILY_AIX, ARCH_PPCLE32, 32, LegacyConstants.LIST_AIX_32),
LINUX_ARM_32(OS_FAMILY_LINUX, ARCH_ARM32, 32, LegacyConstants.LIST_LINUX_ARM),
LINUX_X86_32(OS_FAMILY_LINUX, ARCH_X86_32, 32, LegacyConstants.LIST_LINUX_32),
MACOS_PPC_32(OS_FAMILY_OSX, ARCH_PPCLE32, 32, LegacyConstants.LIST_OSX_32),
SOLARIS_SPARC_32(OS_FAMILY_SOLARIS, ARCH_SPARC32, 32, LegacyConstants.LIST_SOLARIS_32),
WINDOWS_X86_32(OS_FAMILY_WINDOWS, ARCH_X86_32, 32, LegacyConstants.LIST_WINDOWS_32),
/* 64 bit */
AIX_PPC64_64(OS_FAMILY_AIX, ARCH_PPC64, 64, LegacyConstants.LIST_AIX_64),
LINUX_X86_64(OS_FAMILY_LINUX, ARCH_X86_64, 64, LegacyConstants.LIST_LINUX_64),
LINUX_AARCH_64(OS_FAMILY_LINUX, ARCH_AARCH64, 64, LegacyConstants.LIST_LINUX_ARM_64),
LINUX_PPC64LE_64(OS_FAMILY_LINUX, ARCH_PPCLE64, 64, LegacyConstants.LIST_LINUX_64),
MACOS_X86_64(OS_FAMILY_OSX, ARCH_X86_64, 64, LegacyConstants.LIST_OSX_64),
SOLARIS_SPARCV9_64(OS_FAMILY_SOLARIS, ARCH_SPARC64, 64, LegacyConstants.LIST_SOLARIS_64),
WINDOWS_X86_64(OS_FAMILY_WINDOWS, ARCH_X86_64, 64, LegacyConstants.LIST_WINDOWS_64),
WINDOWS_EM64T_64(OS_FAMILY_WINDOWS, ARCH_X86_64, 64, LegacyConstants.LIST_WINDOWS_64),
WINDOWS_IA64_64(OS_FAMILY_WINDOWS, ARCH_IA64, 64, LegacyConstants.LIST_WINDOWS_64);

private final OsInfo osInfo;
private final List<String> legacyPaths;

/**
* Creates a DefaultOsInfo-Item.
*
* @param family the os family. Use {@link NativeOsArchUtil#determineOsFamily(String)}.
* @param architecture the architecture as reported by {@code os.name}.
* @param bitness the bitness (usually 32 or 64).
* @param legacyPaths a list of legacy path fragmets for compatiblity. Use {@link Collections#emptyList()} if in doubt.
* @throws NullPointerException if any parameter is null.
*/
DefaultOsInfo(final String family, final String architecture, final int bitness, final List<String> legacyPaths) {
this.osInfo = OsInfoFactory.from(family, architecture, bitness);
this.legacyPaths = unmodifiableList(legacyPaths);
}

public OsInfo getOsInfo() {
return this.osInfo;
}

public List<String> getLegacyPaths() {
return this.legacyPaths;
}

@Override
public String toString() {
return "DefaultOsInfo{" +
"osInfo=" + this.osInfo +
"legacyPaths=" + this.legacyPaths +
"} " + super.toString();
}

private static class LegacyConstants {

public static final List<String> LIST_AIX_32 = asList("aix_32");
public static final List<String> LIST_LINUX_ARM = asList("linux_arm");
public static final List<String> LIST_LINUX_32 = asList("linux_32");
public static final List<String> LIST_OSX_32 = asList("osx_32");
public static final List<String> LIST_SOLARIS_32 = asList("solaris_32");
public static final List<String> LIST_WINDOWS_32 = asList("windows_32");
public static final List<String> LIST_AIX_64 = asList("aix_64");
public static final List<String> LIST_LINUX_64 = asList("linux_64");
public static final List<String> LIST_LINUX_ARM_64 = asList("linux_arm64");
public static final List<String> LIST_OSX_64 = asList("osx_64");
public static final List<String> LIST_WINDOWS_64 = asList("windows_64");
public static final List<String> LIST_SOLARIS_64 = asList("solaris_64");
}
}
42 changes: 42 additions & 0 deletions src/main/java/org/scijava/nativelib/DefaultOsInfoPathMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.scijava.nativelib;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static java.util.Collections.*;

public enum DefaultOsInfoPathMapping {
INSTANCE;

private final Map<OsInfo, List<String>> mapping;

DefaultOsInfoPathMapping() {
this.mapping = createDefaultMapping();
}

private static Map<OsInfo, List<String>> createDefaultMapping() {
final Map<OsInfo, List<String>> defaultMapping = new ConcurrentHashMap<OsInfo, List<String>>();

for (final DefaultOsInfo defaultOsInfoValue : DefaultOsInfo.values()) {
final OsInfo osInfo = defaultOsInfoValue.getOsInfo();
/* Determine default path by convention. */
final String pathForOsInfo = NativeOsArchUtil.getPathForOsInfo(osInfo);
/* Get legacy pathes for compatiblity. */
final List<String> additionalPathes = defaultOsInfoValue.getLegacyPaths();
final List<String> allPathes = new ArrayList<String>(additionalPathes.size() + 1);
allPathes.add(pathForOsInfo);
allPathes.addAll(additionalPathes);

defaultMapping.put(osInfo, unmodifiableList(allPathes));
}

return Collections.unmodifiableMap(defaultMapping);
}

public Map<OsInfo, List<String>> getMapping() {
return this.mapping;
}
}
Loading