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.launcher.config.ConfigurationGenerator;
022
023/**
024 * This class can be used to check if the current platform match a given platform. For example in a command you may want
025 * a guard that define the platform string format.
026 *
027 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
028 */
029public class PlatformHelper {
030
031    protected final String name;
032
033    protected final String version;
034
035    private ConfigurationGenerator cg;
036
037    public PlatformHelper() {
038        cg = new ConfigurationGenerator();
039        cg.init();
040        name = cg.getUserConfig().getProperty(ConfigurationGenerator.PARAM_PRODUCT_NAME);
041        version = cg.getUserConfig().getProperty(ConfigurationGenerator.PARAM_PRODUCT_VERSION);
042    }
043
044    public String getName() {
045        return name;
046    }
047
048    public String getVersion() {
049        return version;
050    }
051
052    /**
053     * Test whether or not the current platform is same as (or compatible) with the given one.
054     *
055     * @return not implemented, always return true
056     */
057    public boolean matches(String platform) {
058        return true;
059    }
060
061    public boolean isTomcat() {
062        return cg.isTomcat;
063    }
064
065    public boolean isJBoss() {
066        return cg.isJBoss;
067    }
068
069    public boolean isJetty() {
070        return cg.isJetty;
071    }
072
073    /**
074     * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS}
075     */
076    @Deprecated
077    public boolean isWindows() {
078        return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
079    }
080
081    /**
082     * @deprecated Since 7.4. Use {@link SystemUtils#IS_OS_WINDOWS}
083     */
084    @Deprecated
085    public boolean isNotWindows() {
086        return !isWindows();
087    }
088
089    public static String getFullName(String platform) {
090        return null;
091    }
092
093    public static String getPlatformKey(String platform, String version) {
094        return null;
095    }
096
097}