001/*
002 * (C) Copyright 2006-2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu, jcarsique
016 */
017package org.nuxeo.connect.update.task.guards;
018
019import org.apache.commons.lang3.SystemUtils;
020
021import org.nuxeo.common.Environment;
022import org.nuxeo.launcher.config.ConfigurationGenerator;
023
024/**
025 * This class can be used to check if the current platform match a given platform. For example in a command you may want
026 * a guard that define the platform string format.
027 *
028 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
029 */
030public class PlatformHelper {
031
032    protected final String name;
033
034    protected final String version;
035
036    private ConfigurationGenerator cg;
037
038    public PlatformHelper() {
039        cg = new ConfigurationGenerator();
040        cg.init();
041        name = cg.getUserConfig().getProperty(Environment.DISTRIBUTION_NAME);
042        version = cg.getUserConfig().getProperty(Environment.DISTRIBUTION_VERSION);
043    }
044
045    public String getName() {
046        return name;
047    }
048
049    public String getVersion() {
050        return version;
051    }
052
053    /**
054     * Test whether or not the current platform is same as (or compatible) with the given one.
055     *
056     * @return not implemented, always return true
057     */
058    public boolean matches(String platform) {
059        return true;
060    }
061
062    public boolean isTomcat() {
063        return cg.isTomcat;
064    }
065
066    public boolean isJBoss() {
067        return cg.isJBoss;
068    }
069
070    public boolean isJetty() {
071        return cg.isJetty;
072    }
073
074    /**
075     * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS}
076     */
077    @Deprecated
078    public boolean isWindows() {
079        return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
080    }
081
082    /**
083     * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS}
084     */
085    @Deprecated
086    public boolean isNotWindows() {
087        return !isWindows();
088    }
089
090    public static String getFullName(String platform) {
091        return null;
092    }
093
094    public static String getPlatformKey(String platform, String version) {
095        return null;
096    }
097
098}