From afea6af95df6f6dcd7e3e10361627bd6e2b6f612 Mon Sep 17 00:00:00 2001 From: "daeryong.park" Date: Wed, 17 May 2017 15:21:46 +0900 Subject: [PATCH] RTSDK : Add project clean command - Add project clean command - Apply popup menus for build/flash/clean command in ProjectExplorer Change-Id: Ic692dd030c7146133d9316ad3ee96e5eebbfc4fd Signed-off-by: daeryong.park --- rt-ide/tizen.rt.product.plugin/plugin.xml | 129 ++++++++++++++++++- .../src/org/tizen/rt/ide/CleanCommand.java | 140 +++++++++++++++++++++ .../src/org/tizen/rt/ide/RtosCommandManager.java | 18 ++- .../org/tizen/rt/ide/handlers/CleanHandler.java | 104 +++++++++++++++ .../src/org/tizen/rt/ide/util/ResourceUtil.java | 3 + 5 files changed, 385 insertions(+), 9 deletions(-) create mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/CleanCommand.java create mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/CleanHandler.java diff --git a/rt-ide/tizen.rt.product.plugin/plugin.xml b/rt-ide/tizen.rt.product.plugin/plugin.xml index dbbf84a..277d265 100644 --- a/rt-ide/tizen.rt.product.plugin/plugin.xml +++ b/rt-ide/tizen.rt.product.plugin/plugin.xml @@ -15,12 +15,21 @@ categoryId="rtosBuild.commands.category" id="rtosBuild.commands.buildCommand"> - + id="rtosBuild.commands.flashCommand" + name="Flash"> + + + + + @@ -36,6 +45,15 @@ + + + + + + + + @@ -72,7 +96,7 @@ + name="rtosBuild.menus.sampleMenu1"> + + + + + + + + + tooltip="Build TizenRT Project"> + tooltip="Flash TizenRT Project"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/CleanCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/CleanCommand.java new file mode 100644 index 0000000..20933f8 --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/CleanCommand.java @@ -0,0 +1,140 @@ +/* + * 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; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +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.SDKUtil; +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. 17. + * @author Daeryong Park {@literal } + */ +public class CleanCommand { + + private static final String FILE_NAME_BUILD_SCRIPT = "build.xml"; //$NON-NLS-1$ + + private List resultBuildExecute = new ArrayList(); + + private class BuildScript { + public String cmdStr; + public String curDir; + public boolean isShellCmd; + public String shell; + + public BuildScript(String cmdStr, String curDir, boolean isShellCmd, String shell) { + this.cmdStr = cmdStr; + this.curDir = curDir; + this.isShellCmd = isShellCmd; + this.shell = shell; + } + } + + private Map getBuildScripts(File buildScriptFile, Map macros) { + 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"); + cmd = MacroUtil.processMacro(cmd, macros); + String curdir = elm.getAttribute("curdir"); + curdir = MacroUtil.processMacro(curdir, macros); + 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; + } + + protected int executeClean(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { + String activeProjectName = project.getLocation().toString(); + String homePath = activeProjectName; + + String sdkPath = SDKUtil.getSdkPath(); + File buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + + File.separator + FILE_NAME_BUILD_SCRIPT); + if (!buildScriptFile.exists()) { + buildScriptFile = new File(homePath, FILE_NAME_BUILD_SCRIPT); + if (!buildScriptFile.exists()) { + return 1; + } + } + + Map macros = new HashMap(); + macros.put("PROJECT_PATH", homePath); + + Map scripts = getBuildScripts(buildScriptFile, macros); + + ProcessBuilder pb = ProcUtil.genProcessBuilder(null); + + String buildCmdName = "clean"; + BuildScript script = scripts.get(buildCmdName); + if (script == null) { + consoleManager.println("Cannot found clean command : " + buildCmdName); //$NON-NLS-1$ + return 1; + } + int result = ProcUtil.executeProcess(pb, new String[] { script.cmdStr }, script.isShellCmd, script.shell, + script.curDir, consoleManager, resultBuildExecute); + + monitor.worked(1); + if (result != 0) { + return result; + } + + return result; + } + +} diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/RtosCommandManager.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/RtosCommandManager.java index 8962e7c..4534ef4 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/RtosCommandManager.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/RtosCommandManager.java @@ -28,6 +28,7 @@ package org.tizen.rt.ide; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; @@ -176,6 +177,17 @@ public class RtosCommandManager { return processResult(result, consoleManager); } + public static boolean runClean(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { + if (consoleManager == null) { + logger.error("ConsoleManager is null"); //$NON-NLS-1$ + return false; + } + CleanCommand cleanCommand = new CleanCommand(); + int result = cleanCommand.executeClean(project, consoleManager, monitor); + + return processResult(result, consoleManager); + } + /** * Print success status to the Console and if failed print error messages to the Console * @param result @@ -185,11 +197,11 @@ public class RtosCommandManager { private static boolean processResult(int result, ConsoleManager consoleManager) { boolean success = result == 0; if (consoleManager != null) { - consoleManager.print("[STATUS] ", SWT.BOLD, ResourceManager.BLACK); //$NON-NLS-1$ + consoleManager.print("[STATUS] ", SWT.BOLD, ResourceManager.INTENSE_BLACK); //$NON-NLS-1$ if (success) { // success - consoleManager.println(SUCCEED, SWT.BOLD, ResourceManager.GREEN); + consoleManager.println(SUCCEED, SWT.BOLD, ResourceManager.INTENSE_GREEN); } else { // fail - consoleManager.println(FAILED, SWT.BOLD, ResourceManager.RED); + consoleManager.println(FAILED, SWT.BOLD, ResourceManager.INTENSE_RED); } // consoleManager.println("[RESULT]" + result.toString(), SWT.BOLD, // ResourceManager.BLACK); diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/CleanHandler.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/CleanHandler.java new file mode 100644 index 0000000..b614210 --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/CleanHandler.java @@ -0,0 +1,104 @@ +/* + * 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.handlers; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.progress.IProgressService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.rt.ide.Activator; +import org.tizen.rt.ide.RtosCommandManager; +import org.tizen.rt.ide.console.ConsoleManager; +import org.tizen.rt.ide.util.ResourceUtil; +import org.tizen.rt.ide.util.Util; + +/** + * @since 2017. 5. 16. + * @author Daeryong Park {@literal } + */ +public class CleanHandler extends AbstractHandler { + + private final Logger logger = LoggerFactory.getLogger(CleanHandler.class); + + /* (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + final IProject project = ResourceUtil.getCurrentProject(); + if (project == null) { + return null; + } + + boolean ok = MessageDialog.openQuestion(Util.getDisplay().getActiveShell(), + "Clean Project", "Are you sure you want to clean selected project?"); //$NON-NLS-1$ //$NON-NLS-2$ + if (!ok) { + return null; + } + + IWorkbench workbench = Activator.getDefault().getWorkbench(); + IProgressService progressService = workbench.getProgressService(); + IRunnableWithProgress runnable = new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + monitor.beginTask("Clean Project", 3); //$NON-NLS-1$ + + RtosCommandManager.runClean(project, new ConsoleManager(true), monitor); + monitor.worked(1); + + try { + project.refreshLocal(IResource.DEPTH_INFINITE, monitor); + monitor.worked(1); + } catch (CoreException e) { + logger.error(e.getMessage(), e); + } + + monitor.done(); + } + }; + try { + progressService.busyCursorWhile(runnable); + } catch (InvocationTargetException e) { + logger.error(e.getMessage(), e); + } catch (InterruptedException e) { + logger.error(e.getMessage(), e); + } + + return null; + } + +} diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java index 3b82fe0..8bfe7d7 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java @@ -45,6 +45,9 @@ public class ResourceUtil { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) { + return null; + } ISelectionService selectionService = window.getSelectionService(); if (selectionService != null) { ISelection selection = selectionService.getSelection(); -- 2.7.4