import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
private static final String DIR_SDK_DATA = "tizen-sdk-data";
private static final String DIR_CHECKER = "checker";
private static final String DIR_DOCUMENTS = "documents";
+ // PLATFORM directory format: <platform><majorNumber>.<minorNumber>
+ private static final String REG_PROFILE = "[a-zA-Z]+";
+ private static final String REG_VERSION = "(((\\d)|([1-9]\\d{2,}))\\.)((\\d)|([1-9]\\d{2,}))";
+ private static final String REG_DIR_PLATFORM = REG_PROFILE + REG_VERSION;
+ public static final String FORMAT_PLATFORM_NAME = "%s%s";
private final static String SDKSUFFIX = DIR_SDK_DATA + File.separatorChar + "tizensdkpath";
private final static String SDK_INFO_FILE = "sdk.info";
return sdkInstallPath;
}
- //This is temporary code to get platform version path(only for one).
- //TODO: Should change to return string array type for various platform version paths.
+ /**
+ * @deprecated Use {@link #getPlatformPath(PlatformPathInfo platform, String version)} instead.
+ */
public static String getPlatformVersionPath() {
String path = null;
String platformPath = getSDKPath() + File.separator + DIR_PLATFORMS;
- File platforms = new File(platformPath);
+ File platforms = getPlatformDir();
if (platforms.isDirectory()) {
- // platforms.listFiles[0] can cause undetermined result like platforms/tmp.ini/sample
+ path = getLatestPlatformPathInfo().getLatestPlatformPath();
+ }
+
+ if ( path == null ) {
path = platformPath + File.separator + DIR_PLATFORMS_VER;
}
+
return path;
}
+
+ /**
+ * Returns path of the given platform.<br>
+ * If the given platform is null, returns path of a latest platform.<br>
+ * If the given version is null, returns path of a latest version in platform.<br>
+ * Otherwise, returns null if the given version cannot be found in the given platform.
+ */
+ public static String getPlatformPath(PlatformPathInfo platform, String version) {
+ if ( platform == null ) {
+ platform = getLatestPlatformPathInfo();
+ }
+ if ( version == null ) {
+ version = platform.getLatestPlatformVersion();
+ }
+ return platform.getPlatformPath(version);
+ }
+
+ /**
+ * Returns a list of PlatformPathInfo.<br>
+ * This method find all of platform.
+ */
+ public static List<PlatformPathInfo> getPlatformPathInfos() {
+ File platformDir = getPlatformDir();
+ String platformPath = getSDKPath() + File.separator + DIR_PLATFORMS;
+ Map<String, PlatformPathInfo> platformInfoMap = new HashMap<String, PlatformPathInfo>();
+
+ String version = "";
+ String profile = "";
+ String path = "";
+ PlatformPathInfo tempInfo = null;
+ if ( platformDir != null ) {
+ File[] platforms = platformDir.listFiles();
+ for ( File platform : platforms ) {
+ if ( platform.isDirectory() ) {
+ if ( (version = getVersion(platform.getName())) != null ) {
+ profile = getProfile(platform.getName());
+ path = platformPath + File.separator + platform.getName();
+ if ( (tempInfo = platformInfoMap.get(profile)) != null ) {
+ tempInfo.appendVersion(version, path);
+ }
+ else {
+ platformInfoMap.put(profile, new PlatformPathInfo(profile, version, path));
+ }
+ }
+ }
+ }
+ }
+ return new ArrayList<PlatformPathInfo>(platformInfoMap.values());
+ }
+
+ /**
+ * Returns a list of PlatformPathInfo including the given profile.<br>
+ * Otherwise, returns null if the profile is null or cannot be found.
+ */
+ public static PlatformPathInfo getPlatformPathInfo(String profile) {
+ if ( profile == null ) {
+ return null;
+ }
+ List<PlatformPathInfo> platformPathInfoList = getPlatformPathInfos();
+
+ for ( PlatformPathInfo platformPathInfo : platformPathInfoList ) {
+ if ( profile.equals(platformPathInfo.getProfile()) ) {
+ return platformPathInfo;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns latest PlatformPathInfo.<br>
+ * The latest platform is the highest version among all platform.
+ * Otherwise, returns null if this method cannot find the latest platform.
+ */
+ public static PlatformPathInfo getLatestPlatformPathInfo() {
+ List<PlatformPathInfo> platformPathInfoList = getPlatformPathInfos();
+
+ float latestVersion = -1;
+ float tempVersion = 0;
+ PlatformPathInfo latestPlatformPathInfo = null;
+ for ( PlatformPathInfo platformPathInfo : platformPathInfoList ) {
+ tempVersion = Float.parseFloat( platformPathInfo.getLatestPlatformVersion() );
+ if ( latestVersion < tempVersion ) {
+ latestVersion = tempVersion;
+ latestPlatformPathInfo = platformPathInfo;
+ }
+ }
+
+ if ( latestPlatformPathInfo == null ) {
+ return null;
+ }
+ return new PlatformPathInfo(latestPlatformPathInfo.getProfile(),
+ latestPlatformPathInfo.getLatestPlatformVersion(), latestPlatformPathInfo.getLatestPlatformPath());
+ }
+
/**
- * Returns platform version number.
+ * Returns version of latest platform or null.
+ *
+ * @deprecated Use {@link #getVersion()} instead.
*/
public static String getPlatformVersionNum() {
- return DIR_PLATFORMS_VER_NUM;
+ return getVersion(getPlatformVersionName());
+ }
+
+ /**
+ * Returns version of given {@code platform} or null.
+ */
+ public static String getVersion(String platform) {
+ if ( platform.matches(REG_DIR_PLATFORM) ) {
+ return platform.replaceFirst(REG_PROFILE, "");
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns profile of given {@code platform} or null.
+ */
+ public static String getProfile(String platform) {
+ if ( platform.matches(REG_DIR_PLATFORM) ) {
+ return platform.replaceAll(REG_VERSION, "");
+ }
+ else {
+ return null;
+ }
}
/**
- * Returns platform version name like "tizen2.2".
+ * Returns latest platform name like "tizen2.2".
+ *
+ * @deprecated Use {@link PlatformPathInfo#getLatestPlatformName()} instead.
*/
public static String getPlatformVersionName() {
- return DIR_PLATFORMS_VER;
+ return getLatestPlatformPathInfo().getLatestPlatformName();
+ }
+
+ /**
+ * Returns platforms directory or null.
+ */
+ public static File getPlatformDir() {
+ String platformPath = getSDKPath() + File.separator + DIR_PLATFORMS;
+ File platformDir = new File(platformPath);
+ if ( platformDir.isDirectory() ) {
+ return platformDir;
+ }
+ else {
+ return null;
+ }
}
/*
return version;
}
+ /**
+ * @deprecated Use {@link #getSamplesPath(PlatformPathInfo platform, String version)} instead.
+ */
//TODO: Should change to get string array type for various platform version paths.
public static String getSamplesPath() {
return getPlatformVersionPath() + File.separator + DIR_SAMPLES;
}
+
+ /**
+ * Returns a sample path that is installed under the given platform and version.<br>
+ * If this method cannot find the sample path, returns null.
+ */
+ public static String getSamplesPath(PlatformPathInfo platform, String version) {
+ String path = getPlatformPath(platform, version);
+ if ( path == null || StringUtil.isEmpty(path) ) {
+ return null;
+ }
+ else {
+ return path + File.separator + DIR_SAMPLES;
+ }
+ }
+ /**
+ * Returns latest platform name like "tizen2.2".
+ *
+ * @deprecated Use {@link #getSnippetsPath(PlatformPathInfo platform, String version)} instead.
+ */
//TODO: Should change to get string array type for various platform version paths.
public static String getSnippetsPath() {
return getPlatformVersionPath() + File.separator + DIR_SNIPPETS;
}
+
+ /**
+ * Returns a snippets path that is installed under the given platform and version.<br>
+ * If this method cannot find the sample path, returns null.
+ */
+ public static String getSnippetsPath(PlatformPathInfo platform, String version) {
+ String path = getPlatformPath(platform, version);
+ if ( path == null || StringUtil.isEmpty(path) ) {
+ return null;
+ }
+ else {
+ return path + File.separator + DIR_SAMPLES;
+ }
+ }
+ /**
+ * Returns latest platform name like "tizen2.2".
+ *
+ * @deprecated Use {@link #getOnDemandPath(PlatformPathInfo platform, String version)} instead.
+ */
//TODO: Should change to get string array type for various platform version paths.
public static String getOnDemandPath() {
return getPlatformVersionPath() + File.separator + DIR_ON_DEMAND;
}
+
+ /**
+ * Returns a on-demand path that is installed under the given platform and version.<br>
+ * If this method cannot find the sample path, returns null.
+ */
+ public static String getOnDemandPath(PlatformPathInfo platform, String version) {
+ String path = getPlatformPath(platform, version);
+ if ( path == null || StringUtil.isEmpty(path) ) {
+ return null;
+ }
+ else {
+ return path + File.separator + DIR_SAMPLES;
+ }
+ }
public static String getLibraryPath() {
return getSDKPath() + File.separator + DIR_LIBRARY;
--- /dev/null
+/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+* Gun Kim <gune.kim@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.core.application;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This class represents information of the platform path.
+ *
+ * @author Gun Kim<gune.kim@samsung.com>
+ */
+public class PlatformPathInfo {
+ private String profile;
+ // the versions's key means a profile's version,
+ // and its value means path that the version's profile is installed under the path.
+ private Map<String, String> versions = new HashMap<String, String>();
+
+ public PlatformPathInfo(String profile, Map<String, String> versions) {
+ this.profile = profile;
+ this.versions = versions;
+ }
+
+ public PlatformPathInfo(String profile, String version, String path) {
+ this.profile = profile;
+ versions.put(version, path);
+ }
+
+ public String getProfile() {
+ return profile;
+ }
+
+ public Set<String> getVersions() {
+ return versions.keySet();
+ }
+
+ public void appendVersion(String version, String path) {
+ versions.put(version, path);
+ }
+
+ /**
+ * Returns a installed path of the latest profile.
+ * Otherwise empty string if this method cannot find the path.
+ */
+ public String getLatestPlatformPath() {
+ String path = "";
+ float latestVersion = -1;
+ float tempVersion = 0;
+ for ( String curVersion : getVersions() ) {
+ tempVersion = Float.parseFloat( curVersion );
+ if ( latestVersion < tempVersion ) {
+ latestVersion = tempVersion;
+ path = versions.get(curVersion);
+ }
+ }
+
+ return path;
+ }
+
+ /**
+ * Returns a version of the latest profile.
+ * Otherwise empty string if this method cannot find the version.
+ */
+ public String getLatestPlatformVersion() {
+ String version = "";
+ float latestVersion = -1;
+ float tempVersion = 0;
+ for ( String curVersion : getVersions() ) {
+ tempVersion = Float.parseFloat( curVersion );
+ if ( latestVersion < tempVersion ) {
+ latestVersion = tempVersion;
+ version = curVersion;
+ }
+ }
+
+ return version;
+ }
+
+ /**
+ * Returns a installed path of the given version's profile.
+ * Otherwise empty string if this method cannot find the version.
+ */
+ public String getPlatformPath(String version) {
+ String platformPath = versions.get(version);
+
+ if ( platformPath == null ) {
+ return "";
+ }
+ return platformPath;
+ }
+
+ /**
+ * Returns a platform name of the given version's profile.
+ * Otherwise empty string if this method cannot find the version.
+ */
+ public String getPlatformName(String version) {
+ if ( !versions.containsKey(version) ) {
+ return "";
+ }
+ return String.format(InstallPathConfig.FORMAT_PLATFORM_NAME, profile, version);
+ }
+
+ /**
+ * Returns a platform name of the latest profile.
+ * Otherwise empty string if this method cannot find the version.
+ */
+ public String getLatestPlatformName() {
+ return getPlatformName(getLatestPlatformVersion());
+ }
+}