001/* 002 * (C) Copyright 2006-2018 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu, jcarsique 018 */ 019package org.nuxeo.connect.update.task.guards; 020 021import org.apache.commons.lang3.SystemUtils; 022import org.nuxeo.common.Environment; 023import org.nuxeo.launcher.config.ConfigurationGenerator; 024 025/** 026 * This class can be used to check if the current platform match a given platform. For example in a command you may want 027 * a guard that define the platform string format. 028 * 029 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 030 */ 031public class PlatformHelper { 032 033 protected final String name; 034 035 protected final String version; 036 037 private ConfigurationGenerator cg; 038 039 public PlatformHelper() { 040 cg = new ConfigurationGenerator(); 041 cg.init(); 042 name = cg.getEnv().getProperty(Environment.DISTRIBUTION_NAME); 043 version = cg.getEnv().getProperty(Environment.DISTRIBUTION_VERSION); 044 } 045 046 public String getName() { 047 return name; 048 } 049 050 public String getVersion() { 051 return version; 052 } 053 054 /** 055 * Test whether or not the current platform is same as (or compatible) with the given one. 056 * 057 * @return not implemented, always return true 058 */ 059 public boolean matches(String platform) { 060 return true; 061 } 062 063 /** 064 * @deprecated since 11.1, no replacement 065 */ 066 @Deprecated(since = "11.1") 067 public boolean isTomcat() { 068 return true; 069 } 070 071 /** 072 * @deprecated since 11.1, no replacement 073 */ 074 @Deprecated(since = "11.1") 075 public boolean isJetty() { 076 return false; 077 } 078 079 /** 080 * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS} 081 */ 082 @Deprecated 083 public boolean isWindows() { 084 return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; 085 } 086 087 /** 088 * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS} 089 */ 090 @Deprecated 091 public boolean isNotWindows() { 092 return !isWindows(); 093 } 094 095 public static String getFullName(String platform) { 096 return null; 097 } 098 099 public static String getPlatformKey(String platform, String version) { 100 return null; 101 } 102 103}