From 5ed817e60522a787e92fa2c133e3b8e00296fc6e Mon Sep 17 00:00:00 2001 From: "gyeongmin.ju" Date: Mon, 4 Sep 2017 19:03:00 +0900 Subject: [PATCH] RT: apply meta Signed-off-by: gyeongmin.ju --- resources/scripts/.buildSpec.xml | 47 +++ resources/scripts/.debugSpec.xml | 42 +++ resources/scripts/.flashSpec.xml | 25 ++ resources/scripts/build.xml | 18 -- resources/scripts/debug.xml | 24 -- .../tizen/rt/product/meta/model/debug/Execute.java | 18 ++ .../tizen/rt/product/meta/model/flash/Flashes.java | 68 ----- .../rt/product/meta/model/flash/ObjectFactory.java | 7 - .../tizen/rt/product/meta/util/MetaModelUtil.java | 18 +- .../tizen/rt/product/meta/model/LoadModelTest.java | 4 +- rt-ide/tizen.rt.product.plugin/plugin.xml | 2 - .../org/tizen/rt/ide/build/BuildScriptData.java | 186 ------------ .../rt/ide/build/ui/BuildConfigureDialog.java | 2 +- .../rt/ide/build/ui/BuildEnvSettingDialog.java | 2 +- .../org/tizen/rt/ide/commands/BuildCommand.java | 78 +++-- .../rt/ide/commands/BuildConfigureCommand.java | 59 ++-- .../rt/ide/commands/BuildEnvSettingCommand.java | 2 +- .../org/tizen/rt/ide/commands/CleanCommand.java | 41 ++- .../org/tizen/rt/ide/commands/CommandManager.java | 26 +- .../org/tizen/rt/ide/commands/FlashCommand.java | 146 +++++++-- .../ide/{build => commands/model}/BuildOption.java | 2 +- .../rt/ide/commands/model/BuildScriptData.java | 230 +++++++++++++++ .../model}/BuildSettingData.java | 11 +- .../rt/ide/commands/model/DebugScriptData.java | 296 +++++++++++++++++++ .../ide/{flash => commands/model}/FlashOption.java | 2 +- .../rt/ide/commands/model/FlashScriptData.java | 264 +++++++++++++++++ .../src/org/tizen/rt/ide/flash/FlashWizard.java | 117 -------- .../org/tizen/rt/ide/flash/FlashWizardDialog.java | 107 ------- .../FlashOptionDialog.java} | 132 ++++----- .../org/tizen/rt/ide/handlers/FlashHandler.java | 109 +------ .../org/tizen/rt/ide/launch/LaunchShortcut.java | 325 +++++++-------------- .../src/org/tizen/rt/ide/meta/MetaManager.java | 6 +- 32 files changed, 1376 insertions(+), 1040 deletions(-) create mode 100644 resources/scripts/.buildSpec.xml create mode 100644 resources/scripts/.debugSpec.xml create mode 100644 resources/scripts/.flashSpec.xml delete mode 100644 resources/scripts/build.xml delete mode 100644 resources/scripts/debug.xml delete mode 100644 rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/Flashes.java delete mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildScriptData.java rename rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/{build => commands/model}/BuildOption.java (99%) create mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildScriptData.java rename rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/{build => commands/model}/BuildSettingData.java (95%) create mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/DebugScriptData.java rename rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/{flash => commands/model}/FlashOption.java (96%) create mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/FlashScriptData.java delete mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/flash/FlashWizard.java delete mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/flash/FlashWizardDialog.java rename rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/flash/{FlashWizardPage.java => ui/FlashOptionDialog.java} (54%) diff --git a/resources/scripts/.buildSpec.xml b/resources/scripts/.buildSpec.xml new file mode 100644 index 0000000..a337160 --- /dev/null +++ b/resources/scripts/.buildSpec.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/scripts/.debugSpec.xml b/resources/scripts/.debugSpec.xml new file mode 100644 index 0000000..298cabd --- /dev/null +++ b/resources/scripts/.debugSpec.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/scripts/.flashSpec.xml b/resources/scripts/.flashSpec.xml new file mode 100644 index 0000000..6ffdb58 --- /dev/null +++ b/resources/scripts/.flashSpec.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + diff --git a/resources/scripts/build.xml b/resources/scripts/build.xml deleted file mode 100644 index 42b592d..0000000 --- a/resources/scripts/build.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - diff --git a/resources/scripts/debug.xml b/resources/scripts/debug.xml deleted file mode 100644 index ffe42bb..0000000 --- a/resources/scripts/debug.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/debug/Execute.java b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/debug/Execute.java index 2e094e6..22e53df 100644 --- a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/debug/Execute.java +++ b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/debug/Execute.java @@ -64,6 +64,8 @@ public class Execute { protected Params params; @XmlAttribute(name = "name", required = true) protected String name; + @XmlAttribute(name = "path", required = false) + protected String path; @XmlAttribute(name = "command", required = true) protected String command; @XmlAttribute(name = "os", required = true) @@ -120,6 +122,22 @@ public class Execute { } /** + * Gets the value of the path property. + * @return possible object is {@link String } + */ + public String getPath() { + return path; + } + + /** + * Sets the value of the path property. + * @param value allowed object is {@link String } + */ + public void setPath(String value) { + this.path = value; + } + + /** * Gets the value of the os property. * @return possible object is {@link String } */ diff --git a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/Flashes.java b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/Flashes.java deleted file mode 100644 index fcf634f..0000000 --- a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/Flashes.java +++ /dev/null @@ -1,68 +0,0 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2017.06.12 at 05:10:24 PM KST -// - -package org.tizen.rt.product.meta.model.flash; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - *

- * Java class for anonymous complex type. - *

- * The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element ref="{}flash" maxOccurs="unbounded"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "flash" -}) -@XmlRootElement(name = "flashes") -public class Flashes { - - @XmlElement(required = true) - protected List flash; - - /** - * Gets the value of the flash property. - *

- * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object. This is why there is - * not a set method for the flash property. - *

- * For example, to add a new item, do as follows: - * - *

-     * getFlash().add(newItem);
-     * 
- *

- * Objects of the following type(s) are allowed in the list {@link Flash } - */ - public List getFlash() { - if (flash == null) { - flash = new ArrayList(); - } - return this.flash; - } - -} diff --git a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/ObjectFactory.java b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/ObjectFactory.java index cf9f438..ced5190 100644 --- a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/ObjectFactory.java +++ b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/model/flash/ObjectFactory.java @@ -51,13 +51,6 @@ public class ObjectFactory { } /** - * Create an instance of {@link Flashes } - */ - public Flashes createFlashes() { - return new Flashes(); - } - - /** * Create an instance of {@link Flash } */ public Flash createFlash() { diff --git a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/util/MetaModelUtil.java b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/util/MetaModelUtil.java index d5f5995..7e100e0 100755 --- a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/util/MetaModelUtil.java +++ b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/util/MetaModelUtil.java @@ -54,7 +54,7 @@ import org.tizen.rt.product.meta.IModelConstants; import org.tizen.rt.product.meta.RtMetaPlugin; import org.tizen.rt.product.meta.model.build.Build; import org.tizen.rt.product.meta.model.debug.Debugs; -import org.tizen.rt.product.meta.model.flash.Flashes; +import org.tizen.rt.product.meta.model.flash.Flash; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -90,9 +90,9 @@ public class MetaModelUtil { * @throws IOException * @throws JAXBException */ - public static Flashes copyDefaultFlashModelAndLoad(String destination) throws IOException, JAXBException { + public static Flash copyDefaultFlashModelAndLoad(String destination) throws IOException, JAXBException { InputStream source = RtMetaPlugin.class.getResourceAsStream("resources" + File.separator + IModelConstants.FILE_NAME_FLASH_META_XML); - return copyDefaultModelAndLoad(Flashes.class, source, destination); + return copyDefaultModelAndLoad(Flash.class, source, destination); } /** @@ -182,8 +182,8 @@ public class MetaModelUtil { * @return {@link Flashes} model instance * @throws JAXBException */ - public static Flashes loadFlashModel(File flashXmlFile) throws JAXBException { - return loadModel(Flashes.class, flashXmlFile); + public static Flash loadFlashModel(File flashXmlFile) throws JAXBException { + return loadModel(Flash.class, flashXmlFile); } /** @@ -191,8 +191,8 @@ public class MetaModelUtil { * @return {@link Flashes} model instance * @throws JAXBException */ - public static Flashes loadFlashModel(InputStream flashXmlFile) throws JAXBException { - return loadModel(Flashes.class, flashXmlFile); + public static Flash loadFlashModel(InputStream flashXmlFile) throws JAXBException { + return loadModel(Flash.class, flashXmlFile); } /** @@ -200,8 +200,8 @@ public class MetaModelUtil { * @return xml strings of marshaled flash model * @throws JAXBException */ - public static String showFlashModel(Flashes flashModel) throws JAXBException { - return showModel(Flashes.class, flashModel); + public static String showFlashModel(Flash flashModel) throws JAXBException { + return showModel(Flash.class, flashModel); } /** diff --git a/rt-ide/tizen.rt.product.meta/test/src/org/tizen/rt/product/meta/model/LoadModelTest.java b/rt-ide/tizen.rt.product.meta/test/src/org/tizen/rt/product/meta/model/LoadModelTest.java index cf41841..25db5f7 100755 --- a/rt-ide/tizen.rt.product.meta/test/src/org/tizen/rt/product/meta/model/LoadModelTest.java +++ b/rt-ide/tizen.rt.product.meta/test/src/org/tizen/rt/product/meta/model/LoadModelTest.java @@ -39,7 +39,7 @@ import org.tizen.rt.product.meta.IModelConstants; import org.tizen.rt.product.meta.RtMetaPlugin; import org.tizen.rt.product.meta.model.build.Build; import org.tizen.rt.product.meta.model.debug.Debugs; -import org.tizen.rt.product.meta.model.flash.Flashes; +import org.tizen.rt.product.meta.model.flash.Flash; import org.tizen.rt.product.meta.util.MetaModelUtil; import org.xml.sax.SAXException; @@ -63,7 +63,7 @@ public class LoadModelTest { @Test public void flashModelTest() throws JAXBException { InputStream is = RtMetaPlugin.class.getResourceAsStream("resources/flashSpec.xml"); - Flashes model = MetaModelUtil.loadFlashModel(is); + Flash model = MetaModelUtil.loadFlashModel(is); Assert.assertNotNull(model); String result = MetaModelUtil.showFlashModel(model); diff --git a/rt-ide/tizen.rt.product.plugin/plugin.xml b/rt-ide/tizen.rt.product.plugin/plugin.xml index 017d4f7..dd953e0 100644 --- a/rt-ide/tizen.rt.product.plugin/plugin.xml +++ b/rt-ide/tizen.rt.product.plugin/plugin.xml @@ -855,7 +855,6 @@ - diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildScriptData.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildScriptData.java deleted file mode 100644 index 144332b..0000000 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildScriptData.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Common - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * Daeryong Park - * Hyeongseok Heo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - * - S-Core Co., Ltd. - * - */ -package org.tizen.rt.ide.build; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import org.tizen.rt.ide.console.ConsoleManager; -import org.tizen.rt.ide.util.MacroUtil; -import org.tizen.rt.ide.util.ProcUtil; -import org.tizen.rt.ide.util.XMLUtil; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * @since 2017. 5. 18. - * @author Daeryong Park {@literal } - */ -public class BuildScriptData { - - private static class BuildScript { - public String cmdStr; - public String curDir; - public boolean isShellCmd; - public String shell; - - /** - * @param cmdStr command string - * @param curDir current directory - * @param isShellCmd is shell command - * @param shell shell name to use like "/bin/bash" - */ - public BuildScript(String cmdStr, String curDir, boolean isShellCmd, String shell) { - this.cmdStr = cmdStr; - this.curDir = curDir; - this.isShellCmd = isShellCmd; - this.shell = shell; - } - - /** - * @return the cmdStr - */ - public String getCmdStr() { - return cmdStr; - } - - /** - * @return the curDir - */ - public String getCurDir() { - return curDir; - } - - /** - * @return the isShellCmd - */ - public boolean isShellCmd() { - return isShellCmd; - } - - /** - * @return the shell - */ - public String getShell() { - return shell; - } - } - - private Map macros = new HashMap(); - private Map scripts; - private ConsoleManager consoleManager; - - public BuildScriptData(ConsoleManager consoleManager) { - this.consoleManager = consoleManager; - } - - private Map getBuildScripts(File buildScriptFile) { - Document doc = XMLUtil.readXML(buildScriptFile); - - NodeList commands = XMLUtil.getDOMNodes(doc.getDocumentElement(), "/sbi/build/command"); - if (commands == null || commands.getLength() <= 0) { - return null; - } - - Map scripts = new HashMap(); - - int len = commands.getLength(); - for (int i = 0; i < len; i++) { - Node node = commands.item(i); - if (node instanceof Element) { - Element elm = (Element) node; - - String name = elm.getAttribute("name"); - String cmd = elm.getAttribute("command"); - String curdir = elm.getAttribute("curdir"); - String shellcmd = elm.getAttribute("shellcmd"); - boolean isShellCmd = Boolean.valueOf(shellcmd); - String shell = elm.getAttribute("shell"); - - scripts.put(name, new BuildScript(cmd, curdir, isShellCmd, shell)); - } - } - - return scripts; - } - - public String getBuildScriptFileName() { - return "build.xml"; - } - - public void addMacro(String name, String value) { - macros.put(name, value); - } - - public void consolePrintln(String str) { - if(consoleManager != null) { - consoleManager.println(str); - } - } - - public int load(File buildScriptFile) { - consolePrintln("Build project using " + buildScriptFile); - scripts = getBuildScripts(buildScriptFile); - - return (scripts != null)? 0 : 1; - } - - public int load(String buildScriptFilename) { - return load(new File(buildScriptFilename)); - } - - public int doCommand(String buildCmdName, Map env) { - ProcessBuilder pb = ProcUtil.genProcessBuilder(null); - - BuildScript script = scripts.get(buildCmdName); - if (script == null) { - consolePrintln("Cannot found build command : " + buildCmdName); - return 1; - } - - if(env != null) { - pb.environment().putAll(env); - } - - String cmdStr = MacroUtil.processMacro(script.cmdStr, macros); - if(cmdStr == null || cmdStr.isEmpty()) { - return 1; - } - String curDir = MacroUtil.processMacro(script.curDir, macros); - - return ProcUtil.executeProcess(pb, new String[] { cmdStr }, script.isShellCmd, script.shell, - curDir, consoleManager, null); - - } - - public int doCommand(String buildCmdName) { - return doCommand(buildCmdName, null); - } - -} diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildConfigureDialog.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildConfigureDialog.java index f684fd6..a4ad6f2 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildConfigureDialog.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildConfigureDialog.java @@ -21,7 +21,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.build.BuildOption; +import org.tizen.rt.ide.commands.model.BuildOption; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.widgets.Label; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildEnvSettingDialog.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildEnvSettingDialog.java index 44351dd..98ef558 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildEnvSettingDialog.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildEnvSettingDialog.java @@ -19,7 +19,7 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.build.BuildSettingData; +import org.tizen.rt.ide.commands.model.BuildSettingData; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildCommand.java index 4f046c2..d1da939 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildCommand.java @@ -41,10 +41,10 @@ import org.eclipse.swt.widgets.Display; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.build.BuildOption; -import org.tizen.rt.ide.build.BuildScriptData; -import org.tizen.rt.ide.build.BuildSettingData; import org.tizen.rt.ide.build.builder.RtBuilder; +import org.tizen.rt.ide.commands.model.BuildOption; +import org.tizen.rt.ide.commands.model.BuildScriptData; +import org.tizen.rt.ide.commands.model.BuildSettingData; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; import org.tizen.rt.ide.util.SDKUtil; @@ -64,6 +64,14 @@ public class BuildCommand { private static final String PROP_COMMENT_DEBUG_INFO = "TinyARA Debug information"; //$NON-NLS-1$ + protected String getScriptFileName() { + return ".buildSpec.xml"; //$NON-NLS-1$ + } + + protected String getSettingFileName() { + return ".buildSetting.xml"; //$NON-NLS-1$ + } + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { String activeProjectPath = project.getLocation().toString(); @@ -71,40 +79,46 @@ public class BuildCommand { String homePath = activeProjectPath; String outputPath = activeProjectPath + File.separator + PATH_LINUX_BUILD_OUTPUT; - File buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" - + File.separator + "build.xml"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (!buildScriptFile.exists()) { - buildScriptFile = new File(activeProjectPath, "build.xml"); - if (!buildScriptFile.exists()) { - if (consoleManager != null) { - consoleManager.println("Can not found xml file of build spec."); //$NON-NLS-1$ - } - return 1; - } - } - - BuildScriptData buildScript = new BuildScriptData(consoleManager); - buildScript.load(buildScriptFile); - - buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ - - String osDir = project.getLocation().toString() + File.separator + "os"; + String osDir = project.getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ BuildSettingData setting = new BuildSettingData(); String toolchainPath = null; BuildOption buildOption = null; - if (setting.load(new File(osDir, ".buildSetting"))) { + if (setting.load(new File(osDir, getSettingFileName()))) { toolchainPath = setting.getToolchainPath(); - if (toolchainPath != null) { - buildScript.addMacro("TOOLCHAIN", setting.getToolchainPath()); - } - buildOption = setting.getBuildOption(); - if (buildOption != null) { - buildScript.addMacro("BOARD", buildOption.getBoard()); - buildScript.addMacro("BUILD_OPTION", buildOption.getBuildOption()); + } + + File buildScriptFile = null; + if (buildOption != null) { + buildScriptFile = new File(activeProjectPath, "build" + File.separator + "configs" + File.separator + buildOption.getBoard() + File.separator + getScriptFileName()); // $NON-NLS-1$ // $NON-NLS-2$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(activeProjectPath, getScriptFileName()); // $NON-NLS-1$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + + File.separator + getScriptFileName()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + if (buildScriptFile == null || !buildScriptFile.exists()) { + if (consoleManager != null) { + consoleManager.println("Can not found xml file of build spec."); } + return 1; + } + + BuildScriptData buildScript = new BuildScriptData(consoleManager); + buildScript.load(buildScriptFile); + + buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ + if (buildOption != null) { + buildScript.addMacro("BOARD", buildOption.getBoard()); + buildScript.addMacro("BUILD_OPTION", buildOption.getBuildOption()); + } + if (toolchainPath != null) { + buildScript.addMacro("TOOLCHAIN", setting.getToolchainPath()); } String buildCmdName; @@ -125,7 +139,7 @@ public class BuildCommand { buildInfo.setProperty(PROP_NAME_BOARD, setting.getBuildOption().getBoard()); buildInfo.setProperty(PROP_NAME_OPTION, setting.getBuildOption().getBuildOption()); try { - buildInfo.store(new FileWriter(new File(outputPath, FILE_NAME_BUILD_INFO)), PROP_COMMENT_DEBUG_INFO); // $NON-NLS-1$ + buildInfo.store(new FileWriter(new File(outputPath, FILE_NAME_BUILD_INFO)), PROP_COMMENT_DEBUG_INFO); } catch (IOException e) { logger.error(e.getMessage()); } @@ -135,9 +149,9 @@ public class BuildCommand { } public Object execute(IProject project, ConsoleManager consoleManager) throws ExecutionException { - String osDir = project.getLocation().toString() + File.separator + "os"; + String osDir = project.getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ - if (!new File(osDir, ".config").exists()) { + if (!new File(osDir, ".config").exists()) { //$NON-NLS-1$ MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); //$NON-NLS-1$ return null; } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildConfigureCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildConfigureCommand.java index 2fb0bdd..79cbf63 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildConfigureCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildConfigureCommand.java @@ -33,10 +33,10 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.widgets.Shell; -import org.tizen.rt.ide.build.BuildOption; -import org.tizen.rt.ide.build.BuildScriptData; -import org.tizen.rt.ide.build.BuildSettingData; import org.tizen.rt.ide.build.ui.BuildConfigureDialog; +import org.tizen.rt.ide.commands.model.BuildOption; +import org.tizen.rt.ide.commands.model.BuildScriptData; +import org.tizen.rt.ide.commands.model.BuildSettingData; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; import org.tizen.rt.ide.util.SDKUtil; @@ -46,6 +46,14 @@ import org.tizen.rt.ide.util.ViewUtil; * @author Gyeongmin Ju{@literal } (S-Core) */ public class BuildConfigureCommand { + protected String getScriptFileName() { + return ".buildSpec.xml"; //$NON-NLS-1$ + } + + protected String getSettingFileName() { + return ".buildSetting.xml"; //$NON-NLS-1$ + } + protected int configure(IProject project, BuildOption buildOption, ConsoleManager consoleManager, IProgressMonitor monitor) { if (buildOption == null) { @@ -60,40 +68,49 @@ public class BuildConfigureCommand { consoleManager.println("Build Option : " + buildOption.getBuildOption()); //$NON-NLS-1$ } - String activeProjectPath = project.getLocation().toString(); - String sdkPath = SDKUtil.getSdkPath(); - buildOption.getBoard(); - File buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" - + File.separator + "build.xml"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (!buildScriptFile.exists()) { - buildScriptFile = new File(activeProjectPath, "build.xml"); - if (!buildScriptFile.exists()) { - if (consoleManager != null) { - consoleManager.println("Can not found xml file of build spec."); //$NON-NLS-1$ - } - return 1; + String activeProjectPath = project.getLocation().toString(); + + File buildScriptFile = null; + if (buildOption != null) { + buildScriptFile = new File(activeProjectPath, "build" + File.separator + "configs" + File.separator + buildOption.getBoard() + File.separator + getScriptFileName()); // $NON-NLS-1$ // $NON-NLS-2$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(activeProjectPath, getScriptFileName()); // $NON-NLS-1$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + + File.separator + getScriptFileName()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + if (buildScriptFile == null || !buildScriptFile.exists()) { + if (consoleManager != null) { + consoleManager.println("Can not found xml file of build spec."); } + return 1; } BuildScriptData buildScript = new BuildScriptData(consoleManager); buildScript.load(buildScriptFile); buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ - buildScript.addMacro("BOARD", buildOption.getBoard()); - buildScript.addMacro("BUILD_OPTION", buildOption.getBuildOption()); + if (buildOption != null) { + buildScript.addMacro("BOARD", buildOption.getBoard()); //$NON-NLS-1$ + buildScript.addMacro("BUILD_OPTION", buildOption.getBuildOption()); //$NON-NLS-1$ + } - String buildCmdName = "config"; + BuildSettingData buildSetting = new BuildSettingData(); + buildSetting.load(new File(activeProjectPath, "os" + File.separator + getSettingFileName())); //$NON-NLS-1$ + + String buildCmdName = "config"; //$NON-NLS-1$ int result = buildScript.doCommand(buildCmdName); if (result != 0) { return result; } - BuildSettingData buildSetting = new BuildSettingData(); - buildSetting.load(new File(activeProjectPath, "os/.buildSetting")); buildSetting.setBuildOption(buildOption); - buildSetting.write(new File(activeProjectPath, "os/.buildSetting")); + buildSetting.write(new File(activeProjectPath, "os" + File.separator + getSettingFileName())); //$NON-NLS-1$ return result; } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildEnvSettingCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildEnvSettingCommand.java index 9aa9a7c..af94371 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildEnvSettingCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildEnvSettingCommand.java @@ -32,8 +32,8 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.widgets.Shell; -import org.tizen.rt.ide.build.BuildSettingData; import org.tizen.rt.ide.build.ui.BuildEnvSettingDialog; +import org.tizen.rt.ide.commands.model.BuildSettingData; import org.tizen.rt.ide.util.ResourceUtil; import org.tizen.rt.ide.util.ViewUtil; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CleanCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CleanCommand.java index c6575f2..1912f83 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CleanCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CleanCommand.java @@ -28,7 +28,9 @@ package org.tizen.rt.ide.commands; import java.io.File; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; -import org.tizen.rt.ide.build.BuildScriptData; +import org.tizen.rt.ide.commands.model.BuildOption; +import org.tizen.rt.ide.commands.model.BuildScriptData; +import org.tizen.rt.ide.commands.model.BuildSettingData; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.SDKUtil; @@ -41,23 +43,46 @@ public class CleanCommand { private static final String COMMAND_NAME_CLEAN = "clean"; //$NON-NLS-1$ private static final String COMMAND_NAME_DISTCLEAN = "distclean"; //$NON-NLS-1$ + protected String getScriptFileName() { + return ".buildSpec.xml"; //$NON-NLS-1$ + } + protected int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor, boolean useDistClean) { String activeProjectPath = project.getLocation().toString(); String sdkPath = SDKUtil.getSdkPath(); - File buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" - + File.separator + "build.xml"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (!buildScriptFile.exists()) { - buildScriptFile = new File(activeProjectPath, "build.xml"); - if (!buildScriptFile.exists()) { + + String osDir = project.getLocation().toString() + File.separator + "os"; + + BuildSettingData setting = new BuildSettingData(); + + BuildOption buildOption = null; + if (setting.load(new File(osDir, ".buildSetting"))) { + buildOption = setting.getBuildOption(); + } + + File buildScriptFile = null; + if (buildOption != null) { + buildScriptFile = new File(activeProjectPath, "build" + File.separator + "configs" + File.separator + buildOption.getBoard() + File.separator + getScriptFileName()); // $NON-NLS-1$ // $NON-NLS-2$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(activeProjectPath, getScriptFileName()); // $NON-NLS-1$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + + File.separator + getScriptFileName()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + if (buildScriptFile == null || !buildScriptFile.exists()) { + if (consoleManager != null) { consoleManager.println("Can not found xml file of build spec."); //$NON-NLS-1$ - return 1; } + return 1; } BuildScriptData buildScript = new BuildScriptData(consoleManager); buildScript.load(buildScriptFile); - + buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ String buildCmdName = useDistClean ? COMMAND_NAME_DISTCLEAN : COMMAND_NAME_CLEAN; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CommandManager.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CommandManager.java index 40feeaa..92faa8c 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CommandManager.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/CommandManager.java @@ -37,8 +37,8 @@ import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.rt.ide.ResourceManager; +import org.tizen.rt.ide.commands.model.FlashOption; import org.tizen.rt.ide.console.ConsoleManager; -import org.tizen.rt.ide.flash.FlashOption; /** * CommandManager @@ -67,10 +67,10 @@ public class CommandManager { } // TODO - public static List getFlashOptions(String board) { + public static List getFlashOptions(String projectPath, String board) { flashOptionListClear(); - List result = FlashCommand.executeFindFlashOption(board); + List result = FlashCommand.executeFindFlashOption(projectPath, board); return result; } @@ -104,16 +104,16 @@ public class CommandManager { * @param monitor progress monitor * @return success or not */ - public static boolean runFlash(IProject project, FlashOption option, ConsoleManager consoleManager, IProgressMonitor monitor) { - if (consoleManager == null) { - logger.error("ConsoleManager is null"); //$NON-NLS-1$ - return false; - } - FlashCommand flashCommand = new FlashCommand(); - int result = flashCommand.execute(project, option, consoleManager, monitor); - - return processResult(result, consoleManager); - } +// public static boolean runFlash(IProject project, FlashOption option, ConsoleManager consoleManager, IProgressMonitor monitor) { +// if (consoleManager == null) { +// logger.error("ConsoleManager is null"); //$NON-NLS-1$ +// return false; +// } +// FlashCommand flashCommand = new FlashCommand(); +// int result = flashCommand.execute(project, option, consoleManager, monitor); +// +// return processResult(result, consoleManager); +// } /** * @param project selected project diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/FlashCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/FlashCommand.java index a6b4aab..f85172d 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/FlashCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/FlashCommand.java @@ -31,29 +31,84 @@ package org.tizen.rt.ide.commands; import java.io.File; import java.util.ArrayList; import java.util.List; - +import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.resources.WorkspaceJob; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.tizen.rt.ide.Messages; +import org.tizen.rt.ide.commands.model.FlashOption; +import org.tizen.rt.ide.commands.model.FlashScriptData; import org.tizen.rt.ide.console.ConsoleManager; -import org.tizen.rt.ide.flash.FlashOption; -import org.tizen.rt.ide.util.ProcUtil; +import org.tizen.rt.ide.exception.BuildInfoHandlingException; +import org.tizen.rt.ide.flash.ui.FlashOptionDialog; +import org.tizen.rt.ide.meta.BuildInfo; +import org.tizen.rt.ide.meta.BuildInfoManager; +import org.tizen.rt.ide.util.SDKUtil; +import org.tizen.rt.ide.util.ViewUtil; /** - * LinuxCommand - * @author jm.jaemin.kim{@literal } (S-Core) + * FlashCommand + * @author gyeongmin.ju{@literal } (S-Core) */ public class FlashCommand { /** * important PATH */ - private static final String LINUX_EXECUTE_FLASH[] = new String[] { "make", "download", "" }; //$NON-NLS-1$ private static final String PATH_BUILD_CONFIGS = "os"; //$NON-NLS-1$ + private static final String PATH_LINUX_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$ + private static final String FILE_NAME_FLASH_SCRIPT = ".flashSpec.xml"; //$NON-NLS-1$ + private static final String FILE_NAME_BUILD_INFO = "build.info"; //$NON-NLS-1$ + + protected static String getScriptFileName() { + return FILE_NAME_FLASH_SCRIPT; //$NON-NLS-1$ + } + + private static FlashScriptData getScript(String activeProjectPath, String board, ConsoleManager consoleManager) { + String sdkPath = SDKUtil.getSdkPath(); + + File buildScriptFile = null; + if (board != null) { + buildScriptFile = new File(activeProjectPath, "build" + File.separator + "configs" + File.separator + board + File.separator + getScriptFileName()); // $NON-NLS-1$ // $NON-NLS-2$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(activeProjectPath, getScriptFileName()); + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + + File.separator + getScriptFileName()); // $NON-NLS-1$ //$NON-NLS-2$ + } - private List resultFlashExecute = new ArrayList(); + if (buildScriptFile == null || !buildScriptFile.exists()) { + return null; + } - protected static List executeFindFlashOption(String board) { - String[] cfgs = new String[] { "ALL", "RESOURCE", "FOTA_ALL", "TINYARA_OTA0", "TINYARA_OTA1" }; + FlashScriptData buildScript = new FlashScriptData(consoleManager); + buildScript.load(buildScriptFile); + + buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ + if (board != null) { + buildScript.addMacro("BOARD", board); //$NON-NLS-1$ + } + + return buildScript; + } + + public static List executeFindFlashOption(String projectPath, String board) { + FlashScriptData script = getScript(projectPath, board, null); + + List cfgs = script.getOptions(); + if (cfgs == null) { + return null; + } List resultFlashOptionList = new ArrayList(); for (String cfg : cfgs) { @@ -63,24 +118,77 @@ public class FlashCommand { return resultFlashOptionList; } - protected int execute(IProject project, FlashOption flashOption, ConsoleManager consoleManager, - IProgressMonitor monitor) { + public static int execute(IProject project, String board, FlashOption flashOption, ConsoleManager consoleManager, IProgressMonitor monitor) { String activeProjectPath = project.getLocation().toString(); - String curDir = activeProjectPath + File.separator + PATH_BUILD_CONFIGS; - resultFlashExecute.clear(); + FlashScriptData flashScript = getScript(activeProjectPath, board, consoleManager); + if (flashScript == null) { + return 1; + } - LINUX_EXECUTE_FLASH[2] = flashOption.getFlashOption(); + String flashCmdName = "flash"; //$NON-NLS-1$ + int result = flashScript.doCommand(flashCmdName, flashOption.getFlashOption(), null); - int result = ProcUtil.executeProcess(null, LINUX_EXECUTE_FLASH, false, - curDir, consoleManager, resultFlashExecute); - monitor.worked(1); + if (result != 0) { + return result; + } return result; } - protected String getScriptFileName() { - return "flashSpec.xml"; + public Object execute(IProject project, ConsoleManager consoleManager) throws ExecutionException { + String osDir = project.getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ + + if (!new File(osDir, ".config").exists()) { //$NON-NLS-1$ + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); + return null; + } + + String outDir = project.getLocation().toString() + File.separator + "build" + File.separator + "output"; //$NON-NLS-1$ //$NON-NLS-2$ + + if (!new File(outDir, FILE_NAME_BUILD_INFO).exists()) { + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.FlashHandler_NotFoundBuildInfo); + return null; + } + + BuildInfo buildInfo = null; + try { + buildInfo = BuildInfoManager.loadBuildInfo(project); + } catch (BuildInfoHandlingException e) { + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.FlashHandler_BuildInfoIsNotNormal); + return null; + } + + Shell shell = ViewUtil.getWorkbenchWindow().getShell(); + FlashOptionDialog dialog = new FlashOptionDialog(shell, project, buildInfo.getBoard()); + dialog.create(); + int r = dialog.open(); + + if (r == Dialog.OK) { + String option = dialog.getOption(); + scheduleFlash(project, buildInfo.getBoard(), new FlashOption(option, option), consoleManager); + } + + return null; + } + + public static void scheduleFlash(final IProject project, final String board, final FlashOption flashOption, final ConsoleManager consoleManager) { + WorkspaceJob wsJob = new WorkspaceJob("Flashing " + project.getName()) { + @Override + public boolean belongsTo(Object family) { + return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); + } + + @Override + public IStatus runInWorkspace(IProgressMonitor monitor) + throws CoreException { + return (FlashCommand.execute(project, board, flashOption, consoleManager, monitor) == 0) ? Status.OK_STATUS : Status.CANCEL_STATUS; + } + }; + + wsJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); + wsJob.setUser(true); + wsJob.schedule(); } } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildOption.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildOption.java similarity index 99% rename from rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildOption.java rename to rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildOption.java index 897abe8..bb6aca0 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildOption.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildOption.java @@ -26,7 +26,7 @@ * */ -package org.tizen.rt.ide.build; +package org.tizen.rt.ide.commands.model; import java.io.File; import java.io.FilenameFilter; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildScriptData.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildScriptData.java new file mode 100644 index 0000000..2ce3a7f --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildScriptData.java @@ -0,0 +1,230 @@ +/* + * Common + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Gyeongmin Ju + * Hyeongseok Heo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd. + * + */ +package org.tizen.rt.ide.commands.model; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBException; + +import org.tizen.rt.ide.console.ConsoleManager; +import org.tizen.rt.ide.util.MacroUtil; +import org.tizen.rt.ide.util.ProcUtil; +import org.tizen.rt.product.meta.model.build.Build; +import org.tizen.rt.product.meta.model.build.Command; +import org.tizen.rt.product.meta.model.build.Commands; +import org.tizen.rt.product.meta.model.build.Param; +import org.tizen.rt.product.meta.util.MetaModelUtil; + +/** + * @since 2017. 8. 25. + * @author Gyeongmin Ju {@literal } + */ +public class BuildScriptData { + + private static class BuildScript { + public String cmdStr; + public String curDir; + public boolean isShellCmd; + public String shell; + public String[] params; + + /** + * @param cmdStr command string + * @param curDir current directory + * @param isShellCmd is shell command + * @param shell shell name to use like "/bin/bash" + * @param params parameters + */ + public BuildScript(String cmdStr, String curDir, boolean isShellCmd, String shell, String[] params) { + this.cmdStr = cmdStr; + this.curDir = curDir; + this.isShellCmd = isShellCmd; + this.shell = shell; + this.params = params; + } + + /** + * @param cmdStr command string + * @param curDir current directory + * @param isShellCmd is shell command + * @param shell shell name to use like "/bin/bash" + */ + public BuildScript(String cmdStr, String curDir, boolean isShellCmd, String shell) { + this(cmdStr, curDir, isShellCmd, shell, null); + } + + /** + * @return the cmdStr + */ + public String getCmdStr() { + return cmdStr; + } + + /** + * @return the curDir + */ + public String getCurDir() { + return curDir; + } + + /** + * @return the isShellCmd + */ + public boolean isShellCmd() { + return isShellCmd; + } + + /** + * @return the shell + */ + public String getShell() { + return shell; + } + } + + private Map macros = new HashMap(); + private Map scripts; + private ConsoleManager consoleManager; + + public BuildScriptData(ConsoleManager consoleManager) { + this.consoleManager = consoleManager; + } + + private Map getBuildScripts(File buildScriptFile) { + Build buildModel = null; + try { + buildModel = MetaModelUtil.loadBuildModel(buildScriptFile); + } catch (JAXBException e) { + return null; + } + + Map scripts = new HashMap(); + + Commands commands = buildModel.getCommands(); + List cmds = commands.getCommand(); + if(cmds != null) { + for(Command cmd : cmds) { + String[] params = null; + List paramNodes = cmd.getContent(); + if(paramNodes != null && !paramNodes.isEmpty()) { + List paramList = new ArrayList (); + + for (Object paramObj : paramNodes) { + if(paramObj instanceof Param) { + Param param = (Param)paramObj; + String value = param.getValue(); + paramList.add(value); + } + } + + if(!paramList.isEmpty()) { + params = paramList.toArray(new String[paramList.size()]); + } + } + + boolean isShellCmd = Boolean.valueOf(cmd.getShellcmd()); + scripts.put(cmd.getName(), new BuildScript(cmd.getCommand(), cmd.getPath(), isShellCmd, cmd.getShell(), params)); + } + } + + return scripts; + } + + public String getBuildScriptFileName() { + return "build.xml"; + } + + public void addMacro(String name, String value) { + macros.put(name, value); + } + + public void consolePrintln(String str) { + if (consoleManager != null) { + consoleManager.println(str); + } + } + + public int load(File buildScriptFile) { + consolePrintln("Build project using " + buildScriptFile); + scripts = getBuildScripts(buildScriptFile); + + return (scripts != null) ? 0 : 1; + } + + public int load(String buildScriptFilename) { + return load(new File(buildScriptFilename)); + } + + public int doCommand(String buildCmdName, Map env) { + ProcessBuilder pb = ProcUtil.genProcessBuilder(null); + + BuildScript script = scripts.get(buildCmdName); + if (script == null) { + consolePrintln("Cannot found build command : " + buildCmdName); + return 1; + } + + if (env != null) { + pb.environment().putAll(env); + } + + String cmdStr = MacroUtil.processMacro(script.cmdStr, macros); + if (cmdStr == null || cmdStr.isEmpty()) { + return 1; + } + String curDir = MacroUtil.processMacro(script.curDir, macros); + + String[] cmds = null; + + int paramLen = 0; + if (script.params != null) { + paramLen = script.params.length; + } + + if (paramLen > 0) { + cmds = new String[paramLen + 1]; + for (int i = 0; i < paramLen; i++) { + cmds[1 + i] = MacroUtil.processMacro(script.params[i], macros); + } + } else { + cmds = new String[1]; + } + cmds[0] = cmdStr; + + return ProcUtil.executeProcess(pb, cmds, script.isShellCmd, script.shell, + curDir, consoleManager, null); + + } + + public int doCommand(String buildCmdName) { + return doCommand(buildCmdName, null); + } + +} diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildSettingData.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildSettingData.java similarity index 95% rename from rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildSettingData.java rename to rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildSettingData.java index 7a4cb12..094a0c5 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/BuildSettingData.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/BuildSettingData.java @@ -26,7 +26,7 @@ * */ -package org.tizen.rt.ide.build; +package org.tizen.rt.ide.commands.model; import java.io.File; import java.io.FileInputStream; @@ -37,11 +37,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; + +import org.tizen.rt.ide.commands.model.BuildOption; + import java.util.Properties; import java.util.Set; -import org.tizen.rt.ide.build.BuildOption; - /** * @author Gyeongmin Ju{@literal } (S-Core) */ @@ -94,11 +95,11 @@ public class BuildSettingData { if (keys != null) { for (Object key : keys) { if (key instanceof String && ((String) key).startsWith("env.")) { - removeKeys.add((String)key); + removeKeys.add((String) key); } } } - for(String key : removeKeys) { + for (String key : removeKeys) { prop.remove(key); } } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/DebugScriptData.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/DebugScriptData.java new file mode 100644 index 0000000..c00eaf7 --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/DebugScriptData.java @@ -0,0 +1,296 @@ +/* + * Common + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Gyeongmin Ju + * Hyeongseok Heo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd. + * + */ +package org.tizen.rt.ide.commands.model; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBException; + +import org.tizen.rt.ide.console.ConsoleManager; +import org.tizen.rt.product.meta.model.debug.Debug; +import org.tizen.rt.product.meta.model.debug.Debugs; +import org.tizen.rt.product.meta.model.debug.Execute; +import org.tizen.rt.product.meta.model.debug.Options; +import org.tizen.rt.product.meta.model.debug.Param; +import org.tizen.rt.product.meta.util.MetaModelUtil; + +/** + * @since 2017. 8. 25. + * @author Gyeongmin Ju {@literal } + */ +public class DebugScriptData { + + public static class DebugScript { + + public static class DebugCommand { + + public static class Option { + public String name; + public String type; + public String param1; + public String param2; + + public Option(String name, String type, String param1, String param2) { + this.name = name; + this.type = type; + this.param1 = param1; + this.param2 = param2; + } + } + + public static class Param { + public String prefix; + public String value; + + public Param(String prefix, String value) { + this.prefix = prefix; + this.value = value; + } + } + + public String cmdStr; + public String curDir; + public String platform; + public String platformArch; + public List params = null; + public List