diff options
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions')
5 files changed, 390 insertions, 0 deletions
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 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.actions; | ||
12 | |||
13 | import java.io.IOException; | ||
14 | import java.io.OutputStream; | ||
15 | import java.util.ArrayList; | ||
16 | |||
17 | import org.eclipse.cdt.core.CommandLauncher; | ||
18 | import org.eclipse.cdt.core.ConsoleOutputStream; | ||
19 | import org.eclipse.cdt.core.envvar.IEnvironmentVariable; | ||
20 | import org.eclipse.cdt.core.resources.IConsole; | ||
21 | import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
22 | import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; | ||
23 | import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; | ||
24 | import org.eclipse.core.resources.IProject; | ||
25 | import org.eclipse.core.runtime.CoreException; | ||
26 | import org.eclipse.core.runtime.IPath; | ||
27 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
28 | import org.eclipse.core.runtime.Path; | ||
29 | import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator; | ||
30 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; | ||
31 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeMessages; | ||
32 | |||
33 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
34 | |||
35 | @SuppressWarnings("restriction") | ||
36 | public class InvokeSyncAction extends InvokeAction { | ||
37 | protected void executeLocalConsoleCommand(final IConsole console, final String actionName, final String command, | ||
38 | final String[] argumentList, final IPath execDir, final String password) throws CoreException, IOException { | ||
39 | |||
40 | String errMsg = null; | ||
41 | IProject project = getSelectedContainer().getProject(); | ||
42 | // Get a build console for the project | ||
43 | ConsoleOutputStream consoleOutStream = console.getOutputStream(); | ||
44 | // FIXME: we want to remove need for ManagedBuilderManager, but how do we | ||
45 | // get environment variables. | ||
46 | IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); | ||
47 | IConfiguration cfg = info.getDefaultConfiguration(); | ||
48 | |||
49 | StringBuffer buf = new StringBuffer(); | ||
50 | String[] consoleHeader = new String[3]; | ||
51 | |||
52 | consoleHeader[0] = actionName; | ||
53 | consoleHeader[1] = cfg.getName(); | ||
54 | consoleHeader[2] = project.getName(); | ||
55 | buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ | ||
56 | String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$ | ||
57 | new String[]{actionName, execDir.toString()}); //$NON-NLS-1$ | ||
58 | buf.append(invokeMsg); | ||
59 | buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ | ||
60 | buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ | ||
61 | consoleOutStream.write(buf.toString().getBytes()); | ||
62 | consoleOutStream.flush(); | ||
63 | |||
64 | ArrayList<String> additionalEnvs = new ArrayList<String>(); | ||
65 | String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs); | ||
66 | // Get a launcher for the config command | ||
67 | CommandLauncher launcher = new CommandLauncher(); | ||
68 | // Set the environment | ||
69 | IEnvironmentVariable variables[] = ManagedBuildManager | ||
70 | .getEnvironmentVariableProvider().getVariables(cfg, true); | ||
71 | String[] env = null; | ||
72 | ArrayList<String> envList = new ArrayList<String>(); | ||
73 | if (variables != null) { | ||
74 | for (int i = 0; i < variables.length; i++) { | ||
75 | envList.add(variables[i].getName() | ||
76 | + "=" + variables[i].getValue()); //$NON-NLS-1$ | ||
77 | } | ||
78 | // add any additional environment variables specified ahead of script | ||
79 | if (additionalEnvs.size() > 0) | ||
80 | envList.addAll(additionalEnvs); | ||
81 | env = (String[]) envList.toArray(new String[envList.size()]); | ||
82 | } | ||
83 | OutputStream stdout = consoleOutStream; | ||
84 | OutputStream stderr = consoleOutStream; | ||
85 | |||
86 | launcher.showCommand(true); | ||
87 | // Run the shell script via shell command. | ||
88 | Process proc = launcher.execute(new Path(strippedCommand), argumentList, env, | ||
89 | execDir, new NullProgressMonitor()); | ||
90 | |||
91 | if (proc != null) { | ||
92 | // Close the input of the process since we will never write to it | ||
93 | OutputStream out = proc.getOutputStream(); | ||
94 | if (!password.isEmpty()) { | ||
95 | out.write(password.getBytes()); | ||
96 | out.write("\n".getBytes()); | ||
97 | } | ||
98 | out.close(); | ||
99 | |||
100 | if (launcher.waitAndRead(stdout, stderr) != CommandLauncher.OK) { | ||
101 | errMsg = launcher.getErrorMessage(); | ||
102 | } | ||
103 | } else { | ||
104 | errMsg = launcher.getErrorMessage(); | ||
105 | } | ||
106 | |||
107 | if (errMsg != null) | ||
108 | YoctoSDKPlugin.logErrorMessage(errMsg); | ||
109 | } | ||
110 | } | ||
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 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * BMW Car IT - initial implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.actions; | ||
12 | |||
13 | import java.util.Map; | ||
14 | |||
15 | import org.eclipse.cdt.core.model.ICElement; | ||
16 | import org.eclipse.cdt.core.model.ICProject; | ||
17 | import org.eclipse.core.commands.AbstractHandler; | ||
18 | import org.eclipse.core.commands.Command; | ||
19 | import org.eclipse.core.commands.ExecutionEvent; | ||
20 | import org.eclipse.core.commands.ExecutionException; | ||
21 | import org.eclipse.core.commands.State; | ||
22 | import org.eclipse.core.resources.IProject; | ||
23 | import org.eclipse.core.resources.IResource; | ||
24 | import org.eclipse.core.runtime.IAdaptable; | ||
25 | import org.eclipse.core.runtime.Status; | ||
26 | import org.eclipse.jface.dialogs.ErrorDialog; | ||
27 | import org.eclipse.jface.preference.IPreferenceStore; | ||
28 | import org.eclipse.jface.viewers.ISelection; | ||
29 | import org.eclipse.jface.viewers.ITreeSelection; | ||
30 | import org.eclipse.swt.widgets.Display; | ||
31 | import org.eclipse.ui.commands.ICommandService; | ||
32 | import org.eclipse.ui.commands.IElementUpdater; | ||
33 | import org.eclipse.ui.handlers.HandlerUtil; | ||
34 | import org.eclipse.ui.handlers.RadioState; | ||
35 | import org.eclipse.ui.menus.UIElement; | ||
36 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
37 | import org.yocto.sdk.ide.YoctoSDKChecker; | ||
38 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
39 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
40 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
41 | import org.yocto.sdk.ide.YoctoUIElement; | ||
42 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
43 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
44 | |||
45 | public class ProfileSwitchHandler extends AbstractHandler implements IElementUpdater { | ||
46 | private static final String PROJECT_SPECIFIC_ERROR = "Preferences.Profile.ProjectSpecific.Error.Title"; | ||
47 | private static final String PROJECT_SPECIFIC_ERROR_MESSAGE = "Preferences.Profile.ProjectSpecific.Error.Message"; | ||
48 | |||
49 | public static final String PROFILE_SWITCH_COMMAND = "org.yocto.sdk.ide.targetProfile.switch"; //$NON-NLS-N$ | ||
50 | public static final String PROJECT_SPECIFIC_PARAMETER = "##PROJECT_SPECIFIC_PROFILE##"; //$NON-NLS-N$ | ||
51 | |||
52 | @Override | ||
53 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
54 | if(HandlerUtil.matchesRadioState(event)) { | ||
55 | return null; | ||
56 | } | ||
57 | |||
58 | String currentState = event.getParameter(RadioState.PARAMETER_ID); | ||
59 | HandlerUtil.updateRadioState(event.getCommand(), currentState); | ||
60 | |||
61 | switchProfile(getSelectedProject(event), currentState); | ||
62 | |||
63 | return null; | ||
64 | } | ||
65 | |||
66 | public IProject getSelectedProject(ExecutionEvent event) { | ||
67 | ISelection selection = HandlerUtil.getCurrentSelection(event); | ||
68 | |||
69 | if (selection instanceof ITreeSelection) { | ||
70 | Object selectedItem = ((ITreeSelection) selection).getFirstElement(); | ||
71 | if (selectedItem instanceof IResource) { | ||
72 | return ((IResource) selectedItem).getProject(); | ||
73 | } else if (selectedItem instanceof ICElement) { | ||
74 | ICProject cProject = ((ICElement) selectedItem).getCProject(); | ||
75 | if (cProject != null) { | ||
76 | return cProject.getProject(); | ||
77 | } | ||
78 | } else if (selectedItem instanceof IAdaptable) { | ||
79 | Object projectObject = ((IAdaptable) selectedItem).getAdapter(IProject.class); | ||
80 | if (projectObject != null && projectObject instanceof IProject) { | ||
81 | return ((IProject) projectObject); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | return null; | ||
87 | } | ||
88 | |||
89 | private void switchProfile(IProject project, String selectedProfile) { | ||
90 | if (PROJECT_SPECIFIC_PARAMETER.equals(selectedProfile)) { | ||
91 | YoctoUIElement yoctoUIElement = ProjectPreferenceUtils.getElem(project); | ||
92 | SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(yoctoUIElement); | ||
93 | |||
94 | if ((result != SDKCheckResults.SDK_PASS)) { | ||
95 | Display display = Display.getCurrent(); | ||
96 | ErrorDialog.openError(display.getActiveShell(), | ||
97 | YoctoSDKMessages.getString(PROJECT_SPECIFIC_ERROR), | ||
98 | YoctoSDKMessages.getFormattedString(PROJECT_SPECIFIC_ERROR_MESSAGE, | ||
99 | project.getName()), | ||
100 | new Status(Status.ERROR, YoctoSDKPlugin.PLUGIN_ID, result.getMessage())); | ||
101 | return; | ||
102 | } | ||
103 | |||
104 | ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUIElement, project); | ||
105 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, true); | ||
106 | } else { | ||
107 | IPreferenceStore store = YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile); | ||
108 | YoctoUIElement yoctoUIElement = YoctoSDKUtils.getElemFromStore(store); | ||
109 | ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUIElement, project); | ||
110 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, false); | ||
111 | |||
112 | YoctoProfileElement profileSettings = ProjectPreferenceUtils.getProfiles(project); | ||
113 | profileSettings.setSelectedProfile(selectedProfile); | ||
114 | ProjectPreferenceUtils.saveProfiles(profileSettings, project); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | /* | ||
119 | * Workaround for BUG 398647 to allow checking radio items | ||
120 | * in a dynamic contribution | ||
121 | * | ||
122 | * https://bugs.eclipse.org/bugs/show_bug.cgi?id=398647 | ||
123 | */ | ||
124 | @Override | ||
125 | public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) { | ||
126 | ICommandService service = (ICommandService) element.getServiceLocator().getService(ICommandService.class); | ||
127 | String state = (String) parameters.get(RadioState.PARAMETER_ID); | ||
128 | Command command = service.getCommand(PROFILE_SWITCH_COMMAND); | ||
129 | State commandState = command.getState(RadioState.STATE_ID); | ||
130 | if (commandState.getValue().equals(state)) { | ||
131 | element.setChecked(true); | ||
132 | } | ||
133 | } | ||
134 | } | ||
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 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.actions; | ||
12 | |||
13 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; | ||
14 | import org.eclipse.core.resources.IContainer; | ||
15 | import org.eclipse.core.resources.IProject; | ||
16 | import org.eclipse.jface.action.IAction; | ||
17 | import org.eclipse.jface.preference.PreferenceDialog; | ||
18 | import org.eclipse.ui.dialogs.PreferencesUtil; | ||
19 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
20 | |||
21 | |||
22 | @SuppressWarnings("restriction") | ||
23 | public class ReconfigYoctoAction extends InvokeAction { | ||
24 | |||
25 | public void run(IAction action) { | ||
26 | IContainer container = getSelectedContainer(); | ||
27 | if (container == null) | ||
28 | return; | ||
29 | |||
30 | IProject project = container.getProject(); | ||
31 | |||
32 | PreferenceDialog dialog = | ||
33 | PreferencesUtil.createPropertyDialogOn(YoctoSDKPlugin.getActiveWorkbenchShell(), | ||
34 | project, | ||
35 | "org.yocto.sdk.ide.page", | ||
36 | null, | ||
37 | null); | ||
38 | dialog.open(); | ||
39 | } | ||
40 | |||
41 | public void dispose() { | ||
42 | |||
43 | } | ||
44 | } | ||
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 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.actions; | ||
12 | |||
13 | import java.lang.reflect.Method; | ||
14 | |||
15 | import org.eclipse.core.commands.ExecutionEvent; | ||
16 | import org.eclipse.core.commands.ExecutionException; | ||
17 | import org.eclipse.core.expressions.IEvaluationContext; | ||
18 | import org.eclipse.core.resources.IContainer; | ||
19 | import org.eclipse.core.runtime.IStatus; | ||
20 | import org.eclipse.core.runtime.Status; | ||
21 | import org.eclipse.jface.dialogs.ErrorDialog; | ||
22 | import org.eclipse.cdt.internal.autotools.ui.actions.AbstractAutotoolsHandler; | ||
23 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; | ||
24 | import org.eclipse.swt.widgets.Display; | ||
25 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
26 | |||
27 | |||
28 | @SuppressWarnings("restriction") | ||
29 | public class ReconfigYoctoHandler extends AbstractAutotoolsHandler { | ||
30 | |||
31 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
32 | ReconfigYoctoAction action = new ReconfigYoctoAction(); | ||
33 | Method method = null; | ||
34 | |||
35 | try { | ||
36 | /* | ||
37 | * This is hack to workaround upstream eclipse bug #370288 | ||
38 | */ | ||
39 | Class [] params = {ExecutionEvent.class, InvokeAction.class}; | ||
40 | method = AbstractAutotoolsHandler.class.getDeclaredMethod("execute",params ); | ||
41 | } catch (NoSuchMethodException e) { | ||
42 | //no such method, old version of plugin org.eclipse.linuxtools.autotools.ui | ||
43 | method = null; | ||
44 | } catch (Exception e) { | ||
45 | throw new ExecutionException(e.getMessage(), e); | ||
46 | } | ||
47 | |||
48 | if (method != null) { | ||
49 | //new version | ||
50 | Object [] params = {event, action}; | ||
51 | try { | ||
52 | return method.invoke(this, params); | ||
53 | }catch (Exception e) { | ||
54 | throw new ExecutionException(e.getMessage(), e); | ||
55 | } | ||
56 | } else { | ||
57 | //old version | ||
58 | //display a dialog to warn the user | ||
59 | Display.getDefault().syncExec(new Runnable() { | ||
60 | public void run() { | ||
61 | ErrorDialog.openError(null, "Change Yocto Project Settings", "Please update the plugin of \"Autotools support for CDT\"!", | ||
62 | new Status(IStatus.WARNING,YoctoSDKPlugin.PLUGIN_ID,"old version of plugin \"Autotools support for CDT\" detected.")); | ||
63 | } | ||
64 | }); | ||
65 | //try to display the dialog in the old way | ||
66 | Object o = event.getApplicationContext(); | ||
67 | if (o instanceof IEvaluationContext) { | ||
68 | IContainer container = getContainer((IEvaluationContext)o); | ||
69 | if (container != null) { | ||
70 | action.setSelectedContainer(container); | ||
71 | action.run(null); | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | |||
76 | return null; | ||
77 | } | ||
78 | } | ||
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 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.actions; | ||
12 | |||
13 | import org.eclipse.cdt.internal.autotools.ui.Console; | ||
14 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
15 | |||
16 | @SuppressWarnings("restriction") | ||
17 | public class YoctoConsole extends Console { | ||
18 | private static final String CONTEXT_MENU_ID = "YoctoConsole"; | ||
19 | private static final String CONSOLE_NAME = YoctoSDKMessages.getString("Console.SDK.Name"); | ||
20 | |||
21 | public YoctoConsole() { | ||
22 | super(CONSOLE_NAME, CONTEXT_MENU_ID); | ||
23 | } | ||
24 | } | ||