'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>
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 = {
};
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",
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;
case configuration:
suggestion = optionFortSuggestion.getSuggestion();
break;
- case name:
+ case template:
List<String> listResult = CreateProjectCommandData.getTemplateList();
for (String result : listResult) {
suggestion = suggestion + " " + result;
\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
--- /dev/null
+package org.tizen.ncli.ide.shell;
+
+public class CreateNativeProjectCLI extends AbstractCLI
+{
+
+ @Override
+ public void execute()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
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;
/**
* @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)
*
@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();
}
}
/**
* @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;
public void setOutputName(String outputName)
{
- this.outputName = this.outputName + File.separator + outputName + File.separator;
+ this.outputName = outputName;
}
public String getOutputName()
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()
}
// 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
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;
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;
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;
// 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)
{
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)
private void copyLibrary()
{
- String projectName = data.getProjectName();
- String configFile = data.getTizenWebTemplateConfigFile(projectName);
+ String templateName = data.getTemplateName();
+ String configFile = data.getTizenWebTemplateConfigFile(templateName);
try
{
// get options
Options options = tizenAppTemplate.getOptions();
+ if(options == null){
+ return;
+ }
// get support libraries
SupportLibraries sl = options.getSupportLibraries();
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:
// 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);
// 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();
private void copyConfiguration()
{
- pg.copyConfigFile(data.getDestTizenWebProjectConfigFile(data.getProjectName()));
+ pg.copyConfigFile(data.getDestTizenWebProjectConfigFile());
}
private void generateConfiguration()
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
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
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);
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())
destDirFile.mkdir();
}
- templateLibPath = destDirPath + File.separator + WebConstant.BUILTIN_TEMPLATE_LIBRARIES_FOLDER + File.separator;
-
try
{
JarFile jar = new JarFile(jarPath);