CLI: divided some options and add the module which generates .tproject file. 39/12539/3
authorshingil.kang <shingil.kang@samsung.com>
Mon, 18 Nov 2013 13:53:00 +0000 (22:53 +0900)
committershingil.kang <shingil.kang@samsung.com>
Wed, 20 Nov 2013 02:01:56 +0000 (11:01 +0900)
'project' option is divided into 'web-project' and 'native-project' options.
'web-project' and 'native-project' options have each sub-options, '-t(--template)' and '-n(--name)'
generate a file which describe tizen project(.tproject).

Change-Id: I09825d02f878d0a3d76c581817e8f7f26a6a3f70
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/CreateCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateNativeProjectCLI.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateWebProjectCLI.java [moved from org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProjectCLI.java with 58% similarity]
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 f226bb6..1858c86 100644 (file)
@@ -36,7 +36,7 @@ public class TizenAutoComplete {
 
     public static String[][] subCommands = {
         { "list", "device" },
-        { "create", "project security-profile security-profile-item certificate" },
+        { "create", "web-project nativ-project security-profile security-profile-item certificate" },
         { "help", commands } };
     
     public static String[][] options = {
@@ -52,7 +52,8 @@ public class TizenAutoComplete {
         };
 
     public static String[][] optionsForSub = {
-            { "project", "-t --type -n --name -out --output" },
+            { "web-project", "-t --template -n --name" },
+            { "native-project", "-t --template -n --name" },
             { "security-profile", "--kind --active" },
             { "security-profile-item", "--kind --cert --passwd --ca --rootca" },
             { "certificate",
@@ -75,7 +76,7 @@ public class TizenAutoComplete {
         architecture(options[1][0], "--arch", "x86 arm"),
         compiler(options[1][0], "--compiler", "llvm gcc"),
         configuration(options[1][0], "--configuration", "Debug Release Dynamic Analyzer"),
-        name("-n");
+        template("-t");
 
         private String mainCmd;
         private String option;
@@ -282,7 +283,7 @@ public class TizenAutoComplete {
         case configuration:
             suggestion = optionFortSuggestion.getSuggestion();
             break;
-        case name:
+        case template:
             List<String> listResult = CreateProjectCommandData.getTemplateList();
             for (String result : listResult) {
                 suggestion = suggestion + " " + result;
index 04ac98c..519715c 100644 (file)
@@ -14,7 +14,8 @@ 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 = CreateProjectCLI.class),\r
+            @SubCommand(name = "native-project", impl = CreateNativeProjectCLI.class),\r
+            @SubCommand(name = "web-project", impl = CreateWebProjectCLI.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
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateNativeProjectCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateNativeProjectCLI.java
new file mode 100644 (file)
index 0000000..6ed312f
--- /dev/null
@@ -0,0 +1,13 @@
+package org.tizen.ncli.ide.shell;
+
+public class CreateNativeProjectCLI extends AbstractCLI
+{
+
+    @Override
+    public void execute()
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}
@@ -26,6 +26,7 @@
 package org.tizen.ncli.ide.shell;
 
 import java.io.File;
+import java.io.IOException;
 
 import org.kohsuke.args4j.Option;
 import org.kohsuke.args4j.spi.StringOptionHandler;
@@ -37,19 +38,16 @@ import org.tizen.ncli.ide.subcommands.CreateWebProjectCommand;
 /**
  * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
  */
-public class CreateProjectCLI extends AbstractCLI
+public class CreateWebProjectCLI extends AbstractCLI
 {
     private Logger logger = LoggerFactory.getLogger(getClass());
 
-    @Option(name = "-t", aliases = { "--type" }, required = true, usage = "Specify template type")
-    private TizenAppType appType;
+    @Option(name = "-t", aliases = { "--type" }, usage = "Specify template name")
+    private String templateName;
 
-    @Option(name = "-n", aliases = "--name", required = true, usage = "Specify template name")
+    @Option(name = "-n", aliases = { "--name" }, usage = "Specify project name")
     private String projectName;
-    
-    @Option(name = "-out", aliases = {"--output"}, handler=StringOptionHandler.class, usage = "Specify output directory name")
-    public String outputName;
-    
+
     /*
      * (non-Javadoc)
      * 
@@ -58,26 +56,37 @@ public class CreateProjectCLI extends AbstractCLI
     @Override
     public void execute()
     {
-        logger.info("Project Name:{}", projectName);
+        logger.info("Template Name:{}", templateName);
+
+        CreateWebProjectCommand webCommand = new CreateWebProjectCommand();
+
+        // set template name
+        if (templateName != null)
+        {
+            webCommand.setTemplateName(templateName);
+            webCommand.setProjectName(templateName);
+        }
 
-        switch (appType) {
-        case NATIVE:
-//            CreateNativeProjectCommand nativeCommand = new CreateNativeProjectCommand();
-//            nativeCommand.setAppType(appType);
-//            nativeCommand.setProjectName(projectName);
-//            nativeCommand.runCommand();
-            break;
-        case WEB:
-            CreateWebProjectCommand webCommand = new CreateWebProjectCommand();
-            webCommand.setAppType(appType);
+        // set project name
+        if (projectName != null)
             webCommand.setProjectName(projectName);
+
+        // set output directory
+        if (workingDir != null)
+        {
+            try
+            {
+                webCommand.setOutputName(workingDir.getCanonicalPath());
+            } catch (IOException e)
+            {
+                logger.error(e.getMessage());
+            }
+        }
+        else
+        {
             webCommand.setOutputName(currentWorkspacePath);
-            if(outputName != null)
-                webCommand.setOutputName(outputName);            
-            webCommand.runCommand();
-            break;
-        default:
-            break;
         }
+
+        webCommand.runCommand();
     }
 }
index a820ddf..a6e9a7c 100644 (file)
@@ -44,20 +44,23 @@ import org.tizen.web.model.TizenModelFactory;
 /**
  * @author Shingil Kang{@literal <shingil.kang@samsung.com>} (S-core)
  * 
- * 
  */
 public class CreateProjectCommandData
 {
     private static final String PLATFORM_PATH = InstallPathConfig.getPlatformPath(null, null);
     private static final String WEB_PROJECT_PATH = "samples" + File.separator + "web" + File.separator + "Template" + File.separator + "Tizen";
     private static final String TIZEN_WEB_APP_TEMPLATE_FILE = "tizen-app-template.xml";
+    private static final String TIZEN_PROJECT_DESCRIPTION_FILE = ".tproject";
     private static final String TIZEN_PROJECT_FOLDER = "project";
     private static final String TIZEN_PROJECT_CONFIG_PATH = "config" + File.separator + "config.xml";
 
+    public static final String DEFAULT_TEMPLATE_NAME = "TizenBasic";
+    public static final String DEFAULT_PROJECT_NAME = "basic";
+
     public static final Map<String, String> webProjects = new HashMap<String, String>();
 
-    private TizenAppType appType;
-    private String projectName;
+    private String templateName = DEFAULT_TEMPLATE_NAME;
+    private String projectName = DEFAULT_PROJECT_NAME;
     private String outputName = "";
 
     private static TizenAppTemplate tizenAppTemplate;
@@ -94,7 +97,7 @@ public class CreateProjectCommandData
 
     public void setOutputName(String outputName)
     {
-        this.outputName = this.outputName + File.separator + outputName + File.separator;
+        this.outputName = outputName;
     }
 
     public String getOutputName()
@@ -102,29 +105,24 @@ public class CreateProjectCommandData
         return outputName;
     }
 
-    public void setTargetAbsoultePath(File targetAbsoultePath)
-    {
-        this.outputName = targetAbsoultePath.getAbsolutePath();
-    }
-
-    public void setAppType(TizenAppType appType)
+    public void setProjectName(String projectName)
     {
-        this.appType = appType;
+        this.projectName = projectName;
     }
 
-    public TizenAppType getAppType()
+    public String getProjectName()
     {
-        return appType;
+        return projectName;
     }
 
-    public void setProjectName(String projectName)
+    public void setTemplateName(String templateName)
     {
-        this.projectName = projectName;
+        this.templateName = templateName;
     }
 
-    public String getProjectName()
+    public String getTemplateName()
     {
-        return projectName;
+        return templateName;
     }
 
     public String getAppID()
@@ -168,15 +166,16 @@ public class CreateProjectCommandData
     }
 
     // get web project configuration destination path
-    public String getDestTizenWebProjectConfigFile(String id)
+    public String getDestTizenWebProjectConfigFile()
     {
         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 description file path
+    public String getDestTizenProjectDescriptionFile()
+    {
+        return outputName + File.separator + TIZEN_PROJECT_DESCRIPTION_FILE;
+    }
+    
+    
 }
\ No newline at end of file
index f772a6b..d90810a 100644 (file)
@@ -48,6 +48,7 @@ import java.util.jar.JarFile;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 
 import org.kohsuke.args4j.Option;
@@ -57,6 +58,10 @@ import org.tizen.common.Factory;
 import org.tizen.common.core.application.InstallPathConfig;
 import org.tizen.common.core.application.ProfileInfo;
 import org.tizen.common.core.application.TizenProjectDescription;
+import org.tizen.common.core.application.tproject.ObjectFactory;
+import org.tizen.common.core.application.tproject.Platform;
+import org.tizen.common.core.application.tproject.Platforms;
+import org.tizen.common.core.application.tproject.Tproject;
 import org.tizen.common.core.command.ExecutionContext;
 import org.tizen.common.core.command.Prompter;
 import org.tizen.common.core.command.policy.PolicyRegistry;
@@ -79,7 +84,6 @@ import org.tizen.web.apptemplate.model.SupportLibraries;
 import org.tizen.web.apptemplate.model.SupportLibrary;
 import org.tizen.web.apptemplate.model.TizenTemplateKindsOfLibraries;
 import org.tizen.web.common.WebConstant;
-import org.tizen.web.config.schema.model.ObjectFactory;
 import org.tizen.web.config.schema.model.Widget;
 import org.tizen.web.model.TizenAppTemplate;
 import org.tizen.web.model.TizenModelFactory;
@@ -144,13 +148,21 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
         // 5. generate file from template
         processOption();
+        
+        // 6. generate tizen description file
+        makeTizenDescription();
 
         return data;
     }
+    
+    public void setTemplateName(String projectName)
+    {
+        this.data.setTemplateName(projectName);
+    }
 
-    public void setAppType(TizenAppType appType)
+    public void getTemplateName()
     {
-        this.data.setAppType(appType);
+        this.data.getTemplateName();
     }
 
     public void setProjectName(String projectName)
@@ -162,11 +174,18 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
     {
         this.data.setOutputName(projectName);
     }
+    
+    public String getOutputName()
+    {
+        return this.data.getOutputName();
+    }
+    
+   
 
     private void copyWebProjectTemplate()
     {
-        String projectName = data.getProjectName();
-        String projectPath = data.getTizenWebProjectRootPath(projectName);
+        String templateName = data.getTemplateName();
+        String projectPath = data.getTizenWebProjectRootPath(templateName);
         String destDir = data.getOutputName();
 
         // filter file (.project)
@@ -186,8 +205,8 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
     private void copyLibrary()
     {
 
-        String projectName = data.getProjectName();
-        String configFile = data.getTizenWebTemplateConfigFile(projectName);
+        String templateName = data.getTemplateName();
+        String configFile = data.getTizenWebTemplateConfigFile(templateName);
 
         try
         {
@@ -201,6 +220,9 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
         // get options
         Options options = tizenAppTemplate.getOptions();
+        if(options == null){
+            return;
+        }
 
         // get support libraries
         SupportLibraries sl = options.getSupportLibraries();
@@ -327,10 +349,10 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
         switch (kindOfLibrary) {
         case JAVASCRIPT:
-            destDir = data.getOutputName() + "js";
+            destDir = data.getOutputName() + File.separator + "js";
             break;
         case CSS:
-            destDir = data.getOutputName() + "css";
+            destDir = data.getOutputName() + File.separator + "css";
             break;
         case OTHERS: // copy to root folder basically
         default:
@@ -355,14 +377,6 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
         // set default FreeMarker configuration
         cfg = FreeMarkerUtil.getDefaultConfiguration();
 
-        if (tizenAppTemplate == null)
-            return;
-
-        // get options
-        Options options = tizenAppTemplate.getOptions();
-        if (options == null)
-            return;
-
         // get path of template
         String projectDestDir = data.getOutputName();
         File projectDir = new File(projectDestDir);
@@ -376,22 +390,30 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
             // TODO Auto-generated catch block
             log.error(e.getMessage());
         }
+        
+        if (tizenAppTemplate == null)
+            return;
 
-        // building support library model
-        SupportLibraries supportLibraries = options.getSupportLibraries();
-        if (supportLibraries != null)
-        {
-            buildModelForSupportLibraries(supportLibraries);
-        }
-
-        // building option model
-        for (OptionGroup optionGroup : options.getOptionGroup())
+        // get options
+        Options options = tizenAppTemplate.getOptions();
+        if (options != null)
         {
-            buildModelForOptionGroup(optionGroup, optionGroup.getKey()); // key
-                                                                         // ex)
-                                                                         // group1
+            // building support library model
+            SupportLibraries supportLibraries = options.getSupportLibraries();
+            if (supportLibraries != null)
+            {
+                buildModelForSupportLibraries(supportLibraries);
+            }
+    
+            // building option model
+            for (OptionGroup optionGroup : options.getOptionGroup())
+            {
+                buildModelForOptionGroup(optionGroup, optionGroup.getKey()); // key
+                                                                             // ex)
+                                                                             // group1
+            }
         }
-
+        
         // building config model
         buildModelForConfigFile();
 
@@ -538,7 +560,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
 
     private void copyConfiguration()
     {
-        pg.copyConfigFile(data.getDestTizenWebProjectConfigFile(data.getProjectName()));
+        pg.copyConfigFile(data.getDestTizenWebProjectConfigFile());
     }
 
     private void generateConfiguration()
@@ -556,7 +578,7 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
     private File findConfiguration()
     {
         // get configuration file
-        String configurationFilePath = data.getTizenWebProjectConfigFile(data.getProjectName());
+        String configurationFilePath = data.getTizenWebProjectConfigFile(data.getTemplateName());
         File configurationFile = new File(configurationFilePath);
 
         // check if configuration file exists
@@ -565,6 +587,35 @@ 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();
+        Platforms platforms = objFactory.createPlatforms();
+
+        // set latest profile name
+        platform.setName(latestProfileInfo.getLatestPlatformName());
+        platforms.getPlatform().add(platform);
+        tProject.setPlatforms(platforms);
+        
+        // make tizen project description file 
+        File file = new File(data.getDestTizenProjectDescriptionFile());
+        
+        // marshall
+        try {
+            JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
+            Marshaller marshaller = jaxbContext.createMarshaller();
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+            marshaller.marshal(tProject, file);
+        } catch (JAXBException e) {
+            log.error("cannot marshal", e);
+        }
+    }
 
     /**
      * get widget configuration file in a project
@@ -605,13 +656,13 @@ public class CreateWebProjectCommand extends AbstractSubCommand<CreateProjectCom
     private void initializeConfiguration()
     {
 
-        String projectName = data.getProjectName();
+        String projectName = data.getTemplateName();
         // String widgetId = getWidgetURI() + projectName;
 
         // get widget id
         String widgetId = WIDGET_BASE_IDENTIFIER + projectName;
 
-        File configurationFile = new File(data.getDestTizenWebProjectConfigFile(projectName));
+        File configurationFile = new File(data.getDestTizenWebProjectConfigFile());
 
         // get configuration manager
         ITizenConfigurator configurator = unmarshalWidgetConfiguration(configurationFile);
@@ -796,6 +847,8 @@ class ProjectGenUtil
             
             String destDirPath = jarPath + "_dir";
             
+            templateLibPath = destDirPath + File.separator + WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER + File.separator;
+            
             // make it if the destination directory is not created. 
             File destDirFile = new File(destDirPath);
             if (destDirFile.isDirectory())
@@ -807,8 +860,6 @@ class ProjectGenUtil
                 destDirFile.mkdir();
             }
             
-            templateLibPath = destDirPath + File.separator + WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER + File.separator;
-            
             try
             {
                 JarFile jar = new JarFile(jarPath);