From 9dea41f9620b789a78f12c5ea94628c3fc806cf2 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Wed, 18 Dec 2013 10:15:54 +0900 Subject: [PATCH] CLI: added the 'package native project cli module' Initial commit Change-Id: I528b6d2af43766a44235b303c84900b9cf293902 Signed-off-by: shingil.kang --- org.tizen.ncli.ide/META-INF/MANIFEST.MF | 37 +-- .../src/org/tizen/ncli/ide/shell/PackageCLI.java | 40 +-- .../ide/subcommands/PackageNativeCLICommand.java | 282 +++++++++++++++++++++ .../subcommands/PackageNativeCLICommandData.java | 16 ++ 4 files changed, 341 insertions(+), 34 deletions(-) create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommand.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommandData.java diff --git a/org.tizen.ncli.ide/META-INF/MANIFEST.MF b/org.tizen.ncli.ide/META-INF/MANIFEST.MF index 324431c..08348f4 100644 --- a/org.tizen.ncli.ide/META-INF/MANIFEST.MF +++ b/org.tizen.ncli.ide/META-INF/MANIFEST.MF @@ -9,30 +9,19 @@ Require-Bundle: org.tizen.common;bundle-version="2.0.0", org.tizen.common.verrari, org.tizen.common.verrari.realm Import-Package: - org.eclipse.osgi.util;version="1.1.0", - org.tizen.common.sign.command, - org.tizen.common.sign.preferences, - org.tizen.nativecommon.build, - org.tizen.nativecommon.build.exception, - org.tizen.sdblib, - org.tizen.sdblib.service, - org.tizen.web.apptemplate.model, - org.tizen.web.builder, - org.tizen.web.builder.exception, - org.tizen.web.common, - org.tizen.web.config.schema.model, - org.tizen.web.model, - org.tizen.web.project.configuration, - org.tizen.web.project.wizard.model, - org.tizen.web.project.wizard.operation, - org.tizen.web.project.wizard.ui.commandbar, org.eclipse.cdt.core.templateengine, org.eclipse.cdt.core.templateengine.process.processes, org.eclipse.cdt.managedbuilder.core, org.eclipse.cdt.ui.templateengine, + org.eclipse.osgi.util;version="1.1.0", + org.tizen.common.sign.command, + org.tizen.common.sign.preferences, org.tizen.nativeappcommon.templateengine, org.tizen.nativeappcommon.wizards, org.tizen.nativecommon, + org.tizen.nativecommon.build, + org.tizen.nativecommon.build.exception, + org.tizen.nativecommon.build.model, org.tizen.nativecommon.exception, org.tizen.nativecommon.templateengine, org.tizen.nativecommon.templateengine.build, @@ -42,5 +31,17 @@ Import-Package: org.tizen.nativecommon.templateengine.util, org.tizen.nativecpp.templateengine, org.tizen.nativecpp.wizards, - org.tizen.nativecpp.wizards.build + org.tizen.nativecpp.wizards.build, + org.tizen.sdblib, + org.tizen.sdblib.service, + org.tizen.web.apptemplate.model, + org.tizen.web.builder, + org.tizen.web.builder.exception, + org.tizen.web.common, + org.tizen.web.config.schema.model, + org.tizen.web.model, + org.tizen.web.project.configuration, + org.tizen.web.project.wizard.model, + org.tizen.web.project.wizard.operation, + org.tizen.web.project.wizard.ui.commandbar diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/PackageCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/PackageCLI.java index d785284..48c8dd2 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/PackageCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/PackageCLI.java @@ -32,13 +32,15 @@ import org.slf4j.LoggerFactory; import org.tizen.ncli.core.TizenSubCommand; import org.tizen.ncli.ide.subcommands.PackageCLICommand; import org.tizen.ncli.ide.subcommands.PackageCLICommandData; +import org.tizen.ncli.ide.subcommands.PackageNativeCLICommand; +import org.tizen.ncli.ide.subcommands.PackageNativeCLICommandData; @TizenSubCommand(name = "package", usage = "Package tizen project") public class PackageCLI extends AbstractCLI { private Logger log = LoggerFactory.getLogger(getClass()); - - @Option(name = "--type", metaVar = "tpk | wgt", usage = "packaging type") + + @Option(name = "--type", required = true, metaVar = "tpk | wgt", usage = "packaging type") private String type; @Option(name = "--sign", usage = "Specify profile name") @@ -48,26 +50,32 @@ public class PackageCLI extends AbstractCLI public void execute() { log.trace("Execute PackageCLI..."); - PackageCLICommand packageCommand = new PackageCLICommand(); - - log.trace("getRealWorkingPath: {}",getRealWorkingPath()); - packageCommand.setWorkingDir(getRealWorkingPath()); - - PackageCLICommandData data = null; + log.trace("getRealWorkingPath: {}", getRealWorkingPath()); + if (type.equals("wgt")) { - data = packageCommand.runCommand(); + PackageCLICommand packageCommand = new PackageCLICommand(); + packageCommand.setWorkingDir(getRealWorkingPath()); + PackageCLICommandData data = packageCommand.runCommand(); + if (null != data) + { + String wgtPath = data.getWgtPath(); + if (null != wgtPath) + progressLog.info("Package File Location: {}", data.getWgtPath()); + } } else if (type.equals("tpk")) { - // todo - } - if (null != data) - { - String wgtPath = data.getWgtPath(); - if (null != wgtPath) - progressLog.info("Package File Location: {}", data.getWgtPath()); + PackageNativeCLICommand nativePackageCommand = new PackageNativeCLICommand(); + nativePackageCommand.setWorkingDir(getRealWorkingPath()); + PackageNativeCLICommandData nativeData = nativePackageCommand.runCommand(); + if (null != nativeData) + { + String tpkPath = nativeData.getTpkPath(); + if (null != tpkPath) + progressLog.info("Package File Location: {}", nativeData.getTpkPath()); + } } } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommand.java new file mode 100644 index 0000000..bc764bc --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommand.java @@ -0,0 +1,282 @@ +package org.tizen.ncli.ide.subcommands; + +import java.io.File; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.tizen.common.core.application.InstallPathConfig; +import org.tizen.common.util.FileUtil; +import org.tizen.common.util.HostUtil; +import org.tizen.common.util.OSChecker; +import org.tizen.nativecommon.build.SmartBuildInterface; +import org.tizen.nativecommon.build.exception.SBIException; +import org.tizen.nativecommon.build.model.SBIModel; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class PackageNativeCLICommand extends AbstractSubCommand +{ + private static final String PATH_SBI = FileUtil.appendPath(InstallPathConfig.getSDKPath(), "tools/smart-build-interface/bin"); + private static final String CMD_CLI_NATIVE_PACK_LINUX = FileUtil.appendPath(PATH_SBI, "sbi"); + private static final String CMD_CLI_NATIVE_PACK_WINDOWS = FileUtil.appendPath(PATH_SBI, "sbi.bat"); + + protected PackageNativeCLICommandData data = new PackageNativeCLICommandData(); + + protected SmartBuildInterface sbi; + + protected String cprojectPath; + protected String projectFilePath; + protected String manifestPath; + + protected Document projectDoc; + protected Document cprojectDoc; + protected Document manifestDoc; + + protected String projectPath; + protected String activceConfiguration; + protected String workingProjectConfigurationPath; + + protected String targetID; + protected String arch; + protected String packageType = "TPK"; + protected String projectName; + protected String packageName; + protected String version; + + XPath xpath = XPathFactory.newInstance().newXPath(); + + @Override + protected PackageNativeCLICommandData call() + { + if (!setEnv()) + return null; + + sbi = SmartBuildInterface.getInstance(); + + // create documents + cprojectDoc = getDocument(cprojectPath); + projectDoc = getDocument(projectFilePath); + manifestDoc = getDocument(manifestPath); + + // create command + String option = getPackageOption(); + String command = getCLICommand() + getSBIAction(targetID) + option; + progressLog.info("COMMAND = " + command); + + // run command + progressLog.info(HostUtil.returnExecute(command)); + + // set TPK path + setTpkPath(); + + return data; + } + + public void setConfiguration(String configuration) + { + activceConfiguration = configuration; + } + + private boolean setEnv() + { + + // set project path + try + { + workingProjectConfigurationPath = workingDir.getCanonicalPath(); + activceConfiguration = workingDir.getName(); + projectPath = workingDir.getParentFile().getCanonicalPath(); + + log.debug("Base project directory: {}", projectPath); + + // set .project .cproject .manifest file path + cprojectPath = projectPath + File.separatorChar + ".cproject"; + if (!new File(cprojectPath).isFile()) + { + progressLog.error("Not found Tizen native project"); + return false; + } + + projectFilePath = projectPath + File.separatorChar + ".project"; + manifestPath = projectPath + File.separatorChar + "manifest.xml"; + + return true; + } catch (IOException e) + { + log.error("Error occured during setting working directory", e.getMessage()); + } + return false; + } + + private void setTpkPath() + { + String tpkPath = workingProjectConfigurationPath + File.separatorChar + packageName + "-" + version + "-" + arch + ".tpk"; + data.setTpkPath(tpkPath); + log.debug("Package path: {}", tpkPath); + } + + // private void setWorkingProjectConfigurationPath(String projectPath) + // { + // if (new File(projectPath + File.separatorChar + "Debug").isDirectory()) + // workingProjectConfigurationPath = projectPath + File.separatorChar + + // "Debug"; + // else if (new File(projectPath + File.separatorChar + + // "Release").isDirectory()) + // workingProjectConfigurationPath = projectPath + File.separatorChar + + // "Release"; + // else if (new File(projectPath + File.separatorChar + + // "Dynamic Analyzer").isDirectory()) + // workingProjectConfigurationPath = projectPath + File.separatorChar + + // "Dynamic Analyzer"; + // } + + private String getCLICommand() + { + if (OSChecker.isWindows()) + { + return CMD_CLI_NATIVE_PACK_WINDOWS; + } + else + { + return CMD_CLI_NATIVE_PACK_LINUX; + } + } + + private String getSBIAction(String targetId) + { + return String.format(" action %s -- buildpackage", targetId); + } + + public String getPackageOption() + { + targetID = getTargetID(cprojectDoc); + String options = null; + + try + { + options = String.format(" -BUILD_DIR=\"%s\"" + //$NON-NLS-1$ + " -ARCH=%s" + //$NON-NLS-1$ + " -PKG_TYPE=%s" + //$NON-NLS-1$ + " -PKG_NAME=%s" + //$NON-NLS-1$ + " -PRJ_NAME=%s" + //$NON-NLS-1$ + " -ARTIFACT_NAME=%s" + //$NON-NLS-1$ + " -PKG_VER=%s", //$NON-NLS-1$ + + workingProjectConfigurationPath, arch = SBIModel.getBaseArchName(sbi.getRootstrapArchitecture(targetID)), packageType, packageName = getPackageName(manifestDoc), projectName = getProjectName(projectDoc), projectName, version = getVersion(manifestDoc)); + } catch (SBIException e) + { + e.printStackTrace(); + } + return options; + } + + // get document from xml file path + private Document getDocument(String path) + { + File cprojectFile = new File(path); + try + { + // create document + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(cprojectFile); + return document; + } catch (SAXException e) + { + e.printStackTrace(); + } catch (IOException e) + { + e.printStackTrace(); + } catch (ParserConfigurationException e) + { + e.printStackTrace(); + } + return null; + } + + // get target id from document + private String getTargetID(Document doc) + { + try + { + String query = "//*[@superClass='sbi.gnu.cpp.compiler.option']"; + Node superClassNode = (Node) xpath.evaluate(query, doc, XPathConstants.NODE); + + NodeList list = superClassNode.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) + { + // get node from node list + Node node = list.item(i); + if ("listOptionValue".equals(node.getNodeName())) + { + Node valueNode = node.getAttributes().getNamedItem("value"); + targetID = valueNode.getNodeValue(); + return targetID; + } + } + } catch (XPathExpressionException e) + { + e.printStackTrace(); + } + return null; + } + + // get project name from document + private String getProjectName(Document doc) + { + try + { + String query = "//projectDescription/name"; + NodeList nameNodeList = (NodeList) xpath.evaluate(query, doc, XPathConstants.NODESET); + + if (nameNodeList.item(0) != null) + return nameNodeList.item(0).getTextContent(); + + } catch (XPathExpressionException e) + { + e.printStackTrace(); + } + return null; + } + + // get package name from document + private String getPackageName(Document doc) + { + try + { + String query = "//Manifest/Id"; + NodeList nameNodeList = (NodeList) xpath.evaluate(query, doc, XPathConstants.NODESET); + + if (nameNodeList.item(0) != null) + return nameNodeList.item(0).getTextContent(); + + } catch (XPathExpressionException e) + { + e.printStackTrace(); + } + return null; + } + + private String getVersion(Document doc) + { + try + { + String query = "//Manifest/Version"; + NodeList nameNodeList = (NodeList) xpath.evaluate(query, doc, XPathConstants.NODESET); + + if (nameNodeList.item(0) != null) + return nameNodeList.item(0).getTextContent(); + + } catch (XPathExpressionException e) + { + e.printStackTrace(); + } + return null; + } +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommandData.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommandData.java new file mode 100644 index 0000000..2e9d6ce --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/PackageNativeCLICommandData.java @@ -0,0 +1,16 @@ +package org.tizen.ncli.ide.subcommands; + +public class PackageNativeCLICommandData +{ + protected String tpkPath; + + public String getTpkPath() + { + return tpkPath; + } + + public void setTpkPath(String projectPath) + { + this.tpkPath = projectPath; + } +} \ No newline at end of file -- 2.7.4