From 9ef3f1bf43ee1467ce1ebeb6d709f649f9ade472 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Mon, 17 Feb 2014 17:30:25 +0900 Subject: [PATCH] CLI: Fixed a bug where error occured during packaging native project on Windows Added the function which generate packaging windows command Added the exception handling codes Change-Id: Id15141cdc69d5ae32d80ebcefadb3bedfe37c110 Signed-off-by: shingil.kang --- .../ide/subcommands/PackageNativeCLICommand.java | 347 ++++++++++++++++----- 1 file changed, 270 insertions(+), 77 deletions(-) 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 index bc764bc..acc8cd0 100644 --- 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 @@ -1,7 +1,14 @@ package org.tizen.ncli.ide.subcommands; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -13,6 +20,7 @@ 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.IOUtil; import org.tizen.common.util.OSChecker; import org.tizen.nativecommon.build.SmartBuildInterface; import org.tizen.nativecommon.build.exception.SBIException; @@ -26,7 +34,13 @@ public class PackageNativeCLICommand extends AbstractSubCommand command) + { + // get system enviroment + Map env = System.getenv(); - // create documents - cprojectDoc = getDocument(cprojectPath); - projectDoc = getDocument(projectFilePath); - manifestDoc = getDocument(manifestPath); + if (env != null) + { + ProcessBuilder pb = new ProcessBuilder(command); - // create command - String option = getPackageOption(); - String command = getCLICommand() + getSBIAction(targetID) + option; - progressLog.info("COMMAND = " + command); + Map processEnv = pb.environment(); + if (processEnv == null) + { + processEnv = new HashMap(); + } - // run command - progressLog.info(HostUtil.returnExecute(command)); + // set dependency library path + for (Entry entry : env.entrySet()) + { + if (entry.getKey().equalsIgnoreCase("PATH")) + { + String newPath = entry.getValue(); + newPath = MINGW_BIN_PATH + ";" + MSYS_BIN_PATH + ";" + newPath; + processEnv.put(entry.getKey(), newPath); + } + else + { + processEnv.put(entry.getKey(), entry.getValue()); + } + } + + Process proc = null; + BufferedReader in = null; + try + { + proc = pb.start(); + in = new BufferedReader(new InputStreamReader(proc.getInputStream())); + String resultLine = in.readLine(); + while (resultLine != null) + { + progressLog.info(resultLine); + resultLine = in.readLine(); + } - // set TPK path - setTpkPath(); + } catch (Exception e) + { + progressLog.error("Error occured during running packaging command", e.getMessage()); + } finally + { + IOUtil.tryClose(in); + } - return data; + } } public void setConfiguration(String configuration) @@ -118,86 +252,58 @@ public class PackageNativeCLICommand extends AbstractSubCommand addPackageOptionToList(PackageOption packageOption, List packageOptionList) + { + if (packageOption != null) { - return CMD_CLI_NATIVE_PACK_WINDOWS; + packageOptionList.add(packageOption.getBuildTargetPathWithOption()); + packageOptionList.add(packageOption.getArchWithOption()); + packageOptionList.add(packageOption.getPackageTypeWithOption()); + packageOptionList.add(packageOption.getPackageNameWithOption()); + packageOptionList.add(packageOption.getProjectNameWithOption()); + packageOptionList.add(packageOption.getArtifactNameWithOption()); + packageOptionList.add(packageOption.getPackageVersionWithOption()); } else { - return CMD_CLI_NATIVE_PACK_LINUX; + progressLog.error("Packaging option is null"); + return null; } + return packageOptionList; } - private String getSBIAction(String targetId) + private PackageOption getPackageOption(String workingProjectConfigurationPath, String targetID, Document projectDoc, Document manifestDoc) { - return String.format(" action %s -- buildpackage", targetId); - } - - public String getPackageOption() - { - targetID = getTargetID(cprojectDoc); - String options = null; + PackageOption packageOption = 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)); + packageOption = new PackageOption(workingProjectConfigurationPath, SBIModel.getBaseArchName(sbi.getRootstrapArchitecture(targetID)), packageType, getPackageName(manifestDoc), projectName = getProjectName(projectDoc), projectName, getVersion(manifestDoc)); + } catch (SBIException e) { - e.printStackTrace(); + progressLog.error("Error occured during getting SBI options", e.getMessage()); + return null; } - return options; + return packageOption; } - // get document from xml file path - private Document getDocument(String path) + // get document from file path + private Document getDocument(String filePath) throws SAXException, IOException, ParserConfigurationException { - 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; + File file = new File(filePath); + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file); + return document; } // get target id from document @@ -279,4 +385,91 @@ public class PackageNativeCLICommand extends AbstractSubCommand