From 41ac47d732eed8392d60d0f6773e5a279d49b999 Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 12 Dec 2013 13:36:50 +0100 Subject: initial commit of Enea Linux 3.1 Migrated from the internal git server on the dora-enea branch Signed-off-by: Adrian Dudau --- .../yocto/sdk/ide/actions/InvokeSyncAction.java | 110 +++++++++++++++++ .../sdk/ide/actions/ProfileSwitchHandler.java | 134 +++++++++++++++++++++ .../yocto/sdk/ide/actions/ReconfigYoctoAction.java | 44 +++++++ .../sdk/ide/actions/ReconfigYoctoHandler.java | 78 ++++++++++++ .../org/yocto/sdk/ide/actions/YoctoConsole.java | 24 ++++ 5 files changed, 390 insertions(+) create mode 100644 plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java create mode 100644 plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ProfileSwitchHandler.java create mode 100644 plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoAction.java create mode 100644 plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoHandler.java create mode 100644 plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/YoctoConsole.java (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions') diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java new file mode 100644 index 0000000..f39d5fd --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.ide.actions; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; + +import org.eclipse.cdt.core.CommandLauncher; +import org.eclipse.cdt.core.ConsoleOutputStream; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; +import org.eclipse.cdt.core.resources.IConsole; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator; +import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; +import org.eclipse.cdt.internal.autotools.ui.actions.InvokeMessages; + +import org.yocto.sdk.ide.YoctoSDKPlugin; + +@SuppressWarnings("restriction") +public class InvokeSyncAction extends InvokeAction { + protected void executeLocalConsoleCommand(final IConsole console, final String actionName, final String command, + final String[] argumentList, final IPath execDir, final String password) throws CoreException, IOException { + + String errMsg = null; + IProject project = getSelectedContainer().getProject(); + // Get a build console for the project + ConsoleOutputStream consoleOutStream = console.getOutputStream(); + // FIXME: we want to remove need for ManagedBuilderManager, but how do we + // get environment variables. + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IConfiguration cfg = info.getDefaultConfiguration(); + + StringBuffer buf = new StringBuffer(); + String[] consoleHeader = new String[3]; + + consoleHeader[0] = actionName; + consoleHeader[1] = cfg.getName(); + consoleHeader[2] = project.getName(); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$ + new String[]{actionName, execDir.toString()}); //$NON-NLS-1$ + buf.append(invokeMsg); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + consoleOutStream.write(buf.toString().getBytes()); + consoleOutStream.flush(); + + ArrayList additionalEnvs = new ArrayList(); + String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs); + // Get a launcher for the config command + CommandLauncher launcher = new CommandLauncher(); + // Set the environment + IEnvironmentVariable variables[] = ManagedBuildManager + .getEnvironmentVariableProvider().getVariables(cfg, true); + String[] env = null; + ArrayList envList = new ArrayList(); + if (variables != null) { + for (int i = 0; i < variables.length; i++) { + envList.add(variables[i].getName() + + "=" + variables[i].getValue()); //$NON-NLS-1$ + } + // add any additional environment variables specified ahead of script + if (additionalEnvs.size() > 0) + envList.addAll(additionalEnvs); + env = (String[]) envList.toArray(new String[envList.size()]); + } + OutputStream stdout = consoleOutStream; + OutputStream stderr = consoleOutStream; + + launcher.showCommand(true); + // Run the shell script via shell command. + Process proc = launcher.execute(new Path(strippedCommand), argumentList, env, + execDir, new NullProgressMonitor()); + + if (proc != null) { + // Close the input of the process since we will never write to it + OutputStream out = proc.getOutputStream(); + if (!password.isEmpty()) { + out.write(password.getBytes()); + out.write("\n".getBytes()); + } + out.close(); + + if (launcher.waitAndRead(stdout, stderr) != CommandLauncher.OK) { + errMsg = launcher.getErrorMessage(); + } + } else { + errMsg = launcher.getErrorMessage(); + } + + if (errMsg != null) + YoctoSDKPlugin.logErrorMessage(errMsg); + } +} diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ProfileSwitchHandler.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ProfileSwitchHandler.java new file mode 100644 index 0000000..e3e7e60 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ProfileSwitchHandler.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2013 BMW Car IT GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * BMW Car IT - initial implementation + *******************************************************************************/ +package org.yocto.sdk.ide.actions; + +import java.util.Map; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.State; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.handlers.RadioState; +import org.eclipse.ui.menus.UIElement; +import org.yocto.sdk.ide.YoctoProfileElement; +import org.yocto.sdk.ide.YoctoSDKChecker; +import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; +import org.yocto.sdk.ide.YoctoSDKMessages; +import org.yocto.sdk.ide.YoctoSDKPlugin; +import org.yocto.sdk.ide.YoctoUIElement; +import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; +import org.yocto.sdk.ide.utils.YoctoSDKUtils; + +public class ProfileSwitchHandler extends AbstractHandler implements IElementUpdater { + private static final String PROJECT_SPECIFIC_ERROR = "Preferences.Profile.ProjectSpecific.Error.Title"; + private static final String PROJECT_SPECIFIC_ERROR_MESSAGE = "Preferences.Profile.ProjectSpecific.Error.Message"; + + public static final String PROFILE_SWITCH_COMMAND = "org.yocto.sdk.ide.targetProfile.switch"; //$NON-NLS-N$ + public static final String PROJECT_SPECIFIC_PARAMETER = "##PROJECT_SPECIFIC_PROFILE##"; //$NON-NLS-N$ + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + if(HandlerUtil.matchesRadioState(event)) { + return null; + } + + String currentState = event.getParameter(RadioState.PARAMETER_ID); + HandlerUtil.updateRadioState(event.getCommand(), currentState); + + switchProfile(getSelectedProject(event), currentState); + + return null; + } + + public IProject getSelectedProject(ExecutionEvent event) { + ISelection selection = HandlerUtil.getCurrentSelection(event); + + if (selection instanceof ITreeSelection) { + Object selectedItem = ((ITreeSelection) selection).getFirstElement(); + if (selectedItem instanceof IResource) { + return ((IResource) selectedItem).getProject(); + } else if (selectedItem instanceof ICElement) { + ICProject cProject = ((ICElement) selectedItem).getCProject(); + if (cProject != null) { + return cProject.getProject(); + } + } else if (selectedItem instanceof IAdaptable) { + Object projectObject = ((IAdaptable) selectedItem).getAdapter(IProject.class); + if (projectObject != null && projectObject instanceof IProject) { + return ((IProject) projectObject); + } + } + } + + return null; + } + + private void switchProfile(IProject project, String selectedProfile) { + if (PROJECT_SPECIFIC_PARAMETER.equals(selectedProfile)) { + YoctoUIElement yoctoUIElement = ProjectPreferenceUtils.getElem(project); + SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(yoctoUIElement); + + if ((result != SDKCheckResults.SDK_PASS)) { + Display display = Display.getCurrent(); + ErrorDialog.openError(display.getActiveShell(), + YoctoSDKMessages.getString(PROJECT_SPECIFIC_ERROR), + YoctoSDKMessages.getFormattedString(PROJECT_SPECIFIC_ERROR_MESSAGE, + project.getName()), + new Status(Status.ERROR, YoctoSDKPlugin.PLUGIN_ID, result.getMessage())); + return; + } + + ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUIElement, project); + ProjectPreferenceUtils.saveUseProjectSpecificOption(project, true); + } else { + IPreferenceStore store = YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile); + YoctoUIElement yoctoUIElement = YoctoSDKUtils.getElemFromStore(store); + ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUIElement, project); + ProjectPreferenceUtils.saveUseProjectSpecificOption(project, false); + + YoctoProfileElement profileSettings = ProjectPreferenceUtils.getProfiles(project); + profileSettings.setSelectedProfile(selectedProfile); + ProjectPreferenceUtils.saveProfiles(profileSettings, project); + } + } + + /* + * Workaround for BUG 398647 to allow checking radio items + * in a dynamic contribution + * + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=398647 + */ + @Override + public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) { + ICommandService service = (ICommandService) element.getServiceLocator().getService(ICommandService.class); + String state = (String) parameters.get(RadioState.PARAMETER_ID); + Command command = service.getCommand(PROFILE_SWITCH_COMMAND); + State commandState = command.getState(RadioState.STATE_ID); + if (commandState.getValue().equals(state)) { + element.setChecked(true); + } + } +} diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoAction.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoAction.java new file mode 100644 index 0000000..e255fd1 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoAction.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.ide.actions; + +import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.ui.dialogs.PreferencesUtil; +import org.yocto.sdk.ide.YoctoSDKPlugin; + + +@SuppressWarnings("restriction") +public class ReconfigYoctoAction extends InvokeAction { + + public void run(IAction action) { + IContainer container = getSelectedContainer(); + if (container == null) + return; + + IProject project = container.getProject(); + + PreferenceDialog dialog = + PreferencesUtil.createPropertyDialogOn(YoctoSDKPlugin.getActiveWorkbenchShell(), + project, + "org.yocto.sdk.ide.page", + null, + null); + dialog.open(); + } + + public void dispose() { + + } +} diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoHandler.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoHandler.java new file mode 100644 index 0000000..6d508d3 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoHandler.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.ide.actions; + +import java.lang.reflect.Method; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.cdt.internal.autotools.ui.actions.AbstractAutotoolsHandler; +import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; +import org.eclipse.swt.widgets.Display; +import org.yocto.sdk.ide.YoctoSDKPlugin; + + +@SuppressWarnings("restriction") +public class ReconfigYoctoHandler extends AbstractAutotoolsHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + ReconfigYoctoAction action = new ReconfigYoctoAction(); + Method method = null; + + try { + /* + * This is hack to workaround upstream eclipse bug #370288 + */ + Class [] params = {ExecutionEvent.class, InvokeAction.class}; + method = AbstractAutotoolsHandler.class.getDeclaredMethod("execute",params ); + } catch (NoSuchMethodException e) { + //no such method, old version of plugin org.eclipse.linuxtools.autotools.ui + method = null; + } catch (Exception e) { + throw new ExecutionException(e.getMessage(), e); + } + + if (method != null) { + //new version + Object [] params = {event, action}; + try { + return method.invoke(this, params); + }catch (Exception e) { + throw new ExecutionException(e.getMessage(), e); + } + } else { + //old version + //display a dialog to warn the user + Display.getDefault().syncExec(new Runnable() { + public void run() { + ErrorDialog.openError(null, "Change Yocto Project Settings", "Please update the plugin of \"Autotools support for CDT\"!", + new Status(IStatus.WARNING,YoctoSDKPlugin.PLUGIN_ID,"old version of plugin \"Autotools support for CDT\" detected.")); + } + }); + //try to display the dialog in the old way + Object o = event.getApplicationContext(); + if (o instanceof IEvaluationContext) { + IContainer container = getContainer((IEvaluationContext)o); + if (container != null) { + action.setSelectedContainer(container); + action.run(null); + } + } + } + + return null; + } +} diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/YoctoConsole.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/YoctoConsole.java new file mode 100644 index 0000000..4b25d94 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/YoctoConsole.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.ide.actions; + +import org.eclipse.cdt.internal.autotools.ui.Console; +import org.yocto.sdk.ide.YoctoSDKMessages; + +@SuppressWarnings("restriction") +public class YoctoConsole extends Console { + private static final String CONTEXT_MENU_ID = "YoctoConsole"; + private static final String CONSOLE_NAME = YoctoSDKMessages.getString("Console.SDK.Name"); + + public YoctoConsole() { + super(CONSOLE_NAME, CONTEXT_MENU_ID); + } +} -- cgit v1.2.3-54-g00ecf