From d9e30d07cd5edf0c237ab09ec4638c7c50b08a4a Mon Sep 17 00:00:00 2001 From: jooyoul_lee Date: Tue, 10 Dec 2013 18:50:38 +0900 Subject: [PATCH] [Title] path manager sdk info path fixed [Desc.] [Issue] --- .../dynamicanalyzer/workbench/WorkbenchUtils.java | 127 +++++++++++++++------ .../dynamicanalyzer/common/AnalyzerPaths.java | 2 + .../tizen/dynamicanalyzer/common/PathManager.java | 123 ++++++++++++++------ 3 files changed, 181 insertions(+), 71 deletions(-) diff --git a/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/WorkbenchUtils.java b/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/WorkbenchUtils.java index 0e36ab5..5f425e5 100755 --- a/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/WorkbenchUtils.java +++ b/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/WorkbenchUtils.java @@ -34,6 +34,10 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.runtime.Platform; +import org.tizen.dynamicanalyzer.common.AnalyzerPaths; +import org.tizen.dynamicanalyzer.common.CommonConstants; + public class WorkbenchUtils { public static final String WIN_INSTALL_NODE = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";//$NON-NLS-1$ @@ -64,7 +68,7 @@ public class WorkbenchUtils { + "/tools/dynamic-analyzer/tool/windowactivator.bat";//$NON-NLS-1$ public static final String WINDOW_ACTIVATOR_MACOS_PATH = TIZEN_ROOT_PATH + "/tools/dynamic-analyzer/tool/macoswindowactivator.sh";//$NON-NLS-1$ - + private static String logPostFix = null; public static String getLogPostFix() { @@ -111,18 +115,24 @@ public class WorkbenchUtils { public static String getTizenSdkDataPath() { String defaultPath = null; - if (isWin()) { - defaultPath = getRegistryValue(WIN_INSTALL_NODE, WIN_INSTALL_KEY) - + File.separator + TIZEN_SDK_DATA; - } else if (isMac()) { - defaultPath = System.getenv(LINUX_INSTALL_ENV) + File.separator - + TIZEN_SDK_DATA; - } else if (isLinux()) { - defaultPath = System.getenv(LINUX_INSTALL_ENV) + File.separator - + TIZEN_SDK_DATA; - } else { - System.out.println("Please check OS and install the Tizen SDK"); //$NON-NLS-1$ - System.exit(-1); + + // case 1 : sdk.info + defaultPath = getPathFromSdkInfoFile(true); + + if (null == defaultPath) { + if (isWin()) { + defaultPath = getRegistryValue(WIN_INSTALL_NODE, + WIN_INSTALL_KEY) + File.separator + TIZEN_SDK_DATA; + } else if (isMac()) { + defaultPath = System.getenv(LINUX_INSTALL_ENV) + File.separator + + TIZEN_SDK_DATA; + } else if (isLinux()) { + defaultPath = System.getenv(LINUX_INSTALL_ENV) + File.separator + + TIZEN_SDK_DATA; + } else { + System.out.println("Please check OS and install the Tizen SDK"); //$NON-NLS-1$ + System.exit(-1); + } } return defaultPath; } @@ -131,29 +141,34 @@ public class WorkbenchUtils { String rootPath = null; BufferedReader br = null; String line = null; - try { - rootPath = TIZEN_SDK_DATA_PATH + File.separator + INSTALL; - File file = new File(rootPath); - if (!file.isFile()) { - return null; - } - br = new BufferedReader(new InputStreamReader(new FileInputStream( - file))); - line = br.readLine(); - if (null == line) { - return null; - } else { - return line.substring(line.indexOf("=") + 1); //$NON-NLS-1$ - } - } catch (IOException e) { - System.out.println("Fail to read."); //$NON-NLS-1$ - e.printStackTrace(); - } finally { - if (null != br) { - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); + + // case 1 : sdk.info + rootPath = getPathFromSdkInfoFile(false); + if (null == rootPath) { + try { + rootPath = TIZEN_SDK_DATA_PATH + File.separator + INSTALL; + File file = new File(rootPath); + if (!file.isFile()) { + return null; + } + br = new BufferedReader(new InputStreamReader( + new FileInputStream(file))); + line = br.readLine(); + if (null == line) { + return null; + } else { + return line.substring(line.indexOf("=") + 1); //$NON-NLS-1$ + } + } catch (IOException e) { + System.out.println("Fail to read."); //$NON-NLS-1$ + e.printStackTrace(); + } finally { + if (null != br) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } } @@ -253,7 +268,7 @@ public class WorkbenchUtils { return list; } - + public static boolean deleteFile(File file) { if (file.isDirectory()) { String[] children = file.list(); @@ -267,4 +282,42 @@ public class WorkbenchUtils { // Directory is empty so delete return file.delete(); } + + private static String getPathFromSdkInfoFile(boolean isDataPath) { + String retPath = null; + BufferedReader br = null; + String line = null; + // case 1 : sdk.info + try { + String path = null; + path = Platform.getInstallLocation().getURL().getPath(); + if (null != path && !path.isEmpty()) { + String infoPath = path + AnalyzerPaths.SDK_INFO_RELATIVE_PATH; + File infoFile = new File(infoPath); + if (infoFile.exists() && infoFile.isFile()) { + br = new BufferedReader(new InputStreamReader( + new FileInputStream(infoFile))); + line = br.readLine(); // sdkpath + if (isDataPath) { + line = br.readLine(); // sdk data path + } + if (line != null) { + retPath = line.substring(line + .indexOf(CommonConstants.EQUAL) + 1); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (null != br) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return retPath; + } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerPaths.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerPaths.java index cd9c814..86ba509 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerPaths.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerPaths.java @@ -92,4 +92,6 @@ public class AnalyzerPaths { + AnalyzerConstants.TOOLS_FOLDER_NAME + File.separator + "smart-build-interface" + File.separator + "bin" + File.separator + "sbi"; + + public static final String SDK_INFO_RELATIVE_PATH = "../../sdk.info"; //$NON-NLS-1$ } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/PathManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/PathManager.java index 934d323..74f9c11 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/PathManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/PathManager.java @@ -33,6 +33,7 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStreamReader; +import org.eclipse.core.runtime.Platform; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; import org.tizen.dynamicanalyzer.communicator.CommunicatorUtils; @@ -83,50 +84,63 @@ public class PathManager { public static String getTizenSdkDataPath() { String defaultPath = null; - if (AnalyzerUtil.isLinux()) { - defaultPath = System.getenv(AnalyzerConstants.LINUX_INSTALL_ENV) - + File.separator + AnalyzerConstants.TIZEN_SDK_DATA; - } else if (AnalyzerUtil.isWin()) { - defaultPath = getRegistryValue(AnalyzerConstants.WIN_INSTALL_NODE, - AnalyzerConstants.WIN_INSTALL_KEY) - + File.separator - + AnalyzerConstants.TIZEN_SDK_DATA; - } else if (AnalyzerUtil.isMac()) { - defaultPath = System.getenv(AnalyzerConstants.LINUX_INSTALL_ENV) - + File.separator + AnalyzerConstants.TIZEN_SDK_DATA; - } else { - final Shell shell = AnalyzerUtil.getWorkbenchWindow().getShell(); - DADialog dialog = new DADialog(shell, SWT.NONE); // FIXME - dialog.setIcon(ImageResources.DIALOG_WARNING_ICON); - dialog.setMessage(AnalyzerLabels.OS_WARNING); - if (dialog.open() == true) { - System.exit(-1); + + // case 1 : sdk.info + defaultPath = getPathFromSdkInfoFile(true); + + if (null == defaultPath) { + if (AnalyzerUtil.isLinux()) { + defaultPath = System + .getenv(AnalyzerConstants.LINUX_INSTALL_ENV) + + File.separator + AnalyzerConstants.TIZEN_SDK_DATA; + } else if (AnalyzerUtil.isWin()) { + defaultPath = getRegistryValue( + AnalyzerConstants.WIN_INSTALL_NODE, + AnalyzerConstants.WIN_INSTALL_KEY) + + File.separator + AnalyzerConstants.TIZEN_SDK_DATA; + } else if (AnalyzerUtil.isMac()) { + defaultPath = System + .getenv(AnalyzerConstants.LINUX_INSTALL_ENV) + + File.separator + AnalyzerConstants.TIZEN_SDK_DATA; + } else { + final Shell shell = AnalyzerUtil.getWorkbenchWindow() + .getShell(); + DADialog dialog = new DADialog(shell, SWT.NONE); // FIXME + dialog.setIcon(ImageResources.DIALOG_WARNING_ICON); + dialog.setMessage(AnalyzerLabels.OS_WARNING); + if (dialog.open() == true) { + System.exit(-1); + } } } return defaultPath; } - public static String getDefaultRoot() { - String rootPath = null; + private static String getPathFromSdkInfoFile(boolean isDataPath) { + String retPath = null; BufferedReader br = null; String line = null; + // case 1 : sdk.info try { - rootPath = AnalyzerPaths.TIZEN_SDK_DATA_PATH + File.separator - + AnalyzerConstants.INSTALL; - File file = new File(rootPath); - if (!file.isFile()) { - return null; - } - br = new BufferedReader(new InputStreamReader(new FileInputStream( - file))); - line = br.readLine(); - if (null == line) { - return null; - } else { - return line.substring(line.indexOf(CommonConstants.EQUAL) + 1); + String path = null; + path = Platform.getInstallLocation().getURL().getPath(); + if (null != path && !path.isEmpty()) { + String infoPath = path + AnalyzerPaths.SDK_INFO_RELATIVE_PATH; + File infoFile = new File(infoPath); + if (infoFile.exists() && infoFile.isFile()) { + br = new BufferedReader(new InputStreamReader( + new FileInputStream(infoFile))); + line = br.readLine(); // sdkpath + if (isDataPath) { + line = br.readLine(); // sdk data path + } + if (line != null) { + retPath = line.substring(line + .indexOf(CommonConstants.EQUAL) + 1); + } + } } - } catch (IOException e) { e.printStackTrace(); } finally { @@ -138,6 +152,47 @@ public class PathManager { } } } + return retPath; + } + + public static String getDefaultRoot() { + String rootPath = null; + BufferedReader br = null; + String line = null; + + // case 1 : sdk.info + rootPath = getPathFromSdkInfoFile(false); + if (null == rootPath) { + try { + // case 2 : tizensdkpath + rootPath = AnalyzerPaths.TIZEN_SDK_DATA_PATH + File.separator + + AnalyzerConstants.INSTALL; + File file = new File(rootPath); + if (!file.isFile()) { + return null; + } + br = new BufferedReader(new InputStreamReader( + new FileInputStream(file))); + line = br.readLine(); + if (null == line) { + return null; + } else { + return line + .substring(line.indexOf(CommonConstants.EQUAL) + 1); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (null != br) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } return rootPath; } -- 2.7.4