CLI : Fixed a bug where error occurs when loading built-in templates. 74/12074/1
authorshingil.kang <shingil.kang@samsung.com>
Tue, 12 Nov 2013 12:43:01 +0000 (21:43 +0900)
committershingil.kang <shingil.kang@samsung.com>
Tue, 12 Nov 2013 12:43:01 +0000 (21:43 +0900)
fixed the error related with index when reloading built-in templates.

Change-Id: Id69960d9b253898b1885d4d5a797e415038e7a27
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
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 be096d4..c77563e 100644 (file)
@@ -25,6 +25,8 @@
  */
 package org.tizen.ncli.ide.shell;
 
+import java.io.File;
+
 import org.kohsuke.args4j.Option;
 import org.kohsuke.args4j.spi.StringOptionHandler;
 import org.slf4j.Logger;
@@ -45,7 +47,7 @@ public class CreateProjectCLI extends AbstractCLI
     @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")
+    @Option(name = "-out", aliases = {"--output"}handler=StringOptionHandler.class, usage = "Specify output directory name")
     public String outputName;
     
     /*
index 9474ef1..0c1f1c6 100644 (file)
@@ -58,7 +58,7 @@ public class CreateProjectCommandData
 
     private TizenAppType appType;
     private String projectName;
-    private String outputName = System.getProperty("user.dir") + File.separator;
+    private String outputName = System.getProperty("user.dir");
 
     private static TizenAppTemplate tizenAppTemplate;
 
index c0f1392..642a722 100644 (file)
@@ -501,8 +501,6 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
         for (OptionGroup innerOptionGroup : optionGroup.getOptionGroup())
         {
             String addedKey = key + optionGroupSeparator + innerOptionGroup.getKey(); // key
-                                                                                      // ex)
-                                                                                      // group1_group2
             buildModelForOptionGroup(innerOptionGroup, addedKey);
         }
     }
@@ -789,51 +787,62 @@ class ProjectGenUtil
     {
         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;
+        String templateLibPath = urlPath + 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())
+        // if the url is not expressed jar file
+        if(urlPath.contains("!"))
+        {
+            String jarPath = urlPath.replaceAll("file:", "").substring(0, urlPath.lastIndexOf(WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER) - 7);
+            
+            System.out.println("jar path = "  + jarPath);
+           
+            String destDirPath = jarPath + "_dir";
+            
+            // make it if the destination directory is not created. 
+            File destDirFile = new File(destDirPath);
+            if (destDirFile.isDirectory())
             {
-                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());
+                return templateLibPath;
+            }
+            else
+            {
+                destDirFile.mkdir();
+            }
+            
+            templateLibPath = destDirPath + File.separator + WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER + File.separator;
+            
+            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();
                 }
-                fos.close();
-                is.close();
+            } catch (FileNotFoundException e)
+            {
+                logger.error(e.getMessage());
+            } catch (IOException e)
+            {
+                logger.error(e.getMessage());
             }
-        } catch (FileNotFoundException e)
-        {
-            logger.error(e.getMessage());
-        } catch (IOException e)
-        {
-            logger.error(e.getMessage());
         }
+      
         return templateLibPath;
     }
 }