| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package org.apache.commons.lang3; |
| 18 |
|
| 19 |
import java.util.HashMap; |
| 20 |
import java.util.Map; |
| 21 |
|
| 22 |
import org.apache.commons.lang3.arch.Processor; |
| 23 |
import org.apache.commons.lang3.stream.Streams; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class ArchUtils { |
| 34 |
|
| 35 |
private static final Map<String, Processor> ARCH_TO_PROCESSOR; |
| 36 |
|
| 37 |
static { |
| 38 |
ARCH_TO_PROCESSOR = new HashMap<>(); |
| 39 |
init(); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
private static void addProcessor(final String key, final Processor processor) { |
| 50 |
if (ARCH_TO_PROCESSOR.containsKey(key)) { |
| 51 |
throw new IllegalStateException("Key " + key + " already exists in processor map"); |
| 52 |
} |
| 53 |
ARCH_TO_PROCESSOR.put(key, processor); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
private static void addProcessors(final Processor processor, final String... keys) { |
| 64 |
Streams.of(keys).forEach(e -> addProcessor(e, processor)); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public static Processor getProcessor() { |
| 77 |
return getProcessor(SystemProperties.getOsArch()); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static Processor getProcessor(final String value) { |
| 88 |
return ARCH_TO_PROCESSOR.get(value); |
| 89 |
} |
| 90 |
|
| 91 |
private static void init() { |
| 92 |
init_X86_32Bit(); |
| 93 |
init_X86_64Bit(); |
| 94 |
init_IA64_32Bit(); |
| 95 |
init_IA64_64Bit(); |
| 96 |
init_PPC_32Bit(); |
| 97 |
init_PPC_64Bit(); |
| 98 |
init_Aarch_64Bit(); |
| 99 |
init_RISCV_32Bit(); |
| 100 |
init_RISCV_64Bit(); |
| 101 |
} |
| 102 |
|
| 103 |
private static void init_Aarch_64Bit() { |
| 104 |
addProcessors(new Processor(Processor.Arch.BIT_64, Processor.Type.AARCH_64), "aarch64"); |
| 105 |
} |
| 106 |
|
| 107 |
private static void init_IA64_32Bit() { |
| 108 |
addProcessors(new Processor(Processor.Arch.BIT_32, Processor.Type.IA_64), "ia64_32", "ia64n"); |
| 109 |
} |
| 110 |
|
| 111 |
private static void init_IA64_64Bit() { |
| 112 |
addProcessors(new Processor(Processor.Arch.BIT_64, Processor.Type.IA_64), "ia64", "ia64w"); |
| 113 |
} |
| 114 |
|
| 115 |
private static void init_PPC_32Bit() { |
| 116 |
addProcessors(new Processor(Processor.Arch.BIT_32, Processor.Type.PPC), "ppc", "power", "powerpc", "power_pc", "power_rs"); |
| 117 |
} |
| 118 |
|
| 119 |
private static void init_PPC_64Bit() { |
| 120 |
addProcessors(new Processor(Processor.Arch.BIT_64, Processor.Type.PPC), "ppc64", "power64", "powerpc64", "power_pc64", "power_rs64"); |
| 121 |
} |
| 122 |
|
| 123 |
private static void init_RISCV_32Bit() { |
| 124 |
addProcessors(new Processor(Processor.Arch.BIT_32, Processor.Type.RISC_V), "riscv32"); |
| 125 |
} |
| 126 |
|
| 127 |
private static void init_RISCV_64Bit() { |
| 128 |
addProcessors(new Processor(Processor.Arch.BIT_64, Processor.Type.RISC_V), "riscv64"); |
| 129 |
} |
| 130 |
|
| 131 |
private static void init_X86_32Bit() { |
| 132 |
addProcessors(new Processor(Processor.Arch.BIT_32, Processor.Type.X86), "x86", "i386", "i486", "i586", "i686", "pentium"); |
| 133 |
} |
| 134 |
|
| 135 |
private static void init_X86_64Bit() { |
| 136 |
addProcessors(new Processor(Processor.Arch.BIT_64, Processor.Type.X86), "x86_64", "amd64", "em64t", "universal"); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
@Deprecated |
| 145 |
public ArchUtils() { |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
} |