From 8c6fd35237160ad163517f9811cf0a110aa587ab Mon Sep 17 00:00:00 2001 From: "hyunsik.noh" Date: Sun, 17 Nov 2013 17:13:16 +0900 Subject: [PATCH] CLI: Change required options. Some required options are changed as user-friendly. The messages properties files are added. Change-Id: Iccc91e2730e4e0c0a9b1222478bc6d625e231380 Signed-off-by: hyunsik.noh --- org.tizen.ncli.ide/META-INF/MANIFEST.MF | 1 + .../org/tizen/ncli/ide/config/ConfigConstant.java | 4 + .../ncli/ide/messages/BuildNativeMessages.java | 30 ++ .../ide/messages/BuildNativeMessages.properties | 20 + .../org/tizen/ncli/ide/shell/BuildNativeCLI.java | 22 +- .../ide/subcommands/BuildNativeCLICommand.java | 544 ++++++++++++++------- 6 files changed, 429 insertions(+), 192 deletions(-) create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.properties diff --git a/org.tizen.ncli.ide/META-INF/MANIFEST.MF b/org.tizen.ncli.ide/META-INF/MANIFEST.MF index 62acee0..c9ef64d 100644 --- a/org.tizen.ncli.ide/META-INF/MANIFEST.MF +++ b/org.tizen.ncli.ide/META-INF/MANIFEST.MF @@ -9,6 +9,7 @@ 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.nativecommon.build, org.tizen.nativecommon.build.exception, org.tizen.web.apptemplate.model, diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/config/ConfigConstant.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/config/ConfigConstant.java index d52111b..56711d2 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/config/ConfigConstant.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/config/ConfigConstant.java @@ -46,4 +46,8 @@ public class ConfigConstant { //public static final String NATIVE_TEMPLATE_QUERY_URL = "file:///$${TIZEN-SDK-HOME}/platforms/tizen2.2/samples/native/cpp/Template/$${id}"; //public static final String NATIVE_SEARCH_QUERY_URL = "file:///$${TIZEN-SDK-HOME}/platforms/tizen2.2/samples/native/cpp/Template"; //public static final String SEARCH_QUERY_TYPE = "directory"; + + public static final String DEFAULT_BUILD_ARCHITECTURE = "default.build.architecture"; + public static final String DEFAULT_BUILD_COMPILER = "default.build.compiler"; + public static final String DEFAULT_BUILD_CONFIGURATION = "default.build.configuration"; } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.java new file mode 100644 index 0000000..2f91336 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.java @@ -0,0 +1,30 @@ +package org.tizen.ncli.ide.messages; + +import org.eclipse.osgi.util.NLS; + +public class BuildNativeMessages extends NLS { + static { + NLS.initializeMessages(BuildNativeMessages.class.getName(), BuildNativeMessages.class); + } + + public static String CANNOT_CREATE_BUILD_TARGET; + public static String CANNOT_FIND_CPROJECT; + public static String CANNOT_GET_ARTIFACT_TYPE; + public static String CANNOT_GET_PLATFORM_ID; + public static String CANNOT_GET_TOOLCHAIN_ID; + public static String CANNOT_MAKE_BUILD_COMMAND; + public static String CANNOT_READ_CPROJECT; + public static String CANNOT_SET_BUILD_TARGET; + public static String CANNOT_SET_OPTIONS; + public static String CANNOT_WRITE_CPROJECT; + + public static String INVALID_CONFIGURATION; + public static String INVALID_ARG; + public static String INVALID_ARGS; + + public static String NO_CONFIG_BUILD_ARCHITECTURE; + public static String NO_CONFIG_BUILD_CONFIGURATION; + public static String NO_CONFIG_BUILD_COMPILER; + + public static String SUCCESS_SET_TARGET_INFO; +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.properties b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.properties new file mode 100644 index 0000000..afaa900 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/BuildNativeMessages.properties @@ -0,0 +1,20 @@ +CANNOT_CREATE_BUILD_TARGET = Can not create the build target. +CANNOT_FIND_CPROJECT = Can not find the .cproject file in {0}. +CANNOT_GET_ARTIFACT_TYPE = Can not get the artifact type. +CANNOT_GET_PLATFORM_ID = Can not get the platform id. +CANNOT_GET_TOOLCHAIN_ID = Can not get the toolchain id. +CANNOT_MAKE_BUILD_COMMAND = Can not make the build command. +CANNOT_READ_CPROJECT = Can not read the .cproject file. +CANNOT_SET_BUILD_TARGET = Can not set the build target information. +CANNOT_SET_OPTIONS = Can not set the options. +CANNOT_WRITE_CPROJECT = Can not write the build target information. + +INVALID_CONFIGURATION = The {0} is an invalid configuration\nTry to use one of {1} +INVALID_ARG = The {0} is an invalid argument\nTry to use one of {1} +INVALID_ARGS = There are invalid arguments. + +NO_CONFIG_BUILD_ARCHITECTURE = There is no architecture argument. +NO_CONFIG_BUILD_CONFIGURATION = There is no configuration argument. +NO_CONFIG_BUILD_COMPILER = There is no compiler argument. + +SUCCESS_SET_TARGET_INFO = Success to write the build target information \ No newline at end of file diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java index 8ac57c7..5cab5f6 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java @@ -36,17 +36,14 @@ import org.tizen.ncli.ide.subcommands.BuildNativeCLICommand; public class BuildNativeCLI extends AbstractCLI { private Logger log = LoggerFactory.getLogger(getClass()); - @Option(name = "--platform", usage = "Platform id when create new build target") - private String platform; + @Option(name = "--arch", depends="--compiler", metaVar = "x86 | arm", usage = "architecture type") + private String architecture; - @Option(name = "--toolchain", usage = "Toolchain id when create new build target") - private String toolchain; + @Option(name = "--compiler", depends="--arch", metaVar = "gcc | llvm", usage = "compiler type") + private String compiler; - @Option(name = "--build-target", required = true, usage = "") - private String buildTarget; - - @Option(name = "--build-configuration", required = true, usage = "") - private String buildConfiguration; + @Option(name = "--configuration", metaVar = "Debug | Release | Dynamic Analyzer", usage = "") + private String configuration; @Option(name = "--predefine-option", usage = "") private String predefineOption; @@ -64,10 +61,9 @@ public class BuildNativeCLI extends AbstractCLI { command.setWorkingDir(workingDir); command.setCurrentWorkspacePath(currentWorkspacePath); - command.setPlatform(platform); - command.setToolchain(toolchain); - command.setBuildTarget(buildTarget); - command.setBuildConfiguration(buildConfiguration); + command.setArchitecture(architecture); + command.setCompiler(compiler); + command.setConfiguration(configuration); command.setPredefineOption(predefineOption); BuildNative runCommand = command.runCommand(); diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNativeCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNativeCLICommand.java index 72bbf91..abfed7a 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNativeCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNativeCLICommand.java @@ -1,9 +1,11 @@ package org.tizen.ncli.ide.subcommands; import java.io.File; +import java.io.IOException; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; @@ -12,89 +14,244 @@ import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.eclipse.osgi.util.NLS; import org.tizen.common.core.application.InstallPathConfig; import org.tizen.common.util.HostUtil; import org.tizen.common.util.StringUtil; import org.tizen.nativecommon.build.CommonConfigurationManager; import org.tizen.nativecommon.build.SmartBuildInterface; import org.tizen.nativecommon.build.exception.SBIException; +import org.tizen.ncli.ide.config.ConfigConstant; +import org.tizen.ncli.ide.config.Configuration; +import org.tizen.ncli.ide.messages.BuildNativeMessages; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; public class BuildNativeCLICommand extends AbstractSubCommand { - private String platformId; - private String toolchainId; - private String buildConfiguration; - private String predefineOption; + + private Configuration config; + private String predefineOption; + private String architecture; + private String compiler; + private String configuration; + private SmartBuildInterface sbi = null; private String idePath = null; private String importPath = null; private String buildPath = null; - private String buildTarget = null; private String dataPath = null; + + private String toolchainId = null; + private String platformId = null; + private String targetId = null; + private String HEADLESS_CMD = "%s/eclipse -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild " + "-import %s " + "-build %s " + "-data %s " + "-Ea CLI=true " + "-T org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler sbi.gnu.cpp.compiler.option=%s"; + + private enum BuildNativeOption { + architecture(new String[]{"x86", "arm"}, BuildNativeMessages.NO_CONFIG_BUILD_ARCHITECTURE), + compiler(new String[]{"gcc", "llvm"}, BuildNativeMessages.NO_CONFIG_BUILD_COMPILER), + configuration(new String[]{"Debug", "Release", "Dynamic Analyzer"}, BuildNativeMessages.NO_CONFIG_BUILD_CONFIGURATION); + + private String input; + private String[] candidates; + private String noValueMessage; + + private BuildNativeOption(String[] candidates, String noValueMessage) { + this.candidates = candidates; + this.noValueMessage = noValueMessage; + } + + public void setInput(String option) { + this.input = option; + } + + public String getInput() { + return input; + } + + public String[] getCandidates() { + return candidates; + } + + public String getNoValueMessage() { + return noValueMessage; + } + } + //"emulator" means "x86" and "device" means "arm" at this time. + //use CommonConfigurationManager.ARCHGROUP_X86 or CommonConfigurationManager.ARCHGROUP_ARM later. + private String [][] rootstrapByArch = { + {BuildNativeOption.architecture.getCandidates()[0], "emulator"}, + {BuildNativeOption.architecture.getCandidates()[1], "device"} + }; + + private final String[][] cprojectCriteria = { + { "C++ Compiler", "sbi.gnu.cpp.compiler.option" }, + { "C Compiler", "sbi.gnu.c.compiler.option" } + }; + + public BuildNativeCLICommand() { + config = new Configuration(); + } + private boolean setOptions() { + boolean result = true; + + BuildNativeOption[] options = BuildNativeOption.values(); + BuildNativeOption option = null; + String input = null; - private void setArgs() { + for(int i = 0; i < options.length; i++) { + option = options[i]; + input = option.getInput(); + if(input == null) { + System.out.println(option.getNoValueMessage()); + result = false; + break; + } + } + return result; + } + + private boolean validateOptions() { + boolean result = true; + + System.out.println("[ARCHITECTURE]: " + architecture); + System.out.println("[COMPILER]: " + compiler); + System.out.println("[CONFIGURATION]: " + configuration); + + BuildNativeOption[] options = BuildNativeOption.values(); + BuildNativeOption option = null; + String input = null; + String[] candidates = null; + + for(int i = 0; i < options.length; i++) { + result = false; + option = options[i]; + input = option.getInput(); + candidates = option.getCandidates(); + for(int j = 0; j < candidates.length; j++) { + if(input.equals(candidates[j])) { + result = true; + break; + } + } + if(!result) { + String suggestion = ""; + for(int j = 0; j < candidates.length; j++) { + suggestion = suggestion + " \"" + candidates[j] + "\""; + } + System.out.println(NLS.bind(BuildNativeMessages.INVALID_ARG, option, suggestion.trim())); + break; + } + } + return result; + } + + private boolean makeCommand() { + boolean result = true; sbi = SmartBuildInterface.getInstance(); + idePath = InstallPathConfig.getSDKPath() + File.separatorChar + "ide"; + if (workingDir == null) { importPath = currentWorkspacePath; } else { importPath = workingDir.getAbsolutePath(); } - - idePath = InstallPathConfig.getSDKPath() + File.separatorChar + "ide"; - - buildPath = StringUtil.getLastStringAfter(importPath, "/") + "/" + buildConfiguration; - File file = new File(buildPath); - if (!file.exists()) { - file.mkdir(); + + if(!isVaildImportPathAndConfiguration(importPath, configuration)) { + result = false; + } else { + buildPath = StringUtil.getLastStringAfter(importPath, "/") + "/" + configuration; + File file = new File(buildPath); + if (!file.exists()) { + file.mkdir(); + } + dataPath = importPath + "/../" + "headless"; + + if(!getBuildTarget()) { + log.debug(BuildNativeMessages.CANNOT_CREATE_BUILD_TARGET); + result = false; + } else { + System.out.println("[IMPORT PATH]: " + importPath); + System.out.println("[IDE PATH]: " + idePath); + System.out.println("[BUILD PATH]: " + buildPath); + System.out.println("[DATA PATH]: " + dataPath); + } } - dataPath = importPath + "/../" + "headless"; - - log.info("Import Path: " + importPath); - log.info("Ide Path: " + idePath); - log.info("Build Path: " + buildPath); - log.info("Data Path: " + dataPath); + return result; } - - private boolean isValidateArgs() { - if (!isVaildImportPathAndConfiguration(importPath, buildConfiguration)) { - return false; + + private boolean getBuildTarget() { + boolean result = false; + String archKey = null; + + for(int i = 0; i < rootstrapByArch.length; i++) { + if(rootstrapByArch[i][0].equals(architecture)) { + archKey = rootstrapByArch[i][1]; + break; + } } try { - // The build target must be created if there is no input for platform id and toolchain id - if (isValidPair(platformId, toolchainId)) { - createTarget(buildTarget, platformId, toolchainId); - } else { - // target is exist? no -> exit - boolean isExist = false; - List targets = sbi.getTargetList(); - for (String target : targets) { - if (buildTarget.equals(target)) { - isExist = true; - break; + List rootstrapList = sbi.getRootstrapList(); + for(String rootstrap: rootstrapList) { + if(rootstrap.contains(archKey)) { + if(rootstrap.contains("llvm")) { + continue; + } else { + platformId = rootstrap; + System.out.println("[PLATFORM ID]: " + platformId); } } - if (!isExist) { - System.out.println("[ERROR] There is no build target named " + buildTarget); - return false; + } + if(platformId != null) { + String artefactType = getArtifactType(importPath, configuration); + if(artefactType != null) { + System.out.println("[ARTEFACT TYPE]: " + artefactType); + List toolchainList = CommonConfigurationManager.getToolchainList(platformId, artefactType); + for(String toolchain: toolchainList) { + if(toolchain.contains(compiler)) { + toolchainId = toolchain; + System.out.println("[TOOLCHAIN ID]: " + toolchain); + } + } + if(toolchainId != null) { + targetId = platformId + "_" + toolchainId; + + boolean isExist = false; + List targets = sbi.getTargetList(); + for (String target : targets) { + if (targetId.equals(target)) { + isExist = true; + break; + } + } + if(!isExist) { + createTarget(targetId, platformId, toolchainId); + } + result = true; + } else { + log.debug(BuildNativeMessages.CANNOT_GET_TOOLCHAIN_ID); + } + } else { + log.debug(BuildNativeMessages.CANNOT_GET_ARTIFACT_TYPE); } + } else { + log.debug(BuildNativeMessages.CANNOT_GET_PLATFORM_ID); } } catch (SBIException e) { - System.out.println("[ERROR] Create the build target: " + e.getMessage()); - return false; + log.debug("SBIException: " + e.getMessage()); } - return true; + return result; } /* @@ -104,85 +261,102 @@ public class BuildNativeCLICommand extends AbstractSubCommand { */ @Override protected BuildNative call() { - setArgs(); - if (!isValidateArgs()) { - System.out.println("[ERROR] Build Failed - invalid arguments"); - return null; + if(setOptions()) { + if(validateOptions()) { + if(makeCommand()) { + String command = String.format(HEADLESS_CMD, idePath, importPath, buildPath, dataPath, targetId); + System.out.println(HostUtil.returnExecute(command)); + // TODO: how to know building project works well? + setBuildTargetInfo(importPath, configuration); + } else { + System.out.println(BuildNativeMessages.CANNOT_MAKE_BUILD_COMMAND); + } + } else { + System.out.println(BuildNativeMessages.INVALID_ARGS); + return null; + } + } else { + System.out.println(BuildNativeMessages.CANNOT_SET_OPTIONS); } - String command = String.format(HEADLESS_CMD, idePath, importPath, buildPath, dataPath, buildTarget); - System.out.println(HostUtil.returnExecute(command)); - //TODO: how to know building project works well? - setBuildTargetInfo(importPath, buildConfiguration); + return null; } private boolean isVaildImportPathAndConfiguration(String path, String configuration) { + boolean result = false; String cprojectPath = path + "/" + ".cproject"; File cprojectFile = new File(cprojectPath); - if (!cprojectFile.exists()) { - System.out.println("[ERROR] There is no .cproject file in " + path + "."); - return false; - } - String configurations = ""; - try { - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(cprojectFile); - NodeList list = doc.getElementsByTagName("configuration"); - for (int i = 0; i < list.getLength(); i++) { - NamedNodeMap attributeMap = list.item(i).getAttributes(); - String value = attributeMap.getNamedItem("name").getNodeValue(); - configurations = configurations + " " + value; - if (configuration.equals(value)) { - return true; + if (cprojectFile.exists()) { + String configurations = ""; + try { + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(cprojectFile); + NodeList list = doc.getElementsByTagName("configuration"); + for (int i = 0; i < list.getLength(); i++) { + NamedNodeMap attributeMap = list.item(i).getAttributes(); + String value = attributeMap.getNamedItem("name").getNodeValue(); + configurations = configurations + " " + value; + if (configuration.equals(value)) { + result = true; + } } + if(!result) { + System.out.println(NLS.bind(BuildNativeMessages.INVALID_CONFIGURATION, configuration, configurations.trim())); + } + } catch (Exception e) { + log.debug(BuildNativeMessages.CANNOT_READ_CPROJECT); } - } catch (Exception e) { - System.out.println("[ERROR] Validate the build configuration: " + e.getMessage()); - } - System.out.println("[ERROR] The " + configuration + " is a wrong build configuration."); - System.out.println("[ERROR] You can use one of [" + configurations.trim() + "]"); - return false; - } - - private boolean isValidPair(String rootstrapId, String toolchainId) throws SBIException { - if (rootstrapId == null || toolchainId == null) { - return false; + } else { + System.out.println(NLS.bind(BuildNativeMessages.CANNOT_FIND_CPROJECT, path)); } - return ((isSameArch(rootstrapId, toolchainId)) && (supportToolchainType(rootstrapId, toolchainId))); + return result; } private void createTarget(String targetId, String rootstrapId, String toolchainId) throws SBIException { sbi.create(targetId, rootstrapId, toolchainId); } - private boolean isSameArch(String rootstrapId, String toolchainId) throws SBIException { - boolean result = false; - String platformArch = getPlatformArch(rootstrapId); - String toolchainArch = getToolchainArch(toolchainId); - result = CommonConfigurationManager.isSameArchType(platformArch, toolchainArch); - if (!result) { - System.out.println("[ERROR] " + platformArch + " and " + toolchainArch + " are not the same architecutre type"); - } - return result; - } + private String getArtifactType(String path, String configuration) { + String type = null; + String cprojectPath = path + "/" + ".cproject"; + File cprojectFile = new File(cprojectPath); - private boolean supportToolchainType(String rootstrapId, String toolchainId) throws SBIException { - boolean result = false; - String toolchainType = sbi.getToolchainTypeFromToolchainID(toolchainId); - result = sbi.doesRootstrapSupportToolchainType(rootstrapId, toolchainType); - if (!result) { - System.out.println("[ERROR] " + rootstrapId + " and " + toolchainId + " has different support type"); + if (!cprojectFile.exists()) { + System.out.println(NLS.bind(BuildNativeMessages.CANNOT_FIND_CPROJECT, path)); + } else { + Document doc = null; + try { + doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(cprojectFile); + NodeList list = doc.getElementsByTagName("configuration"); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + NamedNodeMap attributeMap = node.getAttributes(); + String value = attributeMap.getNamedItem("name").getNodeValue(); + if (configuration.equals(value)) { + node = attributeMap.getNamedItem("buildArtefactType"); + if(node != null) { + type = node.getNodeValue(); + } + } + } + } catch (SAXException e) { + log.debug("SAXException: " + e.getMessage()); + } catch (IOException e) { + log.debug("IOException: " + e.getMessage()); + } catch (ParserConfigurationException e) { + log.debug("ParserConfigurationException: " + e.getMessage()); + } } - return result; + return type; } private boolean setBuildTargetInfo(String path, String configuration) { - boolean [] setResult = {false, false}; + boolean[] setResult = { false, false }; String cprojectPath = path + "/" + ".cproject"; File cprojectFile = new File(cprojectPath); if (!cprojectFile.exists()) { - System.out.println("[ERROR] There is no .cproject file in " + path); + System.out.println(NLS.bind(BuildNativeMessages.CANNOT_FIND_CPROJECT, path)); return false; } Document doc = null; @@ -192,86 +366,91 @@ public class BuildNativeCLICommand extends AbstractSubCommand { for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); NamedNodeMap attributeMap = node.getAttributes(); - String value = attributeMap.getNamedItem("name").getNodeValue(); - - String[][] criteria = { - {"C++ Compiler", "sbi.gnu.cpp.compiler.option"}, - {"C Compiler", "sbi.gnu.c.compiler.option"} - }; - int index = 0; - Node toolNode = null; - if(configuration.equals(value)) { - while(index < 2) { - if(toolNode == null) { - toolNode = findToolNode(node, criteria[index][0]); - } - if(node != null) { - setResult[index] = setTargetInfo(toolNode, "option", criteria[index][1], buildTarget); - if(setResult[index] == false) { - System.out.println("[ERROR] Could not set the build target info: " +criteria[index][1]); - return false; + Node nameNode = attributeMap.getNamedItem("name"); + if(nameNode != null) { + String value = nameNode.getNodeValue(); + + int index = 0; + Node toolNode = null; + if (configuration.equals(value)) { + while (index < 2) { + if (toolNode == null) { + toolNode = findToolNode(node, cprojectCriteria[index][0]); } - node = toolNode; - index++; - } - while(true) { - toolNode = toolNode.getNextSibling(); - if(toolNode.hasChildNodes()) { - break; + if (node != null) { + setResult[index] = setTargetInfo(toolNode, "option", cprojectCriteria[index][1], targetId); + if (setResult[index] == false) { + log.debug(BuildNativeMessages.CANNOT_SET_BUILD_TARGET + ": " + cprojectCriteria[index][1]); + System.out.println(BuildNativeMessages.CANNOT_SET_BUILD_TARGET); + return false; + } + node = toolNode; + index++; + } + while (true) { + toolNode = toolNode.getNextSibling(); + if (toolNode.hasChildNodes()) { + break; + } } } } } } - } catch (Exception e) { - System.out.println("[ERROR] Could not set the build target info: " + e.getMessage()); - return false; + } catch (SAXException e) { + log.debug("SAXException: " + e.getMessage()); + } catch (IOException e) { + log.debug("IOException: " + e.getMessage()); + } catch (ParserConfigurationException e) { + log.debug("ParserConfigurationException: " + e.getMessage()); } - boolean result = setResult[0]&&setResult[1]; - if(result) { - try { - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - DOMSource source = new DOMSource(doc); - StreamResult streamResult = new StreamResult(cprojectFile); - transformer.transform(source, streamResult); - } catch (TransformerConfigurationException e) { - System.out.println("[ERROR] Could not transform to .cproject file"); - log.info("[ERROR] TransformerConfigurationException: " + e.getMessage()); - } catch (TransformerFactoryConfigurationError e) { - System.out.println("[ERROR] Could not transform to .cproject file"); - log.info("[ERROR] TransformerFactoryConfigurationError: " + e.getMessage()); - } catch (TransformerException e) { - System.out.println("[ERROR] Could not transform to .cproject file"); - log.info("[ERROR] TransformerException: " + e.getMessage()); - } + boolean result = false; + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + DOMSource source = new DOMSource(doc); + StreamResult streamResult = new StreamResult(cprojectFile); + transformer.transform(source, streamResult); + result = true; + } catch (TransformerConfigurationException e) { + log.debug("TransformerConfigurationException: " + e.getMessage()); + } catch (TransformerFactoryConfigurationError e) { + log.debug("TransformerFactoryConfigurationError: " + e.getMessage()); + } catch (TransformerException e) { + log.debug("TransformerException: " + e.getMessage()); + } + if(!result) { + System.out.println(BuildNativeMessages.CANNOT_WRITE_CPROJECT); } return result; } - + private Node findToolNode(Node node, String name) { Node toolNode = null; NodeList children = null; - if(node.hasChildNodes()) { + if (node.hasChildNodes()) { children = node.getChildNodes(); } else { return null; } NamedNodeMap attributeMap = null; String value = null; - + int i = 0; - while( i < children.getLength()) { + while (i < children.getLength()) { node = children.item(i); if ("tool".equals(node.getNodeName())) { attributeMap = node.getAttributes(); - value = attributeMap.getNamedItem("name").getNodeValue(); - if(name.equals(value)) { - return node; + Node nameNode = attributeMap.getNamedItem("name"); + if(nameNode != null) { + value = nameNode.getNodeValue(); + if (name.equals(value)) { + return node; + } } } else { toolNode = findToolNode(node, name); } - if(toolNode == null) { + if (toolNode == null) { i++; } else { break; @@ -279,40 +458,47 @@ public class BuildNativeCLICommand extends AbstractSubCommand { } return toolNode; } - + private boolean setTargetInfo(Node node, String tag, String superClass, String target) { boolean found = false; NodeList children = null; - if(node.hasChildNodes()) { + if (node.hasChildNodes()) { children = node.getChildNodes(); } else { return false; } NamedNodeMap attributeMap = null; String value = null; - + int i = 0; - while( i < children.getLength()) { + while (i < children.getLength()) { node = children.item(i); if ("option".equals(node.getNodeName())) { attributeMap = node.getAttributes(); - value = attributeMap.getNamedItem("superClass").getNodeValue(); - if(superClass.equals(value)) { - NodeList list = node.getChildNodes(); - for(int j = 0; j < list.getLength(); j++) { - node = list.item(j); - if("listOptionValue".equals(node.getNodeName())) { - attributeMap = node.getAttributes(); - node.getAttributes().getNamedItem("value").setNodeValue(buildTarget); - break; + Node superclassNode = attributeMap.getNamedItem("superClass"); + if(superclassNode != null) { + value = superclassNode.getNodeValue(); + if (superClass.equals(value)) { + NodeList list = node.getChildNodes(); + for (int j = 0; j < list.getLength(); j++) { + node = list.item(j); + if ("listOptionValue".equals(node.getNodeName())) { + attributeMap = node.getAttributes(); + Node valueNode = attributeMap.getNamedItem("value"); + if(valueNode != null) { + valueNode.setNodeValue(targetId); + log.debug(BuildNativeMessages.SUCCESS_SET_TARGET_INFO); + break; + } + } } + return true; } - return true; } } else { found = setTargetInfo(node, tag, superClass, target); } - if(found == false) { + if (found == false) { i++; } else { break; @@ -321,28 +507,28 @@ public class BuildNativeCLICommand extends AbstractSubCommand { return found; } - private String getPlatformArch(String rootstrapId) throws SBIException { - return sbi.getArchitectureFromRootstrapID(rootstrapId); - } - - private String getToolchainArch(String toolchainId) throws SBIException { - return sbi.getArchitectureFromToolchainID(toolchainId); - } - - public void setPlatform(String platform) { - this.platformId = platform; - } - - public void setToolchain(String toolchain) { - this.toolchainId = toolchain; + public void setArchitecture(String architecture) { + if(architecture == null) { + architecture = config.getValue(ConfigConstant.DEFAULT_BUILD_ARCHITECTURE); + } + BuildNativeOption.architecture.setInput(architecture); + this.architecture = BuildNativeOption.architecture.getInput(); } - public void setBuildTarget(String buildTarget) { - this.buildTarget = buildTarget; + public void setCompiler(String compiler) { + if(compiler == null) { + compiler = config.getValue(ConfigConstant.DEFAULT_BUILD_COMPILER); + } + BuildNativeOption.compiler.setInput(compiler); + this.compiler = BuildNativeOption.compiler.getInput(); } - public void setBuildConfiguration(String buildConfiguration) { - this.buildConfiguration = buildConfiguration; + public void setConfiguration(String configuration) { + if(configuration == null) { + configuration = config.getValue(ConfigConstant.DEFAULT_BUILD_CONFIGURATION); + } + BuildNativeOption.configuration.setInput(configuration); + this.configuration = BuildNativeOption.configuration.getInput(); } public void setPredefineOption(String predefineOption) { -- 2.7.4