]> gerrit.simantics Code Review - simantics/platform.git/blob
10831342acce39088585d6811ce68347c0e2291b
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.procore.server.environment;
13
14
15 /**
16  * @author Tuukka Lehtonen
17  */
18 public final class ExecutionEnvironment {
19
20     public final OSType os;
21     public final ARCHType arch;
22
23     private ExecutionEnvironment(OSType os, ARCHType arch) {
24         this.os = os;
25         this.arch = arch;
26     }
27
28     public static ExecutionEnvironment calculate() {
29         return new ExecutionEnvironment(calculateOS(), calculateArch());
30     }
31
32     public static ARCHType calculateArch() {
33         String osArch = System.getProperty("os.arch", "");
34         osArch = osArch.toLowerCase();
35         if (osArch.equals("i386") || osArch.equals("i586") || osArch.equals("i686") || osArch.equals("x86"))
36             return ARCHType.X86;
37         if (osArch.startsWith("amd64") || osArch.startsWith("x86_64"))
38             return ARCHType.X86_64;
39         if (osArch.equals("ppc"))
40             return ARCHType.PPC;
41         if (osArch.startsWith("ppc"))
42             return ARCHType.PPC_64;
43         if (osArch.startsWith("sparc"))
44             return ARCHType.SPARC;
45         return ARCHType.UNKNOWN;
46     }
47
48     public static OSType calculateOS() {
49         String osName = System.getProperty("os.name", "");
50         osName = osName.toLowerCase();
51         if (osName.startsWith("mac os x"))
52             return OSType.APPLE;
53         if (osName.startsWith("windows"))
54             return OSType.WINDOWS;
55         if (osName.startsWith("linux"))
56             return OSType.LINUX;
57         if (osName.startsWith("sun"))
58             return OSType.SUN;
59         return OSType.UNKNOWN;
60     }
61
62 }