[Title] Add modules related to the creation of web project 25/11525/1
authorshingil.kang <shingil.kang@samsung.com>
Tue, 29 Oct 2013 08:48:20 +0000 (17:48 +0900)
committershingil.kang <shingil.kang@samsung.com>
Tue, 29 Oct 2013 08:48:20 +0000 (17:48 +0900)
[Desc.]
[Issue]

Change-Id: I41c816590a4f938a58d799442c6063448b74acf4
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
MANIFEST.MF [new file with mode: 0644]
org.tizen.ncli.ide/META-INF/MANIFEST.MF
org.tizen.ncli.ide/src/org/tizen/ncli/ide/config/ConfigConstant.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProjectCLI.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProject.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProjectCommand.java [moved from org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProject.java with 50% similarity]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/ConsolePrompter.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/Launcher.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/PolicyRegistryFactory.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/TemplateModelProvider.java [new file with mode: 0644]

diff --git a/MANIFEST.MF b/MANIFEST.MF
new file mode 100644 (file)
index 0000000..2780568
--- /dev/null
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0\r
+Ant-Version: Apache Ant 1.8.2\r
+Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)\r
+Main-Class: org/tizen/ncli/ide/autocomplete/TizenAutoComplete\r
+\r
index 8fe9e50..3c05fda 100644 (file)
@@ -5,7 +5,10 @@ Bundle-SymbolicName: org.tizen.ncli.ide
 Bundle-Version: 1.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.tizen.common;bundle-version="2.0.0",
- org.tizen.common.builder;bundle-version="2.0.0"
-Import-Package: org.tizen.web.builder,
+ org.tizen.common.builder;bundle-version="2.0.0",
+ org.tizen.common.verrari,
+ org.tizen.common.verrari.realm
+Import-Package: 
+ org.tizen.web.builder,
  org.tizen.web.builder.exception,
  org.tizen.web.common
index a9fa0d4..d52111b 100644 (file)
@@ -6,7 +6,7 @@
  * Contact:\r
  * Hyeongseok Heo <hyeongseok.heo@samsung.com>\r
  * Kangho Kim <kh5325.kim@samsung.com>\r
- * \r
+ *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  */\r
 package org.tizen.ncli.ide.config;\r
 \r
+import java.io.File;\r
+\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
 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
 \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
index 66aeb6e..04ac98c 100644 (file)
@@ -14,7 +14,7 @@ public class CreateCLI extends AbstractCLI {
     \r
     @Argument(index = 0, required = true, handler = SubCommandHandler.class, usage = "Command is needed!")\r
     @SubCommands({ \r
-            @SubCommand(name = "project", impl = CreateProject.class),\r
+            @SubCommand(name = "project", impl = CreateProjectCLI.class),\r
             @SubCommand(name = "security-profile", impl = CreateSecProfileCLI.class),\r
             @SubCommand(name = "security-profile-item", impl = CreateSecProfileItemCLI.class),\r
             @SubCommand(name = "certificate", impl = CreateCertificateCLI.class)\r
@@ -28,6 +28,12 @@ public class CreateCLI extends AbstractCLI {
     @Override\r
     public void execute() {\r
         log.trace("execute Create cli...");\r
+        \r
+        if( null != this.tizenCLI) {\r
+            this.tizenCLI.execute();\r
+        }\r
+        \r
+        \r
     }\r
     \r
        \r
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProjectCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProjectCLI.java
new file mode 100644 (file)
index 0000000..c426f3c
--- /dev/null
@@ -0,0 +1,151 @@
+/*\r
+ * IDE\r
+ *\r
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Contact:\r
+ * Shingi Kang <shingil.kang@samsung.com>\r
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>\r
+ * Kangho Kim <kh5325.kim@samsung.com>\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * Contributors:\r
+ * - S-Core Co., Ltd\r
+ */\r
+package org.tizen.ncli.ide.shell;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStreamReader;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+\r
+import org.kohsuke.args4j.Option;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.tizen.ncli.ide.util.PolicyRegistryFactory;\r
+import org.tizen.common.Factory;\r
+import org.tizen.common.config.Preference;\r
+import org.tizen.common.core.command.ExecutionContext;\r
+import org.tizen.common.core.command.Prompter;\r
+import org.tizen.common.core.command.policy.PolicyRegistry;\r
+import org.tizen.common.file.FileHandler;\r
+import org.tizen.common.file.StandardFileHandler;\r
+import org.tizen.common.verrari.Realm;\r
+import org.tizen.common.verrari.RealmFactory;\r
+import org.tizen.common.verrari.TemplateContext;\r
+import org.tizen.common.verrari.TemplateException;\r
+import org.tizen.ncli.ide.config.ConfigConstant;\r
+import org.tizen.ncli.ide.subcommands.BuildWebCLICommand;\r
+import org.tizen.ncli.ide.subcommands.CreateProject;\r
+import org.tizen.ncli.ide.subcommands.CreateProjectCommand;\r
+import org.tizen.ncli.ide.util.ConsolePrompter;\r
+import org.tizen.ncli.ide.util.Launcher;\r
+import org.tizen.ncli.ide.util.TemplateModelProvider;\r
+\r
+/**\r
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
+ */\r
+public class CreateProjectCLI extends AbstractCLI\r
+{\r
+    private Logger logger = LoggerFactory.getLogger(CreateProjectCLI.class);\r
+\r
+    @Option(name = "-t", aliases = { "--type" })\r
+    private TizenAppType appType;\r
+\r
+    @Option(name = "-n", aliases = "--name", required = true)\r
+    private String projectName;\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.tizen.ncli.ide.shell.AbstractCLI#execute()\r
+     */\r
+    @Override\r
+    public void execute()\r
+    {\r
+        logger.info("Project Name:{}", projectName);\r
+\r
+        CreateProjectCommand command = new CreateProjectCommand();\r
+        command.setAppType(appType);\r
+        command.setProjectName(projectName);\r
+        CreateProject createProject = command.runCommand();\r
+        \r
+        FileHandler fileHandler = new StandardFileHandler();\r
+        Factory<PolicyRegistry> factory = new org.tizen.ncli.ide.util.PolicyRegistryFactory();\r
+        PolicyRegistry pr = factory.create();\r
+        Prompter prompter = new ConsolePrompter( System.out, new InputStreamReader( System.in ));\r
+                \r
+        ExecutionContext context = new ExecutionContext(\r
+                pr,\r
+                prompter,\r
+                fileHandler\r
+            );\r
+        \r
+        // set model provider\r
+        TemplateContext.getInstance().setModelProvider(new TemplateModelProvider(context));\r
+\r
+        // get realm url\r
+        URL url = null;\r
+        try\r
+        {\r
+            url = new URL( ConfigConstant.WEB_REALM_URL );\r
+        } catch (MalformedURLException e1)\r
+        {\r
+            // TODO Auto-generated catch block\r
+            logger.error( "Error: ", e1 );\r
+        }\r
+        \r
+        // create realm\r
+        Realm realm = null;\r
+        try\r
+        {\r
+            realm = RealmFactory.getInstance().create( url );\r
+        }\r
+        catch ( final Throwable e )\r
+        {\r
+            logger.error( "Error: ", e );\r
+            return ;\r
+        }\r
+        \r
+        // put realm constant\r
+        context.setValue( ConfigConstant.REALM, realm );\r
+\r
+        try\r
+        {\r
+            createProject.process(context, appType, projectName);\r
+        } catch (IOException e)\r
+        {\r
+            // TODO Auto-generated catch block\r
+            e.printStackTrace();\r
+        } catch (TemplateException e)\r
+        {\r
+            // TODO Auto-generated catch block\r
+            e.printStackTrace();\r
+        }\r
+\r
+        /*\r
+         switch (appType) {\r
+             case NATIVE:\r
+                 logger.trace("Native app is being created");\r
+             break;\r
+             case WEB:\r
+                 logger.trace("Web app is being created");\r
+                 break;\r
+             default:\r
+                 break;\r
+         }\r
+       */\r
+    }\r
+\r
+}\r
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProject.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProject.java
new file mode 100644 (file)
index 0000000..5871840
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil Kang <shingil.kang@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.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.ncli.ide.subcommands;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.tizen.common.core.command.AbstractCommand;
+import org.tizen.common.core.command.ExecutionContext;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.verrari.Realm;
+import org.tizen.common.verrari.Storage;
+import org.tizen.common.verrari.Template;
+import org.tizen.common.verrari.TemplateContext;
+import org.tizen.common.verrari.TemplateException;
+import org.tizen.common.verrari.realm.CommonRealm;
+import org.tizen.common.verrari.storage.FileStorage;
+import org.tizen.common.verrari.template.TemplateConstants;
+import org.tizen.ncli.ide.config.ConfigConstant;
+import org.tizen.ncli.ide.shell.TizenAppType;
+import org.tizen.ncli.ide.util.TemplateModelProvider;
+
+/**
+ * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
+ *
+ * 
+ */
+public class CreateProject
+{
+    private TizenAppType appType;
+    private String projectName;    
+    
+    CreateProject(TizenAppType appType, String projectName)
+    {
+        this.appType = appType; 
+        this.projectName = projectName;
+    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
+    
+    public void process(
+        final ExecutionContext context,
+        TizenAppType appType,
+        String projectName
+    ) throws IOException, TemplateException
+    {
+        
+        final Realm realm = (Realm) context.getValue( ConfigConstant.REALM );
+        
+        final FileStorage storage = new FileStorage( context.getFileHandler() );
+        
+        final TemplateModelProvider models = new TemplateModelProvider( context );
+        
+        TemplateContext.getInstance().setModelProvider( models );
+        
+        try
+        {
+            template( realm, appType, projectName, models, storage );           
+        }
+        finally
+        {
+            TemplateContext.clear();
+        }
+        
+    }
+
+    protected void
+    template(
+        final Realm realm,
+        TizenAppType appType,
+        String projectName,
+        final TemplateModelProvider models,
+        final Storage storage
+    ) throws IOException, TemplateException
+    {
+        final HashMap<String, Template> ret = new HashMap<String, Template>();
+        
+        String[] projectNames = new String[]{projectName};
+        template( realm, appType, projectNames, models, storage, ret );
+         
+    }
+
+    protected
+    void
+    template(
+        final Realm realm,
+        TizenAppType appType,
+        String[] projectNames,
+        final TemplateModelProvider models,
+        final Storage storage,
+        final HashMap<String, Template> cache
+    )
+    throws IOException, TemplateException
+    {
+        for ( final String projectName : projectNames )
+        {
+            ExecutionContext.getCurrentContext().setValue( "id", projectName );
+            
+            // get template if cached
+            Template template = cache.get( projectName );
+            if ( null == template )
+            {
+                //get template if not cached
+                template = realm.getTemplate( projectName );
+            }
+            
+            cache.put( projectName, template );
+            template.template( models, storage );
+            final String[] dependencies = CommonRealm.separate( template.getAttribute( TemplateConstants.ATTR_DEPENDENCY ) );
+            if ( null == dependencies )
+            {
+                continue;
+            }
+            
+            template( realm, appType, dependencies, models, storage, cache );
+        }
+    }
+}
\ No newline at end of file
@@ -1,62 +1,57 @@
-/*\r
- * IDE\r
- *\r
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>\r
- * Kangho Kim <kh5325.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- */\r
-package org.tizen.ncli.ide.shell;\r
-\r
-import org.kohsuke.args4j.Option;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
- */\r
-public class CreateProject extends AbstractCLI {\r
-    private Logger logger = LoggerFactory.getLogger(CreateProject.class);\r
-    \r
-    @Option(name="-t" , aliases= {"--type"})\r
-    private TizenAppType appType;\r
-    \r
-    @Option(name="-n" , aliases="--name" , required=true)\r
-    private String projectName;\r
-\r
-    /* (non-Javadoc)\r
-     * @see org.tizen.ncli.ide.shell.AbstractCLI#execute()\r
-     */\r
-    @Override\r
-    public void execute() {\r
-        logger.info("Project Name:{}",projectName);\r
-        \r
-        switch (appType) {\r
-        case NATIVE:\r
-            logger.trace("Native app is being created");\r
-            break;\r
-        case WEB:\r
-            logger.trace("Web app is being created");\r
-            break;\r
-        default:\r
-            break;\r
-        }\r
-    }\r
-\r
-}\r
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil Kang <shingil.kang@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.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.ncli.ide.subcommands;
+
+import org.kohsuke.args4j.Option;
+import org.tizen.ncli.ide.shell.TizenAppType;
+
+/**
+ * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
+ *
+ * 
+ */
+public class CreateProjectCommand extends AbstractSubCommand<CreateProject>
+{
+    private TizenAppType appType;
+    private String projectName;
+    
+    public void setAppType(TizenAppType appType)
+    {
+        this.appType = appType;
+    }
+
+    public void setProjectName(String projectName)
+    {
+        this.projectName = projectName;
+    }
+
+    @Override
+    protected CreateProject call()
+    {
+        // TODO Auto-generated method stub
+        return new CreateProject(appType, projectName);
+    }
+}
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/ConsolePrompter.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/ConsolePrompter.java
new file mode 100644 (file)
index 0000000..551776e
--- /dev/null
@@ -0,0 +1,370 @@
+/*
+ * CLI - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Shingil Kang <shingil.kang@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@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.ncli.ide.util;
+
+import static org.tizen.common.core.command.PrompterConstants.SUPPORT_CONSOLE;
+import static org.tizen.common.util.CollectionUtil.isEmpty;
+import static org.tizen.common.util.StringUtil.isEmpty;
+import static org.tizen.common.util.StringUtil.trim;
+
+import java.io.BufferedReader;
+import java.io.Console;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Map;
+
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.UserField;
+import org.tizen.common.core.command.prompter.AbstractPrompter;
+import org.tizen.common.core.command.prompter.ChoiceOption;
+import org.tizen.common.core.command.prompter.GenericOption;
+import org.tizen.common.core.command.prompter.Option;
+import org.tizen.common.util.Assert;
+
+/**
+ * <p>
+ * ConsolePrompter.
+ * 
+ * {@link Prompter} for command line interface
+ * 
+ * Print out using {@link PrintStream} and Read input from console( including standard input )
+ * </p>
+ * 
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+ConsolePrompter
+extends AbstractPrompter
+implements Prompter
+{
+    /**
+     * {@link PrintStream} for output
+     */
+    protected final PrintStream out;
+    
+    /**
+     * {@link BufferedReader} for input
+     */
+    protected final BufferedReader reader;
+    
+    /**
+     * Constructor with {@link PrintStream} and {@link Reader}
+     * 
+     * @param out {@link PrintStream} for output
+     * @param reader {@link Reader} for input
+     */
+    public
+    ConsolePrompter(
+        final PrintStream out,
+        final Reader reader
+    )
+    {
+        Assert.notNull( out );
+        this.out = out;
+        this.reader = new BufferedReader( reader );
+    }
+
+    /* (non-Javadoc)
+     * @see org.tizen.common.core.command.Prompter#interact(java.lang.String, int, org.tizen.common.core.command.prompter.Option[])
+     */
+    @Override
+    public
+    Option
+    interact(
+        final String question,
+        final Option... options
+    )
+    {
+        final HashSet<Option> reducedOptions = new LinkedHashSet<Option>();
+        Option defaultOption = null;
+        final ArrayList<String> optionNames = new ArrayList<String>();
+        for ( final Option option : options )
+        {
+            if ( reducedOptions.contains( option ) )
+            {
+                throw new IllegalArgumentException( "Question can't have duplicated choice(s) :" + option );
+            }
+            optionNames.add( option.getName() );
+            reducedOptions.add( option );
+            if ( option.isDefault() )
+            {
+                if ( null != defaultOption )
+                {
+                    throw new IllegalArgumentException(
+                        "Question must have only one default choice"
+                    );
+                }
+                    
+                defaultOption = option;
+            }
+        }
+        
+        String choice = null;
+        try
+        {
+            while ( true )
+            {
+                printQuestion( question, options );
+                
+                choice = reader.readLine();
+                if ( isEmpty( choice ) )
+                {
+                    return defaultOption;
+                }
+                for ( final Option option : options )
+                {
+                    if ( option.isMatch( choice ) )
+                    {
+                        return option;
+                    }
+                }
+            }
+        } catch ( final IOException e )
+        {
+            throw new IllegalStateException( e );
+        }
+    }
+    
+    /**
+     * Print out question and options for choice
+     * 
+     * @param question message to print
+     * @param options options to suggest
+     */
+    protected
+    void
+    printQuestion(
+        final String question,
+        final Option... options
+    )
+    {
+        out.print( getFullQuestion(question, options) );
+    }
+    
+    private char[] getFullQuestion(String question, Option[] options) {
+        
+        StringBuffer buffer = new StringBuffer();
+        buffer.append(question + "\n");
+        
+        int len = options.length - 1;
+        for(int i = 0; i< len; i++) {
+               if(options[i] instanceof ChoiceOption) {
+                    ChoiceOption choiceOption = (ChoiceOption) options[i];
+                    buffer.append(String.format("%s: (%s), ", choiceOption.getName(), choiceOption.getShortName()));
+                }
+        }
+        
+        if(options[len] instanceof ChoiceOption) {
+            ChoiceOption choiceOption = (ChoiceOption) options[len];
+            buffer.append(String.format("%s: (%s) ", choiceOption.getName(), choiceOption.getShortName()));
+        }
+        
+        buffer.append("?");
+        
+        return buffer.toString().toCharArray();
+    }
+
+    /* (non-Javadoc)
+     * @see org.tizen.common.core.command.Prompter#notify(java.lang.String, java.lang.Object[])
+     */
+    @Override
+    public
+    void
+    notify(
+        final String message
+    )
+    {
+        out.println( message );
+    }
+
+    /* (non-Javadoc)
+     * @see org.tizen.common.core.command.Prompter#cancel()
+     */
+    @Override
+    public void cancel()
+    {
+    }
+
+    /* (non-Javadoc)
+     * @see org.tizen.common.core.command.Prompter#password(java.lang.String)
+     */
+    @Override
+    public
+    Object password(
+        final String message
+    )
+    {
+        out.print( trim( message ) );
+        out.print( " " );
+        Console console = System.console();
+        return console.readPassword();
+    }
+
+    /* (non-Javadoc)
+     * @see org.tizen.common.core.command.Prompter#error(java.lang.String, java.lang.Object[])
+     */
+    @Override
+    public
+    void
+    error(
+        final String message
+    )
+    {
+        out.println( message );
+    }
+
+    /* (non-Javadoc)
+     * @see org.tizen.common.core.command.Prompter#batch(java.util.Collection)
+     */
+    @Override
+    public
+    void
+    batch(
+        final Collection<UserField> userFields,
+        final Map<String, Object> options
+    )
+    {
+        batch( 0, userFields );
+    }
+    
+    /**
+     * <p>
+     * Process <code>fields</code> for <code>depth</code> level
+     * 
+     * process result are stored in <code>answer</code>
+     * </p>
+     * @param depth process depth
+     * @param fields user input specifications
+     * @param answer user answer
+     */
+    protected
+    void
+    batch(
+        final int depth,
+        final Collection<UserField> fields
+    )
+    {
+        for ( final UserField child : fields )
+        {
+            batch( depth, child );
+        }
+    }
+    
+    /**
+     * <p>
+     * Process <code>field</code> for <code>depth</code> level
+     * 
+     * process result are stored in <code>answer</code>
+     * </p>
+     * @param depth process depth
+     * @param field user input specification
+     * @param answer user answer
+     */
+    protected
+    void
+    batch(
+        final int depth,
+        final UserField field
+    )
+    {
+        final String msg = field.getMessage();
+        
+        final Collection<Object> supports = field.getSupports();
+        if ( null != supports && !supports.contains( SUPPORT_CONSOLE ) )
+        {
+            logger.warn( "{} is not supported in {}", field, this );
+            return ;
+        }
+        
+        final Class<?> type = field.getType();
+        
+        boolean bChild = true;
+        
+        if ( field.canModify() )
+        {
+            if ( String.class.equals( type ) )
+            {
+                final GenericOption option = new GenericOption();
+                interact( indent( depth, msg ), option );
+                if ( field.getValue() == null || !isEmpty( option.getAnswer() ) )
+                {
+                    field.setValue( option.getAnswer() );
+                }
+            }
+            else if ( char[].class.equals( type ) || Character[].class.equals( type ) )
+            {
+                field.setValue( password( indent( depth, msg ) ) );
+            }
+            else if ( boolean.class.equals( type ) || Boolean.class.equals( type ) )
+            {
+                final boolean initValue = (null == field.getValue())?true:((Boolean) field.getValue());
+                final ChoiceOption yes = new ChoiceOption( "Yes", initValue );
+                final ChoiceOption no = new ChoiceOption( "No", !initValue );
+                final Object opt = interact( indent( depth, msg ), yes, no );
+                bChild = yes.equals( opt );
+                field.setValue( bChild );
+            }
+        }
+        
+        final Collection<UserField> children = field.getChildren();
+        if ( bChild && !isEmpty( children ) )
+        {
+            notify( indent( depth, msg ) );
+            batch( depth + 1, children );
+        }
+    }
+
+    /**
+     * Make indented message
+     * 
+     * @param depth message depth
+     * @param msg message
+     * 
+     * @return created message
+     */
+    protected
+    String
+    indent(
+        final int depth,
+        final String msg
+    )
+    {
+        final StringBuilder buffer = new StringBuilder();
+        
+        for ( int i = 0 ; i<depth ; ++i )
+        {
+            buffer.append( " " );
+        }
+        buffer.append( msg );
+        return buffer.toString();
+    }
+
+}
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/Launcher.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/Launcher.java
new file mode 100644 (file)
index 0000000..0c2b700
--- /dev/null
@@ -0,0 +1,728 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil kang<shingil.kang@samsung.com> 
+ * Hyeongseok Heo <hyeongseok.heo@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.ncli.ide.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Properties;
+
+//import org.apache.commons.cli.CommandLine;
+//import org.apache.commons.cli.CommandLineParser;
+//import org.apache.commons.cli.GnuParser;
+//import org.apache.commons.cli.OptionBuilder;
+//import org.apache.commons.cli.Options;
+//import org.apache.commons.cli.ParseException;
+//import org.apache.commons.cli.PosixParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.config.Preference;
+import org.tizen.common.config.provider.EnvironmentProvider;
+import org.tizen.common.config.provider.SystemPropertiesProvider;
+import org.tizen.common.core.command.ExecutionContext;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.file.FileHandler;
+import org.tizen.common.file.FileHandler.Attribute;
+import org.tizen.common.file.StandardFileHandler;
+import org.tizen.common.util.CollectionUtil;
+import org.tizen.common.util.IOUtil;
+import org.tizen.common.util.MapUtil;
+import org.tizen.common.util.OSChecker;
+import org.tizen.common.util.PropertyUtil;
+import org.tizen.common.util.StringUtil;
+
+/**
+ * <p>
+ * AbstractLauncher.
+ * 
+ * abstract class for simple command.
+ * 
+ * provide {@link ExecutionContext} for command line
+ * </p>
+ * 
+ * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-Core)
+ */
+public class
+Launcher
+{
+//    
+//    /**
+//     * <p>
+//     * Option for help text
+//     * </p>
+//     */
+//    protected static final String OPT_HELP = "help";
+//    
+//    /**
+//     * <p>
+//     * Description for help option
+//     * 
+//     * This is printed out in usage
+//     * </p>
+//     * 
+//     * @see #OPT_HELP
+//     */
+//    protected static final String DESC_HELP = "Print out this page";
+//    
+//    /**
+//     * <p>
+//     * Option for log level
+//     * 
+//     * This option is shared in shell
+//     * </p>
+//     */
+//    protected static final String OPT_LOG = "log";
+//    
+//    /**
+//     * <p>
+//     * Description for log level option
+//     * 
+//     * This is printed out in usage
+//     * </p>
+//     * 
+//     * @see #OPT_LOG
+//     */
+//    protected static final String DESC_LOG = "Specify log category (error | warn | info | debug | trace)";
+//    
+//    /**
+//     * <p>
+//     * Option for no output
+//     * </p>
+//     */
+//    protected static final String OPT_QUIET = "quiet";
+//    
+//    /**
+//     * <p>
+//     * Description for no output option
+//     * 
+//     * This is printed out in usage
+//     * </p>
+//     * 
+//     * @see #OPT_QUIET
+//     */
+//    protected static final String DESC_QUIET = "Execute silently";
+//    
+//    /**
+//     * <p>
+//     * Property key for command line parameter parser
+//     * </p>
+//     */
+//    protected static final String PROP_PARSER = "tizen.cli.parser";
+//    
+//    
+//    /**
+//     * <p>
+//     * suffix for help properties
+//     * </p>
+//     */
+//    protected static final String SUFFIX_CONFIG = ".properties";
+//    
+//    /**
+//     * <p>
+//     * logger for this object
+//     * </p>
+//     */
+//    protected final Logger logger = LoggerFactory.getLogger( getClass() );
+//    
+//    /**
+//     * <p>
+//     * object for usage help
+//     * </p>
+//     */
+//    protected Help help;
+    
+//    /**
+//     * <p>
+//     * optional flag to be specified by user
+//     * 
+//     * flag is formatted in POSIX style in default
+//     * </p>
+//     */
+//    protected CommandLine cmd;
+    
+    /**
+     * {@link Executor} for Command Line Interface
+     */
+    public Executor executor; 
+
+    /**
+     * A command user inputs
+     */
+//    protected String inputCmd = "";
+//    
+//    /**
+//     * Convert <code>path</code> to canonical path
+//     * 
+//     * @param path relative or abstract path
+//     * 
+//     * @return canonical path
+//     * 
+//     * @throws IOException If file system deny request
+//     */
+//    protected
+//    String
+//    convertPath(
+//        final String  path
+//    )
+//    throws IOException
+//    {
+//        String target = path;
+//        if ((!OSChecker.isWindows())
+//                && target.startsWith("~"+File.separator)) {
+//            target = path.replaceFirst("~", System.getProperty("user.home"));
+//        }
+//        final FileHandler fileHandler = getFileHandler();
+//        return (String) fileHandler.get( target, Attribute.PATH );
+//    }
+
+    /**
+     * return execution command for usage
+     * 
+     * @return execution command
+     */
+//    protected String getSyntax()
+//    {
+//        return getHelp().getSyntax();
+//    }
+//    
+//    /**
+//     * {@link Options} for usage
+//     * 
+//     * @return defined {@link Options}
+//     */
+//    @SuppressWarnings("static-access")
+//    protected
+//    Options
+//    getOptions()
+//    {
+//        final Options options = new Options();
+//        
+//        options.addOption( OptionBuilder.withLongOpt( OPT_HELP ).withDescription( DESC_HELP ).create( OPT_HELP.substring( 0, 1 ) ) );
+//        options.addOption( OptionBuilder.hasArg().withLongOpt( OPT_LOG ).withDescription( DESC_LOG ).create( OPT_LOG.substring( 0, 1 ) ) );
+//        options.addOption( OptionBuilder.withLongOpt( OPT_QUIET ).withDescription( DESC_QUIET ).create( OPT_QUIET.substring( 0, 1 ) ) );
+//
+//        return options;
+//    }
+//
+//    /**
+//     * {@link Options} for usage. A command does not use short option name and argument.
+//     * 
+//     * @return defined {@line Options}
+//     */
+//    protected
+//    Options
+//    getCommands()
+//    {
+//        final Options options = new Options();
+//        return options;
+//    }
+//    
+//    
+//    /**
+//     * <p>
+//     * Create and return {@link Help} instance
+//     * </p>
+//     * 
+//     * @return {@link Help}
+//     */
+//    protected
+//    Help
+//    createHelp() {
+//        return new Help( getOptions() );
+//    }
+//
+//    /**
+//     * <p>
+//     * Return {@link Help} in this cli instance
+//     * </p>
+//     * @return {@link Help}
+//     */
+//    synchronized protected
+//    Help
+//    getHelp()
+//    {
+//        if ( null == help )
+//        {
+//            this.help = createHelp();
+//            final ClassLoader cl = getClass().getClassLoader();
+//            final String resourceName = getClass().getName().replace( '.', '/' ) + SUFFIX_CONFIG;
+//            
+//            logger.trace( "Resource name :{}", resourceName );
+//            try
+//            {
+//                final Enumeration<URL> iter = cl.getResources( resourceName );
+//                while ( iter.hasMoreElements() )
+//                {
+//                    final URL url = iter.nextElement();
+//                    logger.trace( "URL :{}", url );
+//                    final Properties properties = PropertyUtil.loadProperties( url.openStream() );
+//                    logger.debug( "Properties :{}", properties );
+//                    
+//                    for ( final Object key : properties.keySet() )
+//                    {
+//                        final String value = properties.getProperty( (String) key );
+//                        byte[] contents = IOUtil.getBytes( cl.getResourceAsStream( value ), true );
+//                        this.help.addHelpDetail( (String) key, new String( contents, Charset.forName( "utf8" ) ) );
+//                    }
+//                }
+//            }
+//            catch ( final IOException e )
+//            {
+//                logger.warn( "Can't load help", e );
+//            }
+//        }
+//        
+//        return this.help;
+//    }
+//    
+//    /**
+//     * Print out sample usage
+//     * 
+//     * @return sample usage string
+//     */
+//    protected
+//    String
+//    printHelpDetail( String option )
+//    {
+//        final String detailStr = getHelp().getHelpDetail( option );
+//        getPrompter().error( detailStr );
+//        return detailStr;
+//    }
+//    
+//    /**
+//     * Print out usage
+//     * 
+//     * @return usage string
+//     */
+//    protected
+//    String
+//    printHelp()
+//    {
+//        final String helpStr = getHelp().getHelp();
+//        getPrompter().error( helpStr );
+//        return helpStr;
+//    }
+//
+//    /**
+//     * Print out invalid usage
+//     * 
+//     * @return invalid usage string
+//     */
+//    protected
+//    String
+//    printError( String msg )
+//    {
+//        String errorStr = "E: Invalid usage";
+//        if ( !StringUtil.isEmpty( msg ) ) {
+//            errorStr = MessageFormat.format( "E: Invalid usage [{0}]", msg );
+//        }
+//        getPrompter().error( errorStr );
+//        return errorStr;
+//    }
+//
+//    /**
+//     * Entry method for execution
+//     * 
+//     * @param args command line argument
+//     * 
+//     * @throws Exception If unhandled exception occured
+//     */
+//    public void
+//    run(
+//        final String... args
+//    )
+//    throws Exception
+//    {
+//        Preference.register( "OS", new EnvironmentProvider() );
+//        Preference.register( "JVM", new SystemPropertiesProvider() );
+//        executor = new CommandLineExecutor(
+//            new ConsolePrompter( System.out, new InputStreamReader( System.in ) )
+//        );
+//        if ( logger.isTraceEnabled() )
+//        {
+//            logger.trace( "OS Environment :\n{}", MapUtil.toString( System.getenv() ) );
+//            logger.trace( "System properties :\n{}", MapUtil.toString( System.getProperties() ) );
+//            logger.trace( "Args :{}", CollectionUtil.concatenate( Arrays.asList( args ), "," ) );
+//        }
+//        
+//        try
+//        {
+//            Options cmds = this.getCommands();
+//            
+//            if(args.length == 0 && isPrintHelp()) {
+//                printHelp();
+//                return;
+//            }
+//            if(cmds.getOptions().size() > 0 && args.length > 0 && cmds.hasOption(args[0])) {
+//                this.inputCmd = args[0];
+//                String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
+//                this.cmd = parse( newArgs);
+//            }
+//            else {
+//                this.cmd = parse( args );
+//            }
+//            
+//            if ( cmd.hasOption( OPT_QUIET ) )
+//            {
+//                executor = new CommandLineExecutor(
+//                    new ConsolePrompter( new PrintStream( new OutputStream() {
+//                        public void write(int b) throws IOException {
+//                        }
+//                    } ), new InputStreamReader( System.in ) )
+//                );
+//                
+//            }
+//            
+//            if ( cmd.hasOption( OPT_HELP ) )
+//            {
+//                printHelp();
+//                
+//                logger.debug( "Help argument :{}", cmd.getArgList() );
+//                
+//                for ( String keyword : cmd.getArgs() )
+//                {
+//                    printHelpDetail( keyword );
+//                }
+//                return ;
+//            }
+//
+//            execute( cmd );
+//        }
+//        catch ( final ParseException e )
+//        {
+//            
+//            logger.error( "Parsing Error: ", e );
+//            logger.trace( "Invalid usage." );
+//            
+//            // args include "-h, --help" then working 'help'
+//            boolean bPrintHelp = false;
+//            for ( String arg : args ) {
+//                if ( ( "-" + OPT_HELP.substring( 0, 1 ) ).equals( arg ) || ( "--" + OPT_HELP ).equals( arg ) ) {
+//                    printHelp();
+//                    bPrintHelp = true;
+//                    break;
+//                }
+//            }
+//
+//            if ( !bPrintHelp ) {
+//                printError( e.getMessage() );
+//            }
+//
+//            if ( null != cmd ) {
+//                logger.debug( "Help argument :{}", cmd.getArgList() );
+//                
+//                for ( String keyword : cmd.getArgs() )
+//                {
+//                    printHelpDetail( keyword );
+//                }
+//                
+//            }
+//        }
+//        catch ( final Throwable e )
+//        {
+//            handleException( e );
+//        }
+//    }
+//    
+//       /**
+//     * Gets a command that user inputs.
+//     *
+//     * @return a command user inputs
+//     */
+//    protected String getInputCmd() {
+//        return this.inputCmd;
+//    }
+//
+//    /**
+//     * Handle uncaught exception
+//     * 
+//     * @param e uncaught exception
+//     */
+//    protected
+//    void
+//    handleException(
+//        final Throwable e
+//    )
+//    {
+//        getPrompter().error( e.getMessage() );
+//        logger.error( "Command stop because of exception", e );
+//
+//        Throwable iter = e;
+//        while ( null != iter )
+//        {
+//            final String localMessage = iter.getLocalizedMessage();
+//            if ( null != localMessage )
+//            {
+//                logger.error( localMessage );
+//                exit( 1 );
+//            }
+//
+//            final String message = iter.getMessage();
+//            if ( null != message )
+//            {
+//                logger.error( message );
+//                exit( 1 );
+//            }
+//            iter = iter.getCause();
+//        }
+//    }
+//
+//    /**
+//     * Parse arguments <code>args</code> with {@link CommandLineParser}
+//     * 
+//     * @param args arguments to parse
+//     * 
+//     * @return {@link CommandLine} to be parsed
+//     * 
+//     * @throws InstantiationException If custom parser is invalid
+//     * @throws IllegalAccessException If custom parser is invalid
+//     * @throws ParseException If arguements is invalid
+//     */
+//    protected
+//    CommandLine
+//    parse(
+//        final String... args
+//    )
+//    throws InstantiationException, IllegalAccessException, ParseException
+//    {
+//        final CommandLineParser parser = getParser();
+//        
+//        final Options options = getOptions();
+//
+//        final CommandLine cmdLine = parser.parse( options, args );
+//        
+//        return cmdLine;
+//    }
+//    
+//    /**
+//     * Return default parser {@link Class}
+//     * 
+//     * @return {@link Class} for default parser
+//     */
+//    protected
+//    static
+//    Class<?>
+//    getDefaultParserClass()
+//    {
+//        return PosixParser.class;
+//    }
+//    
+//    /**
+//     * Return parser along user selection.
+//     * 
+//     * The selection is specified JVM system properties
+//     * 
+//     * Support two built-in parser
+//     * <ul>
+//     * <li>POSIX style - tar -zxvf foo.tar.gz</li>
+//     * <li>GNU style - du --human-readable --max-depth=1</li>
+//     * </ul>
+//     * 
+//     * if you want use custom parser, specify class name
+//     * 
+//     * @return {@link CommandLineParser} to parse
+//     * 
+//     * @throws InstantiationException If custom parser can't be instantiated
+//     * @throws IllegalAccessException If custom parser's constructor is NOT accessible
+//     * 
+//     * @see #PROP_PARSER
+//     * @see CommandLineParser
+//     */
+//    protected
+//    CommandLineParser
+//    getParser()
+//    throws InstantiationException, IllegalAccessException {
+//        final String parserName = System.getProperty( PROP_PARSER );
+//        logger.trace( "Parser name :{}", parserName );
+//        Class<?> parserClazz = getDefaultParserClass();
+//        try {
+//            if ( null != parserName )
+//            {
+//                parserClazz = Class.forName( parserName );
+//            }
+//        }
+//        catch ( final ClassNotFoundException e )
+//        {
+//            if ( "posix".equalsIgnoreCase( parserName ) )
+//            {   // tar -zxvf foo.tar.gz
+//                parserClazz = PosixParser.class;
+//            }
+//            else if ( "gnu".equalsIgnoreCase( parserName ) )
+//            {
+//                parserClazz = GnuParser.class;
+//            }
+//            else
+//            {
+//                logger.warn( "Invalid argument parser :" + parserName );
+//            }
+//        }
+//        
+//        logger.trace( "Parser class :{}", parserClazz );
+//        
+//        return (CommandLineParser) parserClazz.newInstance();
+//    }
+//
+//    /**
+//     * Return managed command line arguments
+//     * 
+//     * @return managed arguments
+//     * 
+//     * @see CommandLine
+//     */
+//    protected
+//    CommandLine
+//    getCommandLine()
+//    {
+//        return this.cmd;
+//    }
+    
+    /**
+     * Return defined executor for command
+     * 
+     * @return {@link ExecutionContext} to use
+     */
+    public
+    Executor
+    getExecutor()
+    {
+        if ( null == executor )
+        {
+            this.executor = new Executor();
+        }
+    
+        return executor;
+    }
+    
+    /**
+     * Return {@link ExecutionContext} in cli
+     * 
+     * @return {@link ExecutionContext}
+     */
+    public
+    ExecutionContext
+    getExecutionContext()
+    {
+        return getExecutor().getContext();
+    }
+    
+    /**
+     * Return {@link PolicyRegistry} in cli
+     * 
+     * @return {@link PolicyRegistry}
+     */
+    public
+    PolicyRegistry
+    getPolicy()
+    {
+        return getExecutionContext().getPolicyRegistry();
+    }
+    
+    /**
+     * Return {@link FileHandler} in cli
+     * 
+     * @return {@link FileHandler}
+     * 
+     * @see #getExecutionContext()
+     * @see StandardFileHandler
+     */
+    public
+    FileHandler
+    getFileHandler()
+    {
+        return getExecutionContext().getFileHandler();
+    }
+    
+    /**
+     * Return {@link Prompter} in cli
+     * 
+     * @return {@link Prompter}
+     * 
+     * @see #getExecutionContext()
+     */
+    public
+    Prompter
+    getPrompter()
+    {
+        return getExecutionContext().getPrompter();
+    }
+
+//    /**
+//     * Returns whether print help or not if argument is empty.
+//     * 
+//     * @return returns </code>true</code> if it prints help. Else, <code>false</code>.
+//     */
+//    protected
+//    boolean
+//    isPrintHelp() {
+//        return false;
+//    }
+//    
+//    /**
+//     * Gets the uses description of the CLI. 
+//     * 
+//     * @return returns usage description string.
+//     */
+//    protected String getUsageDescription() {
+//        return StringUtil.EMPTY_STRING;
+//    }
+    
+    /**
+     * Terminates the currently running command line interface.<p>
+     * The argument serves as a status code<br>
+     * by convention, a nonzero status code indicates abnormal termination.<br>
+     * This method calls the System.exit method.
+     * 
+     * @param status exit status.
+     */
+    public
+    void
+    exit(int status)
+    {
+        System.exit( status );
+    }
+
+    /**
+     * Execute command
+     * 
+     * Implement execution of command
+     * 
+     * @param cmdLine arguments
+     * 
+     * @throws Exception If Unhandled exception occured
+     */
+//    abstract protected void execute( CommandLine cmdLine ) throws Exception;
+
+
+}
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/PolicyRegistryFactory.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/PolicyRegistryFactory.java
new file mode 100644 (file)
index 0000000..a8c190b
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil Kang <shingil.kang@samsung.com> 
+ * Hyeongseok Heo <hyeongseok.heo@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.ncli.ide.util;
+
+import static org.tizen.common.core.command.Policy.EXIST_OUT_FILE;
+import static org.tizen.common.core.command.Policy.NONEXIST_IN_FILE;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.Factory;
+import org.tizen.common.core.command.Policy;
+import org.tizen.common.core.command.policy.AbstractPolicy;
+import org.tizen.common.core.command.policy.FilePolicy;
+import org.tizen.common.core.command.policy.MessagePolicy;
+import org.tizen.common.core.command.policy.OptionPolicy;
+import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.core.command.prompter.FileHandlingOption;
+
+/**
+ * <p>
+ * PolicyRegistryFactory.
+ * 
+ * {@link Factory} to provide {@link PolicyRegistry}
+ * 
+ * </p>
+ * 
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+PolicyRegistryFactory
+implements Factory<PolicyRegistry>
+{
+    /**
+     * Logger for this instance
+     */
+    protected final Logger logger =
+        LoggerFactory.getLogger( PolicyRegistryFactory.class );
+    
+    /**
+     * <p>
+     * CLIPolicy.
+     * 
+     * {@link Policy} when command line interface
+     * </p>
+     * 
+     * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+     * 
+     * @see PolicyRegistry, {@link Policy}
+     */
+    class CLIPolicy 
+    extends AbstractPolicy
+    {
+        /**
+         * <p>
+         * Constructor with <code>name</code>
+         * </p>
+         * 
+         * @param name policy name
+         */
+        public CLIPolicy( final String name )
+        {
+            super( name );
+        }
+
+        /* (non-Javadoc)
+         * @see org.tizen.common.Adaptable#adapt(java.lang.Class)
+         */
+        @Override
+        @SuppressWarnings("unchecked")
+        public <T>
+        T
+        adapt(
+            final Class<T> clazz
+        )
+        {
+            if ( clazz.isAssignableFrom( FilePolicy.class ) )
+            {
+                return (T) FilePolicy.STOP_PROCESS;
+            }
+            else if ( clazz.isAssignableFrom( MessagePolicy.class) )
+            {
+                return (T) MessagePolicy.PROMPTER;
+            }
+            return null;
+        }
+
+    }
+    /* (non-Javadoc)
+     * @see org.tizen.common.Factory#create()
+     */
+    @Override
+    public
+    PolicyRegistry
+    create()
+    {
+        final PolicyRegistry registry = new PolicyRegistry();
+        
+        registry.register( new CLIPolicy( EXIST_OUT_FILE ) );
+        registry.register( new CLIPolicy( NONEXIST_IN_FILE ) );
+        
+        CLIPolicy existFileWhenCopy = new CLIPolicy(Policy.EXIST_FILE_WHEN_COPY) {
+            
+            @SuppressWarnings("unchecked")
+            @Override
+            public <T> T adapt(Class<T> clazz) {
+                return (T)(new OptionPolicy(FileHandlingOption.OVERWRITE, FileHandlingOption.IGNORE, FileHandlingOption.OVERWRITE_ALL, FileHandlingOption.IGNORE_ALL, FileHandlingOption.CANCEL));
+            }
+        };
+        
+        registry.register(existFileWhenCopy);
+        return registry;
+    }
+
+}
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/TemplateModelProvider.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/TemplateModelProvider.java
new file mode 100644 (file)
index 0000000..9140fba
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Command line interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil Kang <shingil.kang@samsung.com> 
+ * Hyeongseok Heo <hyeongseok.heo@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.ncli.ide.util;
+
+import static org.tizen.common.util.ObjectUtil.nvl;
+import static org.tizen.common.util.StringUtil.nvl;
+
+import java.util.Collection;
+
+import org.tizen.common.config.Preference;
+import org.tizen.common.core.command.ExecutionContext;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.prompter.GenericOption;
+import org.tizen.common.verrari.IModelProvider;
+import org.tizen.common.verrari.template.CommonTemplate;
+
+public class
+TemplateModelProvider
+implements IModelProvider
+{
+    protected static final Object NULL = new Object();
+    
+    protected final ExecutionContext context;
+    
+    
+    public
+    TemplateModelProvider(
+        final ExecutionContext context
+    )
+    {
+        this.context = context;
+    }
+
+    @Override
+    public boolean isEmpty()
+    {
+        return false;
+    }
+
+    @Override
+    public Collection<String> keys()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public
+    Object
+    getModel(
+        final String key
+    )
+    {
+        Object obj = context.getValue( key );
+        if ( NULL.equals( obj ) )
+        {
+            return null;
+        } else if ( null != obj )
+        {
+            return obj;
+        }
+        
+        obj = Preference.getValue( key, null );
+        if ( null != obj )
+        {
+            return obj;
+        }
+        
+        obj = inputFromUser( key );
+        
+        this.context.setValue( key, nvl( obj, NULL ) );
+        
+        return obj;
+    }
+
+    protected Object inputFromUser( final String key )
+    {
+        final Prompter prompter = this.context.getPrompter();
+        final GenericOption opt = new GenericOption();
+
+        CommonTemplate current = CommonTemplate.getCurrentTemplate();
+        String message = "Input " + key + " ?";
+        if ( null != current )
+        {
+            message = nvl( current.getMessage( key ), message );
+        }
+        prompter.interact( message, opt );
+        
+        return opt.getAnswer();
+    }
+
+}