Path: blob/trunk/java/src/org/openqa/selenium/Architecture.java
1865 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617package org.openqa.selenium;1819import java.util.Locale;2021/**22* Represents the known architectures used in WebDriver. It attempts to smooth over some of Java's23* rough edges when dealing with microprocessor architectures by, for instance, allowing you to24* query if a particular architecture is 32- or 64-bit.25*26* @see org.openqa.selenium.Platform27*/28// Useful URLs:29// http://hg.openjdk.java.net/jdk7/modules/jdk/file/a37326fa7f95/src/windows/native/java/lang/java_props_md.c30public enum Architecture {3132// Architecture families3334X86(35"x86",36"i386",37"ia32",38"i686",39"i486",40"i86",41"pentium",42"pentium_pro",43"pentium_pro+mmx",44"pentium+mmx") {45@Override46public int getDataModel() {47return 32;48}49},5051X64("amd64", "ia64", "x86_64"),5253ARM("aarch64", "arm"),5455MIPS32("mips32") {56@Override57public int getDataModel() {58return 32;59}60},6162MIPS64("mips64"),6364// Meta architecture6566ANY("") {67@Override68public boolean is(Architecture compareWith) {69return true;70}71};7273private final String[] archIdentifiers;7475Architecture(String... partOfArch) {76archIdentifiers = partOfArch;77}7879/**80* Heuristic for comparing two architectures. If architectures are found to be in the same81* "architecture family" (e.g. i386, i686, x86 and ia32 are considered related), they will match.82*83* @param compareWith the architecture to compare with84* @return true if architectures belong to the same architecture family, false otherwise85*/86public boolean is(Architecture compareWith) {87return this.equals(compareWith);88}8990/**91* Gets the data model of the architecture. The data model tells you how big memory addresses are92* on the given microprocessor architecture.93*94* @return 32- or 64-bit depending on architecture95*/96public int getDataModel() {97return 64;98}99100@Override101public String toString() {102return name().toLowerCase(Locale.ENGLISH);103}104105/**106* Gets current architecture.107*108* @return current architecture109*/110public static Architecture getCurrent() {111return extractFromSysProperty(System.getProperty("os.arch"));112}113114/**115* Extracts architectures based on system properties in Java and a heuristic to overcome116* differences between JDK implementations. If not able to determine the operating system's117* architecture, it will throw.118*119* @param arch the architecture name to determine the architecture of120* @return the most likely architecture based on the given architecture name121* @throws UnsupportedOperationException if the architecture given is unknown or unsupported122*/123public static Architecture extractFromSysProperty(String arch) {124if (arch != null) {125arch = arch.toLowerCase(Locale.ENGLISH);126}127128// Some architectures are basically the same even though they have different names. ia32, x86,129// i386 and i686 are for WebDriver's purposes the same sort of 32-bit x86-esque architecture.130// So each architecture defined in this enum has an array of strings with the different131// identifiers it matches.132for (Architecture architecture : values()) {133if (architecture == Architecture.ANY) {134continue;135}136137for (String matcher : architecture.archIdentifiers) {138if (matcher.equals(arch)) {139return architecture;140}141}142}143144throw new UnsupportedOperationException("Unknown architecture: " + arch);145}146}147148149