CLI: add progress monitor to show the progress status of creating web/native project. 86/13686/3
authorshingil.kang <shingil.kang@samsung.com>
Thu, 12 Dec 2013 07:16:15 +0000 (16:16 +0900)
committershingil.kang <shingil.kang@samsung.com>
Thu, 12 Dec 2013 10:39:39 +0000 (19:39 +0900)
Change-Id: I522e90a05a3f0ff0fcab65f7f131d3dbbb86dcfd
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateNativeProjectCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateWebProjectCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateNativeProjectCommand.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateNativeProjectCommandData.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateWebProjectCommand.java

index 4c6f65b..9cdd27f 100644 (file)
@@ -1,16 +1,39 @@
+/*
+ * 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>
+ * 
+ * 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.shell;
 
 import java.io.File;
 import java.io.IOException;
 
 import org.kohsuke.args4j.Option;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-//import org.tizen.ncli.ide.subcommands.CreateNativeProjectCommand;
+import org.tizen.ncli.core.TizenSubCommand;
 import org.tizen.ncli.ide.messages.TizenCLIMessages;
 import org.tizen.ncli.ide.subcommands.CreateNativeProjectCommand;
 import org.tizen.ncli.ide.subcommands.CreateNativeProjectCommandData;
 
+@TizenSubCommand(name="native-project" , usage="Create the tizen native project")
 public class CreateNativeProjectCLI extends AbstractCLI
 {
     @Option(name = "-t", aliases = { "--type" }, usage = "Specify template name")
@@ -47,8 +70,7 @@ public class CreateNativeProjectCLI extends AbstractCLI
 
         CreateNativeProjectCommandData data = nativeCommand.runCommand();
         
-        progressLog.info("Project Location : {}",data.getOutputName());
-        progressLog.info("Creating native project succeeded!");
+        progressLog.info("Project Location: {}",data.getOutputName());
     }
 
 }
index e05b755..c861fa9 100644 (file)
@@ -29,6 +29,7 @@ import java.io.File;
 import java.io.IOException;
 
 import org.kohsuke.args4j.Option;
+import org.tizen.ncli.core.TizenSubCommand;
 import org.tizen.ncli.ide.messages.TizenCLIMessages;
 import org.tizen.ncli.ide.subcommands.CreateProjectCommandData;
 import org.tizen.ncli.ide.subcommands.CreateWebProjectCommand;
@@ -36,6 +37,7 @@ import org.tizen.ncli.ide.subcommands.CreateWebProjectCommand;
 /**
  * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
  */
+@TizenSubCommand(name="web-project" , usage="Create the tizen web project")
 public class CreateWebProjectCLI extends AbstractCLI
 {
     @Option(name = "-t", aliases = { "--type" }, usage = "Specify template name")
@@ -52,8 +54,6 @@ public class CreateWebProjectCLI extends AbstractCLI
     @Override
     public void execute()
     {
-        log.info("Template Name:{}", templateName);
-
         CreateWebProjectCommand webCommand = new CreateWebProjectCommand();
 
         // set template name
@@ -79,7 +79,6 @@ public class CreateWebProjectCLI extends AbstractCLI
 
         CreateProjectCommandData data = webCommand.runCommand();
         
-        progressLog.info("project Location : {}",data.getOutputName());
-        progressLog.info("Creating web project succeeded!");
+        progressLog.info("Project Location: {}",data.getOutputName());
     }
 }
index d6f4c41..df73a8c 100644 (file)
@@ -27,6 +27,7 @@ package org.tizen.ncli.ide.subcommands;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.net.URL;
 import java.text.MessageFormat;
 import java.util.HashMap;
@@ -34,6 +35,7 @@ import java.util.Map;
 
 import org.eclipse.cdt.core.templateengine.process.processes.Messages;
 import org.tizen.common.util.FileUtil;
+import org.tizen.core.ide.TextProgressMonitor;
 import org.tizen.nativeappcommon.wizards.TizenProjectWizard;
 import org.tizen.nativecommon.Activator;
 import org.tizen.nativecommon.exception.TizenProcessFailureException;
@@ -49,6 +51,8 @@ public class CreateNativeProjectCommand extends AbstractSubCommand<CreateNativeP
 {
     private CreateNativeProjectCommandData data = new CreateNativeProjectCommandData();
 
+    private static final String CREATE_NATIVE_PROJECT_TASK = "Create Native Project";
+
     public void setTemplateName(String projectName)
     {
         this.data.setTemplateName(projectName);
@@ -82,22 +86,25 @@ public class CreateNativeProjectCommand extends AbstractSubCommand<CreateNativeP
     /*
      * create native project from template.
      * 
-     * 1. get template list 
+     * 1. get template list
      * 2. copy native project template
      */
 
     @Override
     protected CreateNativeProjectCommandData call()
     {
-        progressLog.info("-----------------------------------------------------");
-        progressLog.info("Starting Tizen project creation:");
-        progressLog.info("-----------------------------------------------------");
-        
+        progressMonitor = new TextProgressMonitor(new PrintWriter(System.out));
+        progressMonitor.beginTask(CREATE_NATIVE_PROJECT_TASK, 10);
+
         // get template list
         data.getTemplateList();
+        progressMonitor.update(3);
 
         // copy native project template and generate .cproject and .project file
         copyNativeProjectTemplate();
+        progressMonitor.update(7);
+
+        progressMonitor.endTask();
 
         return data;
     }
@@ -209,11 +216,12 @@ public class CreateNativeProjectCommand extends AbstractSubCommand<CreateNativeP
         public void setBuildConfigMap(String projectType)
         {
             String tempPath = pg.extractBuiltinJarFiles("templates" + File.separator + "Executables");
-            if(tempPath == null){
+            if (tempPath == null)
+            {
                 log.error("No jar folder!");
                 return;
             }
-                
+
             tempPath = tempPath.substring(0, tempPath.lastIndexOf(File.separator));
             cProjectTemplatePath = tempPath.substring(0, tempPath.lastIndexOf(File.separator));
 
@@ -252,7 +260,7 @@ public class CreateNativeProjectCommand extends AbstractSubCommand<CreateNativeP
                 }
             } catch (Exception e)
             {
-                log.error("Error occurred during reading app/shared/static teamplate!\n{}",e.getMessage());
+                log.error("Error occurred during reading app/shared/static teamplate!\n{}", e.getMessage());
             }
         }
 
index e3fb66f..adb620e 100644 (file)
@@ -7,7 +7,7 @@
  * 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
@@ -45,7 +45,7 @@ import org.w3c.dom.Element;
 
 /**
  * This class provides data which is used to create Tizen native project.
- * 
+ *
  * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
  */
 public class CreateNativeProjectCommandData
index 11905f6..9b80da3 100644 (file)
@@ -7,7 +7,7 @@
  * 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
@@ -34,6 +34,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -61,6 +62,7 @@ import org.tizen.common.core.application.tproject.Tproject;
 import org.tizen.common.util.FileUtil;
 import org.tizen.common.util.FreeMarkerUtil;
 import org.tizen.common.util.IOUtil;
+import org.tizen.core.ide.TextProgressMonitor;
 import org.tizen.ncli.ide.messages.TizenCLIMessages;
 import org.tizen.web.apptemplate.model.LibraryElement;
 import org.tizen.web.apptemplate.model.OptionElement;
@@ -81,7 +83,7 @@ import freemarker.template.Configuration;
 
 /**
  * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
- * 
+ *
  */
 public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCommandData>
 {
@@ -100,9 +102,11 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
     private TizenTemplateLibrariesPool libraryPool;
 
+    private static final String CREATE_WEB_PROJECT_TASK = "Create Web Project";
+
     /*
      * create web project from template.
-     * 
+     *
      * 1. get template list
      * 2. copy web project template
      * 3. copy the dependent library
@@ -112,27 +116,38 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
     @Override
     protected CreateProjectCommandData call()
     {
+        progressMonitor = new TextProgressMonitor(new PrintWriter(System.out));
+        progressMonitor.beginTask(CREATE_WEB_PROJECT_TASK,10);
+
         // 1. get template list
         data.getTemplateList();
+        progressMonitor.update(1);
 
         // 2. copy web project template
         copyWebProjectTemplate();
+        progressMonitor.update(3);
 
         // 3. copy the dependent library
         copyLibrary();
+        progressMonitor.update(3);
 
         // 4. generate configuration
         copyConfiguration();
+        progressMonitor.update(1);
 
         // 5. generate file from template
         processOption();
-        
+        progressMonitor.update(1);
+
         // 6. generate tizen description file
         makeTizenDescription();
+        progressMonitor.update(1);
+
+        progressMonitor.endTask();
 
         return data;
     }
-    
+
     public void setTemplateName(String projectName)
     {
         this.data.setTemplateName(projectName);
@@ -157,7 +172,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
     {
         this.data.setOutputName(projectName);
     }
-    
+
     public String getOutputName()
     {
         return this.data.getOutputName();
@@ -212,7 +227,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
         // extract jar file contained built-in library
         String rootPath = pg.extractBuiltinJarFiles(WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER);
-        
+
         // get library pool
         libraryPool = new TizenTemplateLibrariesPool(profileInfo, rootPath);
 
@@ -363,7 +378,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
             // TODO Auto-generated catch block
             log.error(e.getMessage());
         }
-        
+
         if (tizenAppTemplate == null)
             return;
 
@@ -377,7 +392,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
             {
                 buildModelForSupportLibraries(supportLibraries);
             }
-    
+
             // building option model
             for (OptionGroup optionGroup : options.getOptionGroup())
             {
@@ -386,7 +401,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
                                                                              // group1
             }
         }
-        
+
         // building config model
         buildModelForConfigFile();
 
@@ -545,7 +560,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
     /**
      * find widget configuration file in a project
-     * 
+     *
      * @return the configuration file. null if no such file exists.
      */
     private File findConfiguration()
@@ -560,12 +575,12 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
         else
             return null;
     }
-    
+
     private void makeTizenDescription()
     {
         // get latest profile info
         ProfileInfo latestProfileInfo = InstallPathConfig.getLatestProfileInfo();
-        
+
         ObjectFactory objFactory = new ObjectFactory();
         Tproject tProject = objFactory.createTproject();
         Platform platform = objFactory.createPlatform();
@@ -575,10 +590,10 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
         platform.setName(latestProfileInfo.getLatestPlatformName());
         platforms.getPlatform().add(platform);
         tProject.setPlatforms(platforms);
-        
-        // make tizen project description file 
+
+        // make tizen project description file
         File file = new File(data.getDestTizenProjectDescriptionFile());
-        
+
         // marshall
         try {
             JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
@@ -592,7 +607,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
     /**
      * get widget configuration file in a project
-     * 
+     *
      * @return the configuration file. default configuration file if no such
      *         file exists.
      */
@@ -619,7 +634,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
     /**
      * initialize Widget configuration with app ID generation.
-     * 
+     *
      * @param monitor
      *            {@link IProgressMonitor}. if this is null,
      *            {@link NullProgressMonitor} is used.
@@ -721,7 +736,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
     /**
      * 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}
@@ -735,7 +750,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 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>";
@@ -809,33 +824,33 @@ class ProjectGenUtil
 
     /* extract jar file and get the extracted folder path
      * when jar file is already extracted in a folder, return the folder path.
-     * folder path has the name appended '_dir' to jar file name.   
+     * folder path has the name appended '_dir' to jar file name.
      */
-    
+
     public String extractBuiltinJarFiles(String resource)
     {
         URL url = getClass().getClassLoader().getResource(resource);
-        
+
         if(url == null){
             logger.error("not found jar file");
             return null;
         }
-            
+
         String urlPath = url.getPath();
-        
+
         String templateLibPath = urlPath + File.separator;
-        
+
         // if the url is not expressed jar file
         if(urlPath.contains("!"))
         {
             String urlPathTemp = urlPath.replaceAll("file:", "");
             String jarPath = urlPathTemp.substring(0, urlPathTemp.lastIndexOf('!'));
-            
+
             String destDirPath = jarPath + "_dir";
-            
+
             templateLibPath = destDirPath + File.separator + resource + File.separator;
-            
-            // make it if the destination directory is not created. 
+
+            // make it if the destination directory is not created.
             File destDirFile = new File(destDirPath);
             if (destDirFile.isDirectory())
             {
@@ -845,7 +860,7 @@ class ProjectGenUtil
             {
                 destDirFile.mkdir();
             }
-            
+
             try
             {
                 JarFile jar = new JarFile(jarPath);
@@ -877,7 +892,7 @@ class ProjectGenUtil
                 logger.error(e.getMessage());
             }
         }
-      
+
         return templateLibPath;
     }
 }