Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/src/org/openqa/selenium/Architecture.java
1865 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
package org.openqa.selenium;
19
20
import java.util.Locale;
21
22
/**
23
* Represents the known architectures used in WebDriver. It attempts to smooth over some of Java's
24
* rough edges when dealing with microprocessor architectures by, for instance, allowing you to
25
* query if a particular architecture is 32- or 64-bit.
26
*
27
* @see org.openqa.selenium.Platform
28
*/
29
// Useful URLs:
30
// http://hg.openjdk.java.net/jdk7/modules/jdk/file/a37326fa7f95/src/windows/native/java/lang/java_props_md.c
31
public enum Architecture {
32
33
// Architecture families
34
35
X86(
36
"x86",
37
"i386",
38
"ia32",
39
"i686",
40
"i486",
41
"i86",
42
"pentium",
43
"pentium_pro",
44
"pentium_pro+mmx",
45
"pentium+mmx") {
46
@Override
47
public int getDataModel() {
48
return 32;
49
}
50
},
51
52
X64("amd64", "ia64", "x86_64"),
53
54
ARM("aarch64", "arm"),
55
56
MIPS32("mips32") {
57
@Override
58
public int getDataModel() {
59
return 32;
60
}
61
},
62
63
MIPS64("mips64"),
64
65
// Meta architecture
66
67
ANY("") {
68
@Override
69
public boolean is(Architecture compareWith) {
70
return true;
71
}
72
};
73
74
private final String[] archIdentifiers;
75
76
Architecture(String... partOfArch) {
77
archIdentifiers = partOfArch;
78
}
79
80
/**
81
* Heuristic for comparing two architectures. If architectures are found to be in the same
82
* "architecture family" (e.g. i386, i686, x86 and ia32 are considered related), they will match.
83
*
84
* @param compareWith the architecture to compare with
85
* @return true if architectures belong to the same architecture family, false otherwise
86
*/
87
public boolean is(Architecture compareWith) {
88
return this.equals(compareWith);
89
}
90
91
/**
92
* Gets the data model of the architecture. The data model tells you how big memory addresses are
93
* on the given microprocessor architecture.
94
*
95
* @return 32- or 64-bit depending on architecture
96
*/
97
public int getDataModel() {
98
return 64;
99
}
100
101
@Override
102
public String toString() {
103
return name().toLowerCase(Locale.ENGLISH);
104
}
105
106
/**
107
* Gets current architecture.
108
*
109
* @return current architecture
110
*/
111
public static Architecture getCurrent() {
112
return extractFromSysProperty(System.getProperty("os.arch"));
113
}
114
115
/**
116
* Extracts architectures based on system properties in Java and a heuristic to overcome
117
* differences between JDK implementations. If not able to determine the operating system's
118
* architecture, it will throw.
119
*
120
* @param arch the architecture name to determine the architecture of
121
* @return the most likely architecture based on the given architecture name
122
* @throws UnsupportedOperationException if the architecture given is unknown or unsupported
123
*/
124
public static Architecture extractFromSysProperty(String arch) {
125
if (arch != null) {
126
arch = arch.toLowerCase(Locale.ENGLISH);
127
}
128
129
// Some architectures are basically the same even though they have different names. ia32, x86,
130
// i386 and i686 are for WebDriver's purposes the same sort of 32-bit x86-esque architecture.
131
// So each architecture defined in this enum has an array of strings with the different
132
// identifiers it matches.
133
for (Architecture architecture : values()) {
134
if (architecture == Architecture.ANY) {
135
continue;
136
}
137
138
for (String matcher : architecture.archIdentifiers) {
139
if (matcher.equals(arch)) {
140
return architecture;
141
}
142
}
143
}
144
145
throw new UnsupportedOperationException("Unknown architecture: " + arch);
146
}
147
}
148
149