summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java
new file mode 100644
index 0000000..ecceecf
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java
@@ -0,0 +1,106 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 * Ken Gilmer - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13import java.io.File;
14
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.IProjectDescription;
17import org.eclipse.core.resources.IResource;
18import org.eclipse.core.resources.IWorkspaceRoot;
19import org.eclipse.core.resources.ResourcesPlugin;
20import org.eclipse.core.runtime.IProgressMonitor;
21import org.eclipse.core.runtime.IStatus;
22import org.eclipse.core.runtime.Status;
23import org.eclipse.core.runtime.jobs.Job;
24
25import org.yocto.bc.bitbake.BBCommonVars;
26import org.yocto.bc.bitbake.BBRecipe;
27import org.yocto.bc.ui.Activator;
28
29public class BitbakeImportAction extends AbstractBitbakeCommandAction {
30
31 private class ImportJob extends Job {
32
33 public ImportJob() {
34 super(getJobTitle());
35 }
36
37 @Override
38 protected IStatus run(IProgressMonitor monitor) {
39
40 try {
41 BBRecipe br = new BBRecipe(bbs, recipe.getLocationURI().getPath());
42 br.initialize();
43 String filePath = (String) br.get(BBCommonVars.S);
44
45 //"${WORKDIR}/${PN}-${PV}"
46 if (filePath == null) {
47 filePath = ((String) br.get(BBCommonVars.WORKDIR)) + File.separator + ((String) br.get(BBCommonVars.PN)) + "-" + ((String) br.get(BBCommonVars.PV));
48 }
49
50 String projectName = (String) br.get(BBCommonVars.PN);
51
52 if (filePath == null || projectName == null) {
53 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to parse recipe file.");
54 }
55
56 File workdir = new File(filePath);
57
58 if (workdir.exists() && workdir.isFile()) {
59 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, workdir.getPath() + " is an invalid workdir.");
60 }
61
62 if (!workdir.exists()) {
63 execCommands(new String[] {"bitbake -c patch -b " + recipe.getLocationURI().getPath()}, monitor);
64 }
65
66 if (!workdir.exists()) {
67 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to retrieve sources from BitBake. Consult console.");
68 }
69
70 IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
71 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
72 IProject proj = wsroot.getProject(projectName);
73 proj.create(desc, monitor);
74 proj.open(monitor);
75
76 String copyCmd = "cp -r " + workdir.getAbsolutePath() + File.separator + "* \"" + proj.getLocationURI().getPath() + "\"";
77 execCommands(new String[] {copyCmd} , monitor);
78
79 proj.refreshLocal(IResource.DEPTH_INFINITE, monitor);
80
81 } catch (Exception e) {
82 e.printStackTrace();
83 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to create project.", e);
84 }
85
86 return Status.OK_STATUS;
87 }
88
89 }
90
91 @Override
92 public String [] getCommands() {
93 return null;
94 }
95
96
97 @Override
98 public Job getJob() {
99 return new ImportJob();
100 }
101
102 @Override
103 public String getJobTitle() {
104 return "Importing " + recipe.getName();
105 }
106} \ No newline at end of file