diff options
author | Ken Gilmer <kgilmer@gmail.com> | 2010-05-18 21:53:22 -0400 |
---|---|---|
committer | Ken Gilmer <kgilmer@gmail.com> | 2010-05-18 21:53:22 -0400 |
commit | a7e84830627e50adac5c81ae4dad69aa350933fb (patch) | |
tree | 219aa86f4d5f03b29d7bc56f8cdba2702d67082c /org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeImportAction.java | |
parent | e27a6dcce13930bfa711a6e72992597a8d1d07c5 (diff) | |
download | eclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.tar.gz |
org.openembedded.bc.ui: initial commit
Diffstat (limited to 'org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeImportAction.java')
-rw-r--r-- | org.openembedded.bc.ui/src/org/openembedded/bc/ui/actions/BitbakeImportAction.java | 106 |
1 files changed, 106 insertions, 0 deletions
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 |