001/* 002 * (C) Copyright 2010-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 * Nuxeo - initial API and implementation 018 * 019 */ 020package org.nuxeo.ecm.admin.runtime; 021 022import java.util.Arrays; 023 024import org.nuxeo.common.Environment; 025import org.nuxeo.connect.connector.fake.FakeDownloadablePackage; 026import org.nuxeo.connect.packages.dependencies.TargetPlatformFilterHelper; 027import org.nuxeo.connect.platform.PlatformId; 028import org.nuxeo.connect.update.Package; 029import org.nuxeo.runtime.api.Framework; 030 031public class PlatformVersionHelper { 032 033 public static final String UNKNOWN = "Unknown"; 034 035 public static String getApplicationName() { 036 return Framework.getProperty(Environment.PRODUCT_NAME, UNKNOWN); 037 } 038 039 public static String getApplicationVersion() { 040 return Framework.getProperty(Environment.PRODUCT_VERSION, UNKNOWN); 041 } 042 043 public static PlatformId getPlatformId() { 044 if (getDistributionName().equals(UNKNOWN) || getDistributionVersion().equals(UNKNOWN)) { 045 return null; 046 } 047 return PlatformId.parse(getDistributionName(), getDistributionVersion()); 048 } 049 050 public static String getDistributionName() { 051 return Framework.getProperty(Environment.DISTRIBUTION_NAME, UNKNOWN); 052 } 053 054 public static String getDistributionVersion() { 055 return Framework.getProperty(Environment.DISTRIBUTION_VERSION, UNKNOWN); 056 } 057 058 public static String getDistributionDate() { 059 return Framework.getProperty(Environment.DISTRIBUTION_DATE, UNKNOWN); 060 } 061 062 public static String getDistributionHost() { 063 return Framework.getProperty(Environment.DISTRIBUTION_SERVER, UNKNOWN); 064 } 065 066 /** 067 * @deprecated Since 6.0. Use {@link TargetPlatformFilterHelper#isCompatibleWithTargetPlatform(Package, PlatformId)} 068 * @see TargetPlatformFilterHelper 069 */ 070 @Deprecated 071 public static boolean isCompatible(final String[] targetPlatforms, String currentPlatform) { 072 // we use a fake package here because the method of TargetPlatformFilterHelper without a package has become 073 // private 074 FakeDownloadablePackage fakePkg = new FakeDownloadablePackage(null, null); 075 fakePkg.targetPlatforms = Arrays.asList(targetPlatforms); 076 return TargetPlatformFilterHelper.isCompatibleWithTargetPlatform(fakePkg, PlatformId.parse(currentPlatform)); 077 } 078 079 /** 080 * @deprecated Since 6.0. Use {@link TargetPlatformFilterHelper#isCompatibleWithTargetPlatform(Package, PlatformId)} 081 * @see #getPlatformId() 082 * @see TargetPlatformFilterHelper 083 */ 084 @Deprecated 085 public static boolean isCompatible(String[] targetPlatforms) { 086 return isCompatible(targetPlatforms, getPlatformId().asString()); 087 } 088 089}