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 --- .../managedbuilder/job/ExecuteConfigureJob.java | 186 +++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java (limited to 'plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java') diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java new file mode 100644 index 0000000..354d930 --- /dev/null +++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * 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 API and implementation + *******************************************************************************/ +package org.yocto.cmake.managedbuilder.job; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.envvar.IContributedEnvironment; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; +import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.console.IOConsoleOutputStream; +import org.yocto.cmake.managedbuilder.Activator; +import org.yocto.cmake.managedbuilder.YoctoCMakeMessages; +import org.yocto.cmake.managedbuilder.util.ConsoleUtility; +import org.yocto.cmake.managedbuilder.util.SystemProcess; + + +public class ExecuteConfigureJob extends Job { + private SystemProcess configureProcess; + private LinkedList configureCommand; + private IProject project; + private IConfiguration configuration; + private IPath location; + + + public ExecuteConfigureJob(String name, + IProject project, IConfiguration configuration, IPath location) { + super(name); + this.project = project; + this.configuration = configuration; + this.location = location; + createCommands(); + createProcesses(); + } + + protected void createCommands() { + configureCommand = new LinkedList(); + + ITool[] configure = configuration + .getToolsBySuperClassId("org.yocto.cmake.managedbuilder.cmakeconfigure.gnu.exe"); //$NON-NLS-1$ + + addCommand(configure[0]); + + try { + addFlags(configure[0]); + } catch (BuildException e) { + // ignore this exception + } + } + + private void addCommand(ITool configure) { + String command = configuration.getToolCommand(configure); + configureCommand.add(command); + } + + private void addFlags(ITool configure) throws BuildException { + String[] flags = configure.getToolCommandFlags( + project.getLocation(), location); + for (String flag : flags) { + if (flag.contains(" ")) { //$NON-NLS-1$ + String[] separatedFlags = flag.trim().split(" "); //$NON-NLS-1$ + configureCommand.addAll(Arrays.asList(separatedFlags)); + } else { + configureCommand.add(flag); + } + } + } + + protected void createProcesses() { + configureProcess = + new SystemProcess(configureCommand, location.toFile(), getEnvVariablesAsMap(project)); + } + + private Map getEnvVariablesAsMap (IProject project) { + Map result = new HashMap(); + + ICProjectDescription cpdesc = CoreModel.getDefault().getProjectDescription(project, true); + ICConfigurationDescription ccdesc = cpdesc.getActiveConfiguration(); + IEnvironmentVariableManager manager = CCorePlugin.getDefault().getBuildEnvironmentManager(); + IContributedEnvironment env = manager.getContributedEnvironment(); + + for(IEnvironmentVariable var : env.getVariables(ccdesc)) { + result.put(var.getName(), var.getValue()); + } + + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask( + YoctoCMakeMessages.getString("ExecuteConfigureJob.runConfigure"), 20); //$NON-NLS-1$ + + IOConsoleOutputStream cos = + ConsoleUtility.getConsoleOutput(YoctoCMakeMessages.getFormattedString("ExecuteConfigureJob.consoleName", //$NON-NLS-1$ + project.getName())); + monitor.worked(1); + + try { + return buildProject(monitor, cos); + } catch (IOException e) { + if(e.getMessage().startsWith("Cannot run program \"cmake\"")) { //$NON-NLS-1$ + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + MessageDialog.openWarning(null, + YoctoCMakeMessages.getString("ExecuteConfigureJob.cmakeWarning.dialogTitle"), //$NON-NLS-1$ + YoctoCMakeMessages.getString("ExecuteConfigureJob.cmakeWarning.dialogMessage")); //$NON-NLS-1$ + } + }); + return Status.OK_STATUS; + } else { + return new Status(Status.ERROR, + Activator.PLUGIN_ID, Status.OK, + YoctoCMakeMessages.getString("ExecuteConfigureJob.error.couldNotStart"), e); //$NON-NLS-1$ + } + } catch (InterruptedException e) { + return new Status(Status.WARNING, + Activator.PLUGIN_ID, + YoctoCMakeMessages.getString("ExecuteConfigureJob.warning.aborted")); //$NON-NLS-1$ + } finally { + try { + cos.close(); + } catch (IOException e) { + cos = null; + } + } + } + + private IStatus buildProject(IProgressMonitor monitor, + IOConsoleOutputStream cos) throws IOException, InterruptedException { + monitor.subTask( + YoctoCMakeMessages.getString("ExecuteConfigureJob.buildingMakefile")); //$NON-NLS-1$ + configureProcess.start(cos); + int exitValue = configureProcess.waitForResultAndStop(); + monitor.worked(15); + + if (exitValue != 0) { + return new Status(Status.ERROR, Activator.PLUGIN_ID, + YoctoCMakeMessages.getString("ExecuteConfigureJob.error.buildFailed") + " " + exitValue); //$NON-NLS-1$ //$NON-NLS-2$ + } + + return Status.OK_STATUS; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#canceling() + */ + /** + * Cancels the job and interrupts the system process. + * {@inheritDoc} + */ + @Override + protected void canceling() { + configureProcess.interrupt(); + } +} -- cgit v1.2.3-54-g00ecf