From 74d31389044646f411de7fd0b653ef49ac4e8204 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Mon, 18 Nov 2013 22:53:00 +0900 Subject: [PATCH] CLI: divided some options and add the module which generates .tproject file. '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 --- .../ncli/ide/autocomplete/TizenAutoComplete.java | 9 +- .../src/org/tizen/ncli/ide/shell/CreateCLI.java | 3 +- .../ncli/ide/shell/CreateNativeProjectCLI.java | 13 +++ ...ateProjectCLI.java => CreateWebProjectCLI.java} | 59 +++++----- .../ide/subcommands/CreateProjectCommandData.java | 49 ++++---- .../ide/subcommands/CreateWebProjectCommand.java | 123 +++++++++++++++------ 6 files changed, 165 insertions(+), 91 deletions(-) create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateNativeProjectCLI.java rename org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/{CreateProjectCLI.java => CreateWebProjectCLI.java} (58%) diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java index f226bb6..1858c86 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java @@ -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 listResult = CreateProjectCommandData.getTemplateList(); for (String result : listResult) { suggestion = suggestion + " " + result; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateCLI.java index 04ac98c..519715c 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateCLI.java @@ -14,7 +14,8 @@ public class CreateCLI extends AbstractCLI { @Argument(index = 0, required = true, handler = SubCommandHandler.class, usage = "Command is needed!") @SubCommands({ - @SubCommand(name = "project", impl = CreateProjectCLI.class), + @SubCommand(name = "native-project", impl = CreateNativeProjectCLI.class), + @SubCommand(name = "web-project", impl = CreateWebProjectCLI.class), @SubCommand(name = "security-profile", impl = CreateSecProfileCLI.class), @SubCommand(name = "security-profile-item", impl = CreateSecProfileItemCLI.class), @SubCommand(name = "certificate", impl = CreateCertificateCLI.class) 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 index 0000000..6ed312f --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateNativeProjectCLI.java @@ -0,0 +1,13 @@ +package org.tizen.ncli.ide.shell; + +public class CreateNativeProjectCLI extends AbstractCLI +{ + + @Override + public void execute() + { + // TODO Auto-generated method stub + + } + +} 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/CreateWebProjectCLI.java similarity index 58% rename from org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProjectCLI.java rename to org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateWebProjectCLI.java index e43e0c4..927ffee 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateProjectCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/CreateWebProjectCLI.java @@ -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 } (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(); } } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProjectCommandData.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProjectCommandData.java index a820ddf..a6e9a7c 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProjectCommandData.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateProjectCommandData.java @@ -44,20 +44,23 @@ import org.tizen.web.model.TizenModelFactory; /** * @author Shingil Kang{@literal } (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 webProjects = new HashMap(); - 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 diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateWebProjectCommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateWebProjectCommand.java index f772a6b..d90810a 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateWebProjectCommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/CreateWebProjectCommand.java @@ -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