summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java
diff options
context:
space:
mode:
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.java110
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 *******************************************************************************/
11package org.yocto.sdk.ide.actions;
12
13import java.io.IOException;
14import java.io.OutputStream;
15import java.util.ArrayList;
16
17import org.eclipse.cdt.core.CommandLauncher;
18import org.eclipse.cdt.core.ConsoleOutputStream;
19import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
20import org.eclipse.cdt.core.resources.IConsole;
21import org.eclipse.cdt.managedbuilder.core.IConfiguration;
22import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
23import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
24import org.eclipse.core.resources.IProject;
25import org.eclipse.core.runtime.CoreException;
26import org.eclipse.core.runtime.IPath;
27import org.eclipse.core.runtime.NullProgressMonitor;
28import org.eclipse.core.runtime.Path;
29import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator;
30import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction;
31import org.eclipse.cdt.internal.autotools.ui.actions.InvokeMessages;
32
33import org.yocto.sdk.ide.YoctoSDKPlugin;
34
35@SuppressWarnings("restriction")
36public 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}