diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:23:09 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:24:09 +0200 |
commit | c7da892cb23d50d4d85746c9a0b6b14bf570989d (patch) | |
tree | e7136073f386d6156f51766c498c52c30c8df85f /plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java | |
download | eclipse-poky-kepler-c7da892cb23d50d4d85746c9a0b6b14bf570989d.tar.gz |
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java')
-rw-r--r-- | plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java | 110 |
1 files changed, 110 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 | } | ||