Add support for detection of Aarch64.

- Add Processor.Type.AARCH_64.
- Add Processor.isAarch64().
- Update ArchUtils.getProcessor(String) for "aarch64".
This commit is contained in:
Gary Gregory 2021-12-28 09:58:35 -05:00
parent 5d8876279b
commit 16d587d73c
4 changed files with 53 additions and 14 deletions

View File

@ -114,6 +114,9 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Pair.ofNonNull(L, R).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Triple.ofNonNull(L, M, R).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ArrayUtils.containsAny(Object[], Object...).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Processor.Type.AARCH_64.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Processor.isAarch64().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Update ArchUtils.getProcessor(String) for "aarch64".</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump spotbugs-maven-plugin from 4.2.0 to 4.5.0.0 #735, #808, #822, #834.</action>
<action type="update" dev="ggregory" due-to="Dependabot, XenoAmess">Bump actions/cache from v2.1.4 to v2.1.7 #742, #752, #764, #833.</action>

View File

@ -23,10 +23,10 @@ import org.apache.commons.lang3.arch.Processor;
import org.apache.commons.lang3.stream.Streams;
/**
* An utility class for the os.arch System Property. The class defines methods for
* A utility class for the {@code os.arch} System Property. The class defines methods for
* identifying the architecture of the current JVM.
* <p>
* Important: The os.arch System Property returns the architecture used by the JVM
* Important: The {@code os.arch} System Property returns the architecture used by the JVM
* not of the operating system.
* </p>
* @since 3.6
@ -47,6 +47,12 @@ public class ArchUtils {
init_IA64_64Bit();
init_PPC_32Bit();
init_PPC_64Bit();
init_Aarch_64Bit();
}
private static void init_Aarch_64Bit() {
final Processor processor = new Processor(Processor.Arch.BIT_64, Processor.Type.AARCH_64);
addProcessors(processor, "aarch64");
}
private static void init_X86_32Bit() {
@ -120,9 +126,9 @@ public class ArchUtils {
/**
* Returns a {@link Processor} object the given value {@link String}. The {@link String} must be
* like a value returned by the os.arch System Property.
* like a value returned by the {@code os.arch} System Property.
*
* @param value A {@link String} like a value returned by the os.arch System Property.
* @param value A {@link String} like a value returned by the {@code os.arch} System Property.
* @return A {@link Processor} when it exists, else {@code null}.
*/
public static Processor getProcessor(final String value) {

View File

@ -77,6 +77,7 @@ public class Processor {
* The {@link Type} enum defines types of a microprocessor.
* The following types are defined:
* <ul>
* <li>Aarch64</li>
* <li>x86</li>
* <li>ia64</li>
* <li>PPC</li>
@ -85,6 +86,13 @@ public class Processor {
*/
public enum Type {
/**
* ARM 64-bit.
*
* @since 3.13.0
*/
AARCH_64,
/**
* Intel x86 series of instruction set architectures.
*/
@ -122,7 +130,7 @@ public class Processor {
}
/**
* Returns the processor architecture as an {@link Arch} enum.
* Gets the processor architecture as an {@link Arch} enum.
* The processor architecture defines, if the processor has
* a 32 or 64 bit architecture.
*
@ -133,7 +141,7 @@ public class Processor {
}
/**
* Returns the processor type as {@link Type} enum.
* Gets the processor type as {@link Type} enum.
* The processor type defines, if the processor is for example
* a x86 or PPA.
*
@ -144,7 +152,7 @@ public class Processor {
}
/**
* Checks if {@link Processor} is 32 bit.
* Tests if {@link Processor} is 32 bit.
*
* @return {@code true}, if {@link Processor} is {@link Arch#BIT_32}, else {@code false}.
*/
@ -153,7 +161,7 @@ public class Processor {
}
/**
* Checks if {@link Processor} is 64 bit.
* Tests if {@link Processor} is 64 bit.
*
* @return {@code true}, if {@link Processor} is {@link Arch#BIT_64}, else {@code false}.
*/
@ -162,16 +170,18 @@ public class Processor {
}
/**
* Checks if {@link Processor} is type of x86.
* Tests if {@link Processor} is type of Aarch64.
*
* @return {@code true}, if {@link Processor} is {@link Type#X86}, else {@code false}.
*
* @since 3.13.0
*/
public boolean isX86() {
return Type.X86 == type;
public boolean isAarch64() {
return Type.AARCH_64 == type;
}
/**
* Checks if {@link Processor} is type of Intel Itanium.
* Tests if {@link Processor} is type of Intel Itanium.
*
* @return {@code true}. if {@link Processor} is {@link Type#IA_64}, else {@code false}.
*/
@ -180,7 +190,7 @@ public class Processor {
}
/**
* Checks if {@link Processor} is type of Power PC.
* Tests if {@link Processor} is type of Power PC.
*
* @return {@code true}. if {@link Processor} is {@link Type#PPC}, else {@code false}.
*/
@ -188,4 +198,13 @@ public class Processor {
return Type.PPC == type;
}
/**
* Tests if {@link Processor} is type of x86.
*
* @return {@code true}, if {@link Processor} is {@link Type#X86}, else {@code false}.
*/
public boolean isX86() {
return Type.X86 == type;
}
}

View File

@ -38,6 +38,7 @@ public class ArchUtilsTest {
private static final String PPC64 = "ppc64";
private static final String X86 = "x86";
private static final String X86_64 = "x86_64";
private static final String AARCH_64 = "aarch64";
private void assertEqualsArchNotNull(final Processor.Arch arch, final Processor processor) {
assertNotNull(arch);
@ -94,6 +95,10 @@ public class ArchUtilsTest {
processor = ArchUtils.getProcessor(PPC64);
assertEqualsTypeNotNull(Processor.Type.PPC, processor);
assertTrue(processor.isPPC());
processor = ArchUtils.getProcessor(AARCH_64);
assertEqualsTypeNotNull(Processor.Type.AARCH_64, processor);
assertTrue(processor.isAarch64());
}
@Test
@ -162,6 +167,12 @@ public class ArchUtilsTest {
processor = ArchUtils.getProcessor(IA64_32);
assertNotEqualsArchNotNull(Processor.Arch.BIT_64, processor);
assertFalse(processor.is64Bit());
}
processor = ArchUtils.getProcessor(AARCH_64);
assertEqualsArchNotNull(Processor.Arch.BIT_64, processor);
assertNotEqualsArchNotNull(Processor.Arch.BIT_32, processor);
assertTrue(processor.is64Bit());
assertFalse(processor.is32Bit());
}
}