\r
/**\r
* This class provids CLI config key name constant.\r
- *\r
+ * \r
* @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
- *\r
+ * \r
*/\r
public class ConfigConstant {\r
- public static final String KEY = "";\r
- \r
- public static final String REALM = "pic.template.realm";\r
- public static final String CLI_HOME = System.getenv("CLI_HOME");\r
- public static final String REALM_HOME = CLI_HOME + File.separator + "realm";\r
- public static final String WEB_REALM_URL = "file:///" + REALM_HOME + File.separator + "ncli-web-config.json";\r
+ public static final String KEY = "";\r
+\r
+ public static final String REALM = "pic.template.realm";\r
+ public static final String CLI_HOME = System.getenv("CLI_HOME");\r
+ public static final String REALM_HOME = CLI_HOME + File.separator + "realm";\r
+ public static final String WEB_REALM_URL = "file:///" + REALM_HOME + File.separator + "ncli-web-config.json";\r
\r
- //public static final String LOADER = "file:///$${CLI_HOME}/realm/realm.jar";\r
- //public static final String WEB_TEMPLATE_QUERY_URL = "file:///$${TIZEN-SDK-HOME}/platforms/tizen2.2/samples/web/Template/$${id}";\r
- //public static final String WEB_SEARCH_QUERY_URL = "file:///$${TIZEN-SDK-HOME}/platforms/tizen2.2/samples/web/Template";\r
- //public static final String NATIVE_TEMPLATE_QUERY_URL = "file:///$${TIZEN-SDK-HOME}/platforms/tizen2.2/samples/native/cpp/Template/$${id}";\r
- //public static final String NATIVE_SEARCH_QUERY_URL = "file:///$${TIZEN-SDK-HOME}/platforms/tizen2.2/samples/native/cpp/Template";\r
- //public static final String SEARCH_QUERY_TYPE = "directory";\r
- \r
public static final String DEFAULT_BUILD_ARCHITECTURE = "default.build.architecture";\r
public static final String DEFAULT_BUILD_COMPILER = "default.build.compiler";\r
public static final String DEFAULT_BUILD_CONFIGURATION = "default.build.configuration";\r
public static final String DEFAULT_SDB_TIMEOUT = "default.sdb.timeout";\r
- \r
public static final String DEFAULT_PROFILES_PATH = "default.profiles.path";\r
+\r
+ public static final String DEFAULT_BUILD_ARCHITECTURE_VALUE = "x86";\r
+ public static final String DEFAULT_BUILD_COMPILER_VALUE = "llvm";\r
+ public static final String DEFAULT_BUILD_CONFIGURATION_VALUE = "Debug";\r
+ public static final String DEFAULT_SDB_TIMEOUT_VALUE = "60000";\r
+\r
+ public static String getDefaultValues() {\r
+ String valueFormat = "%s=%s\n";\r
+ String defaultValues = String.format(valueFormat, DEFAULT_BUILD_ARCHITECTURE, DEFAULT_BUILD_ARCHITECTURE_VALUE)\r
+ + String.format(valueFormat, DEFAULT_BUILD_COMPILER, DEFAULT_BUILD_COMPILER_VALUE)\r
+ + String.format(valueFormat, DEFAULT_BUILD_CONFIGURATION, DEFAULT_BUILD_CONFIGURATION_VALUE)\r
+ + String.format(valueFormat, DEFAULT_SDB_TIMEOUT, DEFAULT_SDB_TIMEOUT_VALUE);\r
+ return defaultValues;\r
+ }\r
}\r
import org.tizen.common.core.application.InstallPathConfig;\r
import org.tizen.common.util.Assert;\r
import org.tizen.common.util.FileUtil;\r
+import org.tizen.common.util.HostUtil;\r
import org.tizen.common.util.IOUtil;\r
import org.tizen.ncli.ide.CLIConstant;\r
+import org.tizen.ncli.ide.config.ConfigConstant;\r
\r
/**\r
* This class loads Tizen configuration from the specified file named <tt>.tizen-cli-config</tt> .\r
- * \r
- * <p>Tizen configuration file could be located at two location. <br>\r
+ * \r
+ * <p>\r
+ * Tizen configuration file could be located at two location. <br>\r
* First, global configuration file is located under the <tt>user home</tt> location.In Windows it would be C:\Users\accountName.\r
* <br>\r
* Second, local configuration file is located under the <tt>Tizen SDK tools path</tt>.<br>\r
- * <br> \r
+ * <br>\r
* And in case of there is not exist Tizen configuration file at loading , the file will be created automatically.<br>\r
- * The last thing , make sure that local config will have high priority to global config if there is same key. \r
+ * The last thing , make sure that local config will have high priority to global config if there is same key.\r
+ * \r
* @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
*/\r
public class NCLIConfigLoader implements Loader {\r
- private static final String configFileName =".tizen-cli-config";\r
+ private static final String configFileName = ".tizen-cli-config";\r
private static Logger log = LoggerFactory.getLogger(NCLIConfigLoader.class);\r
\r
- /* (non-Javadoc)\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
* @see org.tizen.common.config.Loader#load(java.lang.String)\r
*/\r
@Override\r
public void load(String ns) throws IOException {\r
- Assert.notNull(ns,"Namespace could not be null");\r
- if(CLIConstant.TIZEN_CLI_GLOBAL_KEY.equals(ns)) {\r
- Preference.register(ns, new TizenCLIConfigProvider(loadGlobalConf()));\r
- }else if(CLIConstant.TIZEN_CLI_LOCAL_KEY.equals(ns)) {\r
- Preference.register(ns, new TizenCLIConfigProvider(loadLocalConf()));\r
- }\r
+ Assert.notNull(ns, "Namespace could not be null");\r
+ if (CLIConstant.TIZEN_CLI_GLOBAL_KEY.equals(ns)) {\r
+ Preference.register(ns, new TizenCLIConfigProvider(loadGlobalConf()));\r
+ } else if (CLIConstant.TIZEN_CLI_LOCAL_KEY.equals(ns)) {\r
+ Preference.register(ns, new TizenCLIConfigProvider(loadLocalConf()));\r
+ }\r
}\r
- \r
- \r
+\r
/**\r
* Load local configuration from <tt>Tizen SDK Tools</tt>\r
- * @return localProperties return null if config file not exist. \r
+ * \r
+ * @return localProperties.\r
*/\r
- public static Properties loadLocalConf(){\r
- InputStream inStream = null;\r
- Properties localProp = null;\r
- try {\r
- File file = getLocalConfigFile();\r
- boolean isLocalConfExist = file.exists();\r
- log.trace("isLocalConfExist:{}",isLocalConfExist);\r
- localProp = new Properties();\r
- if(isLocalConfExist) {\r
- inStream = new FileInputStream(file);\r
- localProp.load(inStream);\r
- }else {\r
- log.info("Tizen CLI Local config file does not exist.");\r
- file.createNewFile();\r
- inStream = new FileInputStream(file);\r
- localProp.load(inStream);\r
- }\r
- \r
- }catch (FileNotFoundException e) {\r
- //FIXME something to do\r
- e.printStackTrace();\r
- }catch(IOException io){\r
- //FIXME something to do\r
- io.printStackTrace();\r
- }finally {\r
- IOUtil.tryClose(inStream);\r
- }\r
- return localProp;\r
+ public static Properties loadLocalConf() {\r
+ return loadConf(getLocalConfigFile(), true);\r
}\r
\r
- public static File getLocalConfigFile() {\r
- String sdkToolPath = InstallPathConfig.getToolsPath();\r
- File ret = new File(sdkToolPath+"/"+configFileName); \r
- return ret;\r
- }\r
/**\r
* Load global configuration from <tt>USER HOME</tt>\r
- * @return globalProperties return null if config file not exist.\r
+ * \r
+ * @return globalProperties.\r
*/\r
- public static Properties loadGlobalConf(){\r
+ public static Properties loadGlobalConf() {\r
+ return loadConf(getGlobalConfigFile(), false);\r
+ }\r
+\r
+ public static Properties loadConf(File file, boolean needDefaultValue) {\r
InputStream inStream = null;\r
Properties prop = new Properties();\r
try {\r
- File file = getGlobalConfigFile();\r
- boolean isGlobalConfExist = file.exists();\r
- log.trace("isGlobalConfExist:{}",isGlobalConfExist);\r
- if(isGlobalConfExist) {\r
+ boolean isConfExist = file.exists();\r
+ log.trace("isConfExist:{}", isConfExist);\r
+ if (isConfExist) {\r
inStream = new FileInputStream(file);\r
prop.load(inStream);\r
} else {\r
- log.info("Tizen CLI Global config file does not exist.");\r
- file.createNewFile();\r
- inStream = new FileInputStream(file);\r
- prop.load(inStream);\r
+ log.info("{} file does not exist.", file.getAbsolutePath());\r
+ file.createNewFile();\r
+ if (needDefaultValue) {\r
+ setDefault(file);\r
+ }\r
+ inStream = new FileInputStream(file);\r
+ prop.load(inStream);\r
}\r
- }catch (FileNotFoundException e) {\r
- //FIXME something to do\r
- }catch(IOException io){\r
- //FIXME something to do\r
- }finally {\r
+ } catch (FileNotFoundException e) {\r
+ log.error("FileNotFoundException occurred: {}", file.getAbsolutePath());\r
+ } catch (IOException io) {\r
+ log.error("IOException occurred: {}", file.getAbsolutePath());\r
+ } finally {\r
IOUtil.tryClose(inStream);\r
}\r
return prop;\r
- \r
}\r
\r
- public static File getGlobalConfigFile() {\r
- File userHome = new File(System.getProperty("user.home"));\r
- return new File(userHome.getAbsolutePath()+"/"+configFileName);\r
- }\r
- \r
- \r
+ public static File getLocalConfigFile() {\r
+ return getConfigFile(InstallPathConfig.getToolsPath());\r
+ }\r
+\r
+ public static File getGlobalConfigFile() {\r
+ return getConfigFile(System.getProperty("user.home"));\r
+ }\r
+\r
+ public static File getConfigFile(String pathName) {\r
+ return new File(pathName + HostUtil.FILE_SEPARATOR + configFileName);\r
+ }\r
\r
-}\r
+ private static void setDefault(File file) {\r
+ String defaultValues = ConfigConstant.getDefaultValues();\r
+ try {\r
+ FileUtil.writeTextFile(file, defaultValues, null);\r
+ } catch (IOException e) {\r
+ log.error("IOException occurred: {}", file.getAbsolutePath());\r
+ }\r
+ }\r
+}
\ No newline at end of file