CLI : support for auto completion of template name and add utility for creating web... 39/12039/1
authorshingil.kang <shingil.kang@samsung.com>
Tue, 12 Nov 2013 01:47:16 +0000 (10:47 +0900)
committershingil.kang <shingil.kang@samsung.com>
Tue, 12 Nov 2013 01:47:16 +0000 (10:47 +0900)
support for built-in template libraries
add the option for output directory on which the project is created and the processing logic of project configuration.

Change-Id: I63c89ed76c95c2d88170b29bcde6950738d7b8b5
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProjectCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProjectCommandData.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateWebProjectCommand.java

index e13fb34..228e9ba 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 
 import org.tizen.nativecommon.build.SmartBuildInterface;
 import org.tizen.nativecommon.build.exception.SBIException;
+import org.tizen.ncli.ide.subcommands.CreateProjectCommandData;
 
 public class TizenAutoComplete {
 
@@ -60,7 +61,7 @@ public class TizenAutoComplete {
     };
 
     public enum casesForInputSuggestion {
-        platform("--platform"), toolchain("--toolchain"), buildtarget("--build-target");
+        platform("--platform"), toolchain("--toolchain"), buildtarget("--build-target"), name("-n");
         
         private String option;
 
@@ -260,6 +261,10 @@ public class TizenAutoComplete {
         case buildtarget:
             listResult = sbi.getTargetList();
             break;
+        case name:
+            listResult = CreateProjectCommandData.getTemplateList();
+            break;
+        
         }
         for (String result : listResult) {
             suggestion = suggestion + " " + result;
index 595285c..be096d4 100644 (file)
@@ -26,6 +26,7 @@
 package org.tizen.ncli.ide.shell;
 
 import org.kohsuke.args4j.Option;
+import org.kohsuke.args4j.spi.StringOptionHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 //import org.tizen.ncli.ide.subcommands.CreateNativeProjectCommand;
@@ -38,12 +39,15 @@ public class CreateProjectCLI extends AbstractCLI
 {
     private Logger logger = LoggerFactory.getLogger(getClass());
 
-    @Option(name = "-t", aliases = { "--type" })
+    @Option(name = "-t", aliases = { "--type" }, required = true, usage = "Specify template type")
     private TizenAppType appType;
 
-    @Option(name = "-n", aliases = "--name", required = true)
+    @Option(name = "-n", aliases = "--name", required = true, usage = "Specify template name")
     private String projectName;
     
+    @Option(name = "-out", aliases = {"--output"} ,handler=StringOptionHandler.class, usage = "Specify output directory name")
+    public String outputName;
+    
     /*
      * (non-Javadoc)
      * 
@@ -65,6 +69,8 @@ public class CreateProjectCLI extends AbstractCLI
             CreateWebProjectCommand webCommand = new CreateWebProjectCommand();
             webCommand.setAppType(appType);
             webCommand.setProjectName(projectName);
+            if(outputName != null)
+                webCommand.setOutputName(outputName);
             webCommand.runCommand();
             break;
         default:
index 2a379f2..9474ef1 100644 (file)
@@ -27,12 +27,19 @@ package org.tizen.ncli.ide.subcommands;
 
 import static org.tizen.web.common.WebConstant.WIDGET_CONFIGURATION_FILE;
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import org.tizen.common.AppIdGenerator;
 import org.tizen.common.core.application.InstallPathConfig;
+import org.tizen.common.util.FileUtil;
 import org.tizen.ncli.ide.shell.TizenAppType;
+import org.tizen.web.model.TizenAppTemplate;
+import org.tizen.web.model.TizenModelFactory;
 
 /**
  * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
@@ -51,31 +58,53 @@ public class CreateProjectCommandData
 
     private TizenAppType appType;
     private String projectName;
-    private String targetAbsoultePath = System.getProperty("user.dir") + File.separator + "te";
+    private String outputName = System.getProperty("user.dir") + File.separator;
+
+    private static TizenAppTemplate tizenAppTemplate;
 
     private String APPID = AppIdGenerator.getInstance().create();
 
-    static
+    public static List<String> getTemplateList()
+    {
+        File root = new File(PLATFORM_PATH + File.separator + WEB_PROJECT_PATH);
+
+        List<File> fileArray = new ArrayList<File>();
+        List<String> fileNameArray = new ArrayList<String>();
+
+        try
+        {
+            fileArray = FileUtil.findFiles(root, TIZEN_WEB_APP_TEMPLATE_FILE, true);
+
+            for (File f : fileArray)
+            {
+                tizenAppTemplate = TizenModelFactory.unmarshalAppTemplate(f);
+                String templateName = tizenAppTemplate.getTemplateId();
+                fileNameArray.add(templateName);
+                webProjects.put(templateName, f.getParentFile().getAbsolutePath());
+            }
+
+        } catch (FileNotFoundException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        return fileNameArray;
+    }
+
+    public void setOutputName(String outputName)
     {
-        webProjects.put("tizen-basic", "Basic" + File.separator + "Tizen_Blank");
-        webProjects.put("tizenwebuifw-masterdetail", "Tizen Web UI Framework + File.separator + Tizen_Web_UI_FW_MasterDetail ");
-        webProjects.put("tizenwebuifw-multipage", "Tizen Web UI Framework + File.separator + Tizen_Web_UI_FW_MultiPage");
-        webProjects.put("tizenwebuifw-navigation", "Tizen Web UI Framework + File.separator +  Tizen_Web_UI_FW_NavigationView");
-        webProjects.put("tizenwebuifw-singlepage", "Tizen Web UI Framework" + File.separator + "Tizen_Web_UI_FW_SinglePage");
-        webProjects.put("jqm-masterdetail", "jQuery Mobile" + File.separator + "MasterDetail");
-        webProjects.put("jqm-multipage", "jQuery Mobile" + File.separator + "MultiPage");
-        webProjects.put("jqm-navigatio", "jQuery Mobile" + File.separator + "NavigationView");
-        webProjects.put("jqm-singlepage", "jQuery Mobile" + File.separator + "SinglePage");
+        this.outputName = this.outputName + File.separator + outputName + File.separator;
     }
 
-    public String getTargetAbsoultePath()
+    public String getOutputName()
     {
-        return targetAbsoultePath;
+        return outputName;
     }
 
     public void setTargetAbsoultePath(File targetAbsoultePath)
     {
-        this.targetAbsoultePath = targetAbsoultePath.getAbsolutePath();
+        this.outputName = targetAbsoultePath.getAbsolutePath();
     }
 
     public void setAppType(TizenAppType appType)
@@ -111,9 +140,7 @@ public class CreateProjectCommandData
     // get web template root path
     public String getTizenWebTemplateRootPath(String id)
     {
-        String TemplatePath = PLATFORM_PATH + File.separator + WEB_PROJECT_PATH + File.separator + webProjects.get(id);
-
-        return TemplatePath;
+        return webProjects.get(id);
     }
 
     // get web project root path
@@ -143,12 +170,13 @@ public class CreateProjectCommandData
     // get web project configuration destination path
     public String getDestTizenWebProjectConfigFile(String id)
     {
-        return targetAbsoultePath + File.separator + WIDGET_CONFIGURATION_FILE;
+        return outputName + File.separator + WIDGET_CONFIGURATION_FILE;
     }
 
-    // get web project configuration file
-    public String getTizenWebConfigTemplatePath()
-    {
-        return PLATFORM_PATH + File.separator + WEB_PROJECT_PATH + File.separator + TIZEN_PROJECT_CONFIG_PATH;
-    }
+    // // get web project configuration file
+    // public String getTizenWebConfigTemplatePath()
+    // {
+    // return PLATFORM_PATH + File.separator + WEB_PROJECT_PATH + File.separator
+    // + TIZEN_PROJECT_CONFIG_PATH;
+    // }
 }
\ No newline at end of file
index 8aa096a..c0f1392 100644 (file)
@@ -31,19 +31,28 @@ import static org.tizen.web.common.WebConstant.WIDGET_BASE_IDENTIFIER;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStreamWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Scanner;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 
 import org.kohsuke.args4j.Option;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.tizen.common.Factory;
 import org.tizen.common.core.application.InstallPathConfig;
 import org.tizen.common.core.application.ProfileInfo;
@@ -95,38 +104,47 @@ import freemarker.template.Configuration;
 public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCommandData>
 {
     private CreateProjectCommandData data = new CreateProjectCommandData();
-    
+
     // Freemarker variables
     private Map<String, Object> root = new HashMap<String, Object>();
     private Configuration cfg;
-    
+
     private static String temporaryFileAdditionalName = ".template"; //$NON-NLS-1$
     private static String optionGroupSeparator = "_"; //$NON-NLS-1$
-    
+
     TizenAppTemplate tizenAppTemplate;
-    
+
+    private ProjectGenUtil pg = new ProjectGenUtil();
+
     private TizenTemplateLibrariesPool libraryPool;
-        
-    /* 1. copy web project template
-     * 2. copy the dependent library
-     * 3. copy configuration
-     * 4. generate HTML and XML file from template
+
+    /*
+     * create web project from template.
+     * 
+     * 1. get template list
+     * 2. copy web project template
+     * 3. copy the dependent library
+     * 4. copy configuration
+     * 5. generate HTML and XML file from template
      */
     @Override
     protected CreateProjectCommandData call()
     {
-        //1. copy web project template
+        // 1. get template list
+        data.getTemplateList();
+
+        // 2. copy web project template
         copyWebProjectTemplate();
-        
-        //2. copy the dependent library
+
+        // 3. copy the dependent library
         copyLibrary();
-        
-        //3. generate configuration
+
+        // 4. generate configuration
         copyConfiguration();
-        
-        //4. generate file from template
+
+        // 5. generate file from template
         processOption();
-        
+
         return data;
     }
 
@@ -139,31 +157,38 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
     {
         this.data.setProjectName(projectName);
     }
-    
-    private void copyWebProjectTemplate(){
+
+    public void setOutputName(String projectName)
+    {
+        this.data.setOutputName(projectName);
+    }
+
+    private void copyWebProjectTemplate()
+    {
         String projectName = data.getProjectName();
         String projectPath = data.getTizenWebProjectRootPath(projectName);
-        String destDir = data.getTargetAbsoultePath();
-        
+        String destDir = data.getOutputName();
+
         // filter file (.project)
-        File[] resourceFilter = { new File( ".project" ) };
-        
+        File[] resourceFilter = { new File(".project") };
+
         // copy template resources
         try
         {
-            FileUtil.copyRecursively( projectPath, destDir, true, resourceFilter );
+            FileUtil.copyRecursively(projectPath, destDir, true, resourceFilter);
         } catch (IOException e)
         {
             // TODO Auto-generated catch block
             log.error(e.getMessage());
         }
     }
-    
-    private void copyLibrary(){
-        
+
+    private void copyLibrary()
+    {
+
         String projectName = data.getProjectName();
-        String configFile = data.getTizenWebTemplateConfigFile(projectName); 
-       
+        String configFile = data.getTizenWebTemplateConfigFile(projectName);
+
         try
         {
             // unmarshal app template.
@@ -173,124 +198,146 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
             // TODO Auto-generated catch block
             log.error(e2.getMessage());
         }
-        
+
         // get options
         Options options = tizenAppTemplate.getOptions();
 
         // get support libraries
         SupportLibraries sl = options.getSupportLibraries();
-        
+
         // get profile info
         ProfileInfo profileInfo = InstallPathConfig.getLatestProfileInfo();
+
+        // extract jar file contained built-in library
+        String rootPath = pg.extractBuiltinJarFiles();
         
         // get library pool
-        libraryPool  = new TizenTemplateLibrariesPool(profileInfo);
-        
+        libraryPool = new TizenTemplateLibrariesPool(profileInfo, rootPath);
+
         // get template library groups
-        if (libraryPool != null) { // In case of sample, pool is null
+        if (libraryPool != null)
+        { // In case of sample, pool is null
             List<TizenTemplateLibraryGroup> groupList = libraryPool.getLibraryGroupWithDepends(sl);
-            
+
             // copy libraries
-            for (TizenTemplateLibraryGroup group : groupList) {
+            for (TizenTemplateLibraryGroup group : groupList)
+            {
                 /*
-                if ( isSampleGroup( template ) ) {
-                    group.setSelectedMinifiedWithDependsUpdate( true );
-                }
-                */
-                if ( group.getSelectedElement().getKindsOfLibrary() == TizenTemplateKindsOfLibraries.TIZENWEBUIFW ) {
-                    copyTizenWebUIFWLibrary( group );
+                 * if ( isSampleGroup( template ) ) {
+                 * group.setSelectedMinifiedWithDependsUpdate( true ); }
+                 */
+                if (group.getSelectedElement().getKindsOfLibrary() == TizenTemplateKindsOfLibraries.TIZENWEBUIFW)
+                {
+                    copyTizenWebUIFWLibrary(group);
                 }
-                else {
-                    copyNormalLibrary( group);
+                else
+                {
+                    copyNormalLibrary(group);
                 }
             }
         }
     }
-    
+
     private void copyTizenWebUIFWLibrary(TizenTemplateLibraryGroup group)
     {
         String libraryPath = group.getSelectedLibraryPath();
-        if (libraryPath == null) {
-            return ;
+        if (libraryPath == null)
+        {
+            return;
         }
 
         // cannot find library directory (source)
         File source = new File(libraryPath);
-        if ( !source.exists() ) {
-            String errorMsg = "Cannot find template library resource : " + libraryPath; // TODO : externalize
+        if (!source.exists())
+        {
+            String errorMsg = "Cannot find template library resource : " + libraryPath; // TODO
+                                                                                        // :
+                                                                                        // externalize
         }
 
         // create target directory
         TizenWebUIFWType type = null;
         String elementKey = group.getSelectedElementKey();
-        try {
-            type = TizenWebUIFWType.valueOf( elementKey );
-        } catch (IllegalArgumentException e) {
+        try
+        {
+            type = TizenWebUIFWType.valueOf(elementKey);
+        } catch (IllegalArgumentException e)
+        {
             return;
         }
 
         URI destinationURI = null;
-        switch ( type ) {
+        switch (type) {
         case TizenWebUIFramework_Theme:
         case TizenWebUIFramework_Theme_Images:
-            String themePaths[] = libraryPath.split( "Theme/" );
-            // destinationURI = URI.create(project.getLocationURI() + type.getDestinationPath() + themePaths[1]);
+            String themePaths[] = libraryPath.split("Theme/");
+            // destinationURI = URI.create(project.getLocationURI() +
+            // type.getDestinationPath() + themePaths[1]);
             break;
         default:
-            // destinationURI = URI.create(project.getLocationURI() + type.getDestinationPath());
+            // destinationURI = URI.create(project.getLocationURI() +
+            // type.getDestinationPath());
             break;
         }
 
         // decide target directory
-        if ( type != TizenWebUIFWType.TizenWebUIFramework_Theme ) {
-            destinationURI = URI.create( destinationURI + group.getSelectedElementValue() );
+        if (type != TizenWebUIFWType.TizenWebUIFramework_Theme)
+        {
+            destinationURI = URI.create(destinationURI + group.getSelectedElementValue());
         }
 
         // copy must pre-create directory
-        if ( source.isDirectory() ) {
-            if ( !FileUtil.isExist( destinationURI.getPath() ) ) {
-                FileUtil.createDirectory( new File(destinationURI) );
+        if (source.isDirectory())
+        {
+            if (!FileUtil.isExist(destinationURI.getPath()))
+            {
+                FileUtil.createDirectory(new File(destinationURI));
             }
-        } else {
+        }
+        else
+        {
             File parentFile = new File(destinationURI).getParentFile();
-            if ( !FileUtil.isExist( parentFile.getPath() ) ) {
-                FileUtil.createDirectory( parentFile );
+            if (!FileUtil.isExist(parentFile.getPath()))
+            {
+                FileUtil.createDirectory(parentFile);
             }
         }
         // copyLibrary(source.toURI(), destinationURI);
     }
-    
-    private void copyNormalLibrary(TizenTemplateLibraryGroup group) 
+
+    private void copyNormalLibrary(TizenTemplateLibraryGroup group)
     {
         String libraryPath = group.getSelectedLibraryPath();
-        if (libraryPath == null) {
+        if (libraryPath == null)
+        {
             return;
         }
 
         // cannot find library directory (source)
         File source = new File(libraryPath);
-        if (!source.exists() || !source.isDirectory()) {
-            String errorMsg = "Cannot find template library resource directory : " + libraryPath; 
+        if (!source.exists() || !source.isDirectory())
+        {
+            String errorMsg = "Cannot find template library resource directory : " + libraryPath;
         }
-        
+
         // decide target directory
         TizenTemplateKindsOfLibraries kindOfLibrary = group.getSelectedElement().getKindsOfLibrary();
-        
+
         String destDir;
-        
+
         switch (kindOfLibrary) {
-        case JAVASCRIPT :
-            destDir = data.getTargetAbsoultePath() + "js"; 
+        case JAVASCRIPT:
+            destDir = data.getOutputName() + "js";
             break;
-        case CSS :
-            destDir = data.getTargetAbsoultePath() + "css"; 
+        case CSS:
+            destDir = data.getOutputName() + "css";
             break;
-        case OTHERS : // copy to root folder basically
-        default :
-            destDir = data.getTargetAbsoultePath();
+        case OTHERS: // copy to root folder basically
+        default:
+            destDir = data.getOutputName();
             break;
         }
-        
+
         try
         {
             FileUtil.copyRecursively(libraryPath, destDir, true);
@@ -301,24 +348,25 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
         }
 
     }
-    
-    private void processOption(){
-        
+
+    private void processOption()
+    {
+
         // set default FreeMarker configuration
         cfg = FreeMarkerUtil.getDefaultConfiguration();
 
-        if(tizenAppTemplate == null)
+        if (tizenAppTemplate == null)
             return;
-        
+
         // get options
         Options options = tizenAppTemplate.getOptions();
-        if(options == null)
+        if (options == null)
             return;
-        
-        // get path of template 
-        String projectDestDir = data.getTargetAbsoultePath();
+
+        // get path of template
+        String projectDestDir = data.getOutputName();
         File projectDir = new File(projectDestDir);
-        
+
         // get path which template is loaded on
         try
         {
@@ -328,126 +376,154 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
             // TODO Auto-generated catch block
             log.error(e.getMessage());
         }
-        
+
         // building support library model
         SupportLibraries supportLibraries = options.getSupportLibraries();
-        if (supportLibraries != null) {
+        if (supportLibraries != null)
+        {
             buildModelForSupportLibraries(supportLibraries);
         }
-        
+
         // building option model
-        for (OptionGroup optionGroup : options.getOptionGroup()) {
-            buildModelForOptionGroup(optionGroup, optionGroup.getKey()); // key ex) group1
+        for (OptionGroup optionGroup : options.getOptionGroup())
+        {
+            buildModelForOptionGroup(optionGroup, optionGroup.getKey()); // key
+                                                                         // ex)
+                                                                         // group1
         }
-        
+
         // building config model
         buildModelForConfigFile();
-        
+
         // generate files in project
         generateFilefromProjectRoot(projectDir);
     }
 
-    private void generateFilefromProjectRoot(File projectRootFile){
-        if (projectRootFile.isDirectory()) {   
-            if (projectRootFile.listFiles().length != 0) { 
+    private void generateFilefromProjectRoot(File projectRootFile)
+    {
+        if (projectRootFile.isDirectory())
+        {
+            if (projectRootFile.listFiles().length != 0)
+            {
                 File[] fileList = projectRootFile.listFiles();
-                for (File file : fileList) {
-                    if(file.isDirectory())
+                for (File file : fileList)
+                {
+                    if (file.isDirectory())
                         generateFilefromProjectRoot(file);
-                    
-                    else if(isAvailableTemplate(file.getName())){
+
+                    else if (isAvailableTemplate(file.getName()))
+                    {
                         generateFileFromTemplate(file);
                     }
                 }
             }
         }
     }
-    
-    private boolean isAvailableTemplate(String fileName) {
-        String[] availableExtension = {".html"};
-        String[] availableList = {"app.xml", "config.xml"};
-        
-        for (String res : availableExtension) {
-            if (fileName.indexOf(res) != -1) {
+
+    private boolean isAvailableTemplate(String fileName)
+    {
+        String[] availableExtension = { ".html" };
+        String[] availableList = { "app.xml", "config.xml" };
+
+        for (String res : availableExtension)
+        {
+            if (fileName.indexOf(res) != -1)
+            {
                 return true;
             }
         }
-        
-        for (String res : availableList) {
-            if (fileName.indexOf(res) != -1) {
+
+        for (String res : availableList)
+        {
+            if (fileName.indexOf(res) != -1)
+            {
                 return true;
             }
         }
-        
+
         return false;
     }
-    
-    private void buildModelForSupportLibraries(SupportLibraries supportLibraries) {
-        if (libraryPool != null) { // In case of sample, pool is null
-            
+
+    private void buildModelForSupportLibraries(SupportLibraries supportLibraries)
+    {
+        if (libraryPool != null)
+        { // In case of sample, pool is null
+
             // get template library groups
             List<TizenTemplateLibraryGroup> groupList = libraryPool.getLibraryGroupWithDepends(supportLibraries);
-            
-            for (TizenTemplateLibraryGroup group : groupList) {
+
+            for (TizenTemplateLibraryGroup group : groupList)
+            {
                 // get key
                 String key = group.getKey();
-                
+
                 // get value
                 LibraryElement selectedElement = group.getSelectedElement();
-                String value = group.isSelectedMinified() ?
-                        selectedElement.getMinifiedValue() : selectedElement.getOriginalValue();
-                        
+                String value = group.isSelectedMinified() ? selectedElement.getMinifiedValue() : selectedElement.getOriginalValue();
+
                 // put key and value
-                if (value != null) {
+                if (value != null)
+                {
                     root.put(key, value);
                 }
             }
         }
     }
-    
-    private void buildModelForOptionGroup(OptionGroup optionGroup, String key) {
-        for (OptionElement optionElement : optionGroup.getOptionElement()) {
+
+    private void buildModelForOptionGroup(OptionGroup optionGroup, String key)
+    {
+        for (OptionElement optionElement : optionGroup.getOptionElement())
+        {
             boolean isDefault = (optionElement.isDefaultElement() != null) ? optionElement.isDefaultElement() : false;
-            String addedKey = key + optionGroupSeparator + optionElement.getKey(); // key ex) group1_element
+            String addedKey = key + optionGroupSeparator + optionElement.getKey(); // key
+                                                                                   // ex)
+                                                                                   // group1_element
             String value = optionElement.getValue();
-            
-            switch(optionGroup.getOptionType()) {
-            case MANDATORY :
+
+            switch (optionGroup.getOptionType()) {
+            case MANDATORY:
                 root.put(addedKey, value);
                 break;
-            case MULTI_SELECTION :
+            case MULTI_SELECTION:
                 root.put(addedKey, isDefault ? value : "");
                 break;
-            case SINGLE_SELECTION :
-                if (isDefault) {
+            case SINGLE_SELECTION:
+                if (isDefault)
+                {
                     root.put(key, value);
                 }
                 break;
-            default :
+            default:
             }
         }
-        
+
         // process inner group
-        for (OptionGroup innerOptionGroup : optionGroup.getOptionGroup()) {
-            String addedKey = key + optionGroupSeparator + innerOptionGroup.getKey(); // key ex) group1_group2
+        for (OptionGroup innerOptionGroup : optionGroup.getOptionGroup())
+        {
+            String addedKey = key + optionGroupSeparator + innerOptionGroup.getKey(); // key
+                                                                                      // ex)
+                                                                                      // group1_group2
             buildModelForOptionGroup(innerOptionGroup, addedKey);
         }
     }
-    
-    private void buildModelForConfigFile(){
+
+    private void buildModelForConfigFile()
+    {
         root.put("APP_ID", data.getAppID());
         root.put("WIDGET_ID", data.getProjectName());
     }
-    
-    private void generateFileFromTemplate(File srcFile){
-        
+
+    private void generateFileFromTemplate(File srcFile)
+    {
+
         // rename source file to template file
         String originalFilePath = srcFile.getAbsolutePath();
         String templateFilePath = originalFilePath + temporaryFileAdditionalName;
         File templateFile = new File(templateFilePath);
         srcFile.renameTo(templateFile);
-        
-        try {
+
+        try
+        {
             // generate file from template file
             FreeMarkerUtil.generateDocument(root, cfg, templateFile.getName(), originalFilePath);
         } catch (IOException e)
@@ -456,98 +532,99 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
         } catch (freemarker.template.TemplateException e)
         {
             log.error("Fail to generate HTML files.", e.getMessage());
-        } finally {
+        } finally
+        {
             templateFile.delete();
         }
     }
-    
-    private void copyConfiguration(){
-        String srcConfigurationFilePath = data.getTizenWebConfigTemplatePath();
-        String destConfigurationFilePath = data.getDestTizenWebProjectConfigFile(data.getProjectName());
-        
-        try
-        {
-            FileUtil.copyTo(srcConfigurationFilePath, destConfigurationFilePath);
-        } catch (IOException e)
-        {
-            // TODO Auto-generated catch block
-            log.error(e.getMessage());
-        }
+
+    private void copyConfiguration()
+    {
+        pg.copyConfigFile(data.getDestTizenWebProjectConfigFile(data.getProjectName()));
     }
-    
-    private void generateConfiguration(){
-        
-        //getConfiguration();
-        //initializeConfiguration();
+
+    private void generateConfiguration()
+    {
+
+        // getConfiguration();
+        // initializeConfiguration();
     }
-    
+
     /**
      * find widget configuration file in a project
      * 
      * @return the configuration file. null if no such file exists.
      */
-    private File findConfiguration() {
+    private File findConfiguration()
+    {
         // get configuration file
         String configurationFilePath = data.getTizenWebProjectConfigFile(data.getProjectName());
         File configurationFile = new File(configurationFilePath);
-        
+
         // check if configuration file exists
-        if(configurationFile.isFile())
+        if (configurationFile.isFile())
             return configurationFile;
         else
             return null;
     }
-    
+
     /**
      * get widget configuration file in a project
      * 
-     * @return the configuration file. default configuration file if no such file exists.
+     * @return the configuration file. default configuration file if no such
+     *         file exists.
      */
-    private File getConfiguration() throws URISyntaxException, IOException {
-        
+    private File getConfiguration() throws URISyntaxException, IOException
+    {
+
         File configurationFile = findConfiguration();
-        
+
         // get default configuration file
-        if ( configurationFile == null) {
-              // get URI
-//            URI sourceURI = getRealEntry( DEFAULT_CONFIG_DIR_IN_PLUGIN );
-//            URI destinationURI = project.getLocationURI();
+        if (configurationFile == null)
+        {
+            // get URI
+            // URI sourceURI = getRealEntry( DEFAULT_CONFIG_DIR_IN_PLUGIN );
+            // URI destinationURI = project.getLocationURI();
 
-              // copy a default configuration to the project
-//            EFSUtil.copy( sourceURI, destinationURI, EFS.OVERWRITE, createSubMonitor( monitor, tick ) );
+            // copy a default configuration to the project
+            // EFSUtil.copy( sourceURI, destinationURI, EFS.OVERWRITE,
+            // createSubMonitor( monitor, tick ) );
 
-//            configurationFile = findConfiguration();        
+            // configurationFile = findConfiguration();
         }
         return configurationFile;
     }
-    
+
     /**
      * initialize Widget configuration with app ID generation.
      * 
-     * @param monitor {@link IProgressMonitor}. if this is null, {@link NullProgressMonitor} is used.
+     * @param monitor
+     *            {@link IProgressMonitor}. if this is null,
+     *            {@link NullProgressMonitor} is used.
      * @throws ConfigurationException
      * @throws IOException
      */
-    private void initializeConfiguration(){
-        
+    private void initializeConfiguration()
+    {
+
         String projectName = data.getProjectName();
-        //String widgetId = getWidgetURI() + projectName;
-        
+        // String widgetId = getWidgetURI() + projectName;
+
         // get widget id
         String widgetId = WIDGET_BASE_IDENTIFIER + projectName;
-        
+
         File configurationFile = new File(data.getDestTizenWebProjectConfigFile(projectName));
-        
+
         // get configuration manager
         ITizenConfigurator configurator = unmarshalWidgetConfiguration(configurationFile);
-        
+
         // set default configuration
-        configurator.setId( widgetId );
-        configurator.setName( projectName, null );
-        
+        configurator.setId(widgetId);
+        configurator.setName(projectName, null);
+
         // Setting appid of configuration for new project
-        configurator.setApplication( projectName, null, 0 );
-        
+        configurator.setApplication(projectName, null, 0);
+
         // save
         try
         {
@@ -562,61 +639,201 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
             log.error(e.getMessage());
         }
     }
-    
-    private ITizenConfigurator unmarshalWidgetConfiguration(File configurationFile){
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
+
+    private ITizenConfigurator unmarshalWidgetConfiguration(File configurationFile)
+    {
+
         ITizenConfigurator config = null;
         InputStream input = null;
-        
-        try {
+
+        try
+        {
             JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
             Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-            
+
             input = new FileInputStream(configurationFile);
-                        
-            Object configModel = unmarshaller.unmarshal( input );
-//
+
+            Object configModel = unmarshaller.unmarshal(input);
+            //
             // platform specific model class
-//            TizenProjectDescription tizenDesc = ProjectUtil.getTizenProjectDescription(project);
-//            if ( tizenDesc != null ) {
-//                String platformName = tizenDesc.getPlatformName();
-//                IConfigurationElement[] ces = PluginUtil.getExtensionConfigurationElements( WebConstant.EXTENTION_POINT_CONFIGURATION );
-//                for ( IConfigurationElement ce : ces ) {
-//                    if ( platformName.equalsIgnoreCase( ce.getAttribute( "platform" ) ) ) {
-//                        if ( ce.getAttribute( "class") != null ) {
-//                            config = (ITizenConfigurator) ce.createExecutableExtension( "class" );
-//                            config.init( project, (Widget) configModel );
-//                        }
-//                        break;
-//                    }
-//                }
-//            }
-            // if don't supported platform or class is not setting, then default model is TizenConfiguratorImpl
-            if ( config == null ) {
-//                config = new TizenConfiguratorImpl();
-//                config.init( project, (Widget) configModel );
+            // TizenProjectDescription tizenDesc =
+            // ProjectUtil.getTizenProjectDescription(project);
+            // if ( tizenDesc != null ) {
+            // String platformName = tizenDesc.getPlatformName();
+            // IConfigurationElement[] ces =
+            // PluginUtil.getExtensionConfigurationElements(
+            // WebConstant.EXTENTION_POINT_CONFIGURATION );
+            // for ( IConfigurationElement ce : ces ) {
+            // if ( platformName.equalsIgnoreCase( ce.getAttribute( "platform" )
+            // ) ) {
+            // if ( ce.getAttribute( "class") != null ) {
+            // config = (ITizenConfigurator) ce.createExecutableExtension(
+            // "class" );
+            // config.init( project, (Widget) configModel );
+            // }
+            // break;
+            // }
+            // }
+            // }
+            // if don't supported platform or class is not setting, then default
+            // model is TizenConfiguratorImpl
+            if (config == null)
+            {
+                // config = new TizenConfiguratorImpl();
+                // config.init( project, (Widget) configModel );
             }
 
-        } catch (JAXBException e) {
+        } catch (JAXBException e)
+        {
             log.error(e.getMessage());
         } catch (FileNotFoundException e)
         {
             log.error(e.getMessage());
-        } finally {
-            IOUtil.tryClose( input );
+        } finally
+        {
+            IOUtil.tryClose(input);
         }
         return config;
-        
+
     }
-    
+
     /**
-     * Widget URI getter for the ID of configuration 
+     * Widget URI getter for the ID of configuration
      * 
-     * @return Widget URI String in the preferences. If cannot get this, return default URI String.
-     * {@value org.tizen.web.common.WebConstant#WIDGET_BASE_IDENTIFIER}
+     * @return Widget URI String in the preferences. If cannot get this, return
+     *         default URI String.
+     *         {@value org.tizen.web.common.WebConstant#WIDGET_BASE_IDENTIFIER}
      */
-//    private String getWidgetURI() {
-//        String widgetURI = getPreferenceStore().getString( ATTR_WIDGET_URI );
-//        return widgetURI.isEmpty() ? WIDGET_BASE_IDENTIFIER : widgetURI;
-//    }
-}
\ No newline at end of file
+    // private String getWidgetURI() {
+    // String widgetURI = getPreferenceStore().getString( ATTR_WIDGET_URI );
+    // return widgetURI.isEmpty() ? WIDGET_BASE_IDENTIFIER : widgetURI;
+    // }
+}
+
+class ProjectGenUtil
+{
+    protected final Logger logger = LoggerFactory.getLogger( getClass() );
+    
+    private final String CONFIG_FILE = "/config/Tizen/config.xml";
+    private final String CONFIG_EXTRA_TIZEN_INFO = "    <tizen:application id=\"${APP_ID}.${WIDGET_ID}\" package=\"${APP_ID}\" required_version=\"2.2\"/>";
+    private final String CONFIG_EXTRA_NAME_INFO = "    <name>${WIDGET_ID}</name>";
+
+    public void copyConfigFile(String destConfigPath)
+    {
+        InputStream ips = null;
+        FileOutputStream fos = null;
+
+        try
+        {
+            ips = getClass().getResource(CONFIG_FILE).openStream();
+            fos = new FileOutputStream(destConfigPath);
+            FileUtil.redirectStream(ips, fos);
+        } catch (IOException e)
+        {
+            // logger.error(e.getMessage());
+
+        } finally
+        {
+            IOUtil.tryClose(ips, fos);
+        }
+
+        addExtraInfo2Config(destConfigPath);
+    }
+
+    public void addExtraInfo2Config(String destConfigPath)
+    {
+        OutputStreamWriter out = null;
+        Scanner scanner = null;
+
+        String newLine = System.getProperty("line.separator");
+
+        try
+        {
+            scanner = new Scanner(new FileInputStream(destConfigPath));
+            out = new OutputStreamWriter(new FileOutputStream(destConfigPath + ".output"));
+
+            String line;
+            while (scanner.hasNextLine())
+            {
+                line = scanner.nextLine();
+
+                out.write(line);
+                out.write(newLine);
+
+                if (line.startsWith("<widget"))
+                {
+                    out.write(CONFIG_EXTRA_TIZEN_INFO);
+                    out.write(newLine);
+                    out.write(CONFIG_EXTRA_NAME_INFO);
+                    out.write(newLine);
+                }
+            }
+
+            File destConfigFile = new File(destConfigPath);
+            File outputConfigFile = new File(destConfigPath + ".output");
+
+            destConfigFile.delete();
+            outputConfigFile.renameTo(destConfigFile);
+
+        } catch (IOException e)
+        {
+            logger.error(e.getMessage());
+        } finally
+        {
+            IOUtil.tryClose(scanner, out);
+        }
+
+    }
+
+    public String extractBuiltinJarFiles()
+    {
+        URL url = getClass().getClassLoader().getResource(WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER);
+        String urlPath = url.getPath();
+        String paths[] = urlPath.split("[:!]");
+        String jarPath = paths[1];
+        String destDirPath = jarPath + "_dir";
+        String templateLibPath = destDirPath + File.separator + WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER + File.separator;
+        
+        File destDirFile = new File(destDirPath);
+        if (destDirFile.isDirectory())
+        {
+            return templateLibPath;
+        }
+        else
+        {
+            destDirFile.mkdir();
+        }
+
+        try
+        {
+            JarFile jar = new JarFile(jarPath);
+            Enumeration enum2 = jar.entries();
+            while (enum2.hasMoreElements())
+            {
+                JarEntry file = (JarEntry) enum2.nextElement();
+                File f = new File(destDirPath + File.separator + file.getName());
+                if (file.isDirectory())
+                { // if its a directory, create it
+                    f.mkdir();
+                    continue;
+                }
+                InputStream is = jar.getInputStream(file); // get the input
+                                                           // stream
+                FileOutputStream fos = new FileOutputStream(f);
+                while (is.available() > 0)
+                { // write contents of 'is' to 'fos'
+                    fos.write(is.read());
+                }
+                fos.close();
+                is.close();
+            }
+        } catch (FileNotFoundException e)
+        {
+            logger.error(e.getMessage());
+        } catch (IOException e)
+        {
+            logger.error(e.getMessage());
+        }
+        return templateLibPath;
+    }
+}