001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.utils.helper;
038:
039: import java.util.List;
040: import static org.netbeans.installer.utils.helper.PlatformConstants.*;
041:
042: public enum Platform {
043: /////////////////////////////////////////////////////////////////////////////////
044: // Values
045: GENERIC(null, null, null, null, "Generic"),
046:
047: WINDOWS(OS_FAMILY_WINDOWS, null, null, null, "Windows"), WINDOWS_X86(
048: OS_FAMILY_WINDOWS, HARDWARE_X86, null, null, "Windows X86"), WINDOWS_X64(
049: OS_FAMILY_WINDOWS, HARDWARE_X64, null, null, "Windows X64"),
050:
051: LINUX(OS_FAMILY_LINUX, null, null, null, "Linux"), LINUX_X86(
052: OS_FAMILY_LINUX, HARDWARE_X86, null, null, "Linux X86"), LINUX_X64(
053: OS_FAMILY_LINUX, HARDWARE_X64, null, null, "Linux X64"),
054:
055: SOLARIS(OS_FAMILY_SOLARIS, null, null, null, "Solaris"), SOLARIS_X86(
056: OS_FAMILY_SOLARIS, HARDWARE_X86, null, null, "Solaris X86"), SOLARIS_SPARC(
057: OS_FAMILY_SOLARIS, HARDWARE_SPARC, null, null,
058: "Solaris SPARC"),
059:
060: MACOSX(OS_FAMILY_MACOSX, null, null, null, "MacOS X"), MACOSX_X86(
061: OS_FAMILY_MACOSX, HARDWARE_X86, null, null, "MacOS X Intel"), MACOSX_X64(
062: OS_FAMILY_MACOSX, HARDWARE_X64, null, null,
063: "MacOS X Intel X64"), MACOSX_PPC(OS_FAMILY_MACOSX,
064: HARDWARE_PPC, null, null, "MacOS X PowerPC"), ;
065:
066: /////////////////////////////////////////////////////////////////////////////////
067: // Instance
068: private String osFamily;
069: private String hardwareArch;
070: private String osVersion;
071: private String osFlavor;
072:
073: private String codeName;
074: private String displayName;
075:
076: private Platform(final String osFamily, final String hardwareArch,
077: final String osVersion, final String osFlavor,
078: final String displayName) {
079: this .osFamily = osFamily;
080: this .hardwareArch = hardwareArch;
081: this .osVersion = osVersion;
082: this .osFlavor = osFlavor;
083:
084: if (osFamily != null) {
085: this .codeName = osFamily;
086:
087: if (hardwareArch != null) {
088: this .codeName += SEPARATOR + hardwareArch;
089:
090: if (osVersion != null) {
091: this .codeName += SEPARATOR + osVersion;
092:
093: if (osFlavor != null) {
094: this .codeName += SEPARATOR + osFlavor;
095: }
096: }
097: }
098: } else {
099: this .codeName = "generic";
100: }
101:
102: this .displayName = displayName;
103: }
104:
105: public String getOsFamily() {
106: return osFamily;
107: }
108:
109: public String getHardwareArch() {
110: return hardwareArch;
111: }
112:
113: public String getOsVersion() {
114: return osVersion;
115: }
116:
117: public String getOsFlavor() {
118: return osFlavor;
119: }
120:
121: public String getCodeName() {
122: return codeName;
123: }
124:
125: public String getDisplayName() {
126: return displayName;
127: }
128:
129: public boolean isCompatibleWith(final Platform platform) {
130: if (!platform.osFamily.equals(osFamily)) {
131: return false;
132: }
133:
134: if ((platform.hardwareArch != null)
135: && !platform.hardwareArch.equals(hardwareArch)) {
136: return false;
137: }
138:
139: if ((platform.osVersion != null)
140: && !platform.osVersion.equals(osVersion)) {
141: return false;
142: }
143:
144: if ((platform.osFlavor != null)
145: && !platform.osFlavor.equals(osFlavor)) {
146: return false;
147: }
148:
149: return true;
150: }
151:
152: public boolean isCompatibleWith(final List<Platform> platforms) {
153: for (Platform candidate : platforms) {
154: if (isCompatibleWith(candidate)) {
155: return true;
156: }
157: }
158:
159: return false;
160: }
161:
162: @Override
163: public String toString() {
164: return codeName;
165: }
166:
167: /////////////////////////////////////////////////////////////////////////////////
168: // Constants
169: public static final String SEPARATOR = "-";
170: }
|