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:[email protected]">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.getUserConfig().getProperty(Environment.DISTRIBUTION_NAME); 043 version = cg.getUserConfig().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 public boolean isTomcat() { 064 return cg.isTomcat; 065 } 066 067 public boolean isJetty() { 068 return cg.isJetty; 069 } 070 071 /** 072 * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS} 073 */ 074 @Deprecated 075 public boolean isWindows() { 076 return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; 077 } 078 079 /** 080 * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS} 081 */ 082 @Deprecated 083 public boolean isNotWindows() { 084 return !isWindows(); 085 } 086 087 public static String getFullName(String platform) { 088 return null; 089 } 090 091 public static String getPlatformKey(String platform, String version) { 092 return null; 093 } 094 095}