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