You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2016/06/30 15:55:55 UTC
commons-crypto git commit: [CRYPTO-94] Consistently camel-case type
names: OsInfo.
Repository: commons-crypto
Updated Branches:
refs/heads/master 6dd209052 -> 294d73b24
[CRYPTO-94] Consistently camel-case type names: OsInfo.
Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/294d73b2
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/294d73b2
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/294d73b2
Branch: refs/heads/master
Commit: 294d73b24a5a83d0848e7d9445acb3c03d72cd02
Parents: 6dd2090
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Jun 30 08:55:51 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Jun 30 08:55:51 2016 -0700
----------------------------------------------------------------------
Makefile.common | 4 +-
pom.xml | 2 +-
.../apache/commons/crypto/NativeCodeLoader.java | 6 +-
.../java/org/apache/commons/crypto/OSInfo.java | 216 -------------------
.../java/org/apache/commons/crypto/OsInfo.java | 216 +++++++++++++++++++
5 files changed, 222 insertions(+), 222 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/294d73b2/Makefile.common
----------------------------------------------------------------------
diff --git a/Makefile.common b/Makefile.common
index 2c41b31..7d2e59d 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -32,8 +32,8 @@ JAVA := "$$JAVA_HOME/bin/java"
JAVAC := "$$JAVA_HOME/bin/javac"
JAVAH := "$$JAVA_HOME/bin/javah"
-OSINFO_CLASS := org.apache.commons.crypto.OSInfo
-OSINFO_PROG := $(TARGET)/classes/org/apache/commons/crypto/OSInfo.class
+OSINFO_CLASS := org.apache.commons.crypto.OsInfo
+OSINFO_PROG := $(TARGET)/classes/org/apache/commons/crypto/OsInfo.class
OS_NAME := $(shell $(JAVA) -cp $(TARGET)/classes $(OSINFO_CLASS) --os)
OS_ARCH := $(shell $(JAVA) -cp $(TARGET)/classes $(OSINFO_CLASS) --arch)
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/294d73b2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4fd6e5f..0d3892d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -215,7 +215,7 @@ The following provides more details on the included cryptographic software:
<project.reporting.outputEncoding>${commons.encoding}</project.reporting.outputEncoding>
<!-- The property "target.name" is used to specify the ant target, The All target will use
- OSInfo.java to detect the OS info and arch to generate the native binary for detected platform.
+ OsInfo.java to detect the OS info and arch to generate the native binary for detected platform.
User is able to specify the platform by maven profiles.-->
<target.name>all</target.name>
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/294d73b2/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 1317431..8158908 100644
--- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
@@ -88,12 +88,12 @@ final class NativeCodeLoader {
// Load an OS-dependent native library inside a jar file
nativeLibraryPath = "/org/apache/commons/crypto/native/"
- + OSInfo.getNativeLibFolderPathForCurrentOS();
+ + OsInfo.getNativeLibFolderPathForCurrentOS();
boolean hasNativeLib = hasResource(nativeLibraryPath + "/"
+ nativeLibraryName);
if (!hasNativeLib) {
String altName = "libcommons-crypto.jnilib";
- if (OSInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + "/" + altName)) {
+ if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + "/" + altName)) {
// Fix for openjdk7 for Mac
nativeLibraryName = altName;
hasNativeLib = true;
@@ -103,7 +103,7 @@ final class NativeCodeLoader {
if (!hasNativeLib) {
String errorMessage = String.format(
"no native library is found for os.name=%s and os.arch=%s",
- OSInfo.getOSName(), OSInfo.getArchName());
+ OsInfo.getOSName(), OsInfo.getArchName());
throw new RuntimeException(errorMessage);
}
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/294d73b2/src/main/java/org/apache/commons/crypto/OSInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/OSInfo.java b/src/main/java/org/apache/commons/crypto/OSInfo.java
deleted file mode 100644
index cf386f7..0000000
--- a/src/main/java/org/apache/commons/crypto/OSInfo.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.crypto;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Locale;
-
-/**
- * Provides OS name and architecture name.
- */
-final class OSInfo {
- private final static HashMap<String, String> archMapping = new HashMap<>();
-
- /**
- * The constant string represents for X86 architecture, the value is:
- * {@value #X86}.
- */
- static final String X86 = "x86";
-
- /**
- * The constant string represents for X86_64 architecture, the value is:
- * {@value #X86_64}.
- */
- static final String X86_64 = "x86_64";
-
- /**
- * The constant string represents for IA64_32 architecture, the value is:
- * {@value #IA64_32}.
- */
- static final String IA64_32 = "ia64_32";
-
- /**
- * The constant string represents for IA64 architecture, the value is:
- * {@value #IA64}.
- */
- static final String IA64 = "ia64";
-
- /**
- * The constant string represents for PPC architecture, the value is:
- * {@value #PPC}.
- */
- static final String PPC = "ppc";
-
- /**
- * The constant string represents for PPC64 architecture, the value is:
- * {@value #PPC64}.
- */
- static final String PPC64 = "ppc64";
-
- /**
- * The private constructor of {@link OSInfo}.
- */
- private OSInfo() {
- }
-
- static {
- // x86 mappings
- archMapping.put(X86, X86);
- archMapping.put("i386", X86);
- archMapping.put("i486", X86);
- archMapping.put("i586", X86);
- archMapping.put("i686", X86);
- archMapping.put("pentium", X86);
-
- // x86_64 mappings
- archMapping.put(X86_64, X86_64);
- archMapping.put("amd64", X86_64);
- archMapping.put("em64t", X86_64);
- archMapping.put("universal", X86_64); // Needed for openjdk7 in Mac
-
- // Itenium 64-bit mappings
- archMapping.put(IA64, IA64);
- archMapping.put("ia64w", IA64);
-
- // Itenium 32-bit mappings, usually an HP-UX construct
- archMapping.put(IA64_32, IA64_32);
- archMapping.put("ia64n", IA64_32);
-
- // PowerPC mappings
- archMapping.put(PPC, PPC);
- archMapping.put("power", PPC);
- archMapping.put("powerpc", PPC);
- archMapping.put("power_pc", PPC);
- archMapping.put("power_rs", PPC);
-
- // TODO: PowerPC 64bit mappings
- archMapping.put(PPC64, PPC64);
- archMapping.put("power64", PPC64);
- archMapping.put("powerpc64", PPC64);
- archMapping.put("power_pc64", PPC64);
- archMapping.put("power_rs64", PPC64);
- }
-
- /**
- * The main method.
- *
- * @param args the argv.
- */
- public static void main(String[] args) {
- if (args.length >= 1) {
- if ("--os".equals(args[0])) {
- System.out.print(getOSName());
- return;
- } else if ("--arch".equals(args[0])) {
- System.out.print(getArchName());
- return;
- }
- }
-
- System.out.print(getNativeLibFolderPathForCurrentOS());
- }
-
- /**
- * Gets the native lib folder.
- *
- * @return the current OS's native lib folder.
- */
- static String getNativeLibFolderPathForCurrentOS() {
- return getOSName() + "/" + getArchName();
- }
-
- /**
- * Gets the OS name.
- *
- * @return the OS name.
- */
- static String getOSName() {
- return translateOSNameToFolderName(System.getProperty("os.name"));
- }
-
- /**
- * Gets the architecture name.
- *
- * @return the architecture name.
- */
- static String getArchName() {
- // if running Linux on ARM, need to determine ABI of JVM
- String osArch = System.getProperty("os.arch");
- if (osArch.startsWith("arm")
- && System.getProperty("os.name").contains("Linux")) {
- String javaHome = System.getProperty("java.home");
- try {
- // determine if first JVM found uses ARM hard-float ABI
- String[] cmdarray = {
- "/bin/sh",
- "-c",
- "find '"
- + javaHome
- + "' -name 'libjvm.so' | head -1 | xargs readelf -A | "
- + "grep 'Tag_ABI_VFP_args: VFP registers'" };
- int exitCode = Runtime.getRuntime().exec(cmdarray).waitFor();
- if (exitCode == 0) {
- return "armhf";
- }
- } catch (IOException e) { //NOPMD
- // ignored: fall back to "arm" arch (soft-float ABI)
- } catch (InterruptedException e) { //NOPMD
- // ignored: fall back to "arm" arch (soft-float ABI)
- }
- } else {
- String lc = osArch.toLowerCase(Locale.US);
- if (archMapping.containsKey(lc)) {
- return archMapping.get(lc);
- }
- }
- return translateArchNameToFolderName(osArch);
- }
-
- /**
- * Translates the OS name to folder name.
- *
- * @param osName the OS name.
- * @return the folder name.
- */
- private static String translateOSNameToFolderName(String osName) {
- if (osName.contains("Windows")) {
- return "Windows";
- } else if (osName.contains("Mac")) {
- return "Mac";
- } else if (osName.contains("Linux")) {
- return "Linux";
- } else if (osName.contains("AIX")) {
- return "AIX";
- }
-
- else {
- return osName.replaceAll("\\W", "");
- }
- }
-
- /**
- * Translates the architecture name to folder name.
- *
- * @param archName the architecture name.
- * @return the folder name.
- */
- private static String translateArchNameToFolderName(String archName) {
- return archName.replaceAll("\\W", "");
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/294d73b2/src/main/java/org/apache/commons/crypto/OsInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/OsInfo.java b/src/main/java/org/apache/commons/crypto/OsInfo.java
new file mode 100644
index 0000000..4177022
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/OsInfo.java
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.crypto;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Locale;
+
+/**
+ * Provides OS name and architecture name.
+ */
+final class OsInfo {
+ private final static HashMap<String, String> archMapping = new HashMap<>();
+
+ /**
+ * The constant string represents for X86 architecture, the value is:
+ * {@value #X86}.
+ */
+ static final String X86 = "x86";
+
+ /**
+ * The constant string represents for X86_64 architecture, the value is:
+ * {@value #X86_64}.
+ */
+ static final String X86_64 = "x86_64";
+
+ /**
+ * The constant string represents for IA64_32 architecture, the value is:
+ * {@value #IA64_32}.
+ */
+ static final String IA64_32 = "ia64_32";
+
+ /**
+ * The constant string represents for IA64 architecture, the value is:
+ * {@value #IA64}.
+ */
+ static final String IA64 = "ia64";
+
+ /**
+ * The constant string represents for PPC architecture, the value is:
+ * {@value #PPC}.
+ */
+ static final String PPC = "ppc";
+
+ /**
+ * The constant string represents for PPC64 architecture, the value is:
+ * {@value #PPC64}.
+ */
+ static final String PPC64 = "ppc64";
+
+ /**
+ * The private constructor of {@link OsInfo}.
+ */
+ private OsInfo() {
+ }
+
+ static {
+ // x86 mappings
+ archMapping.put(X86, X86);
+ archMapping.put("i386", X86);
+ archMapping.put("i486", X86);
+ archMapping.put("i586", X86);
+ archMapping.put("i686", X86);
+ archMapping.put("pentium", X86);
+
+ // x86_64 mappings
+ archMapping.put(X86_64, X86_64);
+ archMapping.put("amd64", X86_64);
+ archMapping.put("em64t", X86_64);
+ archMapping.put("universal", X86_64); // Needed for openjdk7 in Mac
+
+ // Itenium 64-bit mappings
+ archMapping.put(IA64, IA64);
+ archMapping.put("ia64w", IA64);
+
+ // Itenium 32-bit mappings, usually an HP-UX construct
+ archMapping.put(IA64_32, IA64_32);
+ archMapping.put("ia64n", IA64_32);
+
+ // PowerPC mappings
+ archMapping.put(PPC, PPC);
+ archMapping.put("power", PPC);
+ archMapping.put("powerpc", PPC);
+ archMapping.put("power_pc", PPC);
+ archMapping.put("power_rs", PPC);
+
+ // TODO: PowerPC 64bit mappings
+ archMapping.put(PPC64, PPC64);
+ archMapping.put("power64", PPC64);
+ archMapping.put("powerpc64", PPC64);
+ archMapping.put("power_pc64", PPC64);
+ archMapping.put("power_rs64", PPC64);
+ }
+
+ /**
+ * The main method.
+ *
+ * @param args the argv.
+ */
+ public static void main(String[] args) {
+ if (args.length >= 1) {
+ if ("--os".equals(args[0])) {
+ System.out.print(getOSName());
+ return;
+ } else if ("--arch".equals(args[0])) {
+ System.out.print(getArchName());
+ return;
+ }
+ }
+
+ System.out.print(getNativeLibFolderPathForCurrentOS());
+ }
+
+ /**
+ * Gets the native lib folder.
+ *
+ * @return the current OS's native lib folder.
+ */
+ static String getNativeLibFolderPathForCurrentOS() {
+ return getOSName() + "/" + getArchName();
+ }
+
+ /**
+ * Gets the OS name.
+ *
+ * @return the OS name.
+ */
+ static String getOSName() {
+ return translateOSNameToFolderName(System.getProperty("os.name"));
+ }
+
+ /**
+ * Gets the architecture name.
+ *
+ * @return the architecture name.
+ */
+ static String getArchName() {
+ // if running Linux on ARM, need to determine ABI of JVM
+ String osArch = System.getProperty("os.arch");
+ if (osArch.startsWith("arm")
+ && System.getProperty("os.name").contains("Linux")) {
+ String javaHome = System.getProperty("java.home");
+ try {
+ // determine if first JVM found uses ARM hard-float ABI
+ String[] cmdarray = {
+ "/bin/sh",
+ "-c",
+ "find '"
+ + javaHome
+ + "' -name 'libjvm.so' | head -1 | xargs readelf -A | "
+ + "grep 'Tag_ABI_VFP_args: VFP registers'" };
+ int exitCode = Runtime.getRuntime().exec(cmdarray).waitFor();
+ if (exitCode == 0) {
+ return "armhf";
+ }
+ } catch (IOException e) { //NOPMD
+ // ignored: fall back to "arm" arch (soft-float ABI)
+ } catch (InterruptedException e) { //NOPMD
+ // ignored: fall back to "arm" arch (soft-float ABI)
+ }
+ } else {
+ String lc = osArch.toLowerCase(Locale.US);
+ if (archMapping.containsKey(lc)) {
+ return archMapping.get(lc);
+ }
+ }
+ return translateArchNameToFolderName(osArch);
+ }
+
+ /**
+ * Translates the OS name to folder name.
+ *
+ * @param osName the OS name.
+ * @return the folder name.
+ */
+ private static String translateOSNameToFolderName(String osName) {
+ if (osName.contains("Windows")) {
+ return "Windows";
+ } else if (osName.contains("Mac")) {
+ return "Mac";
+ } else if (osName.contains("Linux")) {
+ return "Linux";
+ } else if (osName.contains("AIX")) {
+ return "AIX";
+ }
+
+ else {
+ return osName.replaceAll("\\W", "");
+ }
+ }
+
+ /**
+ * Translates the architecture name to folder name.
+ *
+ * @param archName the architecture name.
+ * @return the folder name.
+ */
+ private static String translateArchNameToFolderName(String archName) {
+ return archName.replaceAll("\\W", "");
+ }
+}