From: gyeongmin.ju Date: Tue, 5 Sep 2017 13:47:40 +0000 (+0900) Subject: RT: code refactoring X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26c2f6d19e34d7ebaf886f73cdc47b9eb83e00db;p=sdk%2Fide%2Frt-ide-product.git RT: code refactoring Signed-off-by: gyeongmin.ju --- diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/builder/RtBuilder.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/builder/RtBuilder.java index 2b69a4a..e3ce9c2 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/builder/RtBuilder.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/builder/RtBuilder.java @@ -37,16 +37,21 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IncrementalProjectBuilder; -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.MessageDialog; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.widgets.Display; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tizen.rt.ide.Activator; +import org.tizen.rt.ide.Messages; +import org.tizen.rt.ide.commands.BuildCommand; +import org.tizen.rt.ide.commands.CleanCommand; import org.tizen.rt.ide.commands.CommandManager; import org.tizen.rt.ide.console.ConsoleManager; +import org.tizen.rt.ide.util.ViewUtil; /** * RtBuilder @@ -54,7 +59,9 @@ import org.tizen.rt.ide.console.ConsoleManager; */ public class RtBuilder extends IncrementalProjectBuilder { - public static String BUILDER_ID = "org.tizen.rt.ide.builder.RtBuilder"; + public static String BUILDER_ID = "org.tizen.rt.ide.builder.RtBuilder"; //$NON-NLS-1$ + + private static final String PREF_KEY_USE_DISTCLEAN = "PREF_KEY_USE_DISTCLEAN"; //$NON-NLS-1$ private final Logger logger = LoggerFactory.getLogger(RtBuilder.class); @@ -67,7 +74,14 @@ public class RtBuilder extends IncrementalProjectBuilder { ConsoleManager consoleManager = new ConsoleManager(true); - boolean result = CommandManager.runBuild(project, consoleManager, monitor); + int result = 0; + switch (kind) { + case FULL_BUILD: + BuildCommand buildCommand = new BuildCommand(); + result = buildCommand.execute(project, consoleManager, monitor); + break; + } + try { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (CoreException e) { @@ -76,13 +90,30 @@ public class RtBuilder extends IncrementalProjectBuilder { forgetLastBuiltState(); - if (result) { + if (result == 0) { return new IProject[] { project }; } else { return null; } } + @Override + protected void clean(IProgressMonitor monitor) throws CoreException { + IProject project = getProject(); + + ConsoleManager consoleManager = new ConsoleManager(true); + + CleanCommand cleanCommand = new CleanCommand(); + + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + boolean useDistClean = store.getBoolean(PREF_KEY_USE_DISTCLEAN); + if (useDistClean) { + cleanCommand.setProperty("distclena", "true"); + } + + cleanCommand.execute(project, consoleManager, monitor); + } + public static void addBuilderToProject(IProject fProject) throws CoreException { IProjectDescription desc = fProject.getDescription(); ICommand[] commands = desc.getBuildSpec(); @@ -120,24 +151,4 @@ public class RtBuilder extends IncrementalProjectBuilder { .size()])); fProject.setDescription(description, null); } - - public static void scheduleRebuild(final IProject project) { - WorkspaceJob buildJob = new WorkspaceJob("Building " + project.getName()) { - @Override - public boolean belongsTo(Object family) { - return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); - } - - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) - throws CoreException { - project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); - return Status.OK_STATUS; - } - }; - - buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); - buildJob.setUser(true); - buildJob.schedule(); - } } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/AbstractCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/AbstractCommand.java new file mode 100644 index 0000000..b21deb8 --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/AbstractCommand.java @@ -0,0 +1,57 @@ +/* +* Common +* +* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* jm.jemin.kim +* Gyeongmin Ju +* 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.commands; + +import java.util.Properties; + +/** + * @author Gyeongmin Ju{@literal } (S-Core) + */ +public abstract class AbstractCommand implements Command { + protected Properties properties; + + @Override + public void setProperty(String key, String value) { + if (properties == null) { + properties = new Properties(); + } + + properties.put(key, value); + } + + @Override + public String getProperty(String key) { + if (properties == null) { + return null; + } + + return properties.getProperty(key); + } + +} 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 d1da939..c4a43ff 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 @@ -33,76 +33,67 @@ import java.io.FileWriter; import java.io.IOException; import java.util.Properties; -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.MessageDialog; 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.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.commands.model.ScriptUtil; import org.tizen.rt.ide.console.ConsoleManager; -import org.tizen.rt.ide.util.ResourceUtil; -import org.tizen.rt.ide.util.SDKUtil; /** * @author Gyeongmin Ju{@literal } (S-Core) */ -public class BuildCommand { +public class BuildCommand extends AbstractCommand { private final Logger logger = LoggerFactory.getLogger(BuildCommand.class); - private static final String PATH_LINUX_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$ + private static final String PATH_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$ private static final String PROP_NAME_OPTION = "option"; //$NON-NLS-1$ private static final String PROP_NAME_BOARD = "board"; //$NON-NLS-1$ - private static final String FILE_NAME_BUILD_INFO = "build.info"; //$NON-NLS-1$ + private static final String FILENAME_CONFIG = ".config"; //$NON-NLS-1$ + private static final String FILENAME_BUILD_INFO = "build.info"; //$NON-NLS-1$ + private static final String FILENAME_BUILD_SETTING = ".buildSetting"; //$NON-NLS-1$ + private static final String PROP_COMMENT_DEBUG_INFO = "TizerRT Debug information"; //$NON-NLS-1$ - private static final String PROP_COMMENT_DEBUG_INFO = "TinyARA Debug information"; //$NON-NLS-1$ + private static final String COMMAND_NAME_BUILD = "build"; //$NON-NLS-1$ + private static final String COMMAND_NAME_BUILD_WITH_TOOLCHAIN = "buildWithToolchain"; //$NON-NLS-1$ protected String getScriptFileName() { return ".buildSpec.xml"; //$NON-NLS-1$ } - + protected String getSettingFileName() { - return ".buildSetting.xml"; //$NON-NLS-1$ + return FILENAME_BUILD_SETTING; // $NON-NLS-1$ } - - public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { - String activeProjectPath = project.getLocation().toString(); - - String sdkPath = SDKUtil.getSdkPath(); - String homePath = activeProjectPath; - String outputPath = activeProjectPath + File.separator + PATH_LINUX_BUILD_OUTPUT; - - String osDir = project.getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ + private static int doBuilding(String projectPath, String scriptFileName, String settingFileName, + ConsoleManager consoleManager, Logger logger) { + String osDir = projectPath + File.separator + "os"; //$NON-NLS-1$ + String outputPath = projectPath + File.separator + PATH_BUILD_OUTPUT; + BuildSettingData setting = new BuildSettingData(); String toolchainPath = null; BuildOption buildOption = null; - if (setting.load(new File(osDir, getSettingFileName()))) { + if (setting.load(new File(osDir, settingFileName))) { toolchainPath = setting.getToolchainPath(); 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()) { + File buildScriptFile = ScriptUtil.getScriptFile(projectPath, (buildOption != null) ? buildOption.getBoard() : null, scriptFileName); + if (buildScriptFile == null) { if (consoleManager != null) { consoleManager.println("Can not found xml file of build spec."); } @@ -112,20 +103,20 @@ public class BuildCommand { BuildScriptData buildScript = new BuildScriptData(consoleManager); buildScript.load(buildScriptFile); - buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ + buildScript.addMacro("PROJECT_PATH", projectPath); //$NON-NLS-1$ if (buildOption != null) { - buildScript.addMacro("BOARD", buildOption.getBoard()); - buildScript.addMacro("BUILD_OPTION", buildOption.getBuildOption()); + buildScript.addMacro("BOARD", buildOption.getBoard()); //$NON-NLS-1$ + buildScript.addMacro("BUILD_OPTION", buildOption.getBuildOption()); //$NON-NLS-1$ } if (toolchainPath != null) { - buildScript.addMacro("TOOLCHAIN", setting.getToolchainPath()); + buildScript.addMacro("TOOLCHAIN", setting.getToolchainPath()); //$NON-NLS-1$ } String buildCmdName; if (toolchainPath != null && !toolchainPath.isEmpty()) { - buildCmdName = "buildWithToolchain"; + buildCmdName = COMMAND_NAME_BUILD_WITH_TOOLCHAIN; } else { - buildCmdName = "build"; + buildCmdName = COMMAND_NAME_BUILD; } int result = buildScript.doCommand(buildCmdName, setting.getEnvVariables()); @@ -139,30 +130,49 @@ 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); + buildInfo.store(new FileWriter(new File(outputPath, FILENAME_BUILD_INFO)), PROP_COMMENT_DEBUG_INFO); } catch (IOException e) { logger.error(e.getMessage()); } } - + return result; } - public Object execute(IProject project, ConsoleManager consoleManager) throws ExecutionException { +// public static void scheduleRebuild(String projectName, String projectPath, String scriptFilename, String settingFilename, ConsoleManager consoleManager, Logger logger) { +// WorkspaceJob buildJob = new WorkspaceJob("Building " + projectName) { +// @Override +// public boolean belongsTo(Object family) { +// return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); +// } +// +// @Override +// public IStatus runInWorkspace(IProgressMonitor monitor) +// throws CoreException { +// String outputPath = projectPath + File.separator + PATH_BUILD_OUTPUT; +// BuildCommand.doBuilding(projectPath, outputPath, scriptFilename, settingFilename, consoleManager, logger); +// return Status.OK_STATUS; +// } +// }; +// +// buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); +// buildJob.setUser(true); +// buildJob.schedule(); +// } + + @Override + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { + String activeProjectPath = project.getLocation().toString(); String osDir = project.getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ - if (!new File(osDir, ".config").exists()) { //$NON-NLS-1$ + if (!new File(osDir, FILENAME_CONFIG).exists()) { // $NON-NLS-1$ MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); //$NON-NLS-1$ - return null; + return 1; } - - RtBuilder.scheduleRebuild(project); - - return null; + + BuildCommand.doBuilding(activeProjectPath, getScriptFileName(), getSettingFileName(), consoleManager, logger); + + return 0; } - public Object execute(ConsoleManager consoleManager) throws ExecutionException { - IProject project = ResourceUtil.getCurrentProject(); - return execute(project, consoleManager); - } } 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 79cbf63..cb855cd 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,57 +33,47 @@ 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.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.commands.model.ScriptUtil; +import org.tizen.rt.ide.commands.ui.BuildConfigureDialog; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; -import org.tizen.rt.ide.util.SDKUtil; import org.tizen.rt.ide.util.ViewUtil; /** * @author Gyeongmin Ju{@literal } (S-Core) */ -public class BuildConfigureCommand { +public class BuildConfigureCommand extends AbstractCommand { + private static final String COMMAND_CONFIG = "config"; //$NON-NLS-1$ + 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) { if (consoleManager != null) { - consoleManager.println("Build option not selected."); //$NON-NLS-1$ - consoleManager.println("Execute configure before the build operation."); //$NON-NLS-1$ + consoleManager.println("Build option not selected."); + consoleManager.println("Execute configure before the build operation."); } return 1; } if (consoleManager != null) { - consoleManager.println("Build Option : " + buildOption.getBuildOption()); //$NON-NLS-1$ + consoleManager.println("Build Option : " + buildOption.getBuildOption()); } - String sdkPath = SDKUtil.getSdkPath(); 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()) { + + File buildScriptFile = ScriptUtil.getScriptFile(activeProjectPath, (buildOption != null) ? buildOption.getBoard() : null, getScriptFileName()); + if (buildScriptFile == null) { if (consoleManager != null) { consoleManager.println("Can not found xml file of build spec."); } @@ -101,8 +91,8 @@ public class BuildConfigureCommand { BuildSettingData buildSetting = new BuildSettingData(); buildSetting.load(new File(activeProjectPath, "os" + File.separator + getSettingFileName())); //$NON-NLS-1$ - - String buildCmdName = "config"; //$NON-NLS-1$ + + String buildCmdName = COMMAND_CONFIG; int result = buildScript.doCommand(buildCmdName); if (result != 0) { @@ -115,17 +105,18 @@ public class BuildConfigureCommand { return result; } + @Override public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { Shell shell = ViewUtil.getWorkbenchWindow().getShell(); BuildConfigureDialog dialog = new BuildConfigureDialog(shell, ResourceUtil.getCurrentProject()); dialog.create(); int r = dialog.open(); - if (r == Dialog.OK) { - configure(project, dialog.getBuildOption(), consoleManager, monitor); + if (r != Dialog.OK) { + return 1; } - return 0; + return configure(project, dialog.getBuildOption(), consoleManager, monitor); } } 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 af94371..eb791a8 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 @@ -30,19 +30,22 @@ import java.io.File; import org.eclipse.core.commands.ExecutionException; 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.ui.BuildEnvSettingDialog; import org.tizen.rt.ide.commands.model.BuildSettingData; +import org.tizen.rt.ide.commands.ui.BuildEnvSettingDialog; +import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; import org.tizen.rt.ide.util.ViewUtil; /** * @author Gyeongmin Ju{@literal } (S-Core) */ -public class BuildEnvSettingCommand { +public class BuildEnvSettingCommand extends AbstractCommand { - public Object execute(IProject project) throws ExecutionException { + @Override + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { String osDir = ResourceUtil.getCurrentProject().getLocation().toString() + File.separator + "os"; // read setting @@ -59,6 +62,6 @@ public class BuildEnvSettingCommand { setting.write(new File(osDir, ".buildSetting")); } - return null; + return 0; } } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildKConfigureCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildKConfigureCommand.java index b90df8d..27a3b53 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildKConfigureCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/BuildKConfigureCommand.java @@ -32,32 +32,32 @@ import java.io.File; import java.io.IOException; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; import org.tizen.rt.ide.Messages; +import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; /** * @author Gyeongmin Ju{@literal } (S-Core) */ -public class BuildKConfigureCommand { +public class BuildKConfigureCommand extends AbstractCommand { // private final Logger logger = LoggerFactory.getLogger(getClass()); public static final String[] KERNEL_CONFIG_CMD = new String[] { "gnome-terminal", "--command", "make menuconfig" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - public Object execute() throws ExecutionException { - IProject project = ResourceUtil.getCurrentProject(); - + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { String osDir = project.getLocation().toString() + File.separator + "os"; try { Runtime.getRuntime().exec(KERNEL_CONFIG_CMD, null, new File(osDir)); //$NON-NLS-1$ } catch (IOException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); //$NON-NLS-1$ - return null; + return 1; } - return null; + return 0; } } 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 1912f83..83ca794 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 @@ -4,7 +4,7 @@ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: - * Daeryong Park + * Gyeongmin Ju * Hyeongseok Heo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,51 +31,39 @@ import org.eclipse.core.runtime.IProgressMonitor; 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.commands.model.ScriptUtil; import org.tizen.rt.ide.console.ConsoleManager; -import org.tizen.rt.ide.util.SDKUtil; /** * @since 2017. 5. 17. - * @author Daeryong Park {@literal } + * @author Gyeongmin Ju {@literal } */ -public class CleanCommand { +public class CleanCommand extends AbstractCommand { private static final String COMMAND_NAME_CLEAN = "clean"; //$NON-NLS-1$ private static final String COMMAND_NAME_DISTCLEAN = "distclean"; //$NON-NLS-1$ + private static final String FILENAME_BUILD_SETTING = ".buildSetting"; //$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(); - + @Override + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { + String activeProjectPath = project.getLocation().toString(); String osDir = project.getLocation().toString() + File.separator + "os"; BuildSettingData setting = new BuildSettingData(); BuildOption buildOption = null; - if (setting.load(new File(osDir, ".buildSetting"))) { + if (setting.load(new File(osDir, FILENAME_BUILD_SETTING))) { 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()) { + File buildScriptFile = ScriptUtil.getScriptFile(activeProjectPath, (buildOption != null) ? buildOption.getBoard() : null, getScriptFileName()); + if (buildScriptFile == null) { if (consoleManager != null) { - consoleManager.println("Can not found xml file of build spec."); //$NON-NLS-1$ + consoleManager.println("Can not found xml file of build spec."); } return 1; } @@ -85,6 +73,7 @@ public class CleanCommand { buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ + boolean useDistClean = Boolean.valueOf(getProperty("distclean")); String buildCmdName = useDistClean ? COMMAND_NAME_DISTCLEAN : COMMAND_NAME_CLEAN; int result = buildScript.doCommand(buildCmdName); diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/Command.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/Command.java new file mode 100644 index 0000000..d777e39 --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/Command.java @@ -0,0 +1,46 @@ +/* +* Common +* +* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* jm.jemin.kim +* Gyeongmin Ju +* 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.commands; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.tizen.rt.ide.console.ConsoleManager; + +/** + * @author Gyeongmin Ju{@literal } (S-Core) + */ +public interface Command { + + public void setProperty(String key, String value); + + public String getProperty(String key); + + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor); + +} 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 92faa8c..9a04de5 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 @@ -28,135 +28,119 @@ package org.tizen.rt.ide.commands; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IncrementalProjectBuilder; +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.swt.SWT; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; 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; /** - * CommandManager - * @author jm.jaemin.kim{@literal } (S-Core) + * @author Gyeongmin Ju{@literal } (S-Core) */ public class CommandManager { - private static final String SUCCEED = "SUCCEED"; //$NON-NLS-1$ - private static final String FAILED = "FAILED"; //$NON-NLS-1$ - - protected static List flashOptionList = new ArrayList(); - public static CommandManager rtosCommandManager = null; - public static String DeviceInfoOnConfiguration = null; + public static int doBuildConfigure(IProject project, ConsoleManager consoleManager, Object object) { + BuildConfigureCommand cmd = new BuildConfigureCommand(); + return cmd.execute(project, consoleManager, null); + } - private static final Logger logger = LoggerFactory.getLogger(CommandManager.class); + public static int doBuildEnvSetting(IProject project, ConsoleManager consoleManager, Object object) { + BuildEnvSettingCommand cmd = new BuildEnvSettingCommand(); + return cmd.execute(project, null, null); + } - private CommandManager() { + public static int doBuildKConfigure(IProject project, ConsoleManager consoleManager, Object object) { + BuildKConfigureCommand cmd = new BuildKConfigureCommand(); + return cmd.execute(project, null, null); } - public static CommandManager getDeviceEntryManager() { - if (rtosCommandManager == null) { - rtosCommandManager = new CommandManager(); - } + public static int doBuild(IProject project, ConsoleManager consoleManager, Logger logger) { + WorkspaceJob buildJob = new WorkspaceJob("Building " + project.getName()) { + @Override + public boolean belongsTo(Object family) { + return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); + } - return rtosCommandManager; - } + @Override + public IStatus runInWorkspace(IProgressMonitor monitor) + throws CoreException { + project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + // BuildCommand cmd = new BuildCommand(); + // cmd.execute(project, consoleManager, monitor); + return Status.OK_STATUS; + } + }; - // TODO - public static List getFlashOptions(String projectPath, String board) { - flashOptionListClear(); + buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); + buildJob.setUser(true); + buildJob.schedule(); - List result = FlashCommand.executeFindFlashOption(projectPath, board); - return result; + return 0; } - public static void flashOptionListClear() { - flashOptionList.clear(); - } + public static int doClean(IProject project, boolean useDistClean, ConsoleManager consoleManager, Logger logger) { + WorkspaceJob wsJob = new WorkspaceJob("Cleanging " + project.getName()) { + @Override + public boolean belongsTo(Object family) { + return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); + } - /** - * @param project selected project - * @param option build options - * @param toolchainPath user's toolchain path - * @param consoleManager ConsoleManager instance - * @param monitor progress monitor - * @return success or not - */ - public static boolean runBuild(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { - if (consoleManager == null) { - logger.error("ConsoleManager is null"); //$NON-NLS-1$ - return false; - } - BuildCommand buildCommand = new BuildCommand(); - int result = buildCommand.execute(project, consoleManager, monitor); + @Override + public IStatus runInWorkspace(IProgressMonitor monitor) + throws CoreException { + project.build(IncrementalProjectBuilder.CLEAN_BUILD, monitor); + // CleanCommand cleanCommand = new CleanCommand(); + // cleanCommand.setProperty("distclean", (useDistClean) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + // cleanCommand.execute(project, consoleManager, monitor); + return Status.OK_STATUS; + } + }; - return processResult(result, consoleManager); + wsJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); + wsJob.setUser(true); + wsJob.schedule(); + + return 0; } - /** - * @param project selected project - * @param option flash options - * @param consoleManager ConsoleManager instance - * @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); -// } - - /** - * @param project selected project - * @param consoleManager ConsoleManager instance - * @param monitor progress monitor - * @param useDistClean - * @return success or not - */ - public static boolean runClean(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor, boolean useDistClean) { - if (consoleManager == null) { - logger.error("ConsoleManager is null"); //$NON-NLS-1$ - return false; + public static String doFlashCommand(IProject project, ConsoleManager consoleManager, Logger logger) { + FlashConfigCommand cmd = new FlashConfigCommand(); + int result = cmd.execute(project, consoleManager, null); + if (result != 0) { + return null; } - CleanCommand cleanCommand = new CleanCommand(); - int result = cleanCommand.execute(project, consoleManager, monitor, useDistClean); - return processResult(result, consoleManager); + return cmd.getProperty("flashoption"); //$NON-NLS-1$ } - /** - * Print success status to the Console and if failed print error messages to the Console - * @param result - * @param consoleManager - * @return success or not - */ - private static boolean processResult(int result, ConsoleManager consoleManager) { - boolean success = result == 0; - if (consoleManager != null) { - consoleManager.print("[STATUS] ", SWT.BOLD, ResourceManager.INTENSE_BLACK); //$NON-NLS-1$ - if (success) { // success - consoleManager.println(SUCCEED, SWT.BOLD, ResourceManager.INTENSE_GREEN); - } else { // fail - consoleManager.println(FAILED, SWT.BOLD, ResourceManager.INTENSE_RED); + public static int doFlash(IProject project, String flashOption, ConsoleManager consoleManager, Logger logger) { + WorkspaceJob wsJob = new WorkspaceJob("Flashing " + project.getName()) { + @Override + public boolean belongsTo(Object family) { + return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); } - } else { - if (success) { // success - logger.debug("[STATUS] " + SUCCEED); //$NON-NLS-1$ - } else { // fail - logger.debug("[STATUS] " + FAILED); //$NON-NLS-1$ + + @Override + public IStatus runInWorkspace(IProgressMonitor monitor) + throws CoreException { + FlashCommand cmd = new FlashCommand(); + if (flashOption != null) { + cmd.setProperty("flashoption", flashOption); //$NON-NLS-1$ + } + cmd.execute(project, consoleManager, monitor); + return Status.OK_STATUS; } - // logger.debug("[RESULT]" + result); - } - return success; - } + }; + wsJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); + wsJob.setUser(true); + wsJob.schedule(); + + return 0; + } } 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 f85172d..af8545b 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,14 +31,8 @@ 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; @@ -46,109 +40,64 @@ 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.commands.model.ScriptUtil; +import org.tizen.rt.ide.commands.ui.FlashOptionDialog; import org.tizen.rt.ide.console.ConsoleManager; 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; /** * FlashCommand * @author gyeongmin.ju{@literal } (S-Core) */ -public class FlashCommand { +public class FlashCommand extends AbstractCommand { /** * important PATH */ - 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$ + 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$ - } - if (buildScriptFile == null || !buildScriptFile.exists()) { + private static FlashScriptData getScript(String activeProjectPath, String board, ConsoleManager consoleManager) { + File buildScriptFile = ScriptUtil.getScriptFile(activeProjectPath, board, getScriptFileName()); + if (buildScriptFile == null) { + if (consoleManager != null) { + consoleManager.println("Can not found xml file of flash spec."); + } return null; } - FlashScriptData buildScript = new FlashScriptData(consoleManager); - buildScript.load(buildScriptFile); + FlashScriptData script = new FlashScriptData(consoleManager); + script.load(buildScriptFile); - buildScript.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ + script.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ if (board != null) { - buildScript.addMacro("BOARD", board); //$NON-NLS-1$ + script.addMacro("BOARD", board); //$NON-NLS-1$ } - return buildScript; + return script; } - 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) { - resultFlashOptionList.add(new FlashOption(cfg, cfg)); - } - - return resultFlashOptionList; - } - - public static int execute(IProject project, String board, FlashOption flashOption, ConsoleManager consoleManager, IProgressMonitor monitor) { + @Override + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { String activeProjectPath = project.getLocation().toString(); - - FlashScriptData flashScript = getScript(activeProjectPath, board, consoleManager); - if (flashScript == null) { - return 1; - } - - String flashCmdName = "flash"; //$NON-NLS-1$ - int result = flashScript.doCommand(flashCmdName, flashOption.getFlashOption(), null); - - if (result != 0) { - return result; - } - - return result; - } - - public Object execute(IProject project, ConsoleManager consoleManager) throws ExecutionException { - String osDir = project.getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ + String osDir = activeProjectPath + File.separator + "os"; //$NON-NLS-1$ + String outDir = activeProjectPath + File.separator + "build" + File.separator + "output"; //$NON-NLS-1$ //$NON-NLS-2$ if (!new File(osDir, ".config").exists()) { //$NON-NLS-1$ MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); - return null; + return 1; } - 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; + return 1; } BuildInfo buildInfo = null; @@ -156,39 +105,23 @@ public class FlashCommand { buildInfo = BuildInfoManager.loadBuildInfo(project); } catch (BuildInfoHandlingException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.FlashHandler_BuildInfoIsNotNormal); - return null; + return 1; } - 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); + String option = properties.getProperty("flashoption"); //$NON-NLS-1$ + if (option == null) { + return 1; } - 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); - } + FlashScriptData flashScript = getScript(activeProjectPath, buildInfo.getBoard(), consoleManager); + if (flashScript == null) { + return 1; + } - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) - throws CoreException { - return (FlashCommand.execute(project, board, flashOption, consoleManager, monitor) == 0) ? Status.OK_STATUS : Status.CANCEL_STATUS; - } - }; + String flashCmdName = "flash"; //$NON-NLS-1$ + int result = flashScript.doCommand(flashCmdName, option, null); - wsJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); - wsJob.setUser(true); - wsJob.schedule(); + return result; } } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/FlashConfigCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/FlashConfigCommand.java new file mode 100644 index 0000000..be9db4b --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/FlashConfigCommand.java @@ -0,0 +1,144 @@ +/* +* Common +* +* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* jm.jemin.kim +* Gyeongmin Ju +* 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.commands; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +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.commands.model.ScriptUtil; +import org.tizen.rt.ide.commands.ui.FlashOptionDialog; +import org.tizen.rt.ide.console.ConsoleManager; +import org.tizen.rt.ide.exception.BuildInfoHandlingException; +import org.tizen.rt.ide.meta.BuildInfo; +import org.tizen.rt.ide.meta.BuildInfoManager; +import org.tizen.rt.ide.util.ViewUtil; + +/** + * FlashCommand + * @author gyeongmin.ju{@literal } (S-Core) + */ +public class FlashConfigCommand extends AbstractCommand { + + /** + * important PATH + */ + 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) { + File buildScriptFile = ScriptUtil.getScriptFile(activeProjectPath, board, getScriptFileName()); + if (buildScriptFile == null) { + if (consoleManager != null) { + consoleManager.println("Can not found xml file of flash spec."); + } + return null; + } + + FlashScriptData script = new FlashScriptData(consoleManager); + script.load(buildScriptFile); + + script.addMacro("PROJECT_PATH", activeProjectPath); //$NON-NLS-1$ + if (board != null) { + script.addMacro("BOARD", board); //$NON-NLS-1$ + } + + return script; + } + + private 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) { + resultFlashOptionList.add(new FlashOption(cfg, cfg)); + } + + return resultFlashOptionList; + } + + @Override + public int execute(IProject project, ConsoleManager consoleManager, IProgressMonitor monitor) { + String activeProjectPath = project.getLocation().toString(); + String osDir = activeProjectPath + File.separator + "os"; //$NON-NLS-1$ + String outDir = activeProjectPath + File.separator + "build" + File.separator + "output"; //$NON-NLS-1$ //$NON-NLS-2$ + + if (!new File(osDir, ".config").exists()) { //$NON-NLS-1$ + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); + return 1; + } + + if (!new File(outDir, FILE_NAME_BUILD_INFO).exists()) { + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.FlashHandler_NotFoundBuildInfo); + return 1; + } + + BuildInfo buildInfo = null; + try { + buildInfo = BuildInfoManager.loadBuildInfo(project); + } catch (BuildInfoHandlingException e) { + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.FlashHandler_BuildInfoIsNotNormal); + return 1; + } + + List options = FlashConfigCommand.executeFindFlashOption(activeProjectPath, buildInfo.getBoard()); + + Shell shell = ViewUtil.getWorkbenchWindow().getShell(); + FlashOptionDialog dialog = new FlashOptionDialog(shell, project, options); + dialog.create(); + int r = dialog.open(); + if (r != Dialog.OK) { + return 1; + } + + String option = dialog.getOption(); + + setProperty("flashoption", option); //$NON-NLS-1$ + + return 0; + } + +} 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 index 2ce3a7f..cda2db5 100644 --- 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 @@ -33,6 +33,10 @@ import java.util.Map; import javax.xml.bind.JAXBException; +import org.eclipse.swt.SWT; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.rt.ide.ResourceManager; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.MacroUtil; import org.tizen.rt.ide.util.ProcUtil; @@ -48,6 +52,10 @@ import org.tizen.rt.product.meta.util.MetaModelUtil; */ public class BuildScriptData { + private static final String SUCCEED = "SUCCEED"; //$NON-NLS-1$ + private static final String FAILED = "FAILED"; //$NON-NLS-1$ + private static final Logger logger = LoggerFactory.getLogger(BuildScriptData.class); + private static class BuildScript { public String cmdStr; public String curDir; @@ -165,12 +173,38 @@ public class BuildScriptData { macros.put(name, value); } + public void consolePrint(String str) { + if (consoleManager != null) { + consoleManager.println(str); + } + } + public void consolePrintln(String str) { if (consoleManager != null) { consoleManager.println(str); } } + private boolean processResult(int result, ConsoleManager consoleManager) { + boolean success = result == 0; + if (consoleManager != null) { + consoleManager.print("[STATUS] ", SWT.BOLD, ResourceManager.INTENSE_BLACK); //$NON-NLS-1$ + if (success) { // success + consoleManager.println(SUCCEED, SWT.BOLD, ResourceManager.INTENSE_GREEN); + } else { // fail + consoleManager.println(FAILED, SWT.BOLD, ResourceManager.INTENSE_RED); + } + } else { + if (success) { // success + logger.debug("[STATUS] " + SUCCEED); //$NON-NLS-1$ + } else { // fail + logger.debug("[STATUS] " + FAILED); //$NON-NLS-1$ + } + // logger.debug("[RESULT]" + result); + } + return success; + } + public int load(File buildScriptFile) { consolePrintln("Build project using " + buildScriptFile); scripts = getBuildScripts(buildScriptFile); @@ -218,9 +252,12 @@ public class BuildScriptData { } cmds[0] = cmdStr; - return ProcUtil.executeProcess(pb, cmds, script.isShellCmd, script.shell, + int result = ProcUtil.executeProcess(pb, cmds, script.isShellCmd, script.shell, curDir, consoleManager, null); + processResult(result, consoleManager); + + return result; } public int doCommand(String buildCmdName) { diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/ScriptUtil.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/ScriptUtil.java new file mode 100644 index 0000000..9ca6e8c --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/model/ScriptUtil.java @@ -0,0 +1,36 @@ +package org.tizen.rt.ide.commands.model; + +import java.io.File; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.tizen.rt.ide.util.SDKUtil; + +public class ScriptUtil { + public static File getScriptFile(String homePath, String boardName, String fileName) { + File buildScriptFile = null; + if (boardName != null) { + buildScriptFile = new File(homePath, "build" + File.separator + "configs" + File.separator + boardName + File.separator + fileName); //$NON-NLS-1$ //$NON-NLS-2$ + } + if (buildScriptFile == null || !buildScriptFile.exists()) { + boolean r = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), + "Warning", fileName + " file not found on Board path.\nDo you want use thi default script file?"); + if (!r) { + return null; + } + + buildScriptFile = new File(homePath, "build" + File.separator + "configs" + File.separator + fileName); //$NON-NLS-1$ //$NON-NLS-2$ + if (buildScriptFile == null || !buildScriptFile.exists()) { + String sdkPath = SDKUtil.getSdkPath(); + buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + File.separator + fileName); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + } + + if (buildScriptFile == null || !buildScriptFile.exists()) { + return null; + } + + return buildScriptFile; + } + +} 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/commands/ui/BuildConfigureDialog.java similarity index 99% rename from rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildConfigureDialog.java rename to rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/ui/BuildConfigureDialog.java index a4ad6f2..77e137a 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/commands/ui/BuildConfigureDialog.java @@ -1,4 +1,4 @@ -package org.tizen.rt.ide.build.ui; +package org.tizen.rt.ide.commands.ui; import java.io.File; import java.util.List; 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/commands/ui/BuildEnvSettingDialog.java similarity index 99% rename from rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/ui/BuildEnvSettingDialog.java rename to rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/ui/BuildEnvSettingDialog.java index 98ef558..dc17f8b 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/commands/ui/BuildEnvSettingDialog.java @@ -1,4 +1,4 @@ -package org.tizen.rt.ide.build.ui; +package org.tizen.rt.ide.commands.ui; import java.util.Map; import java.util.Set; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/flash/ui/FlashOptionDialog.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/ui/FlashOptionDialog.java similarity index 95% rename from rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/flash/ui/FlashOptionDialog.java rename to rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/ui/FlashOptionDialog.java index e7db713..2ce0924 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/flash/ui/FlashOptionDialog.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/commands/ui/FlashOptionDialog.java @@ -25,7 +25,7 @@ * - S-Core Co., Ltd * */ -package org.tizen.rt.ide.flash.ui; +package org.tizen.rt.ide.commands.ui; import java.util.List; import org.eclipse.core.resources.IProject; @@ -47,7 +47,6 @@ 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.commands.CommandManager; import org.tizen.rt.ide.commands.model.FlashOption; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -60,7 +59,7 @@ import org.eclipse.swt.layout.GridLayout; public class FlashOptionDialog extends Dialog { private String projectPath; - private String board; + private List options; private String option; private Table table; public TableViewer tableViewer; @@ -69,11 +68,11 @@ public class FlashOptionDialog extends Dialog { * Create the dialog. * @param parentShell */ - public FlashOptionDialog(Shell parentShell, IProject project, String board) { + public FlashOptionDialog(Shell parentShell, IProject project, List options) { super(parentShell); projectPath = project.getLocation().toString(); - this.board = board; + this.options = options; } /** @@ -116,9 +115,7 @@ public class FlashOptionDialog extends Dialog { tableViewer.setLabelProvider(new TableViewerProvider()); tableViewer.setContentProvider(new ArrayContentProvider()); - List opts = CommandManager.getFlashOptions(projectPath, board); - - tableViewer.setInput(opts); + tableViewer.setInput(options); return composite; } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BatchBuildHandler.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BatchBuildHandler.java index 19672e4..510cf68 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BatchBuildHandler.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BatchBuildHandler.java @@ -32,8 +32,7 @@ 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.tizen.rt.ide.commands.BuildCommand; -import org.tizen.rt.ide.commands.BuildConfigureCommand; +import org.tizen.rt.ide.commands.CommandManager; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; @@ -44,8 +43,6 @@ import org.tizen.rt.ide.util.ResourceUtil; */ public class BatchBuildHandler extends AbstractHandler { - // private final Logger logger = LoggerFactory.getLogger(getClass()); - @Override public Object execute(ExecutionEvent event) throws ExecutionException { IProject project = ResourceUtil.getCurrentProject(); @@ -53,19 +50,19 @@ public class BatchBuildHandler extends AbstractHandler { return null; } - String osDir = project.getLocation().toString() + File.separator + "os"; + String osDir = project.getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ ConsoleManager consoleManager = new ConsoleManager(true); - if (!new File(osDir, ".config").exists()) { - BuildConfigureCommand cmd = new BuildConfigureCommand(); - // cmd.execute(project, consoleManager, monitor); - cmd.execute(project, consoleManager, null); + if (!new File(osDir, ".config").exists()) { //$NON-NLS-1$ + int result = CommandManager.doBuildConfigure(project, consoleManager, null); + if (result != 0) { + return null; + } } - if (new File(osDir, ".config").exists()) { - BuildCommand cmd = new BuildCommand(); - cmd.execute(project, consoleManager); + if (new File(osDir, ".config").exists()) { //$NON-NLS-1$ + CommandManager.doBuild(project, consoleManager, null); } return null; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildConfigureHandler.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildConfigureHandler.java index 41b4496..c2e06a3 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildConfigureHandler.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildConfigureHandler.java @@ -34,7 +34,7 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; -import org.tizen.rt.ide.commands.BuildConfigureCommand; +import org.tizen.rt.ide.commands.CommandManager; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; @@ -49,11 +49,11 @@ public class BuildConfigureHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IProject project = ResourceUtil.getCurrentProject(); - String osDir = ResourceUtil.getCurrentProject().getLocation().toString() + File.separator + "os"; + String osDir = ResourceUtil.getCurrentProject().getLocation().toString() + File.separator + "os"; //$NON-NLS-1$ - if (new File(osDir, ".config").exists()) { + if (new File(osDir, ".config").exists()) { //$NON-NLS-1$ boolean r = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), - "Warning", "The previous configuration already exist.\nOverwrite it?"); //$NON-NLS-1$ + "Warning", "The previous configuration already exist.\nOverwrite it?"); if (!r) { return 1; } @@ -61,8 +61,7 @@ public class BuildConfigureHandler extends AbstractHandler { ConsoleManager consoleManager = new ConsoleManager(true); - BuildConfigureCommand cmd = new BuildConfigureCommand(); - cmd.execute(project, consoleManager, null); + CommandManager.doBuildConfigure(project, consoleManager, null); return null; } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildEnvSettingHandler.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildEnvSettingHandler.java index 6cf8c55..47148b2 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildEnvSettingHandler.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildEnvSettingHandler.java @@ -26,22 +26,13 @@ */ package org.tizen.rt.ide.handlers; -import java.io.File; - 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.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.commands.BuildEnvSettingCommand; +import org.tizen.rt.ide.commands.CommandManager; +import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; -import org.tizen.rt.ide.util.ViewUtil; /** * Our sample handler extends AbstractHandler, an IHandler base class. @@ -50,14 +41,13 @@ import org.tizen.rt.ide.util.ViewUtil; */ public class BuildEnvSettingHandler extends AbstractHandler { - private final Logger logger = LoggerFactory.getLogger(BuildEnvSettingHandler.class); - @Override public Object execute(ExecutionEvent event) throws ExecutionException { IProject project = ResourceUtil.getCurrentProject(); - BuildEnvSettingCommand cmd = new BuildEnvSettingCommand(); - cmd.execute(project); + ConsoleManager consoleManager = new ConsoleManager(true); + + CommandManager.doBuildEnvSetting(project, consoleManager, null); return null; } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildHandler.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildHandler.java index 93f383f..b5836e3 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildHandler.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildHandler.java @@ -34,8 +34,7 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; -import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.commands.BuildCommand; +import org.tizen.rt.ide.commands.CommandManager; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; @@ -52,17 +51,16 @@ public class BuildHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IProject project = ResourceUtil.getCurrentProject(); - 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()) { - MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", "TizenRT has not been configured."); //$NON-NLS-1$ + if(!new File(osDir, ".config").exists()) { //$NON-NLS-1$ + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", "TizenRT has not been configured."); return null; } ConsoleManager consoleManager = new ConsoleManager(true); - BuildCommand cmd = new BuildCommand(); - cmd.execute(consoleManager); + CommandManager.doBuild(project, consoleManager, null); return null; } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildKConfigHandler.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildKConfigHandler.java index 4f106e6..9587bf1 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildKConfigHandler.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/BuildKConfigHandler.java @@ -34,7 +34,8 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; -import org.tizen.rt.ide.commands.BuildKConfigureCommand; +import org.tizen.rt.ide.commands.CommandManager; +import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; /** @@ -48,15 +49,16 @@ public class BuildKConfigHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IProject project = ResourceUtil.getCurrentProject(); - 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()) { - MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", "TizenRT has not been configured."); //$NON-NLS-1$ + if(!new File(osDir, ".config").exists()) { //$NON-NLS-1$ + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", "TizenRT has not been configured."); return null; } - BuildKConfigureCommand cmd = new BuildKConfigureCommand(); - cmd.execute(); + ConsoleManager consoleManager = new ConsoleManager(true); + + CommandManager.doBuildKConfigure(project, consoleManager, null); return null; } 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 index 5f647e9..97e2233 100644 --- 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 @@ -43,6 +43,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.rt.ide.Activator; import org.tizen.rt.ide.Messages; +import org.tizen.rt.ide.commands.CleanCommand; import org.tizen.rt.ide.commands.CommandManager; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; @@ -83,34 +84,10 @@ public class CleanHandler extends AbstractHandler { final boolean useDistClean = dialog.getToggleState(); store.setValue(PREF_KEY_USE_DISTCLEAN, useDistClean); - 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$ - - CommandManager.runClean(project, new ConsoleManager(true), monitor, useDistClean); - 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); - } - + ConsoleManager consoleManager = new ConsoleManager(true); + + CommandManager.doClean(project, useDistClean, consoleManager, logger); + return null; } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/FlashHandler.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/FlashHandler.java index 2d906f3..ee6642b 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/FlashHandler.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/handlers/FlashHandler.java @@ -33,7 +33,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.commands.FlashCommand; +import org.tizen.rt.ide.commands.CommandManager; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.ResourceUtil; @@ -48,17 +48,23 @@ public class FlashHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { IProject project = ResourceUtil.getCurrentProject(); - String osDir = ResourceUtil.getCurrentProject().getLocation().toString() + File.separator + "os"; + String osDir = ResourceUtil.getCurrentProject().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; } ConsoleManager consoleManager = new ConsoleManager(true); - FlashCommand cmd = new FlashCommand(); - return cmd.execute(project, consoleManager); + String option = CommandManager.doFlashCommand(project, consoleManager, null); + if (option == null) { + return null; + } + + CommandManager.doFlash(project, option, consoleManager, null); + + return null; } } diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/launch/LaunchShortcut.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/launch/LaunchShortcut.java index bb3ae7b..37b36f0 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/launch/LaunchShortcut.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/launch/LaunchShortcut.java @@ -57,6 +57,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.rt.ide.Messages; import org.tizen.rt.ide.commands.model.DebugScriptData; +import org.tizen.rt.ide.commands.model.ScriptUtil; import org.tizen.rt.ide.console.ConsoleManager; import org.tizen.rt.ide.util.MacroUtil; import org.tizen.rt.ide.util.OSChecker; @@ -82,35 +83,22 @@ public class LaunchShortcut implements ILaunchShortcut { private static final Logger logger = LoggerFactory.getLogger(LaunchShortcut.class); - private static final String PROP_COMMENT_DEBUG_INFO = "TinyARA Debug information"; //$NON-NLS-1$ - private static final String PROP_NAME_SCRIPT = "script"; //$NON-NLS-1$ private static final String PROP_NAME_BOARD = "board"; //$NON-NLS-1$ private static final String FILE_NAME_BUILD_INFO = "build.info"; //$NON-NLS-1$ private static final String PATH_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$ private static final String PATH_BUILD_CONFIGS = "build/configs"; //$NON-NLS-1$ private static final String PROGRAM_NAME = PATH_BUILD_OUTPUT + "/bin/tinyara"; //$NON-NLS-1$ private static final String DEBUGGER_NAME = "arm-none-eabi-gdb"; //$NON-NLS-1$ - private static final String PATH_LINUX_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$ private static final String FILE_NAME_DEBUG_SCRIPT = ".debugSpec.xml"; //$NON-NLS-1$ private final String OPENOCD_LAUNCHTYPE = "ilg.gnuarmeclipse.debug.gdbjtag.openocd.launchConfigurationType"; //$NON-NLS-1$ - private static DebugScriptData getScript(String activeProjectPath, String boardPath, ConsoleManager consoleManager) { - String sdkPath = SDKUtil.getSdkPath(); - - File buildScriptFile = null; - if (boardPath != null) { - buildScriptFile = new File(boardPath, FILE_NAME_DEBUG_SCRIPT); - } - if (buildScriptFile == null || !buildScriptFile.exists()) { - buildScriptFile = new File(activeProjectPath, FILE_NAME_DEBUG_SCRIPT); - } - if (buildScriptFile == null || !buildScriptFile.exists()) { - buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" - + File.separator + FILE_NAME_DEBUG_SCRIPT); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - if (buildScriptFile == null || !buildScriptFile.exists()) { + private static DebugScriptData getScript(String activeProjectPath, String boardName, ConsoleManager consoleManager) { + File buildScriptFile = ScriptUtil.getScriptFile(activeProjectPath, boardName, FILE_NAME_DEBUG_SCRIPT); + if (buildScriptFile == null) { + if (consoleManager != null) { + consoleManager.println("Can not found xml file of flash spec."); + } return null; } @@ -121,11 +109,8 @@ public class LaunchShortcut implements ILaunchShortcut { } private ILaunchConfiguration createConfiguration(String projectName, IPath targetPath, String boardName) throws CoreException { - String sdkPath = SDKUtil.getSdkPath(); String homePath = ResourceUtil.getCurrentProject().getLocation().toString(); - String boardPath = homePath + File.separator + "build" + File.separator + "configs" + File.separator + boardName; //$NON-NLS-1$ //$NON-NLS-2$ - - DebugScriptData debugScriptData = getScript(homePath, boardPath, null); + DebugScriptData debugScriptData = getScript(homePath, boardName, null); if (debugScriptData == null) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosDebug_ERROR_DEBUGSCRIPT_NOT_EXIST); return null;