001/** 002 * Copyright 2011-2012 003 * Ubiquitous Knowledge Processing (UKP) Lab 004 * Technische Universität Darmstadt 005 * All rights reserved. 006 * 007 * This program is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU General Public License 009 * as published by the Free Software Foundation; either version 2 010 * of the License, or (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * For a complete copy of the license please see the file LICENSE distributed 018 * with the cleartk-syntax-berkeley project or visit 019 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. 020 * 021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 024 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 025 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 026 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 027 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 028 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 029 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 030 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 031 * POSSIBILITY OF SUCH DAMAGE. 032 */ 033 034package org.cleartk.util; 035 036import java.util.HashMap; 037import java.util.Map; 038 039import org.apache.commons.lang.SystemUtils; 040 041/** 042 * <br> 043 * Copyright (c) 2011-2012, Technische Universität Darmstadt <br> 044 * All rights reserved. 045 * 046 * 047 * @author Martin Riedl 048 */ 049 050public class PlatformDetection { 051 private String os; 052 053 private String arch; 054 055 public static String OS_WINDOWS = "windows"; 056 057 public static String OS_OSX = "osx"; 058 059 public static String OS_SOLARIS = "solaris"; 060 061 public static String OS_LINUX = "linux"; 062 063 public static String ARCH_PPC = "ppc"; 064 065 public static String ARCH_X86_32 = "x86_32"; 066 067 public static String ARCH_X86_64 = "x86_64"; 068 069 public PlatformDetection() { 070 // resolve OS 071 if (SystemUtils.IS_OS_WINDOWS) { 072 this.os = OS_WINDOWS; 073 } else if (SystemUtils.IS_OS_MAC_OSX) { 074 this.os = OS_OSX; 075 } else if (SystemUtils.IS_OS_SOLARIS) { 076 this.os = OS_SOLARIS; 077 } else if (SystemUtils.IS_OS_LINUX) { 078 this.os = OS_LINUX; 079 } else { 080 throw new IllegalArgumentException("Unknown operating system " + SystemUtils.OS_NAME); 081 } 082 083 // resolve architecture 084 Map<String, String> archMap = new HashMap<String, String>(); 085 archMap.put("x86", ARCH_X86_32); 086 archMap.put("i386", ARCH_X86_32); 087 archMap.put("i486", ARCH_X86_32); 088 archMap.put("i586", ARCH_X86_32); 089 archMap.put("i686", ARCH_X86_32); 090 archMap.put("x86_64", ARCH_X86_64); 091 archMap.put("amd64", ARCH_X86_64); 092 archMap.put("powerpc", ARCH_PPC); 093 this.arch = archMap.get(SystemUtils.OS_ARCH); 094 if (this.arch == null) { 095 throw new IllegalArgumentException("Unknown architecture " + SystemUtils.OS_ARCH); 096 } 097 } 098 099 public String getOs() { 100 return os; 101 } 102 103 public String getArch() { 104 return arch; 105 } 106 107 public void setArch(String arch) { 108 this.arch = arch; 109 } 110 111 public void setOs(String os) { 112 this.os = os; 113 } 114 115 @Override 116 public String toString() { 117 118 return os + "_" + arch; 119 } 120 121 public String getExecutableSuffix() { 122 if (getOs().equals(OS_WINDOWS)) 123 return ".exe"; 124 return ""; 125 } 126}