import java.io.BufferedReader;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
return getSDKPath() + File.separator + DIR_DOCUMENTS;
}
- private static void loadSdkPath() {
+ private static void parseSdkInfoFile(String sdkPath) throws Exception {
+ // TODO: fix for //sdk.info
+ String sdkInfoFile = sdkPath + File.separator + SDK_INFO_FILE;
+ logger.info(String.format("Loading from %s...", sdkInfoFile));
+ if (!new File(sdkInfoFile).exists()) {
+ throw new FileNotFoundException("There is no file " + sdkInfoFile);
+ }
+
InputStream is = null;
try {
- String eclipsePath = org.eclipse.core.runtime.Platform.getInstallLocation().getURL().getPath();
- String sdkPath = new File(eclipsePath).getParent();
- String sdkInfoFile = sdkPath + File.separator + SDK_INFO_FILE;
- // to load from <eclipse>/../sdk.info
- logger.info(String.format("Loading from %s...", sdkInfoFile));
- if (!new File(sdkInfoFile).exists()) {
- throw new Exception("There is no file " + sdkInfoFile);
- }
-
Properties prop = new Properties();
is = StringUtil.toInputStream(HostUtil.getContents(sdkInfoFile));
prop.load(is);
sdkInstallPath = prop.getProperty(SDK_INFO_FILE_KEY_INSTALLED_PATH);
sdkDataPath = prop.getProperty(SDK_INFO_FILE_KEY_DATA_PATH);
logger.info(String.format("Loaded (install_path - %s, data_path - %s)", sdkInstallPath, sdkDataPath));
+ } finally {
+ IOUtil.tryClose(is);
+ }
+ }
+
+ private static void loadSdkPath() {
+ try {
+ String eclipsePath = org.eclipse.core.runtime.Platform.getInstallLocation().getURL().getPath();
+ String sdkPath = new File(eclipsePath).getParent();
+ // to load from <eclipse>/../sdk.info
+ parseSdkInfoFile(sdkPath);
+ } catch (NoClassDefFoundError ncdfe) {
+ // in case of CLI, java.lang.NoClassDefFoundError: org/eclipse/core/runtime/Platform
+ String path = InstallPathConfig.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+ String sdkPath = new File(path).getParent();
+ while (sdkPath != null) {
+ try {
+ parseSdkInfoFile(sdkPath);
+ break;
+ } catch (FileNotFoundException e) {
+ // to find sdk.info up-through
+ sdkPath = new File(sdkPath).getParent();
+ } catch (Exception e) {
+ logger.error("Failed to load from " + sdkPath, e);
+ }
+ }
} catch (Throwable t) {
logger.error("Failed to load from " + SDK_INFO_FILE, t);
- // fallback to load from ~/tizen-sdk-data/tizensdkpath
- loadSdkPathFromDefault();
} finally {
- IOUtil.tryClose(is);
+ if (sdkInstallPath == null || sdkDataPath == null) {
+ // fallback to load from ~/tizen-sdk-data/tizensdkpath
+ loadSdkPathFromDefault();
+ }
}
}