aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions
diff options
context:
space:
mode:
Diffstat (limited to 'org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions')
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/AbstractBitbakeCommandAction.java199
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeBuildRecipeAction.java24
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeCleanRecipeAction.java26
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeImportAction.java106
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeRebuildRecipeAction.java29
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java48
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewRecipeWizardAction.java48
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchVariableWizardAction.java78
8 files changed, 558 insertions, 0 deletions
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/AbstractBitbakeCommandAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/AbstractBitbakeCommandAction.java
new file mode 100644
index 0000000..4e93eee
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/AbstractBitbakeCommandAction.java
@@ -0,0 +1,199 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+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.action.IAction;
+import org.eclipse.jface.preference.JFacePreferences;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
+import org.openembedded.bc.bitbake.BBLanguageHelper;
+import org.openembedded.bc.bitbake.BBSession;
+import org.openembedded.bc.bitbake.ICommandResponseHandler;
+import org.openembedded.bc.ui.Activator;
+import org.openembedded.bc.ui.builder.BitbakeCommanderNature;
+
+
+public abstract class AbstractBitbakeCommandAction implements IWorkbenchWindowActionDelegate {
+
+ private class CommandJob extends Job {
+
+ public CommandJob() {
+ super(getJobTitle());
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ String cmds[] = getCommands();
+ return execCommands(cmds, monitor);
+ }
+
+ }
+ protected IAction action;
+ protected IFile recipe;
+ protected BBSession bbs;
+
+ private Color commandColor, responseColor, errorColor;
+ private boolean errorOccurred = false;
+
+ public AbstractBitbakeCommandAction() {
+ commandColor = JFaceResources.getColorRegistry().get(JFacePreferences.ACTIVE_HYPERLINK_COLOR);
+ responseColor = JFaceResources.getColorRegistry().get(JFacePreferences.HYPERLINK_COLOR);
+ errorColor = JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR);
+ }
+
+ private void checkEnabled(IFile file) {
+ try {
+ if (file.getFileExtension() == null || !file.getFileExtension().equals(BBLanguageHelper.BITBAKE_RECIPE_FILE_EXTENSION)) {
+ action.setEnabled(false);
+ return;
+ }
+
+ IProject project = file.getProject();
+ if (!(project.hasNature(BitbakeCommanderNature.NATURE_ID))) {
+ action.setEnabled(false);
+ return;
+ }
+
+ bbs = Activator.getBBSession(project.getLocationURI().getPath());
+
+ if (bbs != null) {
+ recipe = file;
+ action.setEnabled(true);
+ }
+
+ } catch (CoreException e) {
+ action.setEnabled(false);
+ e.printStackTrace();
+ } catch (Exception e) {
+ action.setEnabled(false);
+ e.printStackTrace();
+ }
+ }
+
+ public void dispose() {
+ }
+
+ /**
+ * Execute array of commands with bitbake and put output in console.
+ *
+ * @param cmds
+ * @param monitor
+ * @return
+ */
+ protected IStatus execCommands(String[] cmds, final IProgressMonitor monitor) {
+ MessageConsole mc = bbs.getConsole();
+ final MessageConsoleStream cmd = mc.newMessageStream();
+ cmd.setColor(commandColor);
+ final MessageConsoleStream out = mc.newMessageStream();
+ final MessageConsoleStream err = mc.newMessageStream();
+ err.setColor(errorColor);
+
+ try {
+ for (int i = 0; i < cmds.length; ++i) {
+ cmd.println(cmds[i]);
+ monitor.subTask(cmds[i]);
+ bbs.getShell().execute(cmds[i], new ICommandResponseHandler() {
+
+ public void response(String line, boolean isError) {
+ if (monitor.isCanceled()) {
+ cmd.println("Interrupting process by user request.");
+ bbs.getShell().interrupt();
+ }
+
+ if (isError) {
+ err.println(line);
+ errorOccurred();
+ } else if (line.startsWith("ERROR:")) {
+ err.println(line);
+ } else {
+ out.println(line);
+ }
+ }
+ });
+ }
+ } catch (IOException e) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
+ } finally {
+ try {
+ if (errorOccurred) {
+ cmd.println("At least one error occured while executing this command. Check output for more details.");
+ }
+ cmd.close();
+ out.close();
+ err.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ protected void errorOccurred() {
+ errorOccurred = true;
+ }
+
+ /**
+ * Return the command to be executed.
+ *
+ * @return
+ */
+ public abstract String[] getCommands();
+
+ public Job getJob() {
+ return new CommandJob();
+ }
+
+ /**
+ * Return the title of the job.
+ *
+ * @return
+ */
+ public abstract String getJobTitle();
+
+ public void init(IWorkbenchWindow window) {
+ }
+
+ public void run(IAction action) {
+ Job job = getJob();
+ job.schedule();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.action = action;
+ if (selection instanceof IStructuredSelection) {
+ Object sel = ((IStructuredSelection) selection).getFirstElement();
+
+ if (sel instanceof IFile) {
+ checkEnabled((IFile) sel);
+ return;
+ }
+ }
+
+ action.setEnabled(false);
+ }
+
+} \ No newline at end of file
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeBuildRecipeAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeBuildRecipeAction.java
new file mode 100644
index 0000000..e8f6708
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeBuildRecipeAction.java
@@ -0,0 +1,24 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+public class BitbakeBuildRecipeAction extends AbstractBitbakeCommandAction {
+
+ @Override
+ public String [] getCommands() {
+ return new String[] {"bitbake -b " + recipe.getLocationURI().getPath()};
+ }
+
+ @Override
+ public String getJobTitle() {
+ return "Building " + recipe.getName();
+ }
+} \ No newline at end of file
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeCleanRecipeAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeCleanRecipeAction.java
new file mode 100644
index 0000000..a0f41c8
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeCleanRecipeAction.java
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+public class BitbakeCleanRecipeAction extends AbstractBitbakeCommandAction {
+
+ @Override
+ public String [] getCommands() {
+ return new String[] {"bitbake -c clean -b " + recipe.getLocationURI().getPath()};
+ }
+
+ @Override
+ public String getJobTitle() {
+ return "Cleaning " + recipe.getName();
+ }
+
+
+} \ No newline at end of file
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeImportAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeImportAction.java
new file mode 100644
index 0000000..e8e093f
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeImportAction.java
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+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.openembedded.bc.bitbake.BBCommonVars;
+import org.openembedded.bc.bitbake.BBRecipe;
+import org.openembedded.bc.ui.Activator;
+
+
+public class BitbakeImportAction extends AbstractBitbakeCommandAction {
+
+ private class ImportJob extends Job {
+
+ public ImportJob() {
+ super(getJobTitle());
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ try {
+ BBRecipe br = new BBRecipe(bbs, recipe.getLocationURI().getPath());
+ br.initialize();
+ String filePath = (String) br.get(BBCommonVars.S);
+
+ //"${WORKDIR}/${PN}-${PV}"
+ if (filePath == null) {
+ filePath = ((String) br.get(BBCommonVars.WORKDIR)) + File.separator + ((String) br.get(BBCommonVars.PN)) + "-" + ((String) br.get(BBCommonVars.PV));
+ }
+
+ String projectName = (String) br.get(BBCommonVars.PN);
+
+ if (filePath == null || projectName == null) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to parse recipe file.");
+ }
+
+ File workdir = new File(filePath);
+
+ if (workdir.exists() && workdir.isFile()) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, workdir.getPath() + " is an invalid workdir.");
+ }
+
+ if (!workdir.exists()) {
+ execCommands(new String[] {"bitbake -c patch -b " + recipe.getLocationURI().getPath()}, monitor);
+ }
+
+ if (!workdir.exists()) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to retrieve sources from BitBake. Consult console.");
+ }
+
+ IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
+ IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject proj = wsroot.getProject(projectName);
+ proj.create(desc, monitor);
+ proj.open(monitor);
+
+ String copyCmd = "cp -r " + workdir.getAbsolutePath() + File.separator + "* \"" + proj.getLocationURI().getPath() + "\"";
+ execCommands(new String[] {copyCmd} , monitor);
+
+ proj.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to create project.", e);
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ }
+
+ @Override
+ public String [] getCommands() {
+ return null;
+ }
+
+
+ @Override
+ public Job getJob() {
+ return new ImportJob();
+ }
+
+ @Override
+ public String getJobTitle() {
+ return "Importing " + recipe.getName();
+ }
+} \ No newline at end of file
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeRebuildRecipeAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeRebuildRecipeAction.java
new file mode 100644
index 0000000..f968b12
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeRebuildRecipeAction.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+/**
+ * Rebuild a recipe.
+ * @author kgilmer
+ *
+ */
+public class BitbakeRebuildRecipeAction extends AbstractBitbakeCommandAction {
+
+ @Override
+ public String [] getCommands() {
+ return new String[] {"bitbake -c rebuild -b " + recipe.getLocationURI().getPath()};
+ }
+
+ @Override
+ public String getJobTitle() {
+ return "Rebuilding " + recipe.getName();
+ }
+} \ No newline at end of file
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java
new file mode 100644
index 0000000..7f71d32
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.openembedded.bc.ui.wizards.importProject.ImportOEProjectWizard;
+
+
+public class LaunchNewBitBakeProjectWizardAction implements IWorkbenchWindowActionDelegate {
+
+ private IWorkbenchWindow window;
+ private IStructuredSelection selection;
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ this.window = window;
+ }
+
+ public void run(IAction action) {
+ ImportOEProjectWizard wizard = new ImportOEProjectWizard();
+
+ wizard.init(window.getWorkbench(), selection);
+ WizardDialog wd = new WizardDialog(window.getShell(), wizard);
+ wd.create();
+ wd.open();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ this.selection = (IStructuredSelection) selection;
+ }
+ }
+} \ No newline at end of file
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewRecipeWizardAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewRecipeWizardAction.java
new file mode 100644
index 0000000..f1f09f8
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchNewRecipeWizardAction.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.openembedded.bc.ui.wizards.NewBitBakeFileRecipeWizard;
+
+
+public class LaunchNewRecipeWizardAction implements IWorkbenchWindowActionDelegate {
+
+ private IWorkbenchWindow window;
+ private IStructuredSelection selection;
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ this.window = window;
+ }
+
+ public void run(IAction action) {
+ NewBitBakeFileRecipeWizard wizard = new NewBitBakeFileRecipeWizard();
+
+ wizard.init(window.getWorkbench(), selection);
+ WizardDialog wd = new WizardDialog(window.getShell(), wizard);
+ wd.create();
+ wd.open();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ this.selection = (IStructuredSelection) selection;
+ }
+ }
+} \ No newline at end of file
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchVariableWizardAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchVariableWizardAction.java
new file mode 100644
index 0000000..b70b05b
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/LaunchVariableWizardAction.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ * Ken Gilmer - initial API and implementation
+ *******************************************************************************/
+package org.openembedded.bc.ui.actions;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.openembedded.bc.ui.Activator;
+import org.openembedded.bc.ui.builder.BitbakeCommanderNature;
+import org.openembedded.bc.ui.wizards.variable.VariableWizard;
+
+
+/**
+ * Action to launch the Variable Wizard.
+ * @author kgilmer
+ *
+ */
+public class LaunchVariableWizardAction implements IWorkbenchWindowActionDelegate {
+
+ private IWorkbenchWindow window;
+ private Map session;
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ this.window = window;
+ }
+
+ public void run(IAction action) {
+ VariableWizard wizard = new VariableWizard(session);
+
+ WizardDialog wd = new WizardDialog(window.getShell(), wizard);
+ wd.create();
+ wd.open();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ session = null;
+
+ if (selection instanceof IStructuredSelection) {
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+
+ if (element instanceof IResource) {
+ IProject p = ((IResource)element).getProject();
+
+ try {
+ if (p.isOpen() && p.hasNature(BitbakeCommanderNature.NATURE_ID)) {
+ session = Activator.getBBSession(((IResource)element).getProject().getLocationURI().getPath());
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ action.setEnabled(session != null);
+ }
+} \ No newline at end of file