summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBCommonVars.java24
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBLanguageHelper.java62
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBRecipe.java45
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java785
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/IBBSessionListener.java18
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java64
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java209
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java46
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java220
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java254
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/BCResourceChangeListener.java64
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java84
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java328
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java50
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java48
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java48
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java89
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java177
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java119
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java106
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ProjectDecorator.java48
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java107
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java127
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java101
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java89
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java210
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java94
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java127
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java47
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java21
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties14
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java69
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/CustomLocalFile.java13
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Messages.java48
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFile.java375
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystem.java103
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystemContributor.java34
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEIgnoreFile.java135
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java108
-rwxr-xr-xplugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/YoctoLocation.java44
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/IModelElement.java15
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/ProjectInfo.java117
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/YoctoHostFile.java326
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/perspectives/BitbakeCommanderPerspective.java89
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/popup/actions/NewAction.java43
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeContentProvider.java61
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java165
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java153
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java56
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java149
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java231
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java592
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java236
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java166
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java371
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java213
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java327
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java69
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java93
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java262
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java43
61 files changed, 8531 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBCommonVars.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBCommonVars.java
new file mode 100644
index 0000000..d905e50
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBCommonVars.java
@@ -0,0 +1,24 @@
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.bitbake;
12
13/**
14 * Constants for commonly used bitbake variables.
15 * @author kgilmer
16 *
17 */
18public class BBCommonVars {
19 public final static String WORKDIR = "WORKDIR";
20 public static final String PN = "PN";
21 public static final String S = "S";
22 public static final String PV = "PV";
23
24}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBLanguageHelper.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBLanguageHelper.java
new file mode 100644
index 0000000..8ebe134
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBLanguageHelper.java
@@ -0,0 +1,62 @@
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 * Lianhao Lu (Intel) - add more bitbake keywords and functions
11 *******************************************************************************/
12package org.yocto.bc.bitbake;
13
14import java.util.Comparator;
15import java.util.Map;
16import java.util.TreeMap;
17
18/**
19 * Here is where all BitBake-related information is centralized.
20 * @author kgilmer
21 *
22 */
23public class BBLanguageHelper {
24
25 public static final String[] BITBAKE_KEYWORDS = new String[] { "inherit", "require", "export", "addtask", "python", "include", "fakeroot", "addhandler", "def"};
26 public static final String[] SHELL_KEYWORDS = new String[] { "while", "do", "if", "fi", "ln", "export", "install", "oe_libinstall", "for", "in", "done", "echo", "then", "cat", "rm", "rmdir", "mkdir", "printf", "exit", "test", "cd", "cp"};
27 public static final String[] BITBAKE_STANDARD_FUNCTIONS = new String[] { "fetch", "unpack", "patch", "configure", "compile", "install", "populate_sysroot", "package"};
28 public static final String BITBAKE_RECIPE_FILE_EXTENSION = "bb";
29
30 /**
31 * @return A map of names and descriptions of commonly used BitBake variables.
32 */
33 public static Map<String, String> getCommonBitbakeVariables() {
34 Map<String, String> m = new TreeMap<String, String>(new Comparator<Object>() {
35
36 public int compare(Object o1, Object o2) {
37
38 return ((String) o1).compareTo(((String) o2));
39 }
40
41 });
42
43 m.put("SECTION", "Category of package");
44 m.put("PR", "Package Release Number");
45 m.put("SRC_URI", "Location of package sources");
46 m.put("DESCRIPTION", "Description of package");
47 m.put("EXTRA_OEMAKE", "Extra flags to pass to the package makefile");
48 m.put("EXTRA_OECONF", "Extra configuration flags for the package makefile");
49 m.put("DEPENDS", "The set of build-time dependent packages");
50 m.put("RDEPENDS", "The set of run-time dependent packages");
51 m.put("HOMEPAGE", "Homepage of the package");
52 m.put("LICENSE", "License of the package");
53 m.put("FILES_${PN}", "Full file path of files on target.");
54 m.put("S", "Package source directory");
55 m.put("PV", "Package version");
56 m.put("AUTHOR", "Author or maintainer of package");
57 m.put("PRIORITY", "Priority of package");
58
59 return m;
60 }
61
62}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBRecipe.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBRecipe.java
new file mode 100644
index 0000000..9092759
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBRecipe.java
@@ -0,0 +1,45 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer, 2013 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.bitbake;
13
14import java.io.IOException;
15import java.net.URI;
16
17/**
18 * Represents the bitbake environment of a recipe package.
19 * @author kgilmer
20 *
21 */
22public class BBRecipe extends BBSession {
23 private final BBSession session;
24 private final URI fileURI;
25
26 public BBRecipe(BBSession session, URI filePath) throws IOException {
27 super(session.shell, session.pinfo.getOriginalURI());
28 this.session = session;
29 this.fileURI = filePath;
30 this.parsingCmd = "DISABLE_SANITY_CHECKS=\"1\" bitbake -e -b " + filePath.getPath() + " >& " + BB_ENV_FILE;
31 }
32
33 @Override
34 public void initialize() throws Exception {
35 if (this.size() == 0) {
36 //System.out.println("Failed to parse " + fileURI);
37 //throw new IOException("Failed to parse " + filePath);
38 }
39 }
40
41 @Override
42 protected URI getDefaultDepends() {
43 return this.fileURI;
44 }
45}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java
new file mode 100644
index 0000000..4434df8
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java
@@ -0,0 +1,785 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer, 2013 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.bitbake;
13
14import java.io.BufferedReader;
15import java.io.File;
16import java.io.FileFilter;
17import java.io.IOException;
18import java.io.StringReader;
19import java.io.InputStream;
20import java.io.InputStreamReader;
21import java.net.URI;
22import java.util.ArrayList;
23import java.util.Arrays;
24import java.util.Collection;
25import java.util.Hashtable;
26import java.util.Iterator;
27import java.util.List;
28import java.util.Map;
29import java.util.Set;
30import java.util.Stack;
31import java.util.concurrent.locks.ReentrantReadWriteLock;
32import java.util.concurrent.locks.Lock;
33
34import org.eclipse.core.resources.IFile;
35import org.eclipse.core.resources.IProject;
36import org.eclipse.core.resources.IResource;
37import org.eclipse.core.runtime.IProgressMonitor;
38import org.eclipse.core.runtime.IStatus;
39import org.eclipse.core.runtime.NullProgressMonitor;
40import org.eclipse.core.runtime.Status;
41import org.eclipse.jface.preference.JFacePreferences;
42import org.eclipse.jface.resource.JFaceResources;
43import org.eclipse.rse.core.model.IHost;
44import org.eclipse.ui.console.ConsolePlugin;
45import org.eclipse.ui.console.IConsole;
46import org.eclipse.ui.console.IConsoleManager;
47import org.eclipse.ui.console.MessageConsole;
48import org.eclipse.ui.console.MessageConsoleStream;
49import org.eclipse.ui.progress.WorkbenchJob;
50
51import org.yocto.bc.ui.model.IModelElement;
52import org.yocto.bc.ui.model.ProjectInfo;
53import org.yocto.remote.utils.RemoteHelper;
54import org.yocto.remote.utils.YoctoCommand;
55
56/**
57 * BBSession encapsulates a global bitbake configuration and is the primary interface
58 * for actions against a BitBake installation.
59 *
60 * @author kgilmer
61 *
62 */
63public class BBSession implements IBBSessionListener, IModelElement, Map {
64 public static final int TYPE_VARIABLE_ASSIGNMENT = 1;
65 public static final int TYPE_UNKNOWN = 2;
66 public static final int TYPE_STATEMENT = 3;
67 public static final int TYPE_FLAG = 4;
68
69 public static final String BB_ENV_FILE = "bitbake.env";
70
71 public static final String CONF_DIR = "conf";
72 public static final String BUILDDIR_INDICATORS [] = {
73 "local.conf",
74 "bblayers.conf",
75 };
76
77 protected final ProjectInfo pinfo;
78 protected final ShellSession shell;
79 protected Map<?,?> properties = null;
80 protected List <URI> depends = null;
81 protected boolean initialized = false;
82 protected boolean errorOccured = false;
83 protected MessageConsole sessionConsole;
84 private final ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock();
85 private final Lock rlock = rwlock.readLock();
86 private final Lock wlock = rwlock.writeLock();
87 protected String parsingCmd;
88 private boolean silent = false;
89 private String errorLines = "";
90
91 public BBSession(ShellSession ssession, URI projectRoot) throws IOException {
92 shell = ssession;
93 this.pinfo = new ProjectInfo();
94 pinfo.setLocationURI(projectRoot);
95 pinfo.setInitScriptPath(ProjectInfoHelper.getInitScriptPath(projectRoot));
96 this.parsingCmd = "DISABLE_SANITY_CHECKS=\"1\" bitbake -e >& " + BB_ENV_FILE;
97 }
98
99 public BBSession(ShellSession ssession, URI projectRoot, boolean silent) throws IOException {
100 this(ssession, projectRoot);
101 this.silent = silent;
102 }
103
104 private Collection adapttoIPath(List<File> asList, IProject project) {
105
106 List pathList = new ArrayList();
107
108 for (Iterator i = asList.iterator(); i.hasNext();) {
109 File f = (File) i.next();
110 IFile ff = project.getFile(stripLeading(f.toString(), project.getLocationURI().getPath()));
111 if (ff.exists()) {
112 pathList.add(ff);
113 }
114 }
115
116 return pathList;
117 }
118
119 private String appendAll(String[] elems, int st) {
120 StringBuffer sb = new StringBuffer();
121
122 for (int i = st; i < elems.length; ++i) {
123 sb.append(elems[i]);
124 }
125
126 return sb.toString();
127 }
128
129 private int charCount(String trimmed, char c) {
130 int i = 0;
131 int p = 0;
132
133 while ((p = trimmed.indexOf(c, p)) > -1) {
134 i++;
135 p++;
136 }
137
138 return i;
139 }
140
141 public void clear() {
142 throw new RuntimeException("BB configuration is read-only.");
143 }
144
145 public boolean containsKey(Object arg0) {
146 try {
147 checkValidAndLock(true);
148 return properties.containsKey(arg0);
149 } catch (Exception e) {
150 e.printStackTrace();
151 return false;
152 }finally {
153 rlock.unlock();
154 }
155 }
156
157 public boolean containsValue(Object arg0) {
158 try {
159 checkValidAndLock(true);
160 return properties.containsValue(arg0);
161 } catch (Exception e) {
162 e.printStackTrace();
163 return false;
164 }finally {
165 rlock.unlock();
166 }
167 }
168
169 public Set entrySet() {
170 try {
171 checkValidAndLock(true);
172 return properties.entrySet();
173 } catch (Exception e) {
174 e.printStackTrace();
175 return null;
176 }finally {
177 rlock.unlock();
178 }
179 }
180
181 @Override
182 public boolean equals(Object arg0) {
183 try {
184 checkValidAndLock(true);
185 return properties.equals(arg0);
186 } catch (Exception e) {
187 e.printStackTrace();
188 return false;
189 }finally {
190 rlock.unlock();
191 }
192 }
193
194 public ShellSession getShell() {
195 return shell;
196 }
197
198 public URI getProjInfoRoot() {
199 return pinfo.getOriginalURI();
200 }
201
202 /**
203 * Recursively generate list of Recipe files from a root directory.
204 *
205 * @param rootDir
206 * @param recipes
207 * @param fileExtension
208 * @param project
209 */
210 private void findRecipes(File rootDir, List recipes, final String fileExtension, IProject project) {
211 File[] children = rootDir.listFiles(new FileFilter() {
212
213 public boolean accept(File pathname) {
214 return pathname.isFile() && pathname.getName().endsWith(fileExtension);
215 }
216
217 });
218
219 if (children != null && children.length > 0) {
220 recipes.addAll(adapttoIPath(Arrays.asList(children), project));
221 }
222
223 File[] childDirs = rootDir.listFiles(new FileFilter() {
224
225 public boolean accept(File pathname) {
226 return pathname.isDirectory();
227 }
228
229 });
230
231 if (childDirs != null && childDirs.length > 0) {
232 for (int i = 0; i < childDirs.length; ++i) {
233 findRecipes(childDirs[i], recipes, fileExtension, project);
234 }
235 }
236 }
237
238 private Collection findRecipes(List paths, IProject project) {
239 List recipes = new ArrayList();
240
241 for (Iterator i = paths.iterator(); i.hasNext();) {
242 String rawPath = (String) i.next();
243 String[] elems = rawPath.split("\\*/\\*");
244
245 if (elems.length == 2) {
246
247 File rootDir = new File(elems[0]);
248
249 findRecipes(rootDir, recipes, elems[1], project);
250 }
251 }
252
253 return recipes;
254 }
255
256 public Object get(Object arg0) {
257 try {
258 checkValidAndLock(true);
259 return properties.get(arg0);
260 } catch (Exception e) {
261 e.printStackTrace();
262 return null;
263 }finally {
264 rlock.unlock();
265 }
266 }
267
268 private List getBitBakeKeywords() {
269 return Arrays.asList(BBLanguageHelper.BITBAKE_KEYWORDS);
270 }
271
272 /**
273 * @return A MessageConsole for this BB session.
274 */
275 public MessageConsole getConsole() {
276 if (sessionConsole == null) {
277 String cName = ProjectInfoHelper.getProjectName(pinfo.getOriginalURI()) + " Console";
278 IConsoleManager conMan = ConsolePlugin.getDefault().getConsoleManager();
279 IConsole[] existing = conMan.getConsoles();
280 for (int i = 0; i < existing.length; i++)
281 if (cName.equals(existing[i].getName())) {
282 sessionConsole = (MessageConsole) existing[i];
283 break;
284 }
285 if (sessionConsole == null) {
286 sessionConsole = new MessageConsole(cName, null);
287 conMan.addConsoles(new IConsole[] { sessionConsole });
288 }
289 }
290
291 ConsolePlugin.getDefault().getConsoleManager().showConsoleView(sessionConsole);
292
293 return sessionConsole;
294 }
295
296 private int getLineType(String line) {
297
298 if (line.contains("=")) {
299 return TYPE_VARIABLE_ASSIGNMENT;
300 }
301
302 for (Iterator i = getBitBakeKeywords().iterator(); i.hasNext();) {
303 if (line.startsWith((String) i.next())) {
304 return TYPE_STATEMENT;
305 }
306 }
307
308 if (line.contains(":")) {
309 return TYPE_FLAG;
310 }
311
312 return TYPE_UNKNOWN;
313 }
314
315 public Collection getRecipeFiles(IProject project) {
316 try {
317 checkValidAndLock(true);
318 if (!initialized) {
319 throw new RuntimeException(this.getClass().getName() + " is not initialized.");
320 }
321 String bbfiles = (String) this.properties.get("BBFILES");
322 List paths = parseBBFiles(bbfiles);
323 return findRecipes(paths, project);
324 } catch (Exception e) {
325 return null;
326 }
327 finally {
328 rlock.unlock();
329 }
330 }
331
332 @Override
333 public int hashCode() {
334 try {
335 checkValidAndLock(true);
336 return properties.hashCode();
337 } catch (Exception e) {
338 e.printStackTrace();
339 return 0;
340 }finally {
341 rlock.unlock();
342 }
343 }
344
345 protected void checkExecuteError(String result, boolean hasErrors) {
346 URI recipeURI = getDefaultDepends();
347 String text = "Parsing " + ((recipeURI != null) ? ("recipe " + recipeURI) : "base configurations");
348 if (hasErrors) {
349 text = text + " ERROR!\n" + result;
350 }else {
351 text = text + " SUCCESS.\n";
352 }
353 if(!silent) {
354 displayInConsole(text, -1, false);
355 }
356 }
357
358 protected void displayInConsole(final String result, final int code, boolean clear) {
359 MessageConsole console = getConsole();
360 final MessageConsoleStream info = console.newMessageStream();
361 if(clear)
362 console.clearConsole();
363 new WorkbenchJob("Display parsing result") {
364 public IStatus runInUIThread(IProgressMonitor monitor) {
365 if(code != 0) {
366 info.setColor(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR));
367 }
368 try {
369 info.println(result);
370 info.close();
371 }catch (Exception e) {
372 e.printStackTrace();
373 }
374 return Status.OK_STATUS;
375 }
376 }.schedule();
377 }
378
379 private void checkValidAndLock(boolean rdlck) throws Exception {
380 if(rdlck)
381 rlock.lock();
382 else
383 wlock.lock();
384 if(!initialized) {
385 //upgrade lock manually
386 if(rdlck) {
387 rlock.unlock();
388 wlock.lock();
389 }
390 try {
391 if(!initialized) { //recheck
392 boolean hasErrors = false;
393 String result = shell.execute(parsingCmd, hasErrors);
394
395 properties = parseBBEnvironment(result);
396
397 if (properties.size() == 0) { // there was an error in sourcing bitbake environment
398 shell.printError(errorLines);
399 errorOccured = true;
400 } else {
401 errorLines = "";
402 errorOccured = false;
403 initialized = true;
404 }
405 RemoteHelper.handleRunCommandRemote(this.pinfo.getConnection(), new YoctoCommand("rm -rf " + result + BB_ENV_FILE, result, ""), new NullProgressMonitor());
406 }
407 } finally {
408 //downgrade lock
409 if(rdlck) {
410 rlock.lock();
411 wlock.unlock();
412 }
413 }
414 }
415 //not release lock
416 }
417
418 public void initialize() throws Exception {
419 try {
420 checkValidAndLock(false);
421 }finally {
422 wlock.unlock();
423 }
424 }
425
426 private boolean isBlockEnd(String trimmed) {
427 return charCount(trimmed, '}') > charCount(trimmed, '{');
428 // return trimmed.indexOf('}') > -1 && trimmed.indexOf('{') == -1;
429 }
430
431 private boolean isBlockStart(String trimmed) {
432 return charCount(trimmed, '{') > charCount(trimmed, '}');
433 // return trimmed.indexOf('{') > -1 && trimmed.indexOf('}') == -1;
434 }
435
436 public boolean isEmpty() {
437 try {
438 checkValidAndLock(true);
439 return properties.isEmpty();
440 } catch (Exception e) {
441 e.printStackTrace();
442 return true;
443 }finally {
444 rlock.unlock();
445 }
446 }
447
448 public Set keySet() {
449 try {
450 checkValidAndLock(true);
451 return properties.keySet();
452 } catch (Exception e) {
453 e.printStackTrace();
454 return null;
455 }finally {
456 rlock.unlock();
457 }
458 }
459
460 protected void parse(String bbOutfilePath, Map outMap) throws Exception {
461 IHost connection = shell.getProjectInfo().getConnection();
462 InputStream is = RemoteHelper.getRemoteInputStream(connection, bbOutfilePath, BB_ENV_FILE, new NullProgressMonitor());
463 RemoteHelper.getRemoteHostFile(connection, bbOutfilePath + BB_ENV_FILE, new NullProgressMonitor());
464 BufferedReader reader = new BufferedReader(new InputStreamReader(is));
465 String line;
466 boolean inLine = false;
467 StringBuffer sb = null;
468 Stack blockStack = new Stack();
469
470 while ((line = reader.readLine()) != null) {
471 errorLines += line;
472 String trimmed = line.trim();
473 if (trimmed.length() == 0 || line.startsWith("#")) {
474 // weed out the blank and comment lines
475 continue;
476 }
477 // Now we look for block start ends, and ignore all code within
478 // blocks.
479 if (isBlockStart(trimmed)) {
480 blockStack.push(trimmed);
481 } else if (isBlockEnd(trimmed)) {
482 blockStack.pop();
483
484 }
485
486 if (!blockStack.isEmpty()) {
487 // we are in a code block, continue until we break into global
488 // scope.
489 continue;
490 }
491 if (trimmed.endsWith("\\")) {
492 if (!inLine) {
493 inLine = true;
494 sb = new StringBuffer(trimmed.substring(0, trimmed.length() - 1));
495 } else {
496 sb.append(trimmed.substring(0, trimmed.length() - 1));
497 }
498 // Only parse the line when we have the complete contents.
499 continue;
500 } else if (inLine) {
501 inLine = false;
502 line = sb.toString();
503 }
504
505 parseLine(line, outMap);
506 }
507 }
508
509 private void parseAdditiveAssignment(String line, String operator, Map mo) throws Exception {
510 String[] elems = splitAssignment(line, "\\+=");
511
512 if (elems.length != 2) {
513 throw new Exception("Unable to parse additive variable assignment in line: " + line);
514 }
515
516 if (!mo.containsKey(elems[0])) {
517 mo.put(elems[0].trim(), elems[1]);
518 } else {
519 String existing = (String) mo.get(elems[0]);
520 if (operator.equals("+=")) {
521 mo.put(elems[0], existing + elems[1]);
522 } else {
523 mo.put(elems[0], elems[1] + existing);
524 }
525 }
526 }
527
528 protected URI getDefaultDepends() {
529 return null;
530 }
531
532 protected Map parseBBEnvironment(String bbOutFilePath) throws Exception {
533 Map env = new Hashtable();
534 this.depends = new ArrayList<URI>();
535
536 parse(bbOutFilePath, env);
537
538 String included = (String) env.get("BBINCLUDED");
539 if(getDefaultDepends() != null) {
540 this.depends.add(getDefaultDepends());
541 }
542 if(included != null) {
543 String[] includedSplitted = included.split(" ");
544 for (String incl : includedSplitted){
545 if (!incl.contains("${")) {
546 this.depends.add(new URI(incl));
547 }
548 }
549 }
550
551 return env;
552 }
553
554
555 private List parseBBFiles(String bbfiles) {
556 return Arrays.asList(bbfiles.split(" "));
557 }
558
559 //Map delegate methods
560
561 private void parseConditionalAssignment(String line, Map mo) throws Exception {
562 String[] elems = splitAssignment(line, "\\?=");
563
564 if (elems.length != 2) {
565 throw new Exception("Unable to parse conditional variable assignment in line: " + line);
566 }
567
568 if (!mo.containsKey(elems[0].trim())) {
569 mo.put(elems[0].trim(), elems[1].trim());
570 }
571 }
572
573 private void parseImmediateAssignment(String line, String delimiter, Map mo) throws Exception {
574 String[] elems = splitAssignment(line, delimiter);
575
576 mo.put(elems[0], substitute(elems[1], mo));
577 }
578
579 private void parseKeyValue(String line, String delimiter, Map mo) throws Exception {
580 String[] elems = splitAssignment(line, delimiter);
581
582 mo.put(elems[0], elems[1]);
583 }
584
585 private void parseLine(String line, Map mo) throws Exception {
586
587 switch (getLineType(line)) {
588 case TYPE_VARIABLE_ASSIGNMENT:
589 parseVariableAssignment(line, mo);
590 break;
591 case TYPE_STATEMENT:
592 case TYPE_FLAG:
593 // for now ignore statements
594 break;
595 case TYPE_UNKNOWN:
596 // we'll gloss over unknown lines as well;
597 break;
598 default:
599 throw new Exception("Unable to parse line: " + line);
600 }
601 }
602
603 private void parseVariableAssignment(String line, Map mo) throws Exception {
604 if (line.contains("?=")) {
605 parseConditionalAssignment(line, mo);
606 } else if (line.contains("+=")) {
607 parseAdditiveAssignment(line, "+=", mo);
608 } else if (line.contains("=+")) {
609 parseAdditiveAssignment(line, "=+", mo);
610 } else if (line.contains(":=")) {
611 parseImmediateAssignment(line, ":=", mo);
612 } else {
613 parseKeyValue(line, "=", mo);
614 }
615
616 }
617
618 private List parseVars(String line) {
619 List l = new ArrayList();
620
621 int i = 0;
622
623 while ((i = line.indexOf("${", i)) > -1) {
624 int i2 = line.indexOf("}", i);
625
626 l.add(line.subSequence(i + 2, i2));
627 i++;
628 }
629
630 return l;
631 }
632
633 public Object put(Object arg0, Object arg1) {
634 throw new RuntimeException("BB configuration is read-only.");
635 }
636
637 public void putAll(Map arg0) {
638 throw new RuntimeException("BB configuration is read-only.");
639 }
640
641 public Object remove(Object arg0) {
642 throw new RuntimeException("BB configuration is read-only.");
643 }
644
645 private String removeQuotes(String line) {
646 line = line.trim();
647
648 if (line.startsWith("\"")) {
649 line = line.substring(1);
650 }
651
652 if (line.endsWith("\"")) {
653 line = line.substring(0, line.length() - 1);
654 }
655
656 return line;
657 }
658
659 public int size() {
660 try {
661 checkValidAndLock(true);
662 return properties.size();
663 }catch (Exception e) {
664 e.printStackTrace();
665 return 0;
666 }finally {
667 rlock.unlock();
668 }
669 }
670
671 private String[] splitAssignment(String line, String seperator) throws Exception {
672 String[] elems = line.split(seperator);
673
674 if (elems.length < 2) {
675 throw new Exception("Unable to parse assignment in line: " + line);
676 } else if (elems.length == 2) {
677
678 elems[0] = elems[0].trim(); // Clean up trailing or leading spaces.
679 if (elems[0].startsWith("export ")) {
680 elems[0] = elems[0].substring("export ".length()).trim();
681 }
682 elems[1] = removeQuotes(elems[1]); // Evaluate variables
683
684 return elems;
685 } else {
686 String[] retVal = new String[2];
687
688 retVal[0] = elems[0];
689 if (retVal[0].startsWith("export ")) {
690 retVal[0] = retVal[0].substring("export ".length()).trim();
691 }
692 retVal[1] = appendAll(elems, 1);
693
694 return retVal;
695 }
696 }
697
698 private String stripLeading(String target, String leading) {
699 if (target.startsWith(leading)) {
700 target = target.substring(leading.length());
701 }
702
703 return target;
704 }
705
706 /**
707 * Return a string with variable substitutions in place.
708 *
709 * @param expression
710 * @return Input string with any substitutions from this file.
711 */
712 public String substitute(String expression, Map mo) {
713
714 List vars = parseVars(expression);
715
716 for (Iterator i = vars.iterator(); i.hasNext();) {
717 String varName = (String) i.next();
718 String varToken = "${" + varName + "}";
719
720 if (mo.containsKey(varName)) {
721 expression = expression.replace(varToken, (String) mo.get(varName));
722 } else if (System.getProperty(varName) != null) {
723 expression = expression.replace(varToken, System.getProperty(varName));
724 } else if (varName.toUpperCase().equals("HOME")) {
725 expression = expression.replace(varToken, System.getProperty("user.home"));
726 }
727 }
728
729 return expression;
730 }
731
732 public Collection values() {
733 try {
734 checkValidAndLock(true);
735 return properties.values();
736 } catch (Exception e) {
737 e.printStackTrace();
738 return null;
739 }finally {
740 rlock.unlock();
741 }
742 }
743
744 public void changeNotified(IResource[] added, IResource[] removed, IResource[] changed) {
745 wlock.lock();
746 try {
747 if (initialized && (removed != null || changed != null)) {
748 for(int i=0;removed != null && i<removed.length;i++) {
749 if (this.depends.contains(removed[i].getLocationURI())) {
750 initialized = false;
751 return;
752 }
753 }
754 if (!depends.isEmpty()) {
755 for(int i=0;changed != null && i<changed.length;i++) {
756 if (changed[i].getLocation() != null && this.depends.contains(changed[i].getLocation().toString())) {
757 initialized = false;
758 return;
759 }
760 }
761 }
762 }
763 }
764 finally {
765 wlock.unlock();
766 }
767 }
768
769 public Map<String, String> getProperties() {
770 return (Map<String, String>) properties;
771 }
772
773 public ProjectInfo getProjectInfo() {
774 return pinfo;
775 }
776
777 public boolean hasErrorOccured() {
778 return errorOccured;
779 }
780
781 public String getErrorLines() {
782 return errorLines;
783 }
784
785}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/IBBSessionListener.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/IBBSessionListener.java
new file mode 100644
index 0000000..4d0054f
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/IBBSessionListener.java
@@ -0,0 +1,18 @@
1/*******************************************************************************
2 * Copyright (c) 2012 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 *******************************************************************************/
11
12package org.yocto.bc.bitbake;
13
14import org.eclipse.core.resources.IResource;
15
16public interface IBBSessionListener {
17 public void changeNotified(IResource[] added, IResource[] removed, IResource[] changed);
18}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java
new file mode 100644
index 0000000..800fe2b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java
@@ -0,0 +1,64 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.bitbake;
13
14import java.io.BufferedReader;
15import java.io.File;
16import java.io.FileOutputStream;
17import java.io.FileReader;
18import java.io.IOException;
19import java.net.URI;
20
21import org.eclipse.core.resources.IProject;
22import org.eclipse.core.resources.ResourcesPlugin;
23
24import org.yocto.bc.ui.model.ProjectInfo;
25
26/**
27 * A helper class for ProjectInfo related tasks.
28 *
29 * @author kgilmer
30 *
31 */
32public class ProjectInfoHelper {
33 public static final String OEFS_SCHEME = "OEFS://";
34 public static final String FILE_SCHEME = "file";
35 public static final String RSE_SCHEME = "rse";
36
37 protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
38 /**
39 * @param path
40 * @return The path to bitbake init script
41 * @throws IOException
42 */
43 public static String getInitScriptPath(URI uri) throws IOException {
44 String val = uri.getPath() + "/" + DEFAULT_INIT_SCRIPT;
45 return val;
46 }
47
48 public static String getProjectName(URI projectRoot) {
49 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
50 for (int i = 0; i < projects.length; ++i) {
51 try {
52 if (projects[i].getLocationURI().equals(projectRoot)) {
53 return projects[i].getName();
54 }
55
56 } catch (Exception e) {
57 // TODO Auto-generated catch block
58 e.printStackTrace();
59 }
60 }
61
62 return null;
63 }
64}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
new file mode 100644
index 0000000..0e262b1
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
@@ -0,0 +1,209 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.bitbake;
13
14import java.io.BufferedReader;
15import java.io.File;
16import java.io.IOException;
17import java.io.InputStream;
18import java.io.InputStreamReader;
19import java.io.OutputStream;
20import java.io.Writer;
21
22import org.eclipse.core.runtime.IProgressMonitor;
23import org.eclipse.core.runtime.NullProgressMonitor;
24import org.eclipse.rse.core.model.IHost;
25import org.eclipse.rse.services.files.IHostFile;
26import org.yocto.bc.ui.model.ProjectInfo;
27import org.yocto.remote.utils.ICommandResponseHandler;
28import org.yocto.remote.utils.RemoteHelper;
29import org.yocto.remote.utils.YoctoCommand;
30
31/**
32 * A class for Linux shell sessions.
33 * @author kgilmer
34 *
35 */
36public class ShellSession {
37 private volatile boolean interrupt = false;
38 /**
39 * String used to isolate command execution
40 */
41 public static final String TERMINATOR = "#234o987dsfkcqiuwey18837032843259d";
42 public static final String LT = System.getProperty("line.separator");
43 public static final String exportCmd = "export BB_ENV_EXTRAWHITE=\\\"DISABLE_SANITY_CHECKS $BB_ENV_EXTRAWHITE\\\"";
44 public static final String exportColumnsCmd = "export COLUMNS=1000";
45 private static final String BUILD_DIR = "/build/";
46
47
48 public static String getFilePath(String file) throws IOException {
49 File f = new File(file);
50
51 if (!f.exists() || f.isDirectory()) {
52 throw new IOException("Path passed is not a file: " + file);
53 }
54
55 StringBuffer sb = new StringBuffer();
56
57 String elems[] = file.split("//");
58
59 for (int i = 0; i < elems.length - 1; ++i) {
60 sb.append(elems[i]);
61 sb.append("//");
62 }
63
64 return sb.toString();
65 }
66 private Process process;
67
68 private OutputStream pos = null;
69 private String shellPath = null;
70 private final String initCmd;
71 private final IHostFile root;
72 private ProjectInfo projectInfo;
73
74 public ProjectInfo getProjectInfo() {
75 return projectInfo;
76 }
77
78 public void setProjectInfo(ProjectInfo projectInfo) {
79 this.projectInfo = projectInfo;
80 }
81
82 public ShellSession(ProjectInfo pInfo, IHostFile root, String initCmd) throws IOException {
83 this.projectInfo = pInfo;
84 this.root = root;
85 this.initCmd = initCmd;
86
87 initializeShell(new NullProgressMonitor());
88 }
89
90 private void initializeShell(IProgressMonitor monitor) throws IOException {
91 try {
92 if (root != null) {
93 IHost connection = projectInfo.getConnection();
94 RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand("source " + initCmd, root.getAbsolutePath(), ""), monitor);
95 RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand(exportCmd, root.getAbsolutePath(), ""), monitor);
96 } else {
97 throw new Exception("Root file not found!");
98 }
99 } catch (Exception e) {
100 e.printStackTrace();
101 }
102 }
103
104 synchronized
105 public String execute(String command) throws IOException {
106 return execute(command, false);
107 }
108
109 synchronized
110 public String execute(String command, boolean hasErrors) throws IOException {
111 try {
112 if (projectInfo.getConnection() != null) {
113 command = getInitCmd() + command;
114 RemoteHelper.handleRunCommandRemote(projectInfo.getConnection(), new YoctoCommand(command, getBuildDirAbsolutePath(), ""), new NullProgressMonitor());
115 return getBuildDirAbsolutePath();
116 }
117 return null;
118 } catch (Exception e) {
119 e.printStackTrace();
120 }
121 return null;
122 }
123
124 private String getBuildDirAbsolutePath() {
125 return root.getAbsolutePath() + BUILD_DIR;
126 }
127
128 private String getInitCmd() {
129 return "source " + initCmd + " " + getBuildDirAbsolutePath()
130 + " > tempsf; rm -rf tempsf;" + exportCmd + ";"
131 + exportColumnsCmd + ";" + "cd " + getBuildDirAbsolutePath()
132 + ";";
133 }
134
135 synchronized
136 public void execute(String command, String terminator, ICommandResponseHandler handler) throws IOException {
137 interrupt = false;
138 InputStream errIs = process.getErrorStream();
139 if (errIs.available() > 0) {
140 clearErrorStream(errIs);
141 }
142 sendToProcessAndTerminate(command);
143
144 BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
145 String std = null;
146
147 do {
148 if (errIs.available() > 0) {
149 byte[] msg = new byte[errIs.available()];
150
151 errIs.read(msg, 0, msg.length);
152 handler.response(new String(msg), true);
153 }
154
155 std = br.readLine();
156
157 if (std != null && !std.endsWith(terminator)) {
158 handler.response(std, false);
159 }
160
161 } while (std != null && !std.endsWith(terminator) && !interrupt);
162
163 if (interrupt) {
164 process.destroy();
165 initializeShell(null);
166 interrupt = false;
167 }
168 }
169
170 private void clearErrorStream(InputStream is) {
171
172 try {
173 byte b[] = new byte[is.available()];
174 is.read(b);
175 System.out.println("clearing: " + new String(b));
176 } catch (IOException e) {
177 e.printStackTrace();
178 //Ignore any error
179 }
180 }
181
182 /**
183 * Send command string to shell process and add special terminator string so
184 * reader knows when output is complete.
185 *
186 * @param command
187 * @throws IOException
188 */
189 private void sendToProcessAndTerminate(String command) throws IOException {
190 pos.write(command.getBytes());
191 pos.write(LT.getBytes());
192 pos.flush();
193 pos.write("echo $?".getBytes());
194 pos.write(TERMINATOR.getBytes());
195 pos.write(LT.getBytes());
196 pos.flush();
197 }
198
199 /**
200 * Interrupt any running processes.
201 */
202 public void interrupt() {
203 interrupt = true;
204 }
205
206 public void printError(String errorLines) {
207 RemoteHelper.getCommandHandler(projectInfo.getConnection()).response(errorLines, true);
208 }
209}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java
new file mode 100644
index 0000000..779ffa2
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java
@@ -0,0 +1,46 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol(Intel) - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.remote.utils;
12
13import java.io.IOException;
14import java.io.Writer;
15
16public class ConsoleWriter extends Writer {
17
18 private StringBuffer sb;
19
20 public ConsoleWriter() {
21 sb = new StringBuffer();
22 }
23
24 @Override
25 public void close() throws IOException {
26 }
27
28 public String getContents() {
29 return sb.toString();
30 }
31
32 @Override
33 public void flush() throws IOException {
34 }
35
36 @Override
37 public void write(char[] cbuf, int off, int len) throws IOException {
38 sb.append(cbuf);
39 }
40
41 @Override
42 public void write(String str) throws IOException {
43 sb.append(str);
44 }
45
46}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java
new file mode 100644
index 0000000..9654cb3
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java
@@ -0,0 +1,220 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol(Intel) - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.remote.utils;
12
13import java.io.IOException;
14import java.lang.reflect.InvocationTargetException;
15import java.util.regex.Matcher;
16import java.util.regex.Pattern;
17
18import org.eclipse.core.runtime.CoreException;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.NullProgressMonitor;
21import org.eclipse.jface.operation.IRunnableWithProgress;
22import org.eclipse.ptp.remote.core.IRemoteConnection;
23import org.eclipse.ptp.remote.core.IRemoteServices;
24import org.eclipse.ptp.remote.core.exception.RemoteConnectionException;
25import org.eclipse.rse.core.model.IHost;
26import org.eclipse.rse.services.shells.IHostShell;
27import org.eclipse.swt.widgets.Display;
28import org.yocto.remote.utils.CommandResponseHandler;
29import org.yocto.remote.utils.OutputProcessor;
30import org.yocto.remote.utils.RemoteHelper;
31import org.yocto.remote.utils.YoctoCommand;
32
33public class YoctoRunnableWithProgress implements IRunnableWithProgress {
34
35 private String taskName;
36 private IRemoteConnection remoteConnection;
37 private IRemoteServices remoteServices;
38 private IProgressMonitor monitor;
39 private final ICalculatePercentage calculator;
40 private int reportedWorkload;
41
42 private final YoctoCommand command;
43
44 public YoctoRunnableWithProgress(YoctoCommand command) throws IOException {
45 this.command = command;
46 this.calculator = new GitCalculatePercentage();
47 }
48
49 private interface ICalculatePercentage {
50 public float calWorkloadDone(String info) throws IllegalArgumentException;
51 }
52
53 private class GitCalculatePercentage implements ICalculatePercentage {
54 final Pattern pattern = Pattern.compile("^Receiving objects:\\s*(\\d+)%.*");
55 @Override
56 public float calWorkloadDone(String info) throws IllegalArgumentException {
57 Matcher m = pattern.matcher(info.trim());
58 if(m.matches()) {
59 return new Float(m.group(1)) / 100;
60 }else {
61 throw new IllegalArgumentException();
62 }
63 }
64 }
65
66 @Override
67 public void run(IProgressMonitor monitor) throws InvocationTargetException,
68 InterruptedException {
69 try {
70 this.monitor = monitor;
71 this.monitor.beginTask(taskName, RemoteHelper.TOTALWORKLOAD);
72
73 if (!remoteConnection.isOpen()) {
74 try {
75 remoteConnection.open(monitor);
76 } catch (RemoteConnectionException e1) {
77 e1.printStackTrace();
78 }
79 }
80
81 remoteServices.initialize(new NullProgressMonitor());
82
83 try {
84 IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName());
85 YoctoThread th = new YoctoThread(connection, command);
86 th.run();
87 } catch (Exception e) {
88 e.printStackTrace();
89 } finally {
90 monitor.done();
91 }
92 } catch (Exception e) {
93 e.printStackTrace();
94 }
95 }
96 class YoctoRunnableOutputProcessor extends OutputProcessor{
97
98 public YoctoRunnableOutputProcessor(IProgressMonitor monitor,
99 IHostShell hostShell, CommandResponseHandler cmdHandler,
100 String task) {
101 super(monitor, hostShell, cmdHandler, task);
102 }
103 @Override
104 protected boolean isErrChStop(char ch) {
105 return (ch == '\n' || ch == '\r');
106 }
107
108 @Override
109 protected boolean isOutChStop(char ch) {
110 return (ch == '\n');
111 }
112
113 @Override
114 protected void processOutputBufferLine(char ch, String str) {
115 processBuffer.addOutputLine(str);
116 }
117
118 @Override
119 protected void processErrorBufferLine(char ch, String str) {
120 processBuffer.addOutputLine(str);
121 if (ch == '\r')
122 reportProgress(str);
123 }
124
125 }
126
127 class YoctoThread implements Runnable{
128 private final IHost connection;
129 private final YoctoCommand command;
130 private final CommandResponseHandler cmdHandler;
131 private IHostShell hostShell;
132
133 YoctoThread(IHost connection, YoctoCommand command){
134 this.connection = connection;
135 this.cmdHandler = RemoteHelper.getCommandHandler(connection);
136 this.command = command;
137 }
138
139 @Override
140 public void run() {
141 try {
142 hostShell = RemoteHelper.runCommandRemote(this.connection, command, monitor);
143 command.setProcessBuffer(new YoctoRunnableOutputProcessor(monitor, hostShell, cmdHandler, taskName).processOutput());
144 } catch (CoreException e) {
145 e.printStackTrace();
146 } catch (Exception e) {
147 e.printStackTrace();
148 }
149 }
150 }
151 private void updateMonitor(final int work){
152
153 Display.getDefault().asyncExec(new Runnable() {
154
155 @Override
156 public void run() {
157 if (monitor != null) {
158 monitor.worked(work);
159 }
160 }
161
162 });
163 }
164
165 private void doneMonitor(){
166 Display.getDefault().asyncExec(new Runnable() {
167 @Override
168 public void run() {
169 monitor.done();
170 }
171 });
172 }
173
174 public void reportProgress(String info) {
175 if(calculator == null) {
176 updateMonitor(1);
177 } else {
178 float percentage;
179 try {
180 percentage = calculator.calWorkloadDone(info);
181 } catch (IllegalArgumentException e) {
182 System.out.println(info);
183 //can't get percentage
184 return;
185 }
186 int delta = (int) (RemoteHelper.TOTALWORKLOAD * percentage - reportedWorkload);
187 if( delta > 0 ) {
188 updateMonitor(delta);
189 reportedWorkload += delta;
190 }
191
192 if (reportedWorkload == RemoteHelper.TOTALWORKLOAD)
193 doneMonitor();
194 }
195 }
196
197 public IRemoteConnection getRemoteConnection() {
198 return remoteConnection;
199 }
200
201 public void setRemoteConnection(IRemoteConnection remoteConnection) {
202 this.remoteConnection = remoteConnection;
203 }
204
205 public String getTaskName() {
206 return taskName;
207 }
208
209 public void setTaskName(String taskName) {
210 this.taskName = taskName;
211 }
212
213 public IRemoteServices getRemoteServices() {
214 return remoteServices;
215 }
216
217 public void setRemoteServices(IRemoteServices remoteServices) {
218 this.remoteServices = remoteServices;
219 }
220}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
new file mode 100644
index 0000000..f53592c
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
@@ -0,0 +1,254 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui;
13
14import java.io.File;
15import java.io.IOException;
16import java.io.Writer;
17import java.lang.reflect.InvocationTargetException;
18import java.net.URI;
19import java.util.Hashtable;
20import java.util.Iterator;
21import java.util.Map;
22
23import org.eclipse.core.resources.IProject;
24import org.eclipse.core.resources.IResource;
25import org.eclipse.core.resources.IResourceChangeEvent;
26import org.eclipse.core.resources.IResourceChangeListener;
27import org.eclipse.core.resources.ResourcesPlugin;
28import org.eclipse.core.runtime.CoreException;
29import org.eclipse.core.runtime.IProgressMonitor;
30import org.eclipse.jface.resource.ImageDescriptor;
31import org.eclipse.jface.resource.ImageRegistry;
32import org.eclipse.rse.services.files.IHostFile;
33import org.eclipse.ui.plugin.AbstractUIPlugin;
34import org.osgi.framework.BundleContext;
35
36import org.yocto.bc.bitbake.BBRecipe;
37import org.yocto.bc.bitbake.BBSession;
38import org.yocto.bc.bitbake.ProjectInfoHelper;
39import org.yocto.bc.bitbake.ShellSession;
40import org.yocto.bc.ui.model.ProjectInfo;
41import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
42import org.yocto.remote.utils.RemoteHelper;
43
44public class Activator extends AbstractUIPlugin {
45
46 // The plug-in ID
47 public static final String PLUGIN_ID = "org.yocto.bc.ui";
48 public static final String IMAGE_VARIABLE = "IMAGE_VARIABLE";
49 public static final String IMAGE_FUNCTION = "IMAGE_FUNCTION";
50
51 // The shared instance
52 private static Activator plugin;
53 private static Map shellMap;
54 private static Map<URI, ProjectInfo> projInfoMap;
55 private static Hashtable bbSessionMap;
56 private static Hashtable bbRecipeMap;
57
58 private IResourceChangeListener listener = new BCResourceChangeListener();
59
60 public static BBRecipe getBBRecipe(BBSession session, URI fileURI) throws IOException {
61 if (bbRecipeMap == null) {
62 bbRecipeMap = new Hashtable();
63 }
64
65 URI key = session.getProjInfoRoot();
66 BBRecipe recipe = (BBRecipe) bbRecipeMap.get(key);
67 if (recipe == null) {
68 recipe = new BBRecipe(session, fileURI);
69 bbRecipeMap.put(key, recipe);
70 }
71
72 return recipe;
73 }
74
75 /**
76 * Get or create a BitBake session passing in ProjectInfo
77 * @param pinfo
78 * @return
79 * @throws IOException
80 */
81 public static BBSession getBBSession(ProjectInfo projectInfo, Writer out, IProgressMonitor monitor) throws IOException {
82 URI projectRoot = projectInfo.getOriginalURI();
83 if (bbSessionMap == null) {
84 bbSessionMap = new Hashtable();
85 }
86
87 BBSession bbs = (BBSession) bbSessionMap.get(projectRoot);
88
89 if (bbs == null) {
90 bbs = new BBSession(getShellSession(projectInfo, out, monitor), projectRoot);
91 bbSessionMap.put(projectRoot, bbs);
92 }
93
94 return bbs;
95 }
96
97 /**
98 * Get or create a BitBake session passing in ProjectInfo
99 * @param pinfo
100 * @return
101 * @throws IOException
102 */
103 public static BBSession getBBSession(ProjectInfo projectInfo, IProgressMonitor monitor) throws Exception {
104 URI projectRoot = projectInfo.getOriginalURI();
105 if (bbSessionMap == null) {
106 bbSessionMap = new Hashtable();
107 }
108
109 BBSession bbs = (BBSession) bbSessionMap.get(projectRoot);
110
111 if (bbs == null || bbs.getShell() == null) {
112 bbs = new BBSession(getShellSession(projectInfo, null, monitor), projectRoot);
113 bbSessionMap.put(projectRoot, bbs);
114 }
115
116 return bbs;
117 }
118
119 /**
120 * Returns the shared instance
121 *
122 * @return the shared instance
123 */
124 public static Activator getDefault() {
125 return plugin;
126 }
127
128 /**
129 * Returns an image descriptor for the image file at the given
130 * plug-in relative path
131 *
132 * @param path the path
133 * @return the image descriptor
134 */
135 public static ImageDescriptor getImageDescriptor(String path) {
136 return imageDescriptorFromPlugin(PLUGIN_ID, path);
137 }
138
139 public static ProjectInfo getProjInfo(URI location) throws CoreException, InvocationTargetException, InterruptedException {
140 if (projInfoMap == null) {
141 projInfoMap = new Hashtable<URI, ProjectInfo>();
142 }
143 if (location != null) {
144 ProjectInfo pi = projInfoMap.get(location);
145 if (pi == null) {
146 pi = new ProjectInfo();
147 pi.setLocationURI(location);
148 try {
149 pi.setInitScriptPath(ProjectInfoHelper.getInitScriptPath(location));
150 } catch (IOException e) {
151 throw new InvocationTargetException(e);
152 }
153
154 projInfoMap.put(location, pi);
155 }
156 return pi;
157 }
158 return null;
159 }
160
161 public static void notifyAllBBSession(IResource[] added, IResource[] removed, IResource[] changed) {
162 Iterator iter;
163 if(bbRecipeMap != null) {
164 iter = bbRecipeMap.values().iterator();
165 while(iter.hasNext()) {
166 BBRecipe p = (BBRecipe)iter.next();
167 p.changeNotified(added, removed, changed);
168 }
169 }
170
171 if(bbSessionMap != null) {
172 iter= bbSessionMap.values().iterator();
173 while(iter.hasNext()) {
174 BBSession p = (BBSession)iter.next();
175 p.changeNotified(added, removed, changed);
176 }
177 }
178 }
179
180 /**
181 * @param absolutePath
182 * @return a cached shell session for a given project root.
183 * @throws IOException
184 */
185 private static ShellSession getShellSession(ProjectInfo projInfo, Writer out, IProgressMonitor monitor) throws IOException {
186 URI absolutePath = projInfo.getOriginalURI();
187 if (shellMap == null) {
188 shellMap = new Hashtable();
189 }
190
191 ShellSession ss = (ShellSession) shellMap.get(absolutePath);
192
193 if (ss == null && RemoteHelper.isInitialized(projInfo.getOriginalURI())) {
194 IHostFile remoteHostFile = RemoteHelper.getRemoteHostFile(projInfo.getConnection(), absolutePath.getPath(), monitor);
195 ss = new ShellSession(projInfo, remoteHostFile, ProjectInfoHelper.getInitScriptPath(absolutePath));
196 }
197
198 return ss;
199 }
200
201 public static void putProjInfo(URI location, ProjectInfo pinfo) {
202 if (projInfoMap == null) {
203 projInfoMap = new Hashtable();
204 }
205
206
207
208 projInfoMap.put(location, pinfo);
209 }
210
211 /**
212 * The constructor
213 */
214 public Activator() {
215 }
216
217 /*
218 * (non-Javadoc)
219 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
220 */
221 @Override
222 public void start(BundleContext context) throws Exception {
223 super.start(context);
224 plugin = this;
225 ResourcesPlugin.getWorkspace().addResourceChangeListener(
226 listener, IResourceChangeEvent.POST_CHANGE);
227 }
228
229 /*
230 * (non-Javadoc)
231 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
232 */
233 @Override
234 public void stop(BundleContext context) throws Exception {
235 ResourcesPlugin.getWorkspace().removeResourceChangeListener(
236 listener);
237 plugin = null;
238 super.stop(context);
239 }
240
241 /**
242 * Reset a configuration
243 * @param path
244 */
245 public static void resetBBSession(String path) {
246 shellMap.remove(path);
247 bbSessionMap.remove(path);
248 }
249
250 protected void initializeImageRegistry(ImageRegistry reg) {
251 reg.put(IMAGE_VARIABLE, Activator.getImageDescriptor("icons/variable.gif"));
252 reg.put(IMAGE_FUNCTION, Activator.getImageDescriptor("icons/function.gif"));
253 }
254}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/BCResourceChangeListener.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/BCResourceChangeListener.java
new file mode 100644
index 0000000..8a2bfdd
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/BCResourceChangeListener.java
@@ -0,0 +1,64 @@
1package org.yocto.bc.ui;
2
3import java.util.HashSet;
4
5import org.eclipse.core.resources.IFile;
6import org.eclipse.core.resources.IProject;
7import org.eclipse.core.resources.IResourceChangeEvent;
8import org.eclipse.core.resources.IResourceChangeListener;
9import org.eclipse.core.resources.IResource;
10import org.eclipse.core.resources.IResourceDelta;
11import org.eclipse.core.resources.IResourceDeltaVisitor;
12import org.eclipse.core.runtime.*;
13import org.yocto.bc.ui.builder.BitbakeCommanderNature;
14
15public class BCResourceChangeListener implements IResourceChangeListener {
16
17 public void resourceChanged(IResourceChangeEvent event) {
18 final HashSet<IResource> removed = new HashSet<IResource>();
19 final HashSet<IResource> changed = new HashSet<IResource>();
20 switch (event.getType()) {
21 case IResourceChangeEvent.POST_CHANGE:
22 try {
23 event.getDelta().accept(new IResourceDeltaVisitor() {
24 public boolean visit(IResourceDelta delta) throws CoreException {
25 IResource res = delta.getResource();
26 Boolean visit= true;
27 if (res instanceof IProject) {
28 visit = false;
29 try {
30 if(((IProject) res).isOpen() &&
31 ((IProject) res).hasNature(BitbakeCommanderNature.NATURE_ID)){
32 visit = true;
33 }
34 }catch (CoreException e) {
35 }
36 }
37 if (visit && (res instanceof IFile))
38 {
39 switch (delta.getKind()) {
40 case IResourceDelta.REMOVED:
41 removed.add(res);
42 break;
43 case IResourceDelta.CHANGED:
44 changed.add(res);
45 break;
46 }
47 }
48 return visit; // visit the children
49 }
50 });
51 //notify all the sessions
52 Activator.notifyAllBBSession(null,
53 removed.toArray(new IResource[removed.size()]),
54 changed.toArray(new IResource[changed.size()]));
55
56 }catch (CoreException e) {
57 e.printStackTrace();
58 }
59 break;
60 default:
61 break;
62 }
63 }
64}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java
new file mode 100644
index 0000000..e92fac0
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java
@@ -0,0 +1,84 @@
1/*******************************************************************************
2 * Copyright (c) 2011 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.bc.ui.actions;
12
13import org.eclipse.ui.PlatformUI;
14import org.eclipse.ui.IWorkbench;
15import org.eclipse.ui.IWorkbenchPage;
16import org.eclipse.ui.IWorkbenchWindow;
17
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IResource;
20import org.eclipse.core.runtime.IAdaptable;
21import org.eclipse.jface.action.IAction;
22import org.eclipse.jface.viewers.ISelection;
23import org.eclipse.jface.viewers.IStructuredSelection;
24
25import org.eclipse.swt.widgets.Shell;
26
27import org.yocto.bc.ui.builder.BitbakeCommanderNature;
28
29
30public class LaunchHobAction {
31 private static final String DIALOG_TITLE = "Launch HOB";
32
33 public void run(IAction action) {
34 IResource resource = getSelectedResource();
35 if (resource == null)
36 return;
37
38 IProject project = resource.getProject();
39 LaunchHobDialog hobDialog = new LaunchHobDialog(new Shell(), DIALOG_TITLE, project);
40 hobDialog.open();
41 String buildDir = hobDialog.getBuildDir();
42
43 if (buildDir != null) {
44 try {
45 BitbakeCommanderNature.launchHob(project,buildDir);
46 } catch (Exception e){
47 System.out.println(e.getMessage());
48 }
49 }
50
51 }
52
53 public void dispose() {
54
55 }
56
57 private IResource getSelectedResource() {
58 IWorkbench iworkbench = PlatformUI.getWorkbench();
59 if (iworkbench == null){
60 return null;
61 }
62 IWorkbenchWindow iworkbenchwindow = iworkbench.getActiveWorkbenchWindow();
63 if (iworkbenchwindow == null) {
64 return null;
65 }
66 IWorkbenchPage iworkbenchpage = iworkbenchwindow.getActivePage();
67 if (iworkbenchpage == null) {
68 return null;
69 }
70 ISelection sel = iworkbenchpage.getSelection();
71
72 if (!(sel instanceof IStructuredSelection))
73 return null;
74 IStructuredSelection ss = (IStructuredSelection) sel;
75 Object element = ss.getFirstElement();
76 if (element instanceof IResource)
77 return (IResource) element;
78 if (!(element instanceof IAdaptable))
79 return null;
80 IAdaptable adaptable = (IAdaptable)element;
81 Object adapter = adaptable.getAdapter(IResource.class);
82 return (IResource) adapter;
83 }
84}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java
new file mode 100644
index 0000000..861360d
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java
@@ -0,0 +1,328 @@
1/*******************************************************************************
2 * Copyright (c) 2011 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.bc.ui.actions;
12
13import java.util.Map;
14import java.util.Iterator;
15import java.util.Map.Entry;
16import java.util.ArrayList;
17import java.util.HashMap;
18import java.util.HashSet;
19import java.io.File;
20import java.io.IOException;
21
22import org.eclipse.jface.dialogs.Dialog;
23import org.eclipse.jface.dialogs.IDialogConstants;
24
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.events.ModifyEvent;
27import org.eclipse.swt.events.ModifyListener;
28import org.eclipse.swt.events.SelectionAdapter;
29import org.eclipse.swt.events.SelectionEvent;
30import org.eclipse.swt.events.SelectionListener;
31import org.eclipse.swt.layout.GridData;
32import org.eclipse.swt.layout.GridLayout;
33import org.eclipse.swt.widgets.Button;
34import org.eclipse.swt.widgets.Combo;
35import org.eclipse.swt.widgets.Composite;
36import org.eclipse.swt.widgets.Control;
37import org.eclipse.swt.widgets.DirectoryDialog;
38import org.eclipse.swt.widgets.Display;
39import org.eclipse.swt.widgets.Label;
40import org.eclipse.swt.widgets.MessageBox;
41import org.eclipse.swt.widgets.Shell;
42import org.eclipse.swt.widgets.Widget;
43
44import org.eclipse.core.resources.IProject;
45import org.eclipse.core.resources.IProjectDescription;
46import org.eclipse.core.resources.ICommand;
47
48import org.yocto.bc.ui.builder.BitbakeBuilder;
49import org.yocto.bc.ui.builder.BitbakeCommanderNature;
50
51public class LaunchHobDialog extends Dialog {
52 private String title;
53 private Button buildButton;
54 private SelectionListener fSelectionListener;
55 private ModifyListener fModifyListener;
56 private Combo build_dir_combo;
57
58 private IProject project;
59 private Shell shell;
60 private String build_dir;
61
62 public LaunchHobDialog(Shell parentShell, String dialogTitle, IProject project) {
63 super(parentShell);
64 this.shell = parentShell;
65 this.project = project;
66 this.title = dialogTitle;
67 setShellStyle(getShellStyle() | SWT.RESIZE);
68
69 fSelectionListener= new SelectionListener() {
70 public void widgetDefaultSelected(SelectionEvent e) {}
71
72 public void widgetSelected(SelectionEvent e) {
73 controlChanged(e.widget);
74 }
75 };
76
77 fModifyListener= new ModifyListener() {
78 public void modifyText(ModifyEvent e) {
79 controlModified(e.widget);
80 }
81 };
82
83 }
84
85 public String getBuildDir() {
86 return build_dir;
87 }
88 @Override
89 protected Control createDialogArea(Composite parent) {
90 final Composite result = (Composite) super.createDialogArea(parent);
91
92 try {
93 createComposite(result);
94 } catch (Exception e) {
95 // TODO Auto-generated catch block
96 System.out.println("Have you ever set the project specific Yocto Settings?");
97 System.out.println(e.getMessage());
98 }
99
100 return result;
101 }
102
103 private void createComposite(Composite composite) throws Exception{
104 Label root_label, sysroot_label;
105
106 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
107 GridLayout layout = new GridLayout(2, false);
108 composite.setLayout(layout);
109
110 gd= new GridData(SWT.FILL, SWT.CENTER, true, false);
111 gd.horizontalSpan= 2;
112 composite.setLayoutData(gd);
113
114 Label build_dir_label = new Label(composite, SWT.NONE);
115 build_dir_label.setText("Bitbake build directory: ");
116 Composite textContainer = new Composite(composite, SWT.NONE);
117 textContainer.setLayout(new GridLayout(2, false));
118 textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
119
120 build_dir_combo = new Combo(textContainer, SWT.DROP_DOWN);
121 build_dir_combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
122 initializeBuildCombo();
123
124 Button buildButton = addDirSelectButton(textContainer, build_dir_combo);
125
126 //we add the listener at the end for avoiding the useless event trigger when control
127 //changed or modified.
128 buildButton.addSelectionListener(fSelectionListener);
129 build_dir_combo.addModifyListener(fModifyListener);
130 }
131
132 private Button addDirSelectButton(final Composite parent, final Combo combo) {
133 Button button = new Button(parent, SWT.PUSH | SWT.LEAD);
134 button.setText("Browse");
135 button.addSelectionListener(new SelectionAdapter() {
136 @Override
137 public void widgetSelected(SelectionEvent event) {
138 String dirName = new DirectoryDialog(parent.getShell()).open();
139
140 if (dirName != null) {
141 combo.add(dirName);
142 combo.setText(dirName);
143 }
144 }
145 });
146 return button;
147 }
148 @Override
149 protected void configureShell(Shell newShell) {
150 super.configureShell(newShell);
151 newShell.setText(title);
152 }
153
154 protected void buttonPressed(int buttonId) {
155 if (buttonId == IDialogConstants.OK_ID) {
156 try {
157 build_dir = build_dir_combo.getText().toString();
158 updateBuildSpec(build_dir);
159 super.buttonPressed(buttonId);
160 } catch (Exception e) {
161 // TODO Auto-generated catch block
162 System.out.println(e.getMessage());
163 }
164 }
165 else if (buttonId == IDialogConstants.CANCEL_ID)
166 {
167 super.buttonPressed(buttonId);
168 }
169 }
170
171 private boolean validateInput() {
172 boolean valid = false;
173 String build_dir = build_dir_combo.getText().toString();
174 if ((build_dir == null) || build_dir.isEmpty()) {
175 Display display = Display.getCurrent();
176 Shell shell = new Shell(display);
177 MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
178 msgBox.setText("Yocto Configuration Error");
179 msgBox.setMessage("The specified build directory is empty!");
180 msgBox.open();
181 if (shell != null)
182 shell.dispose();
183 return valid;
184 }
185 String project_path = project.getLocation().toString();
186 File project_dir_file = new File(project_path);
187 File build_dir_file = new File(build_dir);
188 try {
189 if (isSubDirectory(project_dir_file, build_dir_file)) {
190 Display display = Display.getCurrent();
191 Shell shell = new Shell(display);
192 MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
193 msgBox.setText("Yocto Configuration Error");
194 msgBox.setMessage("The specified build directory is a sub-dir of project path: " + project_path);
195 msgBox.open();
196 if (shell != null)
197 shell.dispose();
198 } else
199 valid = true;
200 } catch (IOException e) {
201 System.out.println(e.getMessage());
202 }
203 return valid;
204 }
205
206 private boolean isSubDirectory(File baseDir, File subDir) throws IOException {
207 baseDir = baseDir.getCanonicalFile();
208 subDir = subDir.getCanonicalFile();
209
210 File parentFile = subDir;
211 while (parentFile != null) {
212 if (baseDir.equals(parentFile)) {
213 return true;
214 }
215 parentFile = parentFile.getParentFile();
216 }
217 return false;
218 }
219
220 private void controlChanged(Widget widget) {
221
222 if (widget == buildButton)
223 {
224 }
225 }
226
227 private void controlModified(Widget widget) {
228 if (widget == build_dir_combo)
229 {
230
231 }
232 }
233
234 private void initializeBuildCombo()
235 {
236 ArrayList<String> items = new ArrayList<String> ();
237
238 try {
239 IProjectDescription desc = project.getDescription();
240
241 ICommand[] buildSpec = desc.getBuildSpec();
242 if ((buildSpec != null) && (buildSpec.length != 0))
243 {
244 for (int i = 0; i < buildSpec.length; i++) {
245 ICommand cmd = buildSpec[i];
246 if (cmd.getBuilderName().equalsIgnoreCase(BitbakeBuilder.HOB_BUILD_ID))
247 {
248 Map<String, String> args = cmd.getArguments();
249 if ((args != null) && !args.isEmpty())
250 {
251 Iterator entries = args.entrySet().iterator();
252 while (entries.hasNext()) {
253 Entry thisEntry = (Entry) entries.next();
254 String key = (String)thisEntry.getKey();
255 if (key.equalsIgnoreCase(BitbakeCommanderNature.BUILD_DIR_KEY)) {
256 build_dir_combo.removeAll();
257 build_dir_combo.setItems(getValues((String)thisEntry.getValue()));
258 }
259 }
260 }
261 }
262 }
263 }
264 } catch (Exception e) {
265 System.out.println(e.getMessage());
266 }
267 }
268
269 private String[] getValues(String value) {
270
271 if ((value != null) && !value.isEmpty())
272 {
273 String[] pieces = value.split(",");
274 for (int i = 0; i < pieces.length; i++)
275 {
276 int start = pieces[i].indexOf("[");
277 if (start >= 0)
278 pieces[i] = pieces[i].substring(start+1);
279 int end = pieces[i].indexOf("]");
280 if (end >= 0)
281 pieces[i] = pieces[i].substring(0, end);
282 pieces[i] = pieces[i].trim();
283 }
284 return pieces;
285 }
286 return null;
287 }
288
289 private void updateBuildSpec(String build_dir)
290 {
291 try {
292 String[] items = build_dir_combo.getItems();
293 HashSet values = new HashSet();
294 Map<String, String> args = new HashMap<String, String>();
295 values.add(build_dir);
296 for (int i = 0; i < items.length; i++) {
297 values.add(items[i]);
298 }
299 args.put(BitbakeCommanderNature.BUILD_DIR_KEY, values.toString());
300 IProjectDescription desc = project.getDescription();
301 ICommand[] buildSpec = desc.getBuildSpec();
302 boolean found = false;
303 if ((buildSpec != null) || (buildSpec.length != 0)) {
304 for (int i = 0; i < buildSpec.length; i++) {
305 ICommand cmd = buildSpec[i];
306 if (cmd.getBuilderName().equalsIgnoreCase(BitbakeBuilder.HOB_BUILD_ID)) {
307 cmd.setArguments(args);
308 desc.setBuildSpec(buildSpec);
309 found = true;
310 break;
311 }
312 }
313 }
314 if (!found) {
315 ICommand[] newBuildSpec = new ICommand[buildSpec.length + 1];
316 System.arraycopy(buildSpec, 0, newBuildSpec, 0, buildSpec.length);
317 ICommand cmd = desc.newCommand();
318 cmd.setBuilderName(BitbakeBuilder.HOB_BUILD_ID);
319 cmd.setArguments(args);
320 newBuildSpec[newBuildSpec.length - 1] = cmd;
321 desc.setBuildSpec(newBuildSpec);
322 }
323 project.setDescription(desc, null);
324 } catch (Exception e) {
325 System.out.println(e.getMessage());
326 }
327 }
328}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java
new file mode 100644
index 0000000..002075a
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java
@@ -0,0 +1,50 @@
1/*******************************************************************************
2 * Copyright (c) 2011 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.bc.ui.actions;
12
13import org.eclipse.core.commands.ExecutionEvent;
14import org.eclipse.core.commands.ExecutionException;
15import org.eclipse.core.commands.IHandlerListener;
16import org.eclipse.core.commands.IHandler;
17
18public class LaunchHobHandler implements IHandler {
19
20 public Object execute(ExecutionEvent event) throws ExecutionException {
21 LaunchHobAction a = new LaunchHobAction();
22 a.run(null);
23 return null;
24 }
25
26 public void addHandlerListener(IHandlerListener handlerListener) {
27 // TODO Auto-generated method stub
28
29 }
30
31 public void dispose() {
32 // TODO Auto-generated method stub
33
34 }
35
36 public boolean isEnabled() {
37 // TODO Auto-generated method stub
38 return true;
39 }
40
41 public boolean isHandled() {
42 // TODO Auto-generated method stub
43 return true;
44 }
45
46 public void removeHandlerListener(IHandlerListener handlerListener) {
47 // TODO Auto-generated method stub
48
49 }
50}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java
new file mode 100644
index 0000000..b8b3144
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java
@@ -0,0 +1,48 @@
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 org.eclipse.jface.action.IAction;
14import org.eclipse.jface.viewers.ISelection;
15import org.eclipse.jface.viewers.IStructuredSelection;
16import org.eclipse.jface.wizard.WizardDialog;
17import org.eclipse.ui.IWorkbenchWindow;
18import org.eclipse.ui.IWorkbenchWindowActionDelegate;
19
20import org.yocto.bc.ui.wizards.importProject.ImportYoctoProjectWizard;
21
22public class LaunchNewBitBakeProjectWizardAction implements IWorkbenchWindowActionDelegate {
23
24 private IWorkbenchWindow window;
25 private IStructuredSelection selection;
26
27 public void dispose() {
28 }
29
30 public void init(IWorkbenchWindow window) {
31 this.window = window;
32 }
33
34 public void run(IAction action) {
35 ImportYoctoProjectWizard wizard = new ImportYoctoProjectWizard();
36
37 wizard.init(window.getWorkbench(), selection);
38 WizardDialog wd = new WizardDialog(window.getShell(), wizard);
39 wd.create();
40 wd.open();
41 }
42
43 public void selectionChanged(IAction action, ISelection selection) {
44 if (selection instanceof IStructuredSelection) {
45 this.selection = (IStructuredSelection) selection;
46 }
47 }
48} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java
new file mode 100644
index 0000000..d30d37b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java
@@ -0,0 +1,48 @@
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 org.eclipse.jface.action.IAction;
14import org.eclipse.jface.viewers.ISelection;
15import org.eclipse.jface.viewers.IStructuredSelection;
16import org.eclipse.jface.wizard.WizardDialog;
17import org.eclipse.ui.IWorkbenchWindow;
18import org.eclipse.ui.IWorkbenchWindowActionDelegate;
19
20import org.yocto.bc.ui.wizards.NewBitBakeFileRecipeWizard;
21
22public class LaunchNewRecipeWizardAction implements IWorkbenchWindowActionDelegate {
23
24 private IWorkbenchWindow window;
25 private IStructuredSelection selection;
26
27 public void dispose() {
28 }
29
30 public void init(IWorkbenchWindow window) {
31 this.window = window;
32 }
33
34 public void run(IAction action) {
35 NewBitBakeFileRecipeWizard wizard = new NewBitBakeFileRecipeWizard();
36
37 wizard.init(window.getWorkbench(), selection);
38 WizardDialog wd = new WizardDialog(window.getShell(), wizard);
39 wd.create();
40 wd.open();
41 }
42
43 public void selectionChanged(IAction action, ISelection selection) {
44 if (selection instanceof IStructuredSelection) {
45 this.selection = (IStructuredSelection) selection;
46 }
47 }
48} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java
new file mode 100644
index 0000000..3104564
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java
@@ -0,0 +1,89 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.actions;
13
14import java.io.IOException;
15import java.lang.reflect.InvocationTargetException;
16import java.util.Map;
17
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IResource;
20import org.eclipse.core.runtime.CoreException;
21import org.eclipse.core.runtime.NullProgressMonitor;
22import org.eclipse.jface.action.IAction;
23import org.eclipse.jface.viewers.ISelection;
24import org.eclipse.jface.viewers.IStructuredSelection;
25import org.eclipse.jface.wizard.WizardDialog;
26import org.eclipse.ui.IWorkbenchWindow;
27import org.eclipse.ui.IWorkbenchWindowActionDelegate;
28import org.yocto.bc.ui.Activator;
29import org.yocto.bc.ui.builder.BitbakeCommanderNature;
30import org.yocto.bc.ui.model.ProjectInfo;
31import org.yocto.bc.ui.wizards.variable.VariableWizard;
32
33/**
34 * Action to launch the Variable Wizard.
35 * @author kgilmer
36 *
37 */
38public class LaunchVariableWizardAction implements IWorkbenchWindowActionDelegate {
39
40 private IWorkbenchWindow window;
41 private Map session;
42
43 public void dispose() {
44 }
45
46 public void init(IWorkbenchWindow window) {
47 this.window = window;
48 }
49
50 public void run(IAction action) {
51 VariableWizard wizard = new VariableWizard(session);
52
53 WizardDialog wd = new WizardDialog(window.getShell(), wizard);
54 wd.create();
55 wd.open();
56 }
57
58 public void selectionChanged(IAction action, ISelection selection) {
59 session = null;
60
61 if (selection instanceof IStructuredSelection) {
62 Object element = ((IStructuredSelection)selection).getFirstElement();
63
64 if (element instanceof IResource) {
65 IProject p = ((IResource)element).getProject();
66
67 try {
68 if (p.isAccessible() && p.isOpen() && p.hasNature(BitbakeCommanderNature.NATURE_ID)) {
69 IProject proj = ((IResource)element).getProject();
70 ProjectInfo projInfo = Activator.getProjInfo(proj.getLocationURI());
71 session = Activator.getBBSession(projInfo, new NullProgressMonitor());
72 }
73 } catch (IOException e) {
74 e.printStackTrace();
75 } catch (CoreException e) {
76 e.printStackTrace();
77 } catch (InvocationTargetException e) {
78 e.printStackTrace();
79 } catch (InterruptedException e) {
80 e.printStackTrace();
81 } catch (Exception e) {
82 e.printStackTrace();
83 }
84 }
85 }
86
87 action.setEnabled(session != null);
88 }
89}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java
new file mode 100644
index 0000000..3705d9b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java
@@ -0,0 +1,177 @@
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.builder;
12
13import java.util.Map;
14
15import javax.xml.parsers.ParserConfigurationException;
16import javax.xml.parsers.SAXParser;
17import javax.xml.parsers.SAXParserFactory;
18
19import org.eclipse.core.resources.IFile;
20import org.eclipse.core.resources.IMarker;
21import org.eclipse.core.resources.IProject;
22import org.eclipse.core.resources.IResource;
23import org.eclipse.core.resources.IResourceDelta;
24import org.eclipse.core.resources.IResourceDeltaVisitor;
25import org.eclipse.core.resources.IncrementalProjectBuilder;
26import org.eclipse.core.runtime.CoreException;
27import org.eclipse.core.runtime.IProgressMonitor;
28import org.xml.sax.SAXException;
29
30public class BitbakeBuilder extends IncrementalProjectBuilder {
31
32 class SampleDeltaVisitor implements IResourceDeltaVisitor {
33 /*
34 * (non-Javadoc)
35 *
36 * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
37 */
38 public boolean visit(IResourceDelta delta) throws CoreException {
39 IResource resource = delta.getResource();
40 switch (delta.getKind()) {
41 case IResourceDelta.ADDED:
42 // handle added resource
43 //checkXML(resource);
44 break;
45 case IResourceDelta.REMOVED:
46 // handle removed resource
47 break;
48 case IResourceDelta.CHANGED:
49 // handle changed resource
50 //checkXML(resource);
51 break;
52 }
53 //return true to continue visiting children.
54 return true;
55 }
56 }
57/*
58 class SampleResourceVisitor implements IResourceVisitor {
59 public boolean visit(IResource resource) {
60
61 return true;
62 }
63 }
64*/
65/* class XMLErrorHandler extends DefaultHandler {
66
67 private IFile file;
68
69 public XMLErrorHandler(IFile file) {
70 this.file = file;
71 }
72
73 private void addMarker(SAXParseException e, int severity) {
74 BitbakeBuilder.this.addMarker(file, e.getMessage(), e
75 .getLineNumber(), severity);
76 }
77
78 @Override
79 public void error(SAXParseException exception) throws SAXException {
80 addMarker(exception, IMarker.SEVERITY_ERROR);
81 }
82
83 @Override
84 public void fatalError(SAXParseException exception) throws SAXException {
85 addMarker(exception, IMarker.SEVERITY_ERROR);
86 }
87
88 @Override
89 public void warning(SAXParseException exception) throws SAXException {
90 addMarker(exception, IMarker.SEVERITY_WARNING);
91 }
92 }
93*/
94 public static final String BUILDER_ID = "org.yocto.bc.ui.builder.BitbakeBuilder";
95 public static final String HOB_BUILD_ID = "org.yocto.bc.ui.builder.HOB";
96
97 private static final String MARKER_TYPE = "org.yocto.bc.ui.xmlProblem";
98
99 private SAXParserFactory parserFactory;
100
101 private void addMarker(IFile file, String message, int lineNumber,
102 int severity) {
103 try {
104 IMarker marker = file.createMarker(MARKER_TYPE);
105 marker.setAttribute(IMarker.MESSAGE, message);
106 marker.setAttribute(IMarker.SEVERITY, severity);
107 if (lineNumber == -1) {
108 lineNumber = 1;
109 }
110 marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
111 } catch (CoreException e) {
112 }
113 }
114
115 /*
116 * (non-Javadoc)
117 *
118 * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
119 * java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
120 */
121 @Override
122 protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
123 throws CoreException {
124 if (kind == FULL_BUILD) {
125 fullBuild(monitor);
126 } else {
127 IResourceDelta delta = getDelta(getProject());
128 if (delta == null) {
129 fullBuild(monitor);
130 } else {
131 incrementalBuild(delta, monitor);
132 }
133 }
134 return null;
135 }
136
137 /*void checkXML(IResource resource) {
138 if (resource instanceof IFile && resource.getName().endsWith(".xml")) {
139 IFile file = (IFile) resource;
140 deleteMarkers(file);
141 XMLErrorHandler reporter = new XMLErrorHandler(file);
142 try {
143 getParser().parse(file.getContents(), reporter);
144 } catch (Exception e1) {
145 }
146 }
147 }*/
148
149 private void deleteMarkers(IFile file) {
150 try {
151 file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO);
152 } catch (CoreException ce) {
153 }
154 }
155
156 protected void fullBuild(final IProgressMonitor monitor)
157 throws CoreException {
158 /*try {
159 getProject().accept(new SampleResourceVisitor());
160 } catch (CoreException e) {
161 }*/
162 }
163
164 private SAXParser getParser() throws ParserConfigurationException,
165 SAXException {
166 if (parserFactory == null) {
167 parserFactory = SAXParserFactory.newInstance();
168 }
169 return parserFactory.newSAXParser();
170 }
171
172 protected void incrementalBuild(IResourceDelta delta,
173 IProgressMonitor monitor) throws CoreException {
174 // the visitor does the work.
175 delta.accept(new SampleDeltaVisitor());
176 }
177}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java
new file mode 100644
index 0000000..25f7894
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java
@@ -0,0 +1,119 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Jessica Zhang - extend to support HOB build
11 * Ioana Grigoropol (Intel) - adapt class for remote support
12 *******************************************************************************/
13package org.yocto.bc.ui.builder;
14
15import java.util.ArrayList;
16
17import org.eclipse.core.resources.ICommand;
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IProjectDescription;
20import org.eclipse.core.resources.IProjectNature;
21import org.eclipse.core.runtime.CoreException;
22import org.eclipse.debug.core.DebugPlugin;
23import org.eclipse.debug.core.ILaunchConfigurationType;
24import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
25import org.eclipse.debug.core.ILaunchManager;
26
27
28public class BitbakeCommanderNature implements IProjectNature {
29
30 /**
31 * ID of this project nature
32 */
33 public static final String NATURE_ID = "org.yocto.bc.ui.builder.BitbakeCommanderNature";
34 public static final String BUILD_DIR_KEY = "org.yocto.bc.ui.builder.BitbakeCommander.BuildDir";
35 private IProject project;
36
37 public static void launchHob(IProject project, String buildDir) {
38 try {
39 ILaunchManager lManager = DebugPlugin.getDefault().getLaunchManager();
40 ILaunchConfigurationType configType =
41 lManager.getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType");
42 ILaunchConfigurationWorkingCopy w_copy = configType.newInstance(null, "hob");
43 ArrayList<String> listValue = new ArrayList<String>();
44 listValue.add(new String("org.eclipse.ui.externaltools.launchGroup"));
45 w_copy.setAttribute("org.eclipse.debug.ui.favoriteGroups", listValue);
46 w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", "/usr/bin/xterm");
47
48 String init_script = project.getLocationURI().getPath() + "/oe-init-build-env ";
49 String argument = "-e \"source " + init_script + buildDir + ";hob";// + ";bash\"";
50
51 w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS", argument);
52 w_copy.launch(ILaunchManager.RUN_MODE, null);
53
54 } catch (CoreException e) {
55 System.out.println(e.getMessage());
56 }
57 }
58 /*
59 * (non-Javadoc)
60 *
61 * @see org.eclipse.core.resources.IProjectNature#configure()
62 */
63 public void configure() throws CoreException {
64 IProjectDescription desc = project.getDescription();
65 ICommand[] commands = desc.getBuildSpec();
66
67 for (int i = 0; i < commands.length; ++i) {
68 if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
69 return;
70 }
71 }
72
73 ICommand[] newCommands = new ICommand[commands.length + 1];
74 System.arraycopy(commands, 0, newCommands, 0, commands.length);
75 ICommand command = desc.newCommand();
76 command.setBuilderName(BitbakeBuilder.BUILDER_ID);
77 newCommands[newCommands.length - 1] = command;
78 desc.setBuildSpec(newCommands);
79 project.setDescription(desc, null);
80 }
81
82 /*
83 * (non-Javadoc)
84 *
85 * @see org.eclipse.core.resources.IProjectNature#deconfigure()
86 */
87 public void deconfigure() throws CoreException {
88 IProjectDescription description = getProject().getDescription();
89 ICommand[] commands = description.getBuildSpec();
90 for (int i = 0; i < commands.length; ++i) {
91 if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
92 ICommand[] newCommands = new ICommand[commands.length - 1];
93 System.arraycopy(commands, 0, newCommands, 0, i);
94 System.arraycopy(commands, i + 1, newCommands, i,
95 commands.length - i - 1);
96 description.setBuildSpec(newCommands);
97 return;
98 }
99 }
100 }
101
102 /*
103 * (non-Javadoc)
104 *
105 * @see org.eclipse.core.resources.IProjectNature#getProject()
106 */
107 public IProject getProject() {
108 return project;
109 }
110
111 /*
112 * (non-Javadoc)
113 *
114 * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
115 */
116 public void setProject(IProject project) {
117 this.project = project;
118 }
119}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java
new file mode 100644
index 0000000..f25148d
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.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.builder;
12
13import java.util.Iterator;
14
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.IProjectDescription;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.core.runtime.IAdaptable;
19import org.eclipse.jface.action.IAction;
20import org.eclipse.jface.viewers.ISelection;
21import org.eclipse.jface.viewers.IStructuredSelection;
22import org.eclipse.ui.IObjectActionDelegate;
23import org.eclipse.ui.IWorkbenchPart;
24
25public class ToggleNatureAction implements IObjectActionDelegate {
26
27 private ISelection selection;
28
29 /*
30 * (non-Javadoc)
31 *
32 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
33 */
34 public void run(IAction action) {
35 if (selection instanceof IStructuredSelection) {
36 for (Iterator it = ((IStructuredSelection) selection).iterator(); it
37 .hasNext();) {
38 Object element = it.next();
39 IProject project = null;
40 if (element instanceof IProject) {
41 project = (IProject) element;
42 } else if (element instanceof IAdaptable) {
43 project = (IProject) ((IAdaptable) element)
44 .getAdapter(IProject.class);
45 }
46 if (project != null) {
47 toggleNature(project);
48 }
49 }
50 }
51 }
52
53 /*
54 * (non-Javadoc)
55 *
56 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
57 * org.eclipse.jface.viewers.ISelection)
58 */
59 public void selectionChanged(IAction action, ISelection selection) {
60 this.selection = selection;
61 }
62
63 /*
64 * (non-Javadoc)
65 *
66 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
67 * org.eclipse.ui.IWorkbenchPart)
68 */
69 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
70 }
71
72 /**
73 * Toggles sample nature on a project
74 *
75 * @param project
76 * to have sample nature added or removed
77 */
78 private void toggleNature(IProject project) {
79 try {
80 IProjectDescription description = project.getDescription();
81 String[] natures = description.getNatureIds();
82
83 for (int i = 0; i < natures.length; ++i) {
84 if (BitbakeCommanderNature.NATURE_ID.equals(natures[i])) {
85 // Remove the nature
86 String[] newNatures = new String[natures.length - 1];
87 System.arraycopy(natures, 0, newNatures, 0, i);
88 System.arraycopy(natures, i + 1, newNatures, i,
89 natures.length - i - 1);
90 description.setNatureIds(newNatures);
91 project.setDescription(description, null);
92 return;
93 }
94 }
95
96 // Add the nature
97 String[] newNatures = new String[natures.length + 1];
98 System.arraycopy(natures, 0, newNatures, 0, natures.length);
99 newNatures[natures.length] = BitbakeCommanderNature.NATURE_ID;
100 description.setNatureIds(newNatures);
101 project.setDescription(description, null);
102 } catch (CoreException e) {
103 }
104 }
105
106}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ProjectDecorator.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ProjectDecorator.java
new file mode 100644
index 0000000..5901ee1
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ProjectDecorator.java
@@ -0,0 +1,48 @@
1package org.yocto.bc.ui.decorators;
2
3import org.eclipse.core.resources.IProject;
4import org.eclipse.core.runtime.CoreException;
5import org.eclipse.jface.resource.ImageDescriptor;
6import org.eclipse.jface.viewers.IDecoration;
7import org.eclipse.jface.viewers.ILabelProviderListener;
8import org.eclipse.jface.viewers.ILightweightLabelDecorator;
9
10import org.yocto.bc.ui.Activator;
11import org.yocto.bc.ui.builder.BitbakeCommanderNature;
12
13public class ProjectDecorator implements ILightweightLabelDecorator {
14
15 private ImageDescriptor image;
16
17 public ProjectDecorator() {
18 image = Activator.getImageDescriptor("icons/oe_decorator.gif");
19 }
20
21
22 public void decorate(Object element, IDecoration decoration) {
23 IProject p = (IProject) element;
24
25 try {
26 if (p.isOpen() && p.hasNature(BitbakeCommanderNature.NATURE_ID)) {
27 decoration.addOverlay(image, IDecoration.TOP_RIGHT);
28 }
29 } catch (CoreException e) {
30 e.printStackTrace();
31 }
32 }
33
34 public void addListener(ILabelProviderListener arg0) {
35 }
36
37 public void dispose() {
38 }
39
40 public boolean isLabelProperty(Object arg0, String arg1) {
41 return false;
42 }
43
44
45 public void removeListener(ILabelProviderListener arg0) {
46 }
47
48}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java
new file mode 100644
index 0000000..0bb3c20
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java
@@ -0,0 +1,107 @@
1/*******************************************************************************
2 * Copyright (c) 2006 IBM Corporation and others.
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 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.decorators;
12
13import java.net.URL;
14
15import org.eclipse.core.resources.IResource;
16import org.eclipse.core.resources.ResourceAttributes;
17import org.eclipse.core.runtime.Path;
18import org.eclipse.core.runtime.Platform;
19import org.eclipse.jface.resource.ImageDescriptor;
20import org.eclipse.jface.viewers.IDecoration;
21import org.eclipse.jface.viewers.ILabelProviderListener;
22import org.eclipse.jface.viewers.ILightweightLabelDecorator;
23
24/**
25 * An example showing how to control when an element is decorated. This example
26 * decorates only elements that are instances of IResource and whose attribute
27 * is 'Read-only'.
28 *
29 * @see ILightweightLabelDecorator
30 */
31public class ReadOnly implements ILightweightLabelDecorator {
32 /**
33 * String constants for the various icon placement options from the template
34 * wizard.
35 */
36 public static final String TOP_RIGHT = "TOP_RIGHT";
37
38 public static final String TOP_LEFT = "TOP_LEFT";
39
40 public static final String BOTTOM_RIGHT = "BOTTOM_RIGHT";
41
42 public static final String BOTTOM_LEFT = "BOTTOM_LEFT";
43
44 public static final String UNDERLAY = "UNDERLAY";
45
46 /** The integer value representing the placement options */
47 private int quadrant;
48
49 /** The icon image location in the project folder */
50 private String iconPath = "icons/read_only.gif"; //NON-NLS-1
51
52 /**
53 * The image description used in
54 * <code>addOverlay(ImageDescriptor, int)</code>
55 */
56 private ImageDescriptor descriptor;
57
58 /* (non-Javadoc)
59 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
60 */
61 public void decorate(Object element, IDecoration decoration) {
62 /**
63 * Checks that the element is an IResource with the 'Read-only' attribute
64 * and adds the decorator based on the specified image description and the
65 * integer representation of the placement option.
66 */
67 IResource resource = (IResource) element;
68 ResourceAttributes attrs = resource.getResourceAttributes();
69 if(attrs!=null) {
70 if (attrs.isReadOnly()){
71 URL url = Platform.find(
72 Platform.getBundle("org.yocto.bc.ui"), new Path(iconPath)); //NON-NLS-1
73
74 if (url == null)
75 return;
76 descriptor = ImageDescriptor.createFromURL(url);
77 quadrant = IDecoration.TOP_RIGHT;
78 decoration.addOverlay(descriptor,quadrant);
79 }
80 }
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
85 */
86 public void addListener(ILabelProviderListener listener) {
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
91 */
92 public void dispose() {
93 }
94
95 /* (non-Javadoc)
96 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
97 */
98 public boolean isLabelProperty(Object element, String property) {
99 return false;
100 }
101
102 /* (non-Javadoc)
103 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
104 */
105 public void removeListener(ILabelProviderListener listener) {
106 }
107} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java
new file mode 100644
index 0000000..5a90fca
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java
@@ -0,0 +1,127 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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.bc.ui.editors.bitbake;
12
13import java.net.URI;
14import java.util.Map;
15
16import org.eclipse.core.runtime.IProgressMonitor;
17import org.eclipse.core.runtime.IStatus;
18import org.eclipse.core.runtime.Status;
19import org.eclipse.core.runtime.jobs.Job;
20import org.eclipse.jface.text.IRegion;
21import org.eclipse.jface.text.ITextHover;
22import org.eclipse.jface.text.ITextViewer;
23import org.eclipse.jface.text.Region;
24import org.yocto.bc.bitbake.BBRecipe;
25import org.yocto.bc.bitbake.BBSession;
26import org.yocto.bc.ui.Activator;
27
28/**
29 * Maps BB Variables in the editor to BBSession
30 * @author kgilmer
31 *
32 */
33class BBVariableTextHover implements ITextHover {
34 private final BBSession session;
35 private volatile Map<String, String> envMap;
36
37 public BBVariableTextHover(BBSession session, URI file) {
38 this.session = session;
39 envMap = getEnvironmentMap();
40 LoadRecipeJob loadRecipeJob = new LoadRecipeJob(getFilename(file), file);
41 loadRecipeJob.schedule();
42 }
43
44 private Map<String, String> getEnvironmentMap() {
45 if (envMap == null)
46 envMap = this.session.getProperties();
47 return envMap;
48 }
49
50 private String getFilename(URI uri) {
51 return uri.getPath();
52 }
53
54 public IRegion getHoverRegion(ITextViewer tv, int off) {
55 return new Region(off, 0);
56 }
57
58 public String getHoverInfo(ITextViewer tv, IRegion r) {
59 try {
60 IRegion lineRegion = tv.getDocument().getLineInformationOfOffset(r.getOffset());
61
62 return getBBVariable(tv.getDocument().get(lineRegion.getOffset(), lineRegion.getLength()).toCharArray(), r.getOffset() - lineRegion.getOffset());
63 } catch (Exception e) {
64 return "";
65 }
66 }
67
68 private String getBBVariable(char[] line, int offset) {
69 // Find start of word.
70 int i = offset;
71
72 while (line[i] != ' ' && line[i] != '$' && i > 0) {
73 i--;
74 }
75
76 if (i < 0 || line[i] != '$') {
77 return ""; //this is not a BB variable.
78 }
79
80 // find end of word
81 int start = i;
82 i = offset;
83
84 while (line[i] != ' ' && line[i] != '}' && i <= line.length) {
85 i++;
86 }
87
88 if (line[i] != '}') {
89 return ""; //this bb variable didn't terminate as expected
90 }
91
92 String key = new String(line, start + 2, i - start - 2);
93 String val = (String) getEnvironmentMap().get(key);
94
95 if (val == null) {
96 val = "";
97 }
98
99 if (val.length() > 64) {
100 val = val.substring(0, 64) + '\n' + val.substring(65);
101 }
102
103 return val;
104 }
105
106 private class LoadRecipeJob extends Job {
107 private final URI filePath;
108
109 public LoadRecipeJob(String name, URI filePath) {
110 super("Extracting BitBake environment for " + name);
111 this.filePath = filePath;
112 }
113
114 @Override
115 protected IStatus run(IProgressMonitor mon) {
116 try {
117 BBRecipe recipe = Activator.getBBRecipe(session, filePath);
118 recipe.initialize();
119 envMap = recipe;
120 } catch (Exception e) {
121 return new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Unable to load session for " + filePath, e);
122 }
123
124 return Status.OK_STATUS;
125 }
126 }
127}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java
new file mode 100644
index 0000000..140a3da
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java
@@ -0,0 +1,101 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.net.URI;
15import java.net.URISyntaxException;
16
17import org.eclipse.core.runtime.NullProgressMonitor;
18import org.eclipse.jface.text.IDocument;
19import org.eclipse.jface.text.IDocumentExtension3;
20import org.eclipse.jface.text.IDocumentPartitioner;
21import org.eclipse.jface.text.rules.FastPartitioner;
22import org.eclipse.jface.text.rules.IPredicateRule;
23import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
24import org.eclipse.jface.text.rules.SingleLineRule;
25import org.eclipse.jface.text.rules.Token;
26import org.eclipse.rse.core.model.IHost;
27import org.eclipse.ui.IFileEditorInput;
28import org.eclipse.ui.editors.text.FileDocumentProvider;
29import org.yocto.remote.utils.RemoteHelper;
30
31/**
32 * Document provider for BB recipe.
33 * @author kgilmer
34 *
35 */
36public class BitBakeDocumentProvider extends FileDocumentProvider {
37 /**
38 * The recipe partitioning. It contains two partition types: {@link #RECIPE_CODE} and
39 * {@link #RECIPE_COMMENT}.
40 */
41 public static final String RECIPE_PARTITIONING= "org.recipeeditor.recipepartitioning"; //$NON-NLS-1$
42
43 public static final String RECIPE_CODE= IDocument.DEFAULT_CONTENT_TYPE;
44 public static final String RECIPE_COMMENT= "RECIPE_COMMENT"; //$NON-NLS-1$
45
46 private IHost connection;
47
48 private final BitBakeSourceViewerConfiguration viewerConfiguration;
49
50 private static final String[] CONTENT_TYPES= {
51 RECIPE_CODE,
52 RECIPE_COMMENT
53 };
54
55 public BitBakeDocumentProvider(BitBakeSourceViewerConfiguration viewerConfiguration) {
56 this.viewerConfiguration = viewerConfiguration;
57 }
58
59 private IDocumentPartitioner createRecipePartitioner() {
60 IPredicateRule[] rules= { new SingleLineRule("#", null, new Token(RECIPE_COMMENT), (char) 0, true, false) }; //$NON-NLS-1$
61
62 RuleBasedPartitionScanner scanner= new RuleBasedPartitionScanner();
63 scanner.setPredicateRules(rules);
64
65 return new FastPartitioner(scanner, CONTENT_TYPES);
66 }
67
68 @Override
69 protected void setupDocument(Object element,IDocument document) {
70 if (document instanceof IDocumentExtension3) {
71 IDocumentExtension3 ext= (IDocumentExtension3) document;
72 IDocumentPartitioner partitioner= createRecipePartitioner();
73 ext.setDocumentPartitioner(RECIPE_PARTITIONING, partitioner);
74 partitioner.connect(document);
75 }
76 }
77
78 @Override
79 public boolean isDeleted(Object element) {
80 if (element instanceof IFileEditorInput) {
81 IFileEditorInput input= (IFileEditorInput) element;
82
83 URI root = viewerConfiguration.getBBSession().getProjInfoRoot();
84 String relPath = input.getFile().getProjectRelativePath().toPortableString();
85 try {
86 URI fileURI = new URI(root.getScheme(), root.getHost(), root.getPath() + "/" + relPath, root.getFragment());
87 if (connection == null)
88 connection = viewerConfiguration.getBBSession().getProjectInfo().getConnection();
89 return !RemoteHelper.fileExistsRemote(connection, new NullProgressMonitor(), fileURI.getPath());
90 } catch (URISyntaxException e) {
91 e.printStackTrace();
92 }
93 }
94
95 return super.isDeleted(element);
96 }
97
98 public void setActiveConnection(IHost connection) {
99 this.connection = connection;
100 }
101}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java
new file mode 100644
index 0000000..11dd335
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java
@@ -0,0 +1,89 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.io.IOException;
15import java.lang.reflect.InvocationTargetException;
16import java.util.ResourceBundle;
17
18import org.eclipse.core.resources.IFile;
19import org.eclipse.core.resources.IProject;
20import org.eclipse.core.runtime.CoreException;
21import org.eclipse.core.runtime.NullProgressMonitor;
22import org.eclipse.core.runtime.Status;
23import org.eclipse.ui.IEditorInput;
24import org.eclipse.ui.IEditorSite;
25import org.eclipse.ui.PartInitException;
26import org.eclipse.ui.part.FileEditorInput;
27import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
28import org.eclipse.ui.texteditor.ContentAssistAction;
29import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
30import org.yocto.bc.ui.Activator;
31import org.yocto.bc.ui.model.ProjectInfo;
32
33/**
34 * Editor for BB Recipe
35 * @author kgilmer
36 *
37 */
38public class BitBakeFileEditor extends AbstractDecoratedTextEditor {
39
40 public static final String EDITOR_ID = "org.yocto.bc.ui.editors.BitBakeFileEditor";
41 static final String CONTENT_ASSIST= "ContentAssist";
42 private BitBakeSourceViewerConfiguration viewerConfiguration;
43 private IFile targetFile;
44
45 public BitBakeFileEditor() {
46 super();
47 viewerConfiguration = new BitBakeSourceViewerConfiguration(getSharedColors(), getPreferenceStore());
48 setSourceViewerConfiguration(viewerConfiguration);
49 setDocumentProvider(new BitBakeDocumentProvider(viewerConfiguration));
50 }
51
52 @Override
53 protected void createActions() {
54 super.createActions();
55
56 ResourceBundle bundle= RecipeEditorMessages.getBundle();
57 ContentAssistAction action= new ContentAssistAction(bundle, "contentAssist.", this); //$NON-NLS-1$
58 action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
59 setAction(CONTENT_ASSIST, action);
60 }
61
62 @Override
63 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
64
65 if (input instanceof FileEditorInput) {
66 IProject p = ((FileEditorInput)input).getFile().getProject();
67 targetFile = ((FileEditorInput)input).getFile();
68 viewerConfiguration.setTargetFile(targetFile);
69
70 try {
71 ProjectInfo projInfo = Activator.getProjInfo(p.getLocationURI());
72 ((BitBakeDocumentProvider)getDocumentProvider()).setActiveConnection(projInfo.getConnection());
73 viewerConfiguration.setBBSession(Activator.getBBSession(projInfo, new NullProgressMonitor()));
74 } catch (IOException e) {
75 e.printStackTrace();
76 throw new PartInitException(Status.CANCEL_STATUS);
77 } catch (InvocationTargetException e) {
78 e.printStackTrace();
79 } catch (CoreException e) {
80 e.printStackTrace();
81 } catch (InterruptedException e) {
82 e.printStackTrace();
83 } catch (Exception e) {
84 e.printStackTrace();
85 }
86 }
87 super.init(site, input);
88 }
89}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java
new file mode 100644
index 0000000..87a51d2
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java
@@ -0,0 +1,210 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.net.URI;
15import java.net.URISyntaxException;
16
17import org.eclipse.core.resources.IFile;
18import org.eclipse.jface.preference.IPreferenceStore;
19import org.eclipse.jface.text.ITextHover;
20import org.eclipse.jface.text.TextAttribute;
21import org.eclipse.jface.text.contentassist.ContentAssistant;
22import org.eclipse.jface.text.contentassist.IContentAssistant;
23import org.eclipse.jface.text.presentation.IPresentationReconciler;
24import org.eclipse.jface.text.presentation.PresentationReconciler;
25import org.eclipse.jface.text.reconciler.IReconciler;
26import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
27import org.eclipse.jface.text.rules.IRule;
28import org.eclipse.jface.text.rules.IToken;
29import org.eclipse.jface.text.rules.IWordDetector;
30import org.eclipse.jface.text.rules.RuleBasedScanner;
31import org.eclipse.jface.text.rules.SingleLineRule;
32import org.eclipse.jface.text.rules.Token;
33import org.eclipse.jface.text.rules.WordRule;
34import org.eclipse.jface.text.source.ISharedTextColors;
35import org.eclipse.jface.text.source.ISourceViewer;
36import org.eclipse.swt.SWT;
37import org.eclipse.swt.graphics.Color;
38import org.eclipse.swt.graphics.RGB;
39import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
40import org.yocto.bc.bitbake.BBLanguageHelper;
41import org.yocto.bc.bitbake.BBSession;
42
43public class BitBakeSourceViewerConfiguration extends TextSourceViewerConfiguration {
44
45 private static final class WordDetector implements IWordDetector {
46 public boolean isWordPart(char c) {
47 return !Character.isWhitespace(c);
48 }
49
50 public boolean isWordStart(char c) {
51 return !Character.isWhitespace(c);
52 }
53 }
54
55 private final ISharedTextColors fSharedColors;
56 private BBSession session;
57 private IFile targetFile;
58 private BBVariableTextHover textHover = null;
59
60 public BitBakeSourceViewerConfiguration(ISharedTextColors sharedColors, IPreferenceStore store) {
61 super(store);
62 fSharedColors = sharedColors;
63 }
64
65 protected void setTargetFile(IFile targetFile) {
66 this.targetFile = targetFile;
67 }
68
69 public ITextHover getTextHover(ISourceViewer sv, String contentType) {
70 //only .bb file support Text Hover.
71 if (textHover == null && targetFile.getFileExtension().equals(BBLanguageHelper.BITBAKE_RECIPE_FILE_EXTENSION)) {
72 URI root = session.getProjInfoRoot();
73 try {
74 String targetFileProjPath = targetFile.getProjectRelativePath().toPortableString();
75 URI targetFileURI = new URI(root.getScheme(), root.getHost(), root.getPath() + "/" +
76 targetFileProjPath, root.getFragment());
77 textHover = new BBVariableTextHover(session, targetFileURI);
78 } catch (URISyntaxException e) {
79 e.printStackTrace();
80 }
81 }
82
83 return textHover;
84 }
85
86 private void addDamagerRepairer(PresentationReconciler reconciler, RuleBasedScanner commentScanner, String contentType) {
87 DefaultDamagerRepairer commentDamagerRepairer = new DefaultDamagerRepairer(commentScanner);
88 reconciler.setDamager(commentDamagerRepairer, contentType);
89 reconciler.setRepairer(commentDamagerRepairer, contentType);
90 }
91
92 private RuleBasedScanner createCommentScanner() {
93 Color green = fSharedColors.getColor(new RGB(16, 96, 16));
94 RuleBasedScanner commentScanner = new RuleBasedScanner();
95 commentScanner.setDefaultReturnToken(new Token(new TextAttribute(green, null, SWT.ITALIC)));
96 return commentScanner;
97 }
98
99 private IRule createCustomFunctionRule() {
100 Color blue = fSharedColors.getColor(new RGB(130, 0, 0));
101 IRule rule = new CustomFunctionRule(new Token(new TextAttribute(blue, null, SWT.BOLD)));
102
103 return rule;
104 }
105
106 private SingleLineRule createFunctionNameRule() {
107 Color red = fSharedColors.getColor(new RGB(150, 0, 96));
108 SingleLineRule stepRule = new SingleLineRule("do_", ")", new Token(new TextAttribute(red, null, SWT.BOLD))); //$NON-NLS-1$ //$NON-NLS-2$
109 stepRule.setColumnConstraint(0);
110 return stepRule;
111 }
112
113 private SingleLineRule createInlineVariableRule() {
114 Color blue = fSharedColors.getColor(new RGB(50, 50, 100));
115 SingleLineRule stepRule = new SingleLineRule("${", "}", new Token(new TextAttribute(blue, null, SWT.BOLD))); //$NON-NLS-1$ //$NON-NLS-2$
116 return stepRule;
117 }
118
119 private WordRule createKeywordRule() {
120 WordRule keywordRule = new WordRule(new WordDetector());
121 IToken token = new Token(new TextAttribute(fSharedColors.getColor(new RGB(96, 96, 0)), null, SWT.NONE));
122
123 for (int i = 0; i < BBLanguageHelper.BITBAKE_KEYWORDS.length; ++i) {
124
125 keywordRule.addWord(BBLanguageHelper.BITBAKE_KEYWORDS[i], token);
126 keywordRule.setColumnConstraint(0);
127 }
128
129 return keywordRule;
130 }
131
132 private RuleBasedScanner createRecipeScanner() {
133 RuleBasedScanner recipeScanner = new RuleBasedScanner();
134
135 IRule[] rules = { createKeywordRule(), createShellKeywordRule(), createStringLiteralRule(), createVariableRule(), createFunctionNameRule(), createCustomFunctionRule(),
136 createInlineVariableRule() };
137 recipeScanner.setRules(rules);
138 return recipeScanner;
139 }
140
141 private WordRule createShellKeywordRule() {
142 WordRule keywordRule = new WordRule(new WordDetector());
143 IToken token = new Token(new TextAttribute(fSharedColors.getColor(new RGB(0, 64, 92)), null, SWT.NONE));
144
145 for (int i = 0; i < BBLanguageHelper.SHELL_KEYWORDS.length; ++i) {
146 keywordRule.addWord(BBLanguageHelper.SHELL_KEYWORDS[i], token);
147 }
148
149 return keywordRule;
150 }
151
152 private SingleLineRule createStringLiteralRule() {
153 Color red = fSharedColors.getColor(new RGB(50, 50, 100));
154 SingleLineRule rule = new SingleLineRule("\"", "\"", new Token(new TextAttribute(red, null, SWT.NONE)), '\\');
155
156 return rule;
157 }
158
159 private IRule createVariableRule() {
160 Color blue = fSharedColors.getColor(new RGB(0, 0, 200));
161 IRule rule = new VariableRule(new Token(new TextAttribute(blue, null, SWT.NONE)));
162
163 return rule;
164 }
165
166 @Override
167 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
168 return new String[] { BitBakeDocumentProvider.RECIPE_CODE, BitBakeDocumentProvider.RECIPE_COMMENT };
169 }
170
171 @Override
172 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
173 return BitBakeDocumentProvider.RECIPE_PARTITIONING;
174 }
175
176 @Override
177 public IContentAssistant getContentAssistant(final ISourceViewer sourceViewer) {
178 ContentAssistant assistant = new ContentAssistant();
179 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
180
181 // assistant.setContentAssistProcessor(new HippieProposalProcessor(),
182 // BitBakeDocumentProvider.RECIPE_COMMENT);
183 assistant.setContentAssistProcessor(new RecipeCompletionProcessor(), BitBakeDocumentProvider.RECIPE_CODE);
184
185 return assistant;
186 }
187
188 public IReconciler getReconciler(ISourceViewer sourceViewer) {
189 return null;
190 }
191
192 @Override
193 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
194 PresentationReconciler reconciler = new PresentationReconciler();
195 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
196
197 addDamagerRepairer(reconciler, createCommentScanner(), BitBakeDocumentProvider.RECIPE_COMMENT);
198 addDamagerRepairer(reconciler, createRecipeScanner(), BitBakeDocumentProvider.RECIPE_CODE);
199
200 return reconciler;
201 }
202
203 public void setBBSession(BBSession session) {
204 this.session = session;
205 }
206
207 public BBSession getBBSession() {
208 return this.session;
209 }
210}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java
new file mode 100644
index 0000000..223a25d
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java
@@ -0,0 +1,94 @@
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.editors.bitbake;
12
13import org.eclipse.jface.text.rules.ICharacterScanner;
14import org.eclipse.jface.text.rules.IRule;
15import org.eclipse.jface.text.rules.IToken;
16import org.eclipse.jface.text.rules.Token;
17
18/**
19 * Rule for def_ BB Recipe functions
20 * @author kgilmer
21 *
22 */
23final class CustomFunctionRule implements IRule {
24
25 /** Token to return for this rule */
26 private final IToken fToken;
27
28 /**
29 * Creates a new operator rule.
30 *
31 * @param token
32 * Token to use for this rule
33 */
34 public CustomFunctionRule(IToken token) {
35 fToken = token;
36 }
37
38 public IToken evaluate(ICharacterScanner scanner) {
39 if (scanner.getColumn() > 0) {
40 return Token.UNDEFINED;
41 }
42
43 int i = scanner.read();
44 int c = 1;
45
46 if (!Character.isLetter(i) && i != 10) {
47 scanner.unread();
48 return Token.UNDEFINED;
49 }
50
51 if (i == 'd' && scanAhead(scanner, "o_".toCharArray())) {
52 scanner.unread();
53 return Token.UNDEFINED;
54 }
55
56 while (i != ICharacterScanner.EOF && i != 10) {
57 i = scanner.read();
58 c++;
59
60 if (i == '(') {
61 readUntil(scanner, ')');
62
63 return fToken;
64 }
65 }
66
67 for (int t = 0; t < c; t++) {
68 scanner.unread();
69 }
70
71 return Token.UNDEFINED;
72 }
73
74 private void readUntil(ICharacterScanner scanner, int c) {
75 int i;
76 do {
77 i = scanner.read();
78 } while (! (i == ICharacterScanner.EOF) && ! (i == c));
79 }
80
81 private boolean scanAhead(ICharacterScanner scanner, char [] chars) {
82 boolean v = true;
83 for (int i = 0; i < chars.length; ++i) {
84 if (! (scanner.read() == chars[i])) {
85 v = false;
86 for (int j = 0; j < i; ++j) {
87 scanner.unread();
88 }
89 break;
90 }
91 }
92 return v;
93 }
94} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java
new file mode 100644
index 0000000..034187a
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java
@@ -0,0 +1,127 @@
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 * Lianhao Lu (Intel) - remove compile warnings
11 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.util.ArrayList;
15import java.util.Arrays;
16import java.util.Iterator;
17import java.util.List;
18import java.util.Map;
19
20import org.eclipse.jface.text.IDocument;
21import org.eclipse.jface.text.ITextViewer;
22import org.eclipse.jface.text.Region;
23import org.eclipse.jface.text.contentassist.ICompletionProposal;
24import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
25import org.eclipse.jface.text.contentassist.IContextInformation;
26import org.eclipse.jface.text.contentassist.IContextInformationValidator;
27import org.eclipse.jface.text.templates.DocumentTemplateContext;
28import org.eclipse.jface.text.templates.Template;
29import org.eclipse.jface.text.templates.TemplateContext;
30import org.eclipse.jface.text.templates.TemplateContextType;
31import org.eclipse.jface.text.templates.TemplateProposal;
32import org.eclipse.swt.graphics.Image;
33import org.eclipse.ui.ide.IDE.SharedImages;
34import org.eclipse.ui.PlatformUI;
35
36import org.yocto.bc.bitbake.BBLanguageHelper;
37import org.yocto.bc.ui.Activator;
38
39class RecipeCompletionProcessor implements IContentAssistProcessor {
40
41 private static final String CONTEXT_ID= "bitbake_variables"; //$NON-NLS-1$
42 private final TemplateContextType fContextType= new TemplateContextType(CONTEXT_ID, "Common BitBake Variables"); //$NON-NLS-1$
43 //private final TemplateContextType fKeywordContextType= new TemplateContextType("bitbake_keywords", "BitBake Keywords"); //$NON-NLS-1$
44 private final TemplateContextType fFunctionContextType = new TemplateContextType("bitbake_functions", "BitBake Functions");
45
46 RecipeCompletionProcessor() {
47 }
48
49 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
50 IDocument document= viewer.getDocument();
51 Region region= new Region(offset, 0);
52
53 TemplateContext templateContext= new DocumentTemplateContext(fContextType, document, offset, 0);
54 //TemplateContext keywordContext = new DocumentTemplateContext(fKeywordContextType, document, offset, 0);
55 TemplateContext functionContext = new DocumentTemplateContext(fFunctionContextType, document, offset, 0);
56
57 List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
58
59 getVariableTemplateProposals(templateContext, region, proposals);
60 // getKeywordTemplateProposals(keywordContext, region, proposals);
61 getAddTaskTemplateProposals(templateContext, region, proposals);
62 getFunctionTemplateProposals(functionContext, region, proposals);
63
64 return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
65 }
66
67 public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
68 return null;
69 }
70
71 private Template generateVariableTemplate(String name, String description) {
72
73 return new Template(name, description, CONTEXT_ID, name + " = \"${" + name.toLowerCase() + "}\"", false);
74 }
75
76 private void getAddTaskTemplateProposals(TemplateContext templateContext, Region region, List<ICompletionProposal> p) {
77 p.add(new TemplateProposal(new Template("addtask", "addtask statement", CONTEXT_ID, "addtask ${task_name} after ${do_previous_task} before ${do_next_task}", false),templateContext, region, PlatformUI.getWorkbench().getSharedImages().getImage(SharedImages.IMG_OBJS_BKMRK_TSK)));
78 }
79
80
81 public char[] getCompletionProposalAutoActivationCharacters() {
82 return null;
83 }
84
85 public char[] getContextInformationAutoActivationCharacters() {
86 return null;
87 }
88
89 public IContextInformationValidator getContextInformationValidator() {
90 return null;
91 }
92
93 public String getErrorMessage() {
94 return null;
95 }
96
97 private void getFunctionTemplateProposals(TemplateContext templateContext, Region region, List<ICompletionProposal> p) {
98 String [] keywords = BBLanguageHelper.BITBAKE_STANDARD_FUNCTIONS;
99 Image img = Activator.getDefault().getImageRegistry().get(Activator.IMAGE_FUNCTION);
100 Arrays.sort(keywords);
101
102 for (int i = 0; i < keywords.length; ++i) {
103 p.add(new TemplateProposal(new Template(keywords[i], keywords[i] + " function", CONTEXT_ID, "do_" + keywords[i] + "() {\n\n}", false), templateContext, region, img));
104 }
105 }
106 /*
107 private void getKeywordTemplateProposals(TemplateContext templateContext, Region region, List<TemplateProposal> p) {
108 String [] keywords = BBLanguageHelper.BITBAKE_KEYWORDS;
109
110 Arrays.sort(keywords);
111
112 for (int i = 0; i < keywords.length; ++i) {
113 p.add(new TemplateProposal(new Template(keywords[i], keywords[i] + " keyword", CONTEXT_ID, keywords[i] + " ", false),templateContext, region, null));
114 }
115 }
116 */
117
118 private void getVariableTemplateProposals(TemplateContext templateContext, Region region, List<ICompletionProposal> p) {
119 Map<String, String> n = BBLanguageHelper.getCommonBitbakeVariables();
120 Image img = Activator.getDefault().getImageRegistry().get(Activator.IMAGE_VARIABLE);
121 for (Iterator<String> i = n.keySet().iterator(); i.hasNext();) {
122 String name = (String) i.next();
123 String description = (String) n.get(name);
124 p.add(new TemplateProposal(generateVariableTemplate(name, description), templateContext, region, img));
125 }
126 }
127} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java
new file mode 100644
index 0000000..f27951b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java
@@ -0,0 +1,47 @@
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.editors.bitbake;
12
13import org.eclipse.jface.action.IMenuManager;
14import org.eclipse.ui.IEditorPart;
15import org.eclipse.ui.IWorkbenchActionConstants;
16import org.eclipse.ui.editors.text.TextEditorActionContributor;
17import org.eclipse.ui.texteditor.ITextEditor;
18import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
19import org.eclipse.ui.texteditor.RetargetTextEditorAction;
20
21public class RecipeEditorActionContributor extends TextEditorActionContributor {
22
23 private RetargetTextEditorAction fContentAssist;
24
25 public RecipeEditorActionContributor() {
26 fContentAssist= new RetargetTextEditorAction(RecipeEditorMessages.getBundle(), "contentAssist."); //$NON-NLS-1$
27 fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
28 }
29
30 @Override
31 public void contributeToMenu(IMenuManager menu) {
32 super.contributeToMenu(menu);
33
34 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
35 if (editMenu != null) {
36 editMenu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, fContentAssist);
37 }
38 }
39
40 @Override
41 public void setActiveEditor(IEditorPart part) {
42 super.setActiveEditor(part);
43 if (part instanceof ITextEditor) {
44 fContentAssist.setAction(getAction((ITextEditor) part, BitBakeFileEditor.CONTENT_ASSIST));
45 }
46 }
47}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java
new file mode 100644
index 0000000..020a25a
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java
@@ -0,0 +1,21 @@
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.editors.bitbake;
12
13import java.util.ResourceBundle;
14
15public class RecipeEditorMessages {
16
17 public static ResourceBundle getBundle() {
18 return ResourceBundle.getBundle(RecipeEditorMessages.class.getName());
19 }
20
21}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties
new file mode 100644
index 0000000..76c670b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties
@@ -0,0 +1,14 @@
1#########################################################
2# Copyright (c) 2006 IBM Corporation and others.
3# All rights reserved. This program and the accompanying materials
4# are made available under the terms of the Common Public License v1.0
5# which accompanies this distribution, and is available at
6# http://www.eclipse.org/legal/cpl-v10.html
7#
8# Contributors:
9# IBM Corporation - initial API and implementation
10##########################################################
11contentAssist.label=Content Assist
12contentAssist.tooltip=Content Assist
13contentAssist.image=
14contentAssist.description= Invokes content assist \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java
new file mode 100644
index 0000000..750705a
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java
@@ -0,0 +1,69 @@
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.editors.bitbake;
12
13import org.eclipse.jface.text.rules.ICharacterScanner;
14import org.eclipse.jface.text.rules.IRule;
15import org.eclipse.jface.text.rules.IToken;
16import org.eclipse.jface.text.rules.Token;
17
18final class VariableRule implements IRule {
19
20 /** Token to return for this rule */
21 private final IToken fToken;
22
23 /**
24 * Creates a new operator rule.
25 *
26 * @param token
27 * Token to use for this rule
28 */
29 public VariableRule(IToken token) {
30 fToken = token;
31 }
32
33 public IToken evaluate(ICharacterScanner scanner) {
34 if (scanner.getColumn() > 0) {
35 return Token.UNDEFINED;
36 }
37
38 int i = scanner.read();
39 int c = 1;
40
41 if (!Character.isLetter(i) && i != 10) {
42 scanner.unread();
43 return Token.UNDEFINED;
44 }
45
46 int p = i;
47
48 while (i != ICharacterScanner.EOF && i != 10) {
49 p = i;
50 i = scanner.read();
51 c++;
52
53 if (i == '=') {
54 scanner.unread();
55
56 if (p == '?' || p == '+') {
57 scanner.unread();
58 }
59 return fToken;
60 }
61 }
62
63 for (int t = 0; t < c; t++) {
64 scanner.unread();
65 }
66
67 return Token.UNDEFINED;
68 }
69} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/CustomLocalFile.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/CustomLocalFile.java
new file mode 100644
index 0000000..b62a1da
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/CustomLocalFile.java
@@ -0,0 +1,13 @@
1package org.yocto.bc.ui.filesystem;
2
3import java.io.File;
4
5import org.eclipse.core.internal.filesystem.local.LocalFile;
6import org.yocto.remote.utils.RemoteHelper;
7
8public class CustomLocalFile extends LocalFile{
9
10 public CustomLocalFile(String projName, File file) {
11 super(new File(RemoteHelper.retrieveProjRootFromMetaArea(projName)));
12 }
13}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Messages.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Messages.java
new file mode 100644
index 0000000..0a82fdd
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Messages.java
@@ -0,0 +1,48 @@
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.filesystem;
12
13import org.eclipse.osgi.util.NLS;
14
15/**
16 * Provides translatable messages for the file system bundle
17 */
18public class Messages extends NLS {
19 private static final String BUNDLE_NAME = "org.eclipse.core.internal.filesystem.messages"; //$NON-NLS-1$
20
21 public static String copying;
22 public static String couldnotDelete;
23 public static String couldnotDeleteReadOnly;
24 public static String couldNotLoadLibrary;
25 public static String couldNotMove;
26 public static String couldNotRead;
27 public static String couldNotWrite;
28 public static String deleteProblem;
29 public static String deleting;
30 public static String failedCreateWrongType;
31 public static String failedMove;
32 public static String failedReadDuringWrite;
33 public static String fileExists;
34 public static String fileNotFound;
35 public static String moving;
36 public static String noFileSystem;
37 public static String noImplDelete;
38 public static String noImplWrite;
39 public static String noScheme;
40 public static String notAFile;
41 public static String readOnlyParent;
42
43 static {
44 // initialize resource bundles
45 NLS.initializeMessages(BUNDLE_NAME, Messages.class);
46 }
47
48}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFile.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFile.java
new file mode 100644
index 0000000..afcd372
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFile.java
@@ -0,0 +1,375 @@
1/*******************************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation, 2013 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 * IBM Corporation - initial API and implementation
10 * Ken Gilmer - adaptation from internal class.
11 * Ioana Grigoropol (Intel) - adapt class for remote support
12 *******************************************************************************/
13package org.yocto.bc.ui.filesystem;
14
15import java.io.File;
16import java.io.FileInputStream;
17import java.io.FileNotFoundException;
18import java.io.FileOutputStream;
19import java.io.IOException;
20import java.io.InputStream;
21import java.io.OutputStream;
22import java.net.URI;
23import java.util.List;
24
25import org.eclipse.core.filesystem.EFS;
26import org.eclipse.core.filesystem.IFileInfo;
27import org.eclipse.core.filesystem.IFileStore;
28import org.eclipse.core.filesystem.IFileSystem;
29import org.eclipse.core.filesystem.URIUtil;
30import org.eclipse.core.filesystem.provider.FileInfo;
31import org.eclipse.core.filesystem.provider.FileStore;
32import org.eclipse.core.runtime.CoreException;
33import org.eclipse.core.runtime.IPath;
34import org.eclipse.core.runtime.IProgressMonitor;
35import org.eclipse.core.runtime.IStatus;
36import org.eclipse.core.runtime.MultiStatus;
37import org.eclipse.core.runtime.NullProgressMonitor;
38import org.eclipse.core.runtime.Status;
39import org.eclipse.osgi.util.NLS;
40import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
41import org.eclipse.rse.services.files.IFileService;
42import org.eclipse.rse.services.files.IHostFile;
43import org.yocto.bc.bitbake.BBSession;
44import org.yocto.bc.bitbake.ProjectInfoHelper;
45import org.yocto.bc.bitbake.ShellSession;
46import org.yocto.bc.ui.Activator;
47import org.yocto.bc.ui.model.ProjectInfo;
48import org.yocto.bc.ui.model.YoctoHostFile;
49
50/**
51 * File system implementation based on storage of files in the local
52 * operating system's file system.
53 */
54public class OEFile extends FileStore {
55 private static int attributes(File aFile) {
56 if (!aFile.exists() || aFile.canWrite())
57 return EFS.NONE;
58 return EFS.ATTRIBUTE_READ_ONLY;
59 }
60
61
62 protected final YoctoHostFile file;
63
64 private List<Object> ignoredPaths;
65
66 /**
67 * The absolute file system path of the file represented by this store.
68 */
69 protected final String filePath;
70
71 private final URI root;
72
73 /**
74 * Creates a new local file.
75 *
76 * @param file The file this local file represents
77 * @param root
78 */
79 public OEFile(URI fileURI, List<Object> ignoredPaths, URI root, ProjectInfo projInfo, IProgressMonitor monitor) throws SystemMessageException {
80 this.ignoredPaths = ignoredPaths;
81 this.root = root;
82 this.file = new YoctoHostFile(projInfo, fileURI, monitor);
83 this.filePath = file.getAbsolutePath();
84 }
85
86 @Override
87 public String[] childNames(int options, IProgressMonitor monitor) {
88 return file.getChildNames(monitor);
89 }
90
91 /*
92 * detect if the path is potential builddir
93 */
94 private boolean isPotentialBuildDir(String path) {
95 String parentPath = path.substring(0, path.lastIndexOf("/"));
96 String name = path.substring(path.lastIndexOf("/") + 1);
97 boolean ret = true;
98 try {
99 IFileService fs = file.getFileService();
100 IHostFile hostFile = fs.getFile(parentPath, name, new NullProgressMonitor());
101 if (!hostFile.isDirectory())
102 return false;
103 IHostFile confDir = fs.getFile(path, BBSession.CONF_DIR, new NullProgressMonitor());
104 if (!confDir.exists() || !confDir.isDirectory())
105 return false;
106 for (int i = 0; i < BBSession.BUILDDIR_INDICATORS.length && ret == true; i++) {
107 IHostFile child = fs.getFile(path + "/" + BBSession.CONF_DIR, BBSession.BUILDDIR_INDICATORS[i], new NullProgressMonitor());
108 if(!child.exists() || !child.isFile()) {
109 ret = false;
110 break;
111 }
112 }
113
114 } catch (SystemMessageException e) {
115 e.printStackTrace();
116 }
117 return ret;
118 }
119
120 /*
121 * try to find items for ignoreList
122 */
123 private void updateIgnorePaths(String path, List<Object> list, IProgressMonitor monitor) {
124 if(isPotentialBuildDir(path)) {
125 BBSession config = null;
126 try {
127 config = Activator.getBBSession(Activator.getProjInfo(root), monitor);
128 config.initialize();
129 } catch(Exception e) {
130 e.printStackTrace();
131 return;
132 }
133 if (config.get("TMPDIR") == null || config.get("DL_DIR") == null || config.get("SSTATE_DIR") == null) {
134 //wrong guess about the buildDir
135 return;
136 }else {
137 if(!list.contains(config.get("TMPDIR"))) {
138 list.add(config.get("TMPDIR"));
139 }
140 if(!list.contains(config.get("DL_DIR"))) {
141 list.add(config.get("DL_DIR"));
142 }
143 if(!list.contains(config.get("SSTATE_DIR"))) {
144 list.add(config.get("SSTATE_DIR"));
145 }
146 }
147 }
148 }
149
150 @Override
151 public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException {
152 String[] children = childNames(options, monitor);
153 IFileStore[] wrapped = new IFileStore[children.length];
154
155 for (int i = 0; i < wrapped.length; i++) {
156 String fullPath = file.getAbsolutePath() + "/" + children[i];
157 updateIgnorePaths(fullPath, ignoredPaths, monitor);
158 if (ignoredPaths.contains(fullPath)) {
159 wrapped[i] = getDeadChild(children[i]);
160 } else {
161 wrapped[i] = getChild(children[i]);
162 }
163 }
164
165 return wrapped;
166 }
167
168 @Override
169 public void copy(IFileStore destFileStore, int options, IProgressMonitor monitor) throws CoreException {
170 if (destFileStore instanceof OEFile) {
171 file.copy(destFileStore, monitor);
172 }
173 }
174
175 @Override
176 public void delete(int options, IProgressMonitor monitor) throws CoreException {
177 if (monitor == null)
178 monitor = new NullProgressMonitor();
179 else
180 monitor = new NullProgressMonitor();
181 try {
182 monitor.beginTask(NLS.bind(Messages.deleting, this), 200);
183 String message = Messages.deleteProblem;
184 MultiStatus result = new MultiStatus(Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, null);
185
186 //don't allow Eclipse to delete entire OE directory
187
188 if (!isProject()) {
189 internalDelete(file, filePath, result, monitor);
190 }
191
192 if (!result.isOK())
193 throw new CoreException(result);
194 } finally {
195 monitor.done();
196 }
197 }
198
199 @Override
200 public boolean equals(Object obj) {
201 if (!(obj instanceof OEFile))
202 return false;
203
204 OEFile otherFile = (OEFile) obj;
205
206 return file.equals(otherFile.file);
207 }
208
209 @Override
210 public IFileInfo fetchInfo(int options, IProgressMonitor monitor) {
211 //in-lined non-native implementation
212 FileInfo info = new FileInfo(file.getName());
213 final long lastModified = file.getModifiedDate();
214 if (lastModified <= 0) {
215 //if the file doesn't exist, all other attributes should be default values
216 info.setExists(false);
217 return info;
218 }
219 info.setLastModified(lastModified);
220 info.setExists(true);
221 info.setLength(file.getSize());
222 info.setDirectory(file.isDirectory());
223 info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, file.exists() && !file.canWrite());
224 info.setAttribute(EFS.ATTRIBUTE_HIDDEN, file.isHidden());
225 return info;
226 }
227
228 @Override
229 public IFileStore getChild(IPath path) {
230 try {
231 return new OEFile(file.getChildURIformPath(path), ignoredPaths, root, file.getProjectInfo(), new NullProgressMonitor());
232 } catch (SystemMessageException e) {
233 e.printStackTrace();
234 return null;
235 }
236 }
237
238 @Override
239 public IFileStore getChild(String name) {
240
241 try {
242 return new OEFile(file.getChildURI(name), ignoredPaths, root, file.getProjectInfo(), new NullProgressMonitor());
243 } catch (SystemMessageException e) {
244 e.printStackTrace();
245 }
246 return null;
247
248 }
249
250 private IFileStore getDeadChild(String name) {
251 return new OEIgnoreFile(file.getChildHostFile(name));
252 }
253
254 /*
255 * (non-Javadoc)
256 * @see org.eclipse.core.filesystem.IFileStore#getFileSystem()
257 */
258 @Override
259 public IFileSystem getFileSystem() {
260 return OEFileSystem.getInstance();
261 }
262
263 @Override
264 public String getName() {
265 return file.getName();
266 }
267
268 @Override
269 public IFileStore getParent() {
270 URI parentURI = file.getParentFile();
271 try {
272 return parentURI == null ? null : new OEFile(parentURI, ignoredPaths, root, file.getProjectInfo(), new NullProgressMonitor());
273 } catch (SystemMessageException e) {
274 e.printStackTrace();
275 return null;
276 }
277 }
278
279 @Override
280 public int hashCode() {
281 return file.hashCode();
282 }
283
284 /**
285 * Deletes the given file recursively, adding failure info to
286 * the provided status object. The filePath is passed as a parameter
287 * to optimize java.io.File object creation.
288 */
289 private boolean internalDelete(YoctoHostFile target, String pathToDelete, MultiStatus status, IProgressMonitor monitor) {
290 target.delete(monitor);
291 return false;
292 }
293
294 @Override
295 public boolean isParentOf(IFileStore other) {
296 if (!(other instanceof OEFile))
297 return false;
298 String thisPath = filePath;
299 String thatPath = ((OEFile) other).filePath;
300 int thisLength = thisPath.length();
301 int thatLength = thatPath.length();
302 //if equal then not a parent
303 if (thisLength >= thatLength)
304 return false;
305 if (getFileSystem().isCaseSensitive()) {
306 if (thatPath.indexOf(thisPath) != 0)
307 return false;
308 } else {
309 if (thatPath.toLowerCase().indexOf(thisPath.toLowerCase()) != 0)
310 return false;
311 }
312 //The common portion must end with a separator character for this to be a parent of that
313 return thisPath.charAt(thisLength - 1) == File.separatorChar || thatPath.charAt(thisLength) == File.separatorChar;
314 }
315
316 /**
317 * @return
318 */
319 private boolean isProject() {
320 return this.file.toString().equals(root);
321 }
322
323 @Override
324 public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
325 file.mkdir(options);
326 return this;
327 }
328
329 @Override
330 public void move(IFileStore destFile, int options, IProgressMonitor monitor) throws CoreException {
331 file.move(destFile, monitor);
332 }
333
334 @Override
335 public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException {
336 return file.getInputStream(options, monitor);
337 }
338
339 @Override
340 public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
341 return file.getOutputStream(options, monitor);
342 }
343
344 @Override
345 public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException {
346 file.putInfo(info, options, monitor);
347 }
348
349 /* (non-Javadoc)
350 * @see org.eclipse.core.filesystem.provider.FileStore#toLocalFile(int, org.eclipse.core.runtime.IProgressMonitor)
351 */
352 @Override
353 public File toLocalFile(int options, IProgressMonitor monitor) throws CoreException {
354 return file.toLocalFile();
355 }
356
357 /* (non-Javadoc)
358 * @see org.eclipse.core.filesystem.IFileStore#toString()
359 */
360 @Override
361 public String toString() {
362 return file.toString();
363 }
364
365 /* (non-Javadoc)
366 * @see org.eclipse.core.filesystem.IFileStore#toURI()
367 */
368 @Override
369 public URI toURI() {
370 return URIUtil.toURI(filePath);
371 }
372 public String getParentPath() {
373 return filePath.substring(0, filePath.lastIndexOf("/"));
374 }
375}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystem.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystem.java
new file mode 100644
index 0000000..a9712d3
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystem.java
@@ -0,0 +1,103 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.filesystem;
13
14import java.io.File;
15import java.lang.reflect.InvocationTargetException;
16import java.net.URI;
17import java.util.ArrayList;
18import java.util.Hashtable;
19import java.util.List;
20import java.util.Map;
21
22import org.eclipse.core.filesystem.IFileStore;
23import org.eclipse.core.filesystem.IFileSystem;
24import org.eclipse.core.filesystem.provider.FileSystem;
25import org.eclipse.core.runtime.CoreException;
26import org.eclipse.core.runtime.NullProgressMonitor;
27import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
28import org.yocto.bc.bitbake.BBSession;
29import org.yocto.bc.ui.Activator;
30import org.yocto.bc.ui.model.ProjectInfo;
31
32/**
33 * A filesystem that ignores specific OE directories that contain derived information.
34 * @author kgilmer
35 *
36 */
37public class OEFileSystem extends FileSystem {
38
39 private static IFileSystem ref;
40 private ProjectInfo projInfo;
41
42 public static IFileSystem getInstance() {
43 return ref;
44 }
45
46 private Map fileStoreCache;
47
48 public OEFileSystem() {
49 ref = this;
50 fileStoreCache = new Hashtable();
51 }
52
53 @Override
54 public IFileStore getStore(URI uri) {
55
56 OEFile uf = (OEFile) fileStoreCache.get(uri);
57 setProjInfo(uri);
58
59 if (uf == null) {
60 BBSession config = null;
61 try {
62 config = Activator.getBBSession(projInfo, new NullProgressMonitor());
63 config.initialize();
64 } catch (Exception e) {
65 return new CustomLocalFile(projInfo.getProjectName(), new File(uri.getPath()));
66 }
67
68 if (config.get("TMPDIR") == null || config.get("DL_DIR") == null || config.get("SSTATE_DIR")== null) {
69 throw new RuntimeException("Invalid local.conf: TMPDIR or DL_DIR or SSTATE_DIR undefined.");
70 }
71
72 List ignoreList = new ArrayList();
73
74 //These directories are ignored because they contain too many files for Eclipse to handle efficiently.
75 ignoreList.add(config.get("TMPDIR"));
76 ignoreList.add(config.get("DL_DIR"));
77 ignoreList.add(config.get("SSTATE_DIR"));
78
79 //FIXME: add project info
80 try {
81 uf = new OEFile(uri, ignoreList, uri, projInfo, new NullProgressMonitor());
82 fileStoreCache.put(uri, uf);
83 } catch (SystemMessageException e) {
84 e.printStackTrace();
85 }
86 }
87
88 return uf;
89 }
90
91 private void setProjInfo(URI uri) {
92 try {
93 if(projInfo == null)
94 projInfo = Activator.getProjInfo(uri);
95 } catch (CoreException e) {
96 e.printStackTrace();
97 } catch (InvocationTargetException e) {
98 e.printStackTrace();
99 } catch (InterruptedException e) {
100 e.printStackTrace();
101 }
102 }
103}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystemContributor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystemContributor.java
new file mode 100644
index 0000000..cfff7d6
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEFileSystemContributor.java
@@ -0,0 +1,34 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol(Intel) - initial API and implementation
11 *******************************************************************************/
12package org.yocto.bc.ui.filesystem;
13
14import java.net.URI;
15
16import org.eclipse.swt.widgets.Shell;
17import org.eclipse.ui.ide.fileSystem.FileSystemContributor;
18
19public class OEFileSystemContributor extends FileSystemContributor {
20
21 public OEFileSystemContributor() {
22 }
23
24 @Override
25 public URI browseFileSystem(String initialPath, Shell shell) {
26 return null;
27 }
28
29 @Override
30 public URI getURI(String string) {
31 return super.getURI(string);
32 }
33
34}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEIgnoreFile.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEIgnoreFile.java
new file mode 100644
index 0000000..2434347
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/OEIgnoreFile.java
@@ -0,0 +1,135 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.filesystem;
13
14import java.io.File;
15import java.io.InputStream;
16import java.io.OutputStream;
17import java.net.URI;
18
19import org.eclipse.core.filesystem.IFileInfo;
20import org.eclipse.core.filesystem.IFileStore;
21import org.eclipse.core.filesystem.IFileSystem;
22import org.eclipse.core.filesystem.provider.FileInfo;
23import org.eclipse.core.runtime.CoreException;
24import org.eclipse.core.runtime.IPath;
25import org.eclipse.core.runtime.IProgressMonitor;
26import org.yocto.bc.ui.model.YoctoHostFile;
27
28public class OEIgnoreFile implements IFileStore {
29
30 private final YoctoHostFile file;
31
32 public OEIgnoreFile(YoctoHostFile file) {
33 this.file = file;
34 }
35
36 public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
37
38 return new IFileInfo[0];
39 }
40
41 public String[] childNames(int options, IProgressMonitor monitor) throws CoreException {
42 return new String[0];
43 }
44
45 public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException {
46
47 return new IFileStore[0];
48 }
49
50 public void copy(IFileStore destination, int options, IProgressMonitor monitor) throws CoreException {
51 // TODO Auto-generated method stub
52
53 }
54
55 public void delete(int options, IProgressMonitor monitor) throws CoreException {
56 // TODO Auto-generated method stub
57
58 }
59
60 public IFileInfo fetchInfo() {
61 // TODO Auto-generated method stub
62 return new FileInfo(file.getName());
63 }
64
65 public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
66 return new FileInfo(file.getName());
67 }
68
69 public Object getAdapter(Class adapter) {
70 // TODO Auto-generated method stub
71 return null;
72 }
73
74 public IFileStore getChild(IPath path) {
75 // TODO Auto-generated method stub
76 return null;
77 }
78
79
80
81 public IFileStore getChild(String name) {
82 return null;
83 }
84
85 public IFileSystem getFileSystem() {
86 // TODO Auto-generated method stub
87 return OEFileSystem.getInstance();
88 }
89
90 public String getName() {
91 return file.getName();
92 }
93
94 public IFileStore getParent() {
95 // TODO Auto-generated method stub
96 return null;
97 }
98
99 public boolean isParentOf(IFileStore other) {
100 // TODO Auto-generated method stub
101 return false;
102 }
103
104 public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
105 return null;
106 }
107
108 public void move(IFileStore destination, int options, IProgressMonitor monitor) throws CoreException {
109 }
110
111 public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException {
112 return null;
113 }
114
115 public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
116 return null;
117 }
118
119 public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException {
120 }
121
122 public File toLocalFile(int options, IProgressMonitor monitor) throws CoreException {
123 return file.toLocalFile();
124 }
125
126 public URI toURI() {
127 return file.toURI();
128 }
129
130 public IFileStore getFileStore(IPath path) {
131 return null;
132 }
133
134
135}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java
new file mode 100644
index 0000000..84c0f32
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/Policy.java
@@ -0,0 +1,108 @@
1/*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
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 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.filesystem;
12
13import java.io.IOException;
14import java.io.InputStream;
15import java.io.OutputStream;
16import java.util.Date;
17
18import org.eclipse.core.runtime.CoreException;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.NullProgressMonitor;
21import org.eclipse.core.runtime.OperationCanceledException;
22import org.eclipse.core.runtime.Status;
23import org.eclipse.core.runtime.SubProgressMonitor;
24
25import org.yocto.bc.ui.Activator;
26
27/**
28 * Grab bag of utility methods for the file system plugin
29 */
30public class Policy {
31
32 /**
33 * General debug flag for the plugin
34 */
35 public static boolean DEBUG = false;
36
37 public static final String PI_FILE_SYSTEM = "org.eclipse.core.filesystem"; //$NON-NLS-1$
38
39 public static void checkCanceled(IProgressMonitor monitor) {
40 if (monitor.isCanceled())
41 throw new OperationCanceledException();
42 }
43
44 /**
45 * Print a debug message to the console.
46 * Pre-pend the message with the current date and the name of the current thread.
47 */
48 public static void debug(String message) {
49 StringBuffer buffer = new StringBuffer();
50 buffer.append(new Date(System.currentTimeMillis()));
51 buffer.append(" - ["); //$NON-NLS-1$
52 buffer.append(Thread.currentThread().getName());
53 buffer.append("] "); //$NON-NLS-1$
54 buffer.append(message);
55 System.out.println(buffer.toString());
56 }
57
58 public static void error(int code, String message) throws CoreException {
59 error(code, message, null);
60 }
61
62 public static void error(int code, String message, Throwable exception) throws CoreException {
63 int severity = code == 0 ? 0 : 1 << (code % 100 / 33);
64 throw new CoreException(new Status(severity, PI_FILE_SYSTEM, code, message, exception));
65 }
66
67 public static void log(int severity, String message, Throwable t) {
68 if (message == null)
69 message = ""; //$NON-NLS-1$
70 Activator.getDefault().getLog().log(new Status(severity, PI_FILE_SYSTEM, 1, message, t));
71 }
72
73 public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
74 return monitor == null ? new NullProgressMonitor() : monitor;
75 }
76
77 /**
78 * Closes a stream and ignores any resulting exception.
79 */
80 public static void safeClose(InputStream in) {
81 try {
82 if (in != null)
83 in.close();
84 } catch (IOException e) {
85 //ignore
86 }
87 }
88
89 /**
90 * Closes a stream and ignores any resulting exception.
91 */
92 public static void safeClose(OutputStream out) {
93 try {
94 if (out != null)
95 out.close();
96 } catch (IOException e) {
97 //ignore
98 }
99 }
100
101 public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) {
102 if (monitor == null)
103 return new NullProgressMonitor();
104 if (monitor instanceof NullProgressMonitor)
105 return monitor;
106 return new SubProgressMonitor(monitor, ticks);
107 }
108}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/YoctoLocation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/YoctoLocation.java
new file mode 100755
index 0000000..40d9345
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/filesystem/YoctoLocation.java
@@ -0,0 +1,44 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol(Intel) - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.filesystem;
12
13import java.net.URI;
14import java.net.URISyntaxException;
15
16public class YoctoLocation{
17 URI oefsURI;
18 URI originalURI;
19
20 public YoctoLocation(){
21 try {
22 oefsURI = new URI("");
23 originalURI = new URI("");
24 } catch (URISyntaxException e) {
25 e.printStackTrace();
26 }
27 }
28
29 public URI getOEFSURI() {
30 return oefsURI;
31 }
32
33 public URI getOriginalURI() {
34 return originalURI;
35 }
36
37 public void setOriginalURI(URI originalURI) {
38 this.originalURI = originalURI;
39 }
40
41 public void setOEFSURI(URI uri) {
42 this.oefsURI = uri;
43 }
44}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/IModelElement.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/IModelElement.java
new file mode 100644
index 0000000..2892df5
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/IModelElement.java
@@ -0,0 +1,15 @@
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.model;
12
13public interface IModelElement {
14 public void initialize() throws Exception;
15}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/ProjectInfo.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/ProjectInfo.java
new file mode 100644
index 0000000..119782d
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/ProjectInfo.java
@@ -0,0 +1,117 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.model;
13
14import java.net.URI;
15import java.net.URISyntaxException;
16
17import org.eclipse.core.runtime.IProgressMonitor;
18import org.eclipse.core.runtime.NullProgressMonitor;
19import org.eclipse.ptp.remote.core.IRemoteServices;
20import org.eclipse.rse.core.model.IHost;
21import org.eclipse.rse.services.files.IFileService;
22import org.yocto.bc.bitbake.ProjectInfoHelper;
23import org.yocto.bc.ui.filesystem.YoctoLocation;
24import org.yocto.remote.utils.RemoteHelper;
25
26public class ProjectInfo implements IModelElement {
27 private String name;
28 private YoctoLocation location;
29 private String init;
30 private IHost connection;
31 private IRemoteServices remoteServices;
32
33 public ProjectInfo() {
34 }
35
36 public String getInitScriptPath() {
37 return init;
38 }
39 public String getProjectName() {
40 return name;
41 }
42 public URI getOriginalURI() {
43 return location.getOriginalURI();
44 }
45
46 public URI getOEFSURI() {
47 return location.getOEFSURI();
48 }
49
50 @Override
51 public void initialize() throws Exception {
52 name = new String();
53 location = new YoctoLocation();
54 init = new String();
55 }
56
57 public void setInitScriptPath(String init) {
58 this.init = init;
59 }
60
61 public void setLocationURI(URI location) {
62 if (this.location == null)
63 this.location = new YoctoLocation();
64 if (location.getScheme().equalsIgnoreCase("oefs")) {
65 if (this.name == null) {
66 String path = location.getPath();
67 this.name = path.substring(path.lastIndexOf("/") + 1);
68 }
69 location = RemoteHelper.retrieveURIFromMetaArea(this.name);
70 }
71 this.location.setOriginalURI(location);
72 try {
73 this.location.setOEFSURI(new URI(ProjectInfoHelper.OEFS_SCHEME + location.getPath() ));
74 } catch (URISyntaxException e) {
75 try {
76 this.location.setOEFSURI(new URI(""));
77 } catch (URISyntaxException e1) {
78 e1.printStackTrace();
79 }
80 e.printStackTrace();
81 }
82 }
83
84 public void setName(String name) {
85 this.name = name;
86 }
87
88 public IHost getConnection() {
89 if (connection == null && RemoteHelper.isInitialized(getOriginalURI())) {
90 connection = RemoteHelper.getRemoteConnectionForURI(location.getOriginalURI(), new NullProgressMonitor());
91 }
92 return connection;
93 }
94
95 public void setConnection(IHost connection) {
96 this.connection = connection;
97 }
98
99 public IRemoteServices getRemoteServices() {
100 return remoteServices;
101 }
102
103 public void setRemoteServices(IRemoteServices remoteServices) {
104 this.remoteServices = remoteServices;
105 }
106
107 public IFileService getFileService(IProgressMonitor monitor){
108 try {
109 if (!RemoteHelper.isInitialized(getOriginalURI()))
110 return null;
111 return RemoteHelper.getConnectedRemoteFileService(connection, monitor);
112 } catch (Exception e) {
113 e.printStackTrace();
114 return null;
115 }
116 }
117}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/YoctoHostFile.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/YoctoHostFile.java
new file mode 100644
index 0000000..7113efb
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/YoctoHostFile.java
@@ -0,0 +1,326 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol(Intel) - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.model;
12
13import java.io.File;
14import java.io.InputStream;
15import java.io.OutputStream;
16import java.net.URI;
17import java.net.URISyntaxException;
18import java.util.ArrayList;
19
20import org.eclipse.core.filesystem.EFS;
21import org.eclipse.core.filesystem.IFileInfo;
22import org.eclipse.core.filesystem.IFileStore;
23import org.eclipse.core.runtime.CoreException;
24import org.eclipse.core.runtime.IPath;
25import org.eclipse.core.runtime.IProgressMonitor;
26import org.eclipse.core.runtime.NullProgressMonitor;
27import org.eclipse.osgi.util.NLS;
28import org.eclipse.rse.core.model.IHost;
29import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
30import org.eclipse.rse.services.files.IFileService;
31import org.eclipse.rse.services.files.IHostFile;
32import org.yocto.bc.ui.filesystem.Messages;
33import org.yocto.bc.ui.filesystem.OEFile;
34import org.yocto.bc.ui.filesystem.Policy;
35import org.yocto.remote.utils.RemoteHelper;
36
37public class YoctoHostFile implements IHostFile{
38 private IHostFile file;
39 private final URI fileURI;
40 private ProjectInfo projectInfo;
41 private IFileService fileService;
42
43 public YoctoHostFile(ProjectInfo pInfo, URI fileURI, IProgressMonitor monitor) throws SystemMessageException {
44 this.projectInfo = pInfo;
45 this.fileURI = fileURI;
46 String path = fileURI.getPath();
47 fileService = projectInfo.getFileService(monitor);
48 file = RemoteHelper.getRemoteHostFile(projectInfo.getConnection(), path, monitor);
49 }
50
51 public YoctoHostFile(ProjectInfo projectInfo, URI uri) {
52 this.fileURI = uri;
53 this.projectInfo = projectInfo;
54 }
55
56 public IHostFile getFile() {
57 return file;
58 }
59 public void setFile(IHostFile file) {
60 this.file = file;
61 }
62 public ProjectInfo getProjectInfo() {
63 return projectInfo;
64 }
65 public void setProjectInfo(ProjectInfo projectInfo) {
66 this.projectInfo = projectInfo;
67 }
68 @Override
69 public String getAbsolutePath() {
70 return file.getAbsolutePath();
71 }
72 @Override
73 public String getName() {
74 return file.getName();
75 }
76 public URI getProjectLocationURI() {
77 return projectInfo.getOriginalURI();
78 }
79 public URI getLocationURI() {
80 projectInfo.getOriginalURI().getPath().indexOf(file.getAbsolutePath());
81 return projectInfo.getOriginalURI();
82 }
83 @Override
84 public boolean isDirectory() {
85 return file.isDirectory();
86 }
87 @Override
88 public String getParentPath() {
89 return file.getParentPath();
90 }
91 public boolean copy(IFileStore destFileStore, IProgressMonitor monitor) {
92 IHostFile destFile;
93 try {
94 OEFile oeFile = (OEFile)destFileStore;
95 String parentPath = oeFile.getParentPath();
96 destFile = fileService.createFile(parentPath, destFileStore.getName(), monitor);
97 fileService.copy(file.getParentPath(), file.getName(), destFile.getParentPath(), destFile.getName(), monitor);
98 } catch (SystemMessageException e) {
99 e.printStackTrace();
100 return false;
101 }
102 return true;
103 }
104 @Override
105 public boolean exists() {
106 return file.exists();
107 }
108 @Override
109 public boolean canRead() {
110 return file.canRead();
111 }
112 @Override
113 public boolean canWrite() {
114 return file.canWrite();
115 }
116 @Override
117 public long getModifiedDate() {
118 return file.getModifiedDate();
119 }
120 @Override
121 public long getSize() {
122 return file.getSize();
123 }
124 @Override
125 public boolean isArchive() {
126 return file.isArchive();
127 }
128 @Override
129 public boolean isFile() {
130 return file.isFile();
131 }
132 @Override
133 public boolean isHidden() {
134 return file.isHidden();
135 }
136 @Override
137 public boolean isRoot() {
138 return file.isRoot();
139 }
140 @Override
141 public void renameTo(String newName) {
142 file.renameTo(newName);
143 }
144 public URI getParentFile() {
145 if (file.getParentPath().isEmpty())
146 return null;
147 try {
148 return new URI(fileURI.getScheme(), fileURI.getHost(), file.getParentPath(), fileURI.getFragment());
149 } catch (URISyntaxException e) {
150 e.printStackTrace();
151 return null;
152 }
153 }
154 public boolean delete(IProgressMonitor monitor) {
155 try {
156 fileService.delete(file.getParentPath(), file.getName(), monitor);
157 } catch (SystemMessageException e) {
158 e.printStackTrace();
159 return false;
160 }
161 return true;
162 }
163
164 /**
165 * This method is called after a failure to modify a file or directory.
166 * Check to see if the parent is read-only and if so then
167 * throw an exception with a more specific message and error code.
168 *
169 * @param target The file that we failed to modify
170 * @param exception The low level exception that occurred, or <code>null</code>
171 * @throws CoreException A more specific exception if the parent is read-only
172 */
173 private void checkReadOnlyParent() throws CoreException {
174 String parent = file.getParentPath();
175 String parentOfParent = parent.substring(0, parent.lastIndexOf("/"));
176 IHostFile parentFile;
177 try {
178 parentFile = fileService.getFile(parentOfParent, parent, new NullProgressMonitor());
179 if (parentFile == null || !parentFile.canRead() || !parentFile.canWrite()) {
180 String message = NLS.bind(Messages.readOnlyParent, parent);
181 Policy.error(EFS.ERROR_PARENT_READ_ONLY, message, null);
182 }
183 } catch (SystemMessageException e) {
184 e.printStackTrace();
185 }
186
187 }
188
189 public void mkdir(int options) {
190 try {
191
192 if (!file.isDirectory()) {
193 file = fileService.createFolder(file.getParentPath(), file.getName(), new NullProgressMonitor());
194 if (!file.isDirectory()) {
195 checkReadOnlyParent();
196 String message = NLS.bind(Messages.failedCreateWrongType, file.getAbsolutePath());
197 Policy.error(EFS.ERROR_WRONG_TYPE, message);
198 }
199 }
200 } catch (SystemMessageException e1) {
201 e1.printStackTrace();
202 } catch (CoreException e) {
203 e.printStackTrace();
204 }
205
206 }
207
208 public String[] getChildNames(IProgressMonitor monitor) {
209 if (file.isDirectory()) {
210 IHostFile[] files;
211 try {
212 files = fileService.list(file.getAbsolutePath(), "*", IFileService.FILE_TYPE_FILES_AND_FOLDERS, monitor);
213 ArrayList<String> names = new ArrayList<String>();
214
215 for (IHostFile f : files) {
216 names.add(f.getName());
217 }
218
219 String[] arrNames = new String[names.size()];
220 names.toArray(arrNames);
221 return arrNames;
222 } catch (SystemMessageException e) {
223 e.printStackTrace();
224 }
225 }
226 return new String[]{};
227 }
228 public IHost getConnection() {
229 return projectInfo.getConnection();
230 }
231
232 public URI getChildURI(String name) {
233 try {
234 return new URI(fileURI.getScheme(), fileURI.getHost(), fileService.getFile(file.getAbsolutePath(), name, null).getAbsolutePath(), fileURI.getFragment());
235 } catch (URISyntaxException e) {
236 e.printStackTrace();
237 } catch (SystemMessageException e) {
238 e.printStackTrace();
239 }
240 return null;
241 }
242 public File toLocalFile() {
243 //TODO
244 //fileService.getFile(file.getParentPath(), file.getName(), null);
245 return null;
246 }
247 public URI toURI() {
248 return fileURI;
249 }
250 public YoctoHostFile getChildHostFile(String name) {
251 try {
252 return new YoctoHostFile(projectInfo, getChildURI(name), new NullProgressMonitor());
253 } catch (SystemMessageException e) {
254 e.printStackTrace();
255 return null;
256 }
257 }
258
259 public URI getChildURIformPath(IPath path) {
260 try {
261 String fileName = path.lastSegment();
262 path = path.removeLastSegments(1);
263 String newPath = fileService.getFile(file.getAbsolutePath() + "/" + path.toPortableString(), fileName, null).getAbsolutePath();
264 return new URI(fileURI.getScheme(), fileURI.getHost(), newPath, fileURI.getFragment());
265 } catch (URISyntaxException e) {
266 e.printStackTrace();
267 return null;
268 } catch (SystemMessageException e) {
269 e.printStackTrace();
270 return null;
271 }
272 }
273
274 public void move(IFileStore destFile, IProgressMonitor monitor) {
275 try {
276 fileService.move(file.getParentPath(), file.getName(), destFile.getParent().toURI().getPath(), destFile.getName(), monitor);
277 } catch (SystemMessageException e) {
278 e.printStackTrace();
279 }
280 }
281
282 public OutputStream getOutputStream(int options, IProgressMonitor monitor) {
283 try {
284 return fileService.getOutputStream(file.getParentPath(), file.getName(), options, monitor);
285 } catch (SystemMessageException e) {
286 e.printStackTrace();
287 return null;
288 }
289 }
290
291 public InputStream getInputStream(int options, IProgressMonitor monitor) {
292 try {
293 return fileService.getInputStream(file.getParentPath(), file.getName(), false, monitor);
294 } catch (SystemMessageException e) {
295 e.printStackTrace();
296 return null;
297 }
298 }
299
300 public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) {
301 try {
302 if ((options & EFS.SET_LAST_MODIFIED) != 0)
303 fileService.setLastModified(file.getParentPath(), file.getName(), info.getLastModified(), monitor);
304 } catch (SystemMessageException e) {
305 e.printStackTrace();
306 }
307 }
308
309 public IFileService getFileService() {
310 return fileService;
311 }
312
313 public void setFileService(IFileService fileService) {
314 this.fileService = fileService;
315 }
316
317 @Override
318 public String toString() {
319 URI uri = this.projectInfo.getOriginalURI();
320 try {
321 return new URI(uri.getScheme(), uri.getHost(), fileURI.getPath(), uri.getFragment()).toString();
322 } catch (URISyntaxException e) {
323 return fileURI.toString();
324 }
325 }
326}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/perspectives/BitbakeCommanderPerspective.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/perspectives/BitbakeCommanderPerspective.java
new file mode 100644
index 0000000..b9ddcb6
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/perspectives/BitbakeCommanderPerspective.java
@@ -0,0 +1,89 @@
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.perspectives;
12
13import org.eclipse.ui.IFolderLayout;
14import org.eclipse.ui.IPageLayout;
15import org.eclipse.ui.IPerspectiveFactory;
16import org.eclipse.ui.console.IConsoleConstants;
17
18import org.yocto.bc.ui.views.RecipeView;
19
20public class BitbakeCommanderPerspective implements IPerspectiveFactory {
21
22 private IPageLayout factory;
23
24 public BitbakeCommanderPerspective() {
25 super();
26 }
27
28 private void addActionSets() {
29 factory.addActionSet("org.yocto.bc.ui.actionSet");
30 factory.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET); // NON-NLS-1
31 }
32
33 private void addNewWizardShortcuts() {
34 factory.addNewWizardShortcut("org.yocto.bc.ui.wizards.NewRecipeWizard");// NON-NLS-1
35 //factory.addNewWizardShortcut("org.yocto.bc.ui.wizards.newproject.NewBBCProjectWizard");// NON-NLS-1
36 factory.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");// NON-NLS-1
37 }
38
39 private void addPerspectiveShortcuts() {
40 // factory.addPerspectiveShortcut("org.eclipse.team.ui.TeamSynchronizingPerspective");
41 // //NON-NLS-1
42 // factory.addPerspectiveShortcut("org.eclipse.team.cvs.ui.cvsPerspective");
43 // //NON-NLS-1
44 factory.addPerspectiveShortcut("org.eclipse.ui.resourcePerspective"); // NON-NLS-1
45 }
46
47 private void addViews() {
48 IFolderLayout bottom = factory.createFolder("bottomRight", // NON-NLS-1
49 IPageLayout.BOTTOM, 0.75f, factory.getEditorArea());
50
51 bottom.addView(IPageLayout.ID_PROBLEM_VIEW);
52 bottom.addView("org.eclipse.team.ui.GenericHistoryView"); // NON-NLS-1
53 bottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);
54
55 IFolderLayout topLeft = factory.createFolder("topLeft", // NON-NLS-1
56 IPageLayout.LEFT, 0.25f, factory.getEditorArea());
57 topLeft.addView(IPageLayout.ID_RES_NAV);
58 //llu detach RecipeView
59 //topLeft.addView(RecipeView.ID_VIEW); // NON-NLS-1
60
61 }
62
63 private void addViewShortcuts() {
64 // factory.addShowViewShortcut("org.eclipse.ant.ui.views.AntView");
65 // //NON-NLS-1
66 // factory.addShowViewShortcut("org.eclipse.team.ccvs.ui.AnnotateView");
67 // //NON-NLS-1
68 // factory.addShowViewShortcut("org.eclipse.pde.ui.DependenciesView");
69 // //NON-NLS-1
70 // factory.addShowViewShortcut("org.eclipse.jdt.junit.ResultView");
71 // //NON-NLS-1
72 factory.addShowViewShortcut("org.eclipse.team.ui.GenericHistoryView"); // NON-NLS-1
73 factory.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW);
74 // factory.addShowViewShortcut(JavaUI.ID_PACKAGES);
75 factory.addShowViewShortcut(IPageLayout.ID_RES_NAV);
76 // factory.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
77 // factory.addShowViewShortcut(IPageLayout.ID_OUTLINE);
78 }
79
80 public void createInitialLayout(IPageLayout factory) {
81 this.factory = factory;
82 addViews();
83 addActionSets();
84 addNewWizardShortcuts();
85 addPerspectiveShortcuts();
86 addViewShortcuts();
87 }
88
89}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/popup/actions/NewAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/popup/actions/NewAction.java
new file mode 100644
index 0000000..3bdf5d3
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/popup/actions/NewAction.java
@@ -0,0 +1,43 @@
1package org.yocto.bc.ui.popup.actions;
2
3import org.eclipse.jface.action.IAction;
4import org.eclipse.jface.dialogs.MessageDialog;
5import org.eclipse.jface.viewers.ISelection;
6import org.eclipse.swt.widgets.Shell;
7import org.eclipse.ui.IActionDelegate;
8import org.eclipse.ui.IObjectActionDelegate;
9import org.eclipse.ui.IWorkbenchPart;
10
11public class NewAction implements IObjectActionDelegate {
12
13 /**
14 * Constructor for Action1.
15 */
16 public NewAction() {
17 super();
18 }
19
20 /**
21 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
22 */
23 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
24 }
25
26 /**
27 * @see IActionDelegate#run(IAction)
28 */
29 public void run(IAction action) {
30 Shell shell = new Shell();
31 MessageDialog.openInformation(
32 shell,
33 "Yocto Project BitBake Commander UI Plug-in",
34 "New Action was executed.");
35 }
36
37 /**
38 * @see IActionDelegate#selectionChanged(IAction, ISelection)
39 */
40 public void selectionChanged(IAction action, ISelection selection) {
41 }
42
43}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeContentProvider.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeContentProvider.java
new file mode 100644
index 0000000..2346031
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeContentProvider.java
@@ -0,0 +1,61 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.views;
13
14import java.util.ArrayList;
15import java.util.Collection;
16import java.util.List;
17
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IProjectNature;
20import org.eclipse.core.resources.ResourcesPlugin;
21import org.eclipse.core.runtime.CoreException;
22import org.eclipse.jface.viewers.IStructuredContentProvider;
23import org.eclipse.jface.viewers.Viewer;
24
25import org.yocto.bc.bitbake.BBSession;
26import org.yocto.bc.ui.Activator;
27import org.yocto.bc.ui.builder.BitbakeCommanderNature;
28
29class RecipeContentProvider implements IStructuredContentProvider {
30 public void dispose() {
31 }
32
33 public Object[] getElements(Object parent) {
34 List recipes = new ArrayList();
35 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
36 IProjectNature nature = null;
37 for (int i = 0; i < projects.length; ++i) {
38 try {
39 if (projects[i].isOpen() && projects[i].hasNature(BitbakeCommanderNature.NATURE_ID)) {
40 recipes.addAll(getRecipesFromProject(projects[i]));
41 }
42 } catch (CoreException e) {
43 // TODO Auto-generated catch block
44 e.printStackTrace();
45 } catch (Exception e) {
46 // TODO Auto-generated catch block
47 e.printStackTrace();
48 }
49 }
50
51 return recipes.toArray();
52 }
53
54 private Collection getRecipesFromProject(IProject project) throws Exception {
55 BBSession session = Activator.getBBSession(Activator.getProjInfo(project.getLocationURI()), null);
56 return session.getRecipeFiles(project);
57 }
58
59 public void inputChanged(Viewer v, Object oldInput, Object newInput) {
60 }
61}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java
new file mode 100644
index 0000000..fdbd8e0
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java
@@ -0,0 +1,165 @@
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.views;
12
13import org.eclipse.core.resources.IFile;
14import org.eclipse.jface.action.Action;
15import org.eclipse.jface.action.IMenuListener;
16import org.eclipse.jface.action.IMenuManager;
17import org.eclipse.jface.action.IToolBarManager;
18import org.eclipse.jface.action.MenuManager;
19import org.eclipse.jface.action.Separator;
20import org.eclipse.jface.viewers.DoubleClickEvent;
21import org.eclipse.jface.viewers.IDoubleClickListener;
22import org.eclipse.jface.viewers.ISelection;
23import org.eclipse.jface.viewers.IStructuredSelection;
24import org.eclipse.jface.viewers.ITableLabelProvider;
25import org.eclipse.jface.viewers.LabelProvider;
26import org.eclipse.jface.viewers.TableViewer;
27import org.eclipse.jface.viewers.ViewerSorter;
28import org.eclipse.swt.SWT;
29import org.eclipse.swt.graphics.Image;
30import org.eclipse.swt.widgets.Composite;
31import org.eclipse.swt.widgets.Menu;
32import org.eclipse.ui.IActionBars;
33import org.eclipse.ui.ISharedImages;
34import org.eclipse.ui.IWorkbenchActionConstants;
35import org.eclipse.ui.PartInitException;
36import org.eclipse.ui.PlatformUI;
37import org.eclipse.ui.part.FileEditorInput;
38import org.eclipse.ui.part.ViewPart;
39
40import org.yocto.bc.ui.editors.bitbake.BitBakeFileEditor;
41
42public class RecipeView extends ViewPart {
43 class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
44 public Image getColumnImage(Object obj, int index) {
45 return getImage(obj);
46 }
47
48 public String getColumnText(Object obj, int index) {
49
50 if (obj instanceof IFile) {
51 return ((IFile) obj).getName();
52 }
53
54 return getText(obj);
55 }
56
57 @Override
58 public Image getImage(Object obj) {
59 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
60 }
61 }
62 public static final String ID_VIEW = "org.yocto.bc.ui.views.RecipeView";
63private TableViewer viewer;
64
65 /* private Action action1;
66 private Action action2;
67 */ private Action doubleClickAction;
68
69 private void contributeToActionBars() {
70 IActionBars bars = getViewSite().getActionBars();
71 fillLocalPullDown(bars.getMenuManager());
72 fillLocalToolBar(bars.getToolBarManager());
73 }
74
75 @Override
76 public void createPartControl(Composite parent) {
77 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
78 viewer.setContentProvider(new RecipeContentProvider());
79 viewer.setLabelProvider(new ViewLabelProvider());
80 viewer.setSorter(new ViewerSorter());
81 viewer.setInput(getViewSite());
82 makeActions();
83 hookContextMenu();
84 hookDoubleClickAction();
85 contributeToActionBars();
86 }
87
88 private void fillContextMenu(IMenuManager manager) {
89/* manager.add(action1);
90 manager.add(action2);
91*/ // Other plug-ins can contribute there actions here
92 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
93 }
94
95 private void fillLocalPullDown(IMenuManager manager) {
96/* manager.add(action1);
97 manager.add(new Separator());
98 manager.add(action2);
99*/ }
100
101 private void fillLocalToolBar(IToolBarManager manager) {
102/* manager.add(action1);
103 manager.add(action2);
104*/ }
105
106 private void hookContextMenu() {
107 MenuManager menuMgr = new MenuManager("#PopupMenu");
108 menuMgr.setRemoveAllWhenShown(true);
109 menuMgr.addMenuListener(new IMenuListener() {
110 public void menuAboutToShow(IMenuManager manager) {
111 RecipeView.this.fillContextMenu(manager);
112 }
113 });
114 Menu menu = menuMgr.createContextMenu(viewer.getControl());
115 viewer.getControl().setMenu(menu);
116 getSite().registerContextMenu(menuMgr, viewer);
117 }
118
119 private void hookDoubleClickAction() {
120 viewer.addDoubleClickListener(new IDoubleClickListener() {
121 public void doubleClick(DoubleClickEvent event) {
122 doubleClickAction.run();
123 }
124 });
125 }
126
127 private void makeActions() {
128/* action1 = new Action() {
129 public void run() {
130 }
131 };
132 action1.setText("Action 1");
133 action1.setToolTipText("Action 1 tooltip");
134 action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
135
136 action2 = new Action() {
137 public void run() {
138 }
139 };
140 action2.setText("Action 2");
141 action2.setToolTipText("Action 2 tooltip");
142 action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
143*/ doubleClickAction = new Action() {
144 @Override
145 public void run() {
146 ISelection selection = viewer.getSelection();
147 Object obj = ((IStructuredSelection) selection).getFirstElement();
148
149 if (obj instanceof IFile) {
150 try {
151 RecipeView.this.getViewSite().getPage().openEditor(new FileEditorInput((IFile) obj), BitBakeFileEditor.EDITOR_ID);
152 } catch (PartInitException e) {
153 // TODO Auto-generated catch block
154 e.printStackTrace();
155 }
156 }
157 }
158 };
159 }
160
161 @Override
162 public void setFocus() {
163 viewer.getControl().setFocus();
164 }
165} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java
new file mode 100644
index 0000000..c8eea71
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java
@@ -0,0 +1,153 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards;
13
14import org.eclipse.jface.viewers.ISelection;
15import org.eclipse.swt.widgets.Text;
16
17import java.net.URI;
18import java.net.URISyntaxException;
19import java.util.ArrayList;
20
21public class BitbakeRecipeUIElement {
22
23 private String container;
24 private String file;
25 private String description;
26 private String license;
27 private String checksum;
28 private String homepage;
29 private String author;
30 private String section;
31 private String srcuri;
32 private String md5sum;
33 private String sha256sum;
34 private URI metaDir;
35 private ArrayList inheritance;
36
37 public BitbakeRecipeUIElement()
38 {
39 this.container = "";
40 this.file = "";
41 this.description = "";
42 this.license = "";
43 this.checksum = "";
44 this.homepage = "";
45 this.author = "";
46 this.section = "";
47 this.srcuri = "";
48 this.md5sum = "";
49 this.sha256sum = "";
50 this.inheritance = new ArrayList();
51 try {
52 this.metaDir = new URI("");
53 } catch (URISyntaxException e) {
54 e.printStackTrace();
55 }
56 }
57
58 public String getContainer() {
59 return container;
60 }
61 public void setContainer(String value) {
62 this.container = value;
63 }
64 public String getFile() {
65 return file;
66 }
67 public void setFile(String value) {
68 this.file = value;
69 }
70 public String getDescription() {
71 return description;
72 }
73
74 public void setDescription(String value) {
75 this.description = value;
76 }
77
78 public String getLicense() {
79 return license;
80 }
81
82 public void setLicense(String value) {
83 this.license = value;
84 }
85
86 public String getChecksum() {
87 return checksum;
88 }
89 public void setChecksum(String value) {
90 this.checksum = value;
91 }
92
93 public String getHomePage() {
94 return homepage;
95 }
96
97 public void setHomePage(String value) {
98 this.homepage = value;
99 }
100
101 public String getAuthor() {
102 return author;
103 }
104
105 public void setAuthor(String value) {
106 this.author = value;
107 }
108
109 public String getSection() {
110 return section;
111 }
112 public void setSection(String value) {
113 this.section = value;
114 }
115 public String getSrcuri() {
116 return srcuri;
117 }
118 public void setSrcuri(String value) {
119 this.srcuri = value;
120 }
121
122 public String getMd5sum() {
123 return md5sum;
124 }
125
126 public void setMd5sum(String value) {
127 this.md5sum = value;
128 }
129
130 public String getsha256sum() {
131 return sha256sum;
132 }
133
134 public void setSha256sum(String value) {
135 this.sha256sum = value;
136 }
137
138 public ArrayList<String> getInheritance() {
139 return inheritance;
140 }
141
142 public void setInheritance(ArrayList<String> value) {
143 this.inheritance = value;
144 }
145
146 public URI getMetaDir() {
147 return metaDir;
148 }
149
150 public void setMetaDir(URI value) {
151 metaDir = value;
152 }
153}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java
new file mode 100644
index 0000000..8b47498
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java
@@ -0,0 +1,56 @@
1package org.yocto.bc.ui.wizards;
2import java.util.Map;
3
4import org.eclipse.jface.wizard.Wizard;
5import org.eclipse.swt.widgets.Composite;
6
7
8
9public abstract class FiniteStateWizard extends Wizard {
10 private boolean finishable = false;
11 private boolean canFinish = false;
12
13 public FiniteStateWizard() {
14 }
15
16 public abstract boolean performFinish();
17
18 /**
19 * @return Returns if the wizard is finishable in its current state.
20 */
21 public boolean isFinishable() {
22 return finishable;
23 }
24 /**
25 * @param finishable Change the finish state of the wizard.
26 */
27 public void setFinishable(boolean finishable) {
28 this.finishable = finishable;
29 }
30
31 /* (non-Javadoc)
32 * @see org.eclipse.jface.wizard.IWizard#createPageControls(org.eclipse.swt.widgets.Composite)
33 */
34 public void createPageControls(Composite pageContainer) {
35 super.createPageControls(pageContainer);
36 }
37
38 /*
39 * (non-Javadoc) Method declared on IWizard.
40 */
41 public boolean canFinish() {
42 if (canFinish)
43 return true;
44 return super.canFinish();
45 }
46
47 public void setCanFinish(boolean canFinish) {
48 this.canFinish = canFinish;
49 }
50
51 /**
52 * Retrive the model object from the wizard.
53 * @return
54 */
55 public abstract Map getModel();
56}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java
new file mode 100644
index 0000000..a83a389
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java
@@ -0,0 +1,149 @@
1package org.yocto.bc.ui.wizards;
2import java.util.Map;
3
4import org.eclipse.jface.viewers.ISelectionChangedListener;
5import org.eclipse.jface.viewers.SelectionChangedEvent;
6import org.eclipse.jface.wizard.WizardPage;
7import org.eclipse.swt.events.ModifyEvent;
8import org.eclipse.swt.events.ModifyListener;
9import org.eclipse.swt.events.SelectionEvent;
10import org.eclipse.swt.events.SelectionListener;
11import org.eclipse.swt.widgets.Composite;
12import org.eclipse.swt.widgets.Event;
13import org.eclipse.swt.widgets.Listener;
14
15public abstract class FiniteStateWizardPage extends WizardPage {
16 protected Map model = null;
17 protected FiniteStateWizard wizard = null;
18 private static boolean previousState = false;
19 /**
20 * @param pageName
21 */
22 protected FiniteStateWizardPage(String name, Map model) {
23 super(name);
24 this.model = model;
25 this.setPageComplete(false);
26 }
27
28 /*
29 * (non-Javadoc)
30 *
31 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
32 */
33 public abstract void createControl(Composite parent);
34
35 protected void setModelWizard() {
36 if (wizard == null) {
37 wizard = (FiniteStateWizard)FiniteStateWizardPage.this.getWizard();
38 }
39 }
40
41 /**
42 * Add page validation logic here. Returning <code>true</code> means that
43 * the page is complete and the user can go to the next page.
44 *
45 * @return
46 */
47 protected abstract boolean validatePage();
48
49 /**
50 * This method should be implemented by ModelWizardPage classes. This method
51 * is called after the <code>validatePage()</code> returns successfully.
52 * Update the model with the contents of the controls on the page.
53 */
54 protected abstract void updateModel();
55
56 /**
57 * Helper method to see if a field has some sort of text in it.
58 * @param value
59 * @return
60 */
61 protected boolean hasContents(String value) {
62 if (value == null || value.length() == 0) {
63 return false;
64 }
65
66 return true;
67 }
68
69 /**
70 * This method is called right before a page is displayed.
71 * This occurs on user action (Next/Back buttons).
72 */
73 public abstract void pageDisplay();
74
75 /**
76 * This method is called on the concrete WizardPage after the user has
77 * gone to the page after.
78 */
79 public abstract void pageCleanup();
80
81 /* (non-Javadoc)
82 * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
83 */
84 public void setVisible(boolean arg0) {
85
86 if (!arg0 && previousState) {
87 pageCleanup();
88 } else if (arg0 && !previousState) {
89 pageDisplay();
90 } else if (arg0 && previousState) {
91 pageDisplay();
92 }
93
94 previousState = arg0;
95
96 super.setVisible(arg0);
97 }
98
99 public class ValidationListener implements SelectionListener, ModifyListener, Listener, ISelectionChangedListener {
100
101 /*
102 * (non-Javadoc)
103 *
104 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
105 */
106 public void widgetSelected(SelectionEvent e) {
107 validate();
108 }
109
110 /*
111 * (non-Javadoc)
112 *
113 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
114 */
115 public void widgetDefaultSelected(SelectionEvent e) {
116 }
117
118 /*
119 * (non-Javadoc)
120 *
121 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
122 */
123 public void modifyText(ModifyEvent e) {
124 validate();
125 }
126
127 public void validate() {
128 if (validatePage()) {
129 updateModel();
130 setPageComplete(true);
131 return;
132 }
133
134 setPageComplete(false);
135 }
136
137 /* (non-Javadoc)
138 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
139 */
140 public void handleEvent(Event event) {
141
142 validate();
143 }
144
145 public void selectionChanged(SelectionChangedEvent event) {
146 validate();
147 }
148 }
149}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
new file mode 100644
index 0000000..3a2ac71
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
@@ -0,0 +1,231 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Jessica Zhang (Intel) - Extend to support auto-fill base on src_uri value
11 * Ioana Grigoropol (Intel) - adapt class for remote support
12 *******************************************************************************/
13package org.yocto.bc.ui.wizards;
14
15import java.io.ByteArrayInputStream;
16import java.io.IOException;
17import java.io.InputStream;
18import java.io.File;
19import java.lang.reflect.InvocationTargetException;
20import java.util.ArrayList;
21
22import org.eclipse.core.resources.IContainer;
23import org.eclipse.core.resources.IFile;
24import org.eclipse.core.resources.IProject;
25import org.eclipse.core.resources.IResource;
26import org.eclipse.core.resources.IWorkspaceRoot;
27import org.eclipse.core.resources.ResourcesPlugin;
28import org.eclipse.core.runtime.CoreException;
29import org.eclipse.core.runtime.IProgressMonitor;
30import org.eclipse.core.runtime.IStatus;
31import org.eclipse.core.runtime.Path;
32import org.eclipse.core.runtime.Status;
33import org.eclipse.jface.dialogs.MessageDialog;
34import org.eclipse.jface.operation.IRunnableWithProgress;
35import org.eclipse.jface.viewers.ISelection;
36import org.eclipse.jface.viewers.IStructuredSelection;
37import org.eclipse.jface.wizard.Wizard;
38import org.eclipse.rse.core.model.IHost;
39import org.eclipse.ui.INewWizard;
40import org.eclipse.ui.IWorkbench;
41import org.eclipse.ui.IWorkbenchPage;
42import org.eclipse.ui.IWorkbenchWizard;
43import org.eclipse.ui.PartInitException;
44import org.eclipse.ui.PlatformUI;
45import org.eclipse.ui.ide.IDE;
46
47import org.yocto.bc.bitbake.BBLanguageHelper;
48import org.yocto.bc.ui.Activator;
49import org.yocto.bc.ui.model.ProjectInfo;
50import org.yocto.remote.utils.RemoteHelper;
51import org.yocto.remote.utils.YoctoCommand;
52
53public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard {
54 private NewBitBakeFileRecipeWizardPage page;
55 private ISelection selection;
56 private IHost connection;
57
58 public NewBitBakeFileRecipeWizard() {
59 super();
60 setNeedsProgressMonitor(true);
61 }
62
63 @Override
64 public void addPages() {
65 page = new NewBitBakeFileRecipeWizardPage(selection, connection);
66 addPage(page);
67 }
68
69 private void doFinish(BitbakeRecipeUIElement element, IProgressMonitor monitor) throws CoreException {
70 String fileName = element.getFile();
71 monitor.beginTask("Creating " + fileName, 2);
72 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
73 IResource resource = root.findMember(new Path(element.getContainer()));
74 if (!resource.exists() || !(resource instanceof IContainer)) {
75 throwCoreException("Container \"" + element.getContainer() + "\" does not exist.");
76 }
77 IContainer container = (IContainer) resource;
78
79 // If the extension wasn't specified, assume .bb
80 if (!fileName.endsWith(".bb") && !fileName.endsWith(".inc") && !fileName.endsWith(".conf")) {
81 fileName = fileName + ".bb";
82 }
83
84 final IFile file = container.getFile(new Path(fileName));
85 try {
86 InputStream stream = openContentStream(element);
87 if (file.exists()) {
88 file.setContents(stream, true, true, monitor);
89 } else {
90 file.create(stream, true, monitor);
91 }
92 stream.close();
93 } catch (IOException e) {
94 }
95 monitor.worked(1);
96 monitor.setTaskName("Opening file for editing...");
97 getShell().getDisplay().asyncExec(new Runnable() {
98 public void run() {
99 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
100 try {
101 IDE.openEditor(page, file, true);
102 } catch (PartInitException e) {
103 }
104 }
105 });
106 monitor.worked(1);
107 }
108
109 /**
110 * We will accept the selection in the workbench to see if we can initialize
111 * from it.
112 *
113 * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
114 */
115 public void init(IWorkbench workbench, IStructuredSelection selection) {
116 this.selection = selection;
117 if (selection instanceof IStructuredSelection) {
118 Object element = selection.getFirstElement();
119
120 if (element instanceof IResource) {
121 IProject p = ((IResource)element).getProject();
122 try {
123 ProjectInfo projInfo = Activator.getProjInfo(p.getLocationURI());
124 this.connection = projInfo.getConnection();
125 } catch (CoreException e) {
126 e.printStackTrace();
127 } catch (InvocationTargetException e) {
128 e.printStackTrace();
129 } catch (InterruptedException e) {
130 e.printStackTrace();
131 }
132
133 }
134 }
135 }
136
137 /**
138 * We will initialize file contents with a sample text.
139 * @param srcuri
140 * @param author
141 * @param homepage
142 * @param license
143 * @param description
144 * @param fileName
145 * @param newPage
146 */
147
148 private InputStream openContentStream(BitbakeRecipeUIElement element) {
149
150 StringBuffer sb = new StringBuffer();
151
152 sb.append("DESCRIPTION = \"" + element.getDescription() + "\"\n");
153
154 if (element.getAuthor().length() > 0) {
155 sb.append("AUTHOR = \"" + element.getAuthor() + "\"\n");
156 }
157
158 if (element.getHomePage().length() > 0) {
159 sb.append("HOMEPAGE = \"" + element.getHomePage() + "\"\n");
160 }
161
162 if (element.getSection().length() > 0) {
163 sb.append("SECTION = \"" + element.getSection() + "\"\n");
164 }
165
166 if (element.getLicense().length() > 0) {
167 sb.append("LICENSE = \"" + element.getLicense() + "\"\n");
168 }
169
170 if (element.getChecksum().length() > 0) {
171 sb.append("LIC_FILES_CHKSUM = \"" + element.getChecksum() + "\"\n");
172 }
173
174 if (element.getSrcuri().length() > 0) {
175 sb.append("SRC_URI = \"" + element.getSrcuri() + "\"\n");
176 }
177
178 if (element.getMd5sum().length() > 0) {
179 sb.append("SRC_URI[md5sum] = \"" + element.getMd5sum() + "\"\n");
180 }
181
182 if (element.getsha256sum().length() > 0) {
183 sb.append("SRC_URI[sha256sum] = \"" + element.getsha256sum() + "\"\n");
184 }
185
186 ArrayList<String> inheritance = element.getInheritance();
187 if (!inheritance.isEmpty()) {
188 Object ia[] = inheritance.toArray();
189 String inheritance_str = "inherit ";
190 for(int i=0; i<ia.length; i++)
191 inheritance_str += ((String) ia[i]) + " ";
192 sb.append(inheritance_str);
193 }
194 sb.append("\n");
195
196 return new ByteArrayInputStream(sb.toString().getBytes());
197 }
198
199 @Override
200 public boolean performFinish() {
201 final BitbakeRecipeUIElement element = page.populateUIElement();
202
203 IRunnableWithProgress op = new IRunnableWithProgress() {
204 public void run(IProgressMonitor monitor) throws InvocationTargetException {
205 try {
206 doFinish(element, monitor);
207 RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand("rm -rf " + element.getMetaDir() + "/temp", "", ""), monitor);
208 } catch (Exception e) {
209 throw new InvocationTargetException(e);
210 } finally {
211 monitor.done();
212 }
213 }
214 };
215 try {
216 getContainer().run(true, false, op);
217 } catch (InterruptedException e) {
218 return false;
219 } catch (InvocationTargetException e) {
220 Throwable realException = e.getTargetException();
221 MessageDialog.openError(getShell(), "Error", realException.getMessage());
222 return false;
223 }
224 return true;
225 }
226
227 private void throwCoreException(String message) throws CoreException {
228 IStatus status = new Status(IStatus.ERROR, "org.yocto.bc.ui", IStatus.OK, message, null);
229 throw new CoreException(status);
230 }
231}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
new file mode 100644
index 0000000..3bdcffd
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -0,0 +1,592 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Jessica Zhang (Intel) - Extend to support auto-fill base on src_uri value
11 * Ioana Grigoropol (Intel) - adapt class for remote support
12 *******************************************************************************/
13package org.yocto.bc.ui.wizards;
14
15import java.util.List;
16import org.eclipse.core.resources.IContainer;
17import org.eclipse.core.resources.IProject;
18import org.eclipse.core.resources.IResource;
19import org.eclipse.core.resources.ResourcesPlugin;
20import org.eclipse.core.runtime.CoreException;
21import org.eclipse.core.runtime.IProgressMonitor;
22import org.eclipse.core.runtime.NullProgressMonitor;
23import org.eclipse.core.runtime.Path;
24import org.eclipse.core.runtime.IPath;
25import org.eclipse.core.runtime.SubProgressMonitor;
26import org.eclipse.jface.operation.IRunnableWithProgress;
27import org.eclipse.jface.viewers.ISelection;
28import org.eclipse.jface.viewers.IStructuredSelection;
29import org.eclipse.jface.window.Window;
30import org.eclipse.jface.wizard.WizardPage;
31import org.eclipse.rse.core.model.IHost;
32import org.eclipse.rse.services.files.IFileService;
33import org.eclipse.rse.services.files.IHostFile;
34import org.eclipse.swt.SWT;
35import org.eclipse.swt.events.ModifyEvent;
36import org.eclipse.swt.events.ModifyListener;
37import org.eclipse.swt.events.SelectionAdapter;
38import org.eclipse.swt.events.SelectionEvent;
39import org.eclipse.swt.layout.GridData;
40import org.eclipse.swt.layout.GridLayout;
41import org.eclipse.swt.widgets.Button;
42import org.eclipse.swt.widgets.Composite;
43import org.eclipse.swt.widgets.DirectoryDialog;
44import org.eclipse.swt.widgets.FileDialog;
45import org.eclipse.swt.widgets.Label;
46import org.eclipse.swt.widgets.Text;
47import org.eclipse.ui.dialogs.ContainerSelectionDialog;
48import org.yocto.bc.ui.Activator;
49import org.yocto.bc.ui.model.ProjectInfo;
50import org.yocto.remote.utils.ProcessStreamBuffer;
51import org.yocto.remote.utils.RemoteHelper;
52import org.yocto.remote.utils.YoctoCommand;
53
54import java.util.HashMap;
55import java.util.Hashtable;
56import java.util.Set;
57import java.util.ArrayList;
58import java.util.Enumeration;
59import java.util.Iterator;
60import java.util.regex.Pattern;
61
62import java.io.BufferedReader;
63import java.io.InputStreamReader;
64import java.io.File;
65import java.io.FileReader;
66import java.io.IOException;
67import java.io.FileInputStream;
68import java.io.InputStream;
69import java.io.FilenameFilter;
70import java.security.MessageDigest;
71import java.lang.reflect.InvocationTargetException;
72import java.math.BigInteger;
73import java.net.URI;
74import java.net.URISyntaxException;
75
76public class NewBitBakeFileRecipeWizardPage extends WizardPage {
77 private Text containerText;
78 private Text fileText;
79
80 private Text descriptionText;
81 private Text licenseText;
82 private Text checksumText;
83 private Text homepageText;
84 private Text authorText;
85 private Text sectionText;
86 private Text txtSrcURI;
87 private Text md5sumText;
88 private Text sha256sumText;
89 private Button btnPopulate;
90
91 private BitbakeRecipeUIElement element;
92
93 private ISelection selection;
94 private URI metaDirLoc;
95 private ArrayList inheritance;
96 private final IHost connection;
97
98 private String tempFolderPath;
99 private String srcFileNameExt;
100 private String srcFileName;
101
102 public static final String TEMP_FOLDER_NAME = "temp";
103 public static final String TAR_BZ2_EXT = ".tar.bz2";
104 public static final String TAR_GZ_EXT = ".tar.gz";
105 public static final String HTTP = "http";
106 public static final String FTP ="ftp";
107 public static final String BB_RECIPE_EXT =".bb";
108 private static final String COPYING_FILE = "COPYING";
109
110 private static final String CMAKE_LIST = "cmakelists.txt";
111 private static final String CMAKE = "cmake";
112 private static final String SETUP_SCRIPT = "setup.py";
113 private static final String DISUTILS = "disutils";
114 private static final String CONFIGURE_IN = "configure.in";
115 private static final String CONFIGURE_AC = "configure.ac";
116 private static final String AUTOTOOLS = "autotools";
117
118 private static final String md5Pattern = "^[0-9a-f]{32}$";
119 protected static final String sha256Pattern = "^[0-9a-f]{64}$";
120
121 private static final String MIRRORS_FILE = "mirrors.bbclass";
122 private static final String CLASSES_FOLDER = "classes";
123
124 private HashMap<String, String> mirrorTable;
125 private URI extractDir;
126
127 protected ProcessStreamBuffer md5Buffer;
128 protected ProcessStreamBuffer sha256Buffer;
129 protected ProcessStreamBuffer md5CopyingBuffer;
130
131 public NewBitBakeFileRecipeWizardPage(ISelection selection, IHost connection) {
132 super("wizardPage");
133 setTitle("BitBake Recipe");
134 setDescription("Create a new BitBake recipe.");
135 this.selection = selection;
136 this.connection = connection;
137 element = new BitbakeRecipeUIElement();
138 inheritance = new ArrayList();
139 }
140
141 public void createControl(Composite parent) {
142 final Composite container = new Composite(parent, SWT.NULL);
143 GridLayout layout = new GridLayout();
144 container.setLayout(layout);
145 layout.numColumns = 3;
146 layout.verticalSpacing = 9;
147
148 Label label = new Label(container, SWT.NULL);
149 GridData gd = new GridData();
150 gd.horizontalSpan = 3;
151 label.setLayoutData(gd);
152
153 label = new Label(container, SWT.NULL);
154 label.setText("Recipe &Directory:");
155
156 containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
157 gd = new GridData(GridData.FILL_HORIZONTAL);
158 containerText.setLayoutData(gd);
159 containerText.addModifyListener(new ModifyListener() {
160 public void modifyText(ModifyEvent e) {
161 dialogChanged();
162 }
163 });
164
165 Button buttonBrowse = new Button(container, SWT.PUSH);
166 buttonBrowse.setText("Browse...");
167 buttonBrowse.addSelectionListener(new SelectionAdapter() {
168 @Override
169 public void widgetSelected(SelectionEvent e) {
170 handleBrowse(container, containerText);
171 }
172 });
173
174 label = new Label(container, SWT.NULL);
175 gd = new GridData();
176 gd.horizontalSpan = 3;
177 label.setLayoutData(gd);
178
179 label = new Label(container, SWT.NULL);
180 label.setText("SRC_&URI:");
181
182 txtSrcURI = new Text(container, SWT.BORDER | SWT.SINGLE);
183 gd = new GridData(GridData.FILL_HORIZONTAL);
184 txtSrcURI.setLayoutData(gd);
185 txtSrcURI.addModifyListener(new ModifyListener() {
186 public void modifyText(ModifyEvent e) {
187 if (txtSrcURI.getText().trim().isEmpty()) {
188 if (btnPopulate != null)
189 btnPopulate.setEnabled(false);
190 } else if (btnPopulate != null){
191 btnPopulate.setEnabled(true);
192 }
193 dialogChanged();
194 }
195 });
196
197 btnPopulate = new Button(container, SWT.PUSH);
198 btnPopulate.setText("Populate...");
199 btnPopulate.setEnabled(false);
200 btnPopulate.addSelectionListener(new SelectionAdapter() {
201 @Override
202 public void widgetSelected(SelectionEvent e) {
203 handlePopulate();
204 }
205 });
206
207 createField(container, "&Recipe Name:", (fileText = new Text(container, SWT.BORDER | SWT.SINGLE)));
208 createField(container, "SRC_URI[&md5sum]:", (md5sumText = new Text(container, SWT.BORDER | SWT.SINGLE)));
209 createField(container, "SRC_URI[&sha256sum]:", (sha256sumText = new Text(container, SWT.BORDER | SWT.SINGLE)));
210 createField(container, "License File &Checksum:", (checksumText = new Text(container, SWT.BORDER | SWT.SINGLE)));
211 createField(container, "&Package Description:", (descriptionText = new Text(container, SWT.BORDER | SWT.SINGLE)));
212 createField(container, "&License:", (licenseText = new Text(container, SWT.BORDER | SWT.SINGLE)));
213
214 createField(container, "&Homepage:", (homepageText = new Text(container, SWT.BORDER | SWT.SINGLE)));
215 createField(container, "Package &Author:", (authorText = new Text(container, SWT.BORDER | SWT.SINGLE)));
216 createField(container, "&Section:", (sectionText = new Text(container, SWT.BORDER | SWT.SINGLE)));
217
218 initialize();
219 dialogChanged();
220 setControl(container);
221 }
222
223 private void createField(Composite container, String title, Text control) {
224 Label label = new Label(container, SWT.NONE);
225 label.setText(title);
226 label.moveAbove(control);
227
228 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
229 gd.horizontalSpan = 2;
230 control.setLayoutData(gd);
231 control.addModifyListener(new ModifyListener() {
232
233 public void modifyText(ModifyEvent e) {
234 dialogChanged();
235 }
236
237 });
238 }
239
240 private void dialogChanged() {
241 String containerName = containerText.getText();
242 IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(containerName));
243 String fileName = fileText.getText();
244
245 if (containerName.length() == 0) {
246 updateStatus("Directory must be specified");
247 return;
248 }
249
250 if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
251 updateStatus("File container must exist");
252 return;
253 }
254 if (!container.isAccessible()) {
255 updateStatus("Project must be writable");
256 return;
257 }
258
259 IProject project = container.getProject();
260 ProjectInfo projInfo = null;
261 try {
262 projInfo = Activator.getProjInfo(project.getLocationURI());
263 } catch (InvocationTargetException e) {
264 e.printStackTrace();
265 } catch (CoreException e) {
266 e.printStackTrace();
267 } catch (InterruptedException e) {
268 e.printStackTrace();
269 }
270 metaDirLoc = RemoteHelper.createNewURI(projInfo.getOriginalURI(), "meta");
271
272 if (fileName.length() == 0) {
273 updateStatus("File name must be specified");
274 return;
275 }
276 if (fileName.contains(" ")) {
277 updateStatus("File name must be valid with no space in it");
278 return;
279 }
280 if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
281 updateStatus("File name must be valid");
282 return;
283 }
284
285 if (descriptionText.getText().length() == 0) {
286 updateStatus("Recipe must have a description");
287 return;
288 }
289
290 if (licenseText.getText().length() == 0) {
291 updateStatus("Recipe must have a license");
292 return;
293 }
294
295 if (txtSrcURI.getText().length() == 0) {
296 updateStatus("SRC_URI can't be empty");
297 }
298
299 updateStatus(null);
300 }
301
302 public BitbakeRecipeUIElement populateUIElement() {
303 element.setAuthor(authorText.getText());
304 element.setChecksum(checksumText.getText());
305 element.setContainer(containerText.getText());
306 element.setDescription(descriptionText.getText());
307 element.setFile(fileText.getText());
308 element.setHomePage(homepageText.getText());
309 element.setLicense(licenseText.getText());
310 element.setMd5sum(md5sumText.getText());
311 element.setSection(sectionText.getText());
312 element.setSha256sum(sha256sumText.getText());
313 element.setSrcuri(txtSrcURI.getText());
314 element.setInheritance(inheritance);
315 element.setMetaDir(metaDirLoc);
316
317 return element;
318 }
319
320 private void handleBrowse(final Composite parent, final Text text) {
321 ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, "Select project directory");
322 if (dialog.open() == Window.OK) {
323 Object[] result = dialog.getResult();
324 if (result.length == 1) {
325 text.setText(((Path) result[0]).toString());
326 }
327 }
328 }
329
330 private void handlePopulate() {
331 try {
332 IProgressMonitor monitor = new NullProgressMonitor();
333 URI srcURI = new URI(txtSrcURI.getText().trim());
334 String scheme = srcURI.getScheme();
335 this.srcFileNameExt = getSrcFileName(true);
336 this.srcFileName = getSrcFileName(false);
337 if ((scheme.equals(HTTP) || scheme.equals(FTP))
338 && (srcFileNameExt.endsWith(TAR_GZ_EXT) || srcFileNameExt.endsWith(TAR_BZ2_EXT))) {
339 handleRemotePopulate(srcURI, monitor);
340 } else {
341 String packageName = srcFileName.replace("-", "_");
342 fileText.setText(packageName + BB_RECIPE_EXT);
343
344 handleLocalPopulate(srcURI, monitor);
345 }
346 } catch (URISyntaxException e) {
347 e.printStackTrace();
348 } catch (InvocationTargetException e) {
349 e.printStackTrace();
350 } catch (InterruptedException e) {
351 e.printStackTrace();
352 }
353 }
354
355 private String getSrcFileName(boolean withExt){
356 URI srcURI;
357 try {
358 srcURI = new URI(txtSrcURI.getText().trim());
359 String path = srcURI.getPath();
360 String fileName = path.substring(path.lastIndexOf("/") + 1);
361 if (withExt)
362 return fileName;
363 else {
364 if (fileName.endsWith(TAR_BZ2_EXT)) {
365 return fileName.substring(0, fileName.indexOf(TAR_BZ2_EXT));
366 } else if(fileName.endsWith(TAR_GZ_EXT)){
367 return fileName.substring(0, fileName.indexOf(TAR_GZ_EXT));
368 }
369 }
370 } catch (URISyntaxException e) {
371 e.printStackTrace();
372 }
373 return "";
374 }
375 private void handleRemotePopulate(final URI srcURI, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
376 populateRecipeName();
377
378 this.getContainer().run(true, true, new IRunnableWithProgress() {
379
380 @Override
381 public void run(IProgressMonitor monitor) throws InvocationTargetException,
382 InterruptedException {
383 monitor.beginTask("Populating recipe fields ... ", 100);
384 try {
385 String metaDirLocPath = metaDirLoc.getPath();
386 monitor.subTask("Cleaning environment");
387 YoctoCommand rmYCmd = new YoctoCommand("rm -rf " + TEMP_FOLDER_NAME, metaDirLocPath, "");
388 RemoteHelper.handleRunCommandRemote(connection, rmYCmd, new SubProgressMonitor(monitor, 5));
389
390 YoctoCommand mkdirYCmd = new YoctoCommand( "mkdir " + TEMP_FOLDER_NAME, metaDirLocPath, "");
391 RemoteHelper.handleRunCommandRemote(connection, mkdirYCmd, new SubProgressMonitor(monitor, 5));
392
393 updateTempFolderPath();
394 monitor.worked(10);
395
396 monitor.subTask("Downloading package sources");
397
398 updateTempFolderPath();
399
400 YoctoCommand wgetYCmd = new YoctoCommand("wget " + srcURI.toURL(), tempFolderPath, "");
401 RemoteHelper.handleRunCommandRemote(connection, wgetYCmd, new SubProgressMonitor(monitor, 40));
402
403 monitor.worked(50);
404
405 monitor.subTask("Compute package checksums");
406 String md5Cmd = "md5sum " + srcFileNameExt;
407 YoctoCommand md5YCmd = new YoctoCommand(md5Cmd, tempFolderPath, "");
408
409 RemoteHelper.handleRunCommandRemote(connection, md5YCmd, new SubProgressMonitor(monitor, 10));
410 md5Buffer = md5YCmd.getProcessBuffer();
411
412 monitor.worked(60);
413
414 String sha256Cmd = "sha256sum " + srcFileNameExt;
415 YoctoCommand sha256YCmd = new YoctoCommand(sha256Cmd, tempFolderPath, "");
416 RemoteHelper.handleRunCommandRemote(connection, sha256YCmd, new SubProgressMonitor(monitor, 10));
417 sha256Buffer = sha256YCmd.getProcessBuffer();
418
419 monitor.worked(70);
420
421 monitor.subTask("Extracting package");
422 extractDir = extractPackage(srcURI, new SubProgressMonitor(monitor, 0));
423 monitor.worked(80);
424
425 YoctoCommand licenseChecksumCmd = populateLicenseFileChecksum(extractDir, new SubProgressMonitor(monitor, 10));
426 md5CopyingBuffer = licenseChecksumCmd.getProcessBuffer();
427
428 monitor.subTask("Creating mirror lookup table");
429 mirrorTable = createMirrorLookupTable(new SubProgressMonitor(monitor, 10));
430
431 monitor.worked(90);
432 monitor.done();
433 } catch (Exception e) {
434 e.printStackTrace();
435 }
436 }
437 });
438 updateSrcUri(mirrorTable, srcURI);
439 populateInheritance(extractDir, monitor);
440
441 String md5Val = md5Buffer.getOutputLineContaining(srcFileNameExt, md5Pattern);
442 md5sumText.setText(Pattern.matches(md5Pattern, md5Val) ? md5Val : "");
443 String sha256Val = sha256Buffer.getOutputLineContaining(srcFileNameExt, sha256Pattern);
444 sha256sumText.setText(Pattern.matches(sha256Pattern, sha256Val) ? sha256Val : "");
445 String checkSumVal = md5CopyingBuffer.getOutputLineContaining(COPYING_FILE, md5Pattern);
446 checksumText.setText(RemoteHelper.createNewURI(extractDir, COPYING_FILE).toString() + ";md5=" + (Pattern.matches(md5Pattern, checkSumVal) ? checkSumVal : ""));
447 }
448
449 private void updateTempFolderPath(){
450 this.tempFolderPath = getMetaFolderPath() + TEMP_FOLDER_NAME + "/";
451 }
452
453 private String getMetaFolderPath(){
454 String sep = metaDirLoc.getPath().endsWith("/")? "" : "/";
455 return metaDirLoc.getPath() + sep;
456 }
457
458 private void handleLocalPopulate(URI srcURI, IProgressMonitor monitor) {
459 populateLicenseFileChecksum(srcURI, monitor);
460 populateInheritance(srcURI, monitor);
461 }
462
463 private URI extractPackage(URI srcURI, IProgressMonitor monitor) {
464 try {
465 String path = srcFileNameExt;
466 String tarCmd = "tar ";
467 if (path.endsWith(TAR_BZ2_EXT)) {
468 tarCmd += "-zxvf ";
469 } else if(path.endsWith(TAR_GZ_EXT)){
470 tarCmd += "-xvf ";
471 }
472
473 RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand(tarCmd + path, tempFolderPath, ""), monitor);
474
475 return RemoteHelper.createNewURI(metaDirLoc, TEMP_FOLDER_NAME + "/" + srcFileName);
476
477 } catch (Exception e) {
478 e.printStackTrace();
479 }
480 return null;
481 }
482
483 private void populateInheritance(URI extractDir, IProgressMonitor monitor) {
484 IHostFile[] hostFiles = RemoteHelper.getRemoteDirContent(connection, metaDirLoc.getPath(), "", IFileService.FILE_TYPE_FILES, monitor);
485 if (hostFiles == null)
486 return;
487
488 for (IHostFile file: hostFiles) {
489 String fileName = file.getName();
490 if (fileName.equalsIgnoreCase(CMAKE_LIST)){
491 inheritance.add(CMAKE);
492 } else if (fileName.equalsIgnoreCase(SETUP_SCRIPT)) {
493 inheritance.add(DISUTILS);
494 } else if (fileName.equalsIgnoreCase(CONFIGURE_AC) || file.getName().equalsIgnoreCase(CONFIGURE_IN)) {
495 inheritance.add(AUTOTOOLS);
496 }
497 }
498 }
499
500 private YoctoCommand populateLicenseFileChecksum(URI extractDir, IProgressMonitor monitor) {
501 if (extractDir == null)
502 throw new RuntimeException("Something went wrong during source extraction!");
503
504 try {
505 YoctoCommand catCmd = new YoctoCommand("md5sum " + COPYING_FILE, extractDir.getPath(), "");
506 RemoteHelper.handleRunCommandRemote(connection, catCmd, monitor);
507 return catCmd;
508 } catch (Exception e) {
509 throw new RuntimeException("Unable to process file for MD5 calculation", e);
510 }
511
512 }
513
514 private HashMap<String, String> createMirrorLookupTable(IProgressMonitor monitor) throws Exception {
515 HashMap<String, String> mirrorMap = new HashMap<String, String>();
516
517 YoctoCommand cmd = new YoctoCommand("cat " + MIRRORS_FILE, getMetaFolderPath() + CLASSES_FOLDER, "");
518 RemoteHelper.handleRunCommandRemote(connection, cmd, monitor);
519
520 if (!cmd.getProcessBuffer().hasErrors()){
521 String delims = "[\\t]+";
522 List<String> outputLines = cmd.getProcessBuffer().getOutputLines();
523 for (String outLine : outputLines) {
524 String[] tokens = outLine.split(delims);
525 if (tokens.length < 2)
526 continue;
527 String endingStr = " \\n \\";
528 int idx = tokens[1].lastIndexOf(endingStr);
529 String key = tokens[1].substring(0, idx);
530 mirrorMap.put(key, tokens[0]);
531 }
532 }
533 return mirrorMap;
534 }
535
536 private void populateRecipeName() {
537 String fileName = fileText.getText();
538 if (!fileName.isEmpty())
539 return;
540
541 String recipeFile = srcFileName.replace("-", "_");
542 recipeFile += BB_RECIPE_EXT;
543 if (recipeFile != null)
544 fileText.setText(recipeFile);
545 }
546
547 private void updateSrcUri(HashMap<String, String> mirrorsMap, URI srcUri) {
548 Set<String> mirrors = mirrorsMap.keySet();
549 Iterator<String> iter = mirrors.iterator();
550 String mirror_key = null;
551 String srcURL = srcUri.toString();
552
553 while (iter.hasNext()) {
554 String value = iter.next();
555 if (srcURL.startsWith(value)) {
556 mirror_key = value;
557 break;
558 }
559 }
560
561 if (mirror_key != null) {
562 String replace_string = mirrorsMap.get(mirror_key);
563 if (replace_string != null)
564 srcURL = replace_string + srcURL.substring(mirror_key.length());
565 }
566 int idx = srcURL.lastIndexOf("-");
567 String new_src_uri = srcURL.substring(0, idx)+"-${PV}" + TAR_GZ_EXT;
568 txtSrcURI.setText(new_src_uri);
569 }
570
571 private void initialize() {
572 if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
573 IStructuredSelection ssel = (IStructuredSelection) selection;
574 if (ssel.size() > 1)
575 return;
576 Object obj = ssel.getFirstElement();
577 if (obj instanceof IResource) {
578 IContainer container;
579 if (obj instanceof IContainer)
580 container = (IContainer) obj;
581 else
582 container = ((IResource) obj).getParent();
583 containerText.setText(container.getFullPath().toString());
584 }
585 }
586 }
587
588 private void updateStatus(String message) {
589 setErrorMessage(message);
590 setPageComplete(message == null);
591 }
592}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java
new file mode 100644
index 0000000..71ea70c
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java
@@ -0,0 +1,236 @@
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.wizards.importProject;
12
13import java.io.File;
14import java.util.Map;
15
16import org.eclipse.core.resources.IProject;
17import org.eclipse.core.resources.IResource;
18import org.eclipse.core.resources.IWorkspaceRoot;
19import org.eclipse.core.resources.ResourcesPlugin;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.swt.SWT;
22import org.eclipse.swt.events.SelectionAdapter;
23import org.eclipse.swt.events.SelectionEvent;
24import org.eclipse.swt.layout.GridData;
25import org.eclipse.swt.layout.GridLayout;
26import org.eclipse.swt.widgets.Button;
27import org.eclipse.swt.widgets.Composite;
28import org.eclipse.swt.widgets.DirectoryDialog;
29import org.eclipse.swt.widgets.FileDialog;
30import org.eclipse.swt.widgets.Label;
31import org.eclipse.swt.widgets.Text;
32import org.eclipse.ui.PlatformUI;
33
34import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
35
36/**
37 * Main property page for new project wizard.
38 * @author kgilmer
39 *
40 */
41public class BBCProjectPage extends FiniteStateWizardPage {
42
43 private class FileOpenSelectionAdapter extends SelectionAdapter {
44 @Override
45 public void widgetSelected(SelectionEvent e) {
46 FileDialog fd = new FileDialog(PlatformUI.getWorkbench()
47 .getDisplay().getActiveShell(), SWT.OPEN);
48
49 fd.setText("Open Configuration Script");
50 fd.setFilterPath(txtProjectLocation.getText());
51
52 String selected = fd.open();
53
54 if (selected != null) {
55 txtInit.setText(selected);
56 updateModel();
57 }
58 }
59 }
60 public static final String PAGE_TITLE = "Yocto Project BitBake Commander Project";
61 private Text txtProjectLocation;
62
63 private Text txtInit;
64 private ValidationListener validationListener;
65 private Text txtProjectName;
66
67 public BBCProjectPage(Map model) {
68 super(PAGE_TITLE, model);
69 setTitle("Create new Yocto Project BitBake Commander project");
70 setMessage("Enter information to create a BitBake Commander project.");
71 }
72
73 public void createControl(Composite parent) {
74 GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL);
75 GridData gdVU = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
76
77 Composite top = new Composite(parent, SWT.NONE);
78 top.setLayoutData(new GridData(GridData.FILL_BOTH));
79 top.setLayout(new GridLayout());
80
81 Composite projectNameComp = new Composite(top, SWT.NONE);
82 GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL);
83 projectNameComp.setLayoutData(gdProjName);
84 projectNameComp.setLayout(new GridLayout(2, false));
85 Label lblProjectName = new Label(projectNameComp, SWT.NONE);
86 lblProjectName.setText("N&ame:");
87
88 txtProjectName = new Text(projectNameComp, SWT.BORDER);
89 txtProjectName.setLayoutData(gdFillH);
90 txtProjectName.setFocus();
91 validationListener = new ValidationListener();
92
93 txtProjectName.addModifyListener(validationListener);
94
95 Label lblProjectLocation = new Label(projectNameComp, SWT.None);
96 lblProjectLocation.setText("&Location:");
97
98 Composite locComposite = new Composite(projectNameComp, SWT.NONE);
99 GridData gd = new GridData(GridData.VERTICAL_ALIGN_END
100 | GridData.FILL_HORIZONTAL);
101 gd.horizontalIndent = 0;
102 locComposite.setLayoutData(gd);
103 GridLayout gl = new GridLayout(2, false);
104 gl.marginWidth = 0;
105 locComposite.setLayout(gl);
106
107 txtProjectLocation = new Text(locComposite, SWT.BORDER);
108 txtProjectLocation.setLayoutData(gdFillH);
109 txtProjectLocation.addModifyListener(validationListener);
110
111 Button button = new Button(locComposite, SWT.PUSH);
112 button.setText("Browse...");
113 button.addSelectionListener(new SelectionAdapter() {
114 @Override
115 public void widgetSelected(SelectionEvent e) {
116 handleBrowse();
117 }
118 });
119
120 Label lblInit = new Label(projectNameComp, SWT.NONE);
121 lblInit.setText("Init Script:");
122
123 Composite initComposite = new Composite(projectNameComp, SWT.NONE);
124 gd = new GridData(GridData.VERTICAL_ALIGN_END
125 | GridData.FILL_HORIZONTAL);
126 gd.horizontalIndent = 0;
127 initComposite.setLayoutData(gd);
128 gl = new GridLayout(2, false);
129 gl.marginWidth = 0;
130 initComposite.setLayout(gl);
131
132 txtInit = new Text(initComposite, SWT.BORDER);
133 GridData gdi = new GridData(GridData.FILL_HORIZONTAL);
134 txtInit.setLayoutData(gdi);
135 txtInit.addModifyListener(validationListener);
136
137 Button btnLoadInit = new Button(initComposite, SWT.PUSH);
138 btnLoadInit.setLayoutData(gdVU);
139 btnLoadInit.setText("Choose...");
140 btnLoadInit.addSelectionListener(new FileOpenSelectionAdapter());
141
142 if (System.getenv("OEROOT") != null) {
143 txtProjectLocation.setText(System.getenv("OEROOT"));
144 }
145
146 setControl(top);
147 }
148
149 private void handleBrowse() {
150 DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.None);
151 String dir = dialog.open();
152 if (dir != null) {
153 txtProjectLocation.setText(dir);
154 }
155 }
156
157 private String getFileSegment(String initScriptPath) {
158 //return the first segment of " " seperated array, or full string if no " " exists
159 return initScriptPath.split(" ")[0];
160 }
161
162 private boolean isValidProjectName(String projectName) {
163 if (projectName.indexOf('$') > -1) {
164 return false;
165 }
166
167 return true;
168 }
169
170
171 @Override
172 public void pageCleanup() {
173 // TODO Auto-generated method stub
174
175 }
176
177 @Override
178 public void pageDisplay() {
179 // TODO Auto-generated method stub
180
181 }
182
183 @Override
184 protected void updateModel() {
185 model.put(ImportYoctoProjectWizard.KEY_NAME, txtProjectName.getText());
186 model.put(ImportYoctoProjectWizard.KEY_LOCATION, txtProjectLocation.getText());
187 model.put(ImportYoctoProjectWizard.KEY_INITPATH, txtInit.getText());
188 }
189
190
191 @Override
192 protected boolean validatePage() {
193 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
194
195 IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT);
196
197 if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) {
198 setErrorMessage("Invalid project name: " + txtProjectName.getText());
199 return false;
200 }
201
202 IProject proj = wsroot.getProject(txtProjectName.getText());
203 if (proj.exists()) {
204 setErrorMessage("A project with the name " + txtProjectName.getText()
205 + " already exists");
206 return false;
207 }
208
209 if (txtProjectLocation.getText().trim().length() == 0) {
210 setErrorMessage("Set directory that contains Poky tree");
211 return false;
212 }
213
214 File f = new File(txtProjectLocation.getText());
215 if (!f.exists() || !f.isDirectory()) {
216 setErrorMessage("Invalid Directory");
217 return false;
218 }
219
220 if (txtInit.getText().length() == 0) {
221 setErrorMessage("Set configuration file before BitBake is launched.");
222 return false;
223 }
224
225 File f2 = new File(getFileSegment(txtInit.getText()));
226 if (!f2.exists() || f2.isDirectory()) {
227 setErrorMessage("The configuration file is invalid.");
228 return false;
229 }
230
231 setErrorMessage(null);
232 setMessage("All the entries are valid, press \"Finish\" to create the new yocto bitbake project,"+
233 "this will take a while. Please don't interrupt till there's output in the Yocto Console window...");
234 return true;
235 }
236}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java
new file mode 100644
index 0000000..75f1763
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java
@@ -0,0 +1,166 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards.importProject;
13
14import java.io.IOException;
15import java.io.Writer;
16import java.net.URI;
17import java.util.Hashtable;
18import java.util.Map;
19
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.Status;
22import org.eclipse.jface.viewers.IStructuredSelection;
23import org.eclipse.ui.IImportWizard;
24import org.eclipse.ui.IWorkbench;
25import org.eclipse.ui.IWorkbenchPage;
26import org.eclipse.ui.IWorkbenchWindow;
27import org.eclipse.ui.PlatformUI;
28import org.eclipse.ui.console.ConsolePlugin;
29import org.eclipse.ui.console.IConsole;
30import org.eclipse.ui.console.IConsoleConstants;
31import org.eclipse.ui.console.IConsoleManager;
32import org.eclipse.ui.console.IConsoleView;
33import org.eclipse.ui.console.MessageConsole;
34import org.yocto.bc.ui.Activator;
35import org.yocto.bc.ui.model.ProjectInfo;
36import org.yocto.bc.ui.wizards.FiniteStateWizard;
37import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;
38import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
39
40public class ImportYoctoProjectWizard extends FiniteStateWizard implements IImportWizard {
41 protected final static String KEY_OEROOT = "OEROOT";
42 public static final String KEY_NAME = "NAME";
43 public static final String KEY_LOCATION = "LOCATION";
44 public static final String KEY_INITPATH = "INITPATH";
45 protected static final String KEY_PINFO = "PINFO";
46
47 private Map projectModel;
48 private IWorkbench workbench;
49 private IStructuredSelection selection;
50
51 private MessageConsole myConsole;
52
53 public ImportYoctoProjectWizard() {
54 projectModel = new Hashtable();
55 }
56
57 public Map getModel() {
58 return projectModel;
59 }
60
61 @Override
62 public void addPages() {
63 addPage(new BBCProjectPage(projectModel));
64 //addPage(new ConsolePage(projectModel));
65 }
66
67
68 public boolean performFinish() {
69 ProjectInfo pinfo = new ProjectInfo();
70 pinfo.setInitScriptPath((String) projectModel.get(ImportYoctoProjectWizard.KEY_INITPATH));
71 pinfo.setLocationURI((URI) projectModel.get(ImportYoctoProjectWizard.KEY_LOCATION));
72 pinfo.setName((String) projectModel.get(ImportYoctoProjectWizard.KEY_NAME));
73
74 try {
75 ConsoleWriter cw = new ConsoleWriter();
76 this.getContainer().run(false, false, new BBConfigurationInitializeOperation(pinfo, cw));
77 myConsole.newMessageStream().println(cw.getContents());
78 } catch (Exception e) {
79 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
80 this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage());
81 //valid = false;
82 //setPageComplete(valid);
83 return false;
84 }
85
86 //valid = true;
87 projectModel.put(ImportYoctoProjectWizard.KEY_PINFO, pinfo);
88 //setPageComplete(valid);
89 //ProjectInfo pinfo = (ProjectInfo) projectModel.get(KEY_PINFO);
90 Activator.putProjInfo(pinfo.getOEFSURI(), pinfo);
91 try {
92 getContainer().run(false, false, new CreateBBCProjectOperation(pinfo));
93 } catch (Exception e) {
94 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
95 this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage());
96 return false;
97 }
98
99 return true;
100 }
101
102 public void init(IWorkbench workbench, IStructuredSelection selection) {
103 this.workbench = workbench;
104 this.selection = selection;
105 this.setNeedsProgressMonitor(true);
106 setWindowTitle("BitBake Commander Project");
107
108 myConsole = findConsole("Yocto Console");
109 IWorkbench wb = PlatformUI.getWorkbench();
110 IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
111 IWorkbenchPage page = win.getActivePage();
112 String id = IConsoleConstants.ID_CONSOLE_VIEW;
113 try {
114 IConsoleView view = (IConsoleView) page.showView(id);
115 view.display(myConsole);
116 } catch (Exception e) {
117 e.printStackTrace();
118 }
119 }
120
121 private MessageConsole findConsole(String name) {
122 ConsolePlugin plugin = ConsolePlugin.getDefault();
123 IConsoleManager conMan = plugin.getConsoleManager();
124 IConsole[] existing = conMan.getConsoles();
125 for (int i = 0; i < existing.length; i++)
126 if (name.equals(existing[i].getName()))
127 return (MessageConsole) existing[i];
128 // no console found, so create a new one
129 MessageConsole myConsole = new MessageConsole(name, null);
130 conMan.addConsoles(new IConsole[] { myConsole });
131 return myConsole;
132 }
133
134 private class ConsoleWriter extends Writer {
135
136 private StringBuffer sb;
137
138 public ConsoleWriter() {
139 sb = new StringBuffer();
140 }
141 @Override
142 public void close() throws IOException {
143 }
144
145 public String getContents() {
146 return sb.toString();
147 }
148
149 @Override
150 public void flush() throws IOException {
151 }
152
153 @Override
154 public void write(char[] cbuf, int off, int len) throws IOException {
155 //txtConsole.getText().concat(new String(cbuf));
156 sb.append(cbuf);
157 }
158
159 @Override
160 public void write(String str) throws IOException {
161 sb.append(str);
162 }
163
164 }
165
166}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java
new file mode 100644
index 0000000..6d7c440
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java
@@ -0,0 +1,371 @@
1/*******************************************************************************
2 * Copyright (c) 2013 Intel Corporation and others.
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.bc.ui.wizards.install;
12
13import java.net.URI;
14
15import org.eclipse.core.filesystem.URIUtil;
16import org.eclipse.core.resources.IProject;
17import org.eclipse.core.runtime.Path;
18import org.eclipse.core.runtime.Platform;
19import org.eclipse.jface.operation.IRunnableContext;
20import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea;
21import org.eclipse.ptp.remote.core.IRemoteFileManager;
22import org.eclipse.swt.SWT;
23import org.eclipse.swt.events.ModifyEvent;
24import org.eclipse.swt.events.ModifyListener;
25import org.eclipse.swt.events.SelectionAdapter;
26import org.eclipse.swt.events.SelectionEvent;
27import org.eclipse.swt.layout.GridData;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.widgets.Button;
30import org.eclipse.swt.widgets.Composite;
31import org.eclipse.swt.widgets.Control;
32import org.eclipse.swt.widgets.Group;
33import org.eclipse.swt.widgets.Label;
34import org.eclipse.swt.widgets.Text;
35import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
36import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
37
38import java.net.URI;
39
40import org.eclipse.core.filesystem.URIUtil;
41import org.eclipse.core.resources.IProject;
42import org.eclipse.core.runtime.Path;
43import org.eclipse.core.runtime.Platform;
44import org.eclipse.jface.operation.IRunnableContext;
45import org.eclipse.ptp.rdt.ui.messages.Messages;
46//import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider;
47//import org.eclipse.ptp.rdt.core.serviceproviders.
48import org.eclipse.ptp.remote.core.IRemoteConnection;
49import org.eclipse.ptp.remote.core.IRemoteFileManager;
50import org.eclipse.ptp.remote.core.IRemoteServices;
51import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager;
52import org.eclipse.ptp.remote.ui.IRemoteUIConstants;
53import org.eclipse.ptp.remote.ui.IRemoteUIFileManager;
54import org.eclipse.ptp.remote.ui.IRemoteUIServices;
55import org.eclipse.ptp.remote.ui.RemoteUIServices;
56import org.eclipse.ptp.remote.ui.widgets.RemoteConnectionWidget;
57import org.eclipse.swt.SWT;
58import org.eclipse.swt.events.ModifyEvent;
59import org.eclipse.swt.events.ModifyListener;
60import org.eclipse.swt.events.SelectionAdapter;
61import org.eclipse.swt.events.SelectionEvent;
62import org.eclipse.swt.layout.GridData;
63import org.eclipse.swt.layout.GridLayout;
64import org.eclipse.swt.widgets.Button;
65import org.eclipse.swt.widgets.Composite;
66import org.eclipse.swt.widgets.Control;
67import org.eclipse.swt.widgets.Group;
68import org.eclipse.swt.widgets.Label;
69import org.eclipse.swt.widgets.Text;
70import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
71import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
72
73
74public class BBCRemoteProjectContentsLocationArea {
75
76 /**
77 * IErrorMessageReporter is an interface for type that allow message
78 * reporting.
79 *
80 */
81 public interface IErrorMessageReporter {
82 /**
83 * Report the error message
84 *
85 * @param errorMessage
86 * String or <code>null</code>. If the errorMessage is null
87 * then clear any error state.
88 * @param infoOnly
89 * the message is an informational message, but the dialog
90 * cannot continue
91 *
92 */
93 public void reportError(String errorMessage, boolean infoOnly);
94 }
95
96 private static final String FILE_SCHEME = "file"; //$NON-NLS-1$
97
98 private IProject fExistingProject;
99
100 private final IErrorMessageReporter fErrorReporter;
101
102 private final IRunnableContext fContext;
103
104 //private RemoteBuildServiceProvider fProvider;
105
106 private IRemoteConnection fSelectedConnection;
107
108 private String fProjectName = IDEResourceInfoUtils.EMPTY_STRING;
109
110 private Button fBrowseButton;
111
112 private Text fLocationText;
113
114 private RemoteConnectionWidget fRemoteConnectionWidget;
115
116 // public RemoteProjectContentsLocationArea(IServiceProvider provider,
117 // Composite composite) {
118 // if(provider instanceof RemoteBuildServiceProvider)
119 // fProvider = (RemoteBuildServiceProvider) provider;
120 // else
121 // throw new IllegalArgumentException(); // should never happen
122 // createContents(composite);
123 // }
124 /**
125 * @since 3.1
126 */
127 public BBCRemoteProjectContentsLocationArea(IErrorMessageReporter reporter, Composite composite, IRunnableContext context) {
128 fErrorReporter = reporter;
129 fContext = context;
130 createContents(composite);
131 }
132
133 /**
134 * Check if the entry in the widget location is valid. If it is valid return
135 * null. Otherwise return a string that indicates the problem.
136 *
137 * @return String
138 */
139 public String checkValidLocation() {
140
141 String locationFieldContents = fLocationText.getText();
142 if (locationFieldContents.length() == 0) {
143 return IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationEmpty;
144 }
145
146 URI newPath = getProjectLocationURI();
147 if (newPath == null) {
148 return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationError;
149 }
150
151 if (fExistingProject != null) {
152 URI projectPath = fExistingProject.getLocationURI();
153 if (projectPath != null && URIUtil.equals(projectPath, newPath)) {
154 return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationIsSelf;
155 }
156 }
157
158 return null;
159 }
160
161 /**
162 * Return the browse button. Usually referenced in order to set the layout
163 * data for a dialog.
164 *
165 * @return Button
166 */
167 public Button[] getButtons() {
168 return new Button[] { fBrowseButton, fRemoteConnectionWidget.getButton() };
169 }
170
171 /**
172 * Returns the name of the selected connection.
173 */
174 public IRemoteConnection getConnection() {
175 return fSelectedConnection;
176 }
177
178 /**
179 * Return the location for the project.
180 *
181 * @return String
182 */
183 public String getProjectLocation() {
184 return fLocationText.getText();
185 }
186
187 /**
188 * Get the URI for the location field if possible.
189 *
190 * @return URI or <code>null</code> if it is not valid.
191 */
192 public URI getProjectLocationURI() {
193 if (fSelectedConnection == null)
194 return null;
195 return fSelectedConnection.getRemoteServices().getFileManager(fSelectedConnection).toURI(fLocationText.getText());
196 }
197
198 public IRemoteConnection getRemoteConnection() {
199 return fSelectedConnection;
200 }
201
202 public IRemoteServices getRemoteServices() {
203 if (fSelectedConnection != null)
204 return fSelectedConnection.getRemoteServices();
205 return null;
206 }
207
208 /**
209 * Return whether or not we are currently showing the default location for
210 * the project.
211 *
212 * @return boolean
213 */
214 public boolean isDefault() {
215 // return useDefaultsButton.getSelection();
216 return false;
217 }
218
219 /**
220 * Set the project to base the contents off of.
221 *
222 * @param existingProject
223 */
224 public void setExistingProject(IProject existingProject) {
225 fProjectName = existingProject.getName();
226 fExistingProject = existingProject;
227 }
228
229 /**
230 * Set the text to the default or clear it if not using the defaults.
231 *
232 * @param newName
233 * the name of the project to use. If <code>null</code> use the
234 * existing project name.
235 */
236 public void updateProjectName(String newName) {
237 fProjectName = newName;
238 if (isDefault()) {
239 fLocationText.setText(getDefaultPathDisplayString());
240 }
241
242 }
243
244 /**
245 * Attempt to open a connection.
246 */
247 private void checkConnection() {
248 IRemoteUIConnectionManager mgr = getUIConnectionManager();
249 if (mgr != null) {
250 mgr.openConnectionWithProgress(fRemoteConnectionWidget.getShell(), fContext, fSelectedConnection);
251 }
252 }
253
254 /**
255 * Return the path we are going to display. If it is a file URI then remove
256 * the file prefix.
257 *
258 * Only do this if the connection is open. Otherwise we will attempt to
259 * connect to the first machine in the list, which is annoying.
260 *
261 * @return String
262 */
263 private String getDefaultPathDisplayString() {
264 if (getRemoteConnection() != null && getRemoteConnection().isOpen()) {
265 IRemoteFileManager fileMgr = fSelectedConnection.getRemoteServices().getFileManager(getRemoteConnection());
266 URI defaultURI = fileMgr.toURI(getRemoteConnection().getWorkingDirectory());
267
268 // Handle files specially. Assume a file if there is no project to
269 // query
270 if (defaultURI != null && defaultURI.getScheme().equals(FILE_SCHEME)) {
271 return Platform.getLocation().append(fProjectName).toOSString();
272 }
273 if (defaultURI == null) {
274 return ""; //$NON-NLS-1$
275 }
276 return new Path(defaultURI.getPath()).append(fProjectName).toOSString();
277 }
278 return ""; //$NON-NLS-1$
279 }
280
281 /**
282 * @return
283 */
284 private IRemoteUIConnectionManager getUIConnectionManager() {
285 IRemoteUIConnectionManager connectionManager = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices())
286 .getUIConnectionManager();
287 return connectionManager;
288 }
289
290 private void handleConnectionSelected() {
291 fSelectedConnection = fRemoteConnectionWidget.getConnection();
292 fLocationText.setText(getDefaultPathDisplayString());
293 }
294
295 protected Control createContents(Composite parent) {
296 Group container = new Group(parent, SWT.SHADOW_ETCHED_IN);
297
298 GridLayout layout = new GridLayout();
299 layout.numColumns = 3;
300 container.setLayout(layout);
301 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
302 container.setLayoutData(gd);
303
304 fRemoteConnectionWidget = new RemoteConnectionWidget(container, SWT.NONE, null, RemoteConnectionWidget.FLAG_FORCE_PROVIDER_SELECTION, null);
305 gd = new GridData();
306 gd.horizontalSpan = 3;
307 fRemoteConnectionWidget.setLayoutData(gd);
308 fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() {
309 @Override
310 public void widgetSelected(SelectionEvent e) {
311 handleConnectionSelected();
312 }
313 });
314
315 Label locationLabel = new Label(container, SWT.LEFT);
316 locationLabel.setText(Messages.getString("RemoteProjectContentsLocationArea.3")); //$NON-NLS-1$
317
318 fLocationText = new Text(container, SWT.SINGLE | SWT.BORDER);
319 gd = new GridData(GridData.FILL_HORIZONTAL);
320 gd.horizontalSpan = 1;
321 gd.grabExcessHorizontalSpace = true;
322 gd.widthHint = 250;
323 fLocationText.setLayoutData(gd);
324 fLocationText.addModifyListener(new ModifyListener() {
325 public void modifyText(ModifyEvent e) {
326 fErrorReporter.reportError(checkValidLocation(), false);
327 }
328 });
329
330 // new connection button
331 fBrowseButton = new Button(container, SWT.PUSH);
332 fBrowseButton.setText(Messages.getString("RemoteProjectContentsLocationArea.4")); //$NON-NLS-1$
333 fBrowseButton.addSelectionListener(new SelectionAdapter() {
334 @Override
335 public void widgetSelected(SelectionEvent e) {
336 if (fSelectedConnection != null) {
337 checkConnection();
338 if (fSelectedConnection.isOpen()) {
339 IRemoteUIServices remoteUIServices = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices());
340 if (remoteUIServices != null) {
341 IRemoteUIFileManager fileMgr = remoteUIServices.getUIFileManager();
342 if (fileMgr != null) {
343 fileMgr.setConnection(fSelectedConnection);
344 String correctPath = fLocationText.getText();
345 String selectedPath = fileMgr.browseDirectory(
346 fLocationText.getShell(),
347 Messages.getString("RemoteProjectContentsLocationArea.5", fSelectedConnection.getName()), correctPath, IRemoteUIConstants.NONE); //$NON-NLS-1$
348 if (selectedPath != null) {
349 fLocationText.setText(selectedPath);
350 }
351 }
352 }
353 }
354 }
355 }
356 });
357
358 return container;
359 }
360
361 /*
362 * (non-Javadoc)
363 *
364 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
365 */
366 protected void okPressed() {
367 // set the connection
368 //fProvider.setRemoteToolsConnection(fSelectedConnection);
369
370 }
371}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
new file mode 100644
index 0000000..f64401c
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -0,0 +1,213 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards.install;
13
14import java.io.BufferedReader;
15import java.io.File;
16import java.io.IOException;
17import java.io.InputStreamReader;
18import java.io.Writer;
19import java.lang.reflect.InvocationTargetException;
20import java.net.URI;
21import java.util.Hashtable;
22import java.util.Map;
23import java.util.regex.Matcher;
24import java.util.regex.Pattern;
25
26import org.eclipse.core.runtime.IProgressMonitor;
27import org.eclipse.core.runtime.IStatus;
28import org.eclipse.core.runtime.Status;
29import org.eclipse.jface.operation.IRunnableWithProgress;
30import org.eclipse.jface.viewers.IStructuredSelection;
31import org.eclipse.jface.wizard.IWizardContainer;
32import org.eclipse.jface.wizard.WizardPage;
33import org.eclipse.ptp.remote.core.IRemoteConnection;
34import org.eclipse.ptp.remote.core.IRemoteServices;
35import org.eclipse.rse.core.model.IHost;
36import org.eclipse.ui.IWorkbench;
37import org.eclipse.ui.IWorkbenchPage;
38import org.eclipse.ui.IWorkbenchWindow;
39import org.eclipse.ui.IWorkbenchWizard;
40import org.eclipse.ui.PlatformUI;
41import org.eclipse.ui.console.ConsolePlugin;
42import org.eclipse.ui.console.IConsole;
43import org.eclipse.ui.console.IConsoleConstants;
44import org.eclipse.ui.console.IConsoleManager;
45import org.eclipse.ui.console.IConsoleView;
46import org.eclipse.ui.console.MessageConsole;
47import org.eclipse.ui.console.MessageConsoleStream;
48import org.yocto.bc.remote.utils.YoctoRunnableWithProgress;
49import org.yocto.bc.ui.Activator;
50import org.yocto.bc.ui.model.ProjectInfo;
51import org.yocto.bc.ui.wizards.FiniteStateWizard;
52import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;
53import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
54import org.yocto.remote.utils.CommandResponseHandler;
55import org.yocto.remote.utils.ICommandResponseHandler;
56import org.yocto.remote.utils.RemoteHelper;
57import org.yocto.remote.utils.YoctoCommand;
58import org.yocto.bc.remote.utils.ConsoleWriter;
59
60/**
61 * A wizard for installing a fresh copy of an OE system.
62 *
63 * @author kgilmer
64 *
65 * A Wizard for creating a fresh Yocto bitbake project and new poky build tree from git
66 *
67 * @modified jzhang
68 *
69 */
70public class InstallWizard extends FiniteStateWizard implements
71 IWorkbenchWizard {
72
73 static final String KEY_PINFO = "KEY_PINFO";
74 protected static final String OPTION_MAP = "OPTION_MAP";
75 protected static final String INSTALL_SCRIPT = "INSTALL_SCRIPT";
76 protected static final String INSTALL_DIRECTORY = "Install Directory";
77 protected static final String INIT_SCRIPT = "Init Script";
78
79 protected static final String SELECTED_CONNECTION = "SEL_CONNECTION";
80 protected static final String SELECTED_REMOTE_SERVICE = "SEL_REMOTE_SERVICE";
81
82 protected static final String PROJECT_NAME = "Project Name";
83 protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
84 protected static final String DEFAULT_INSTALL_DIR = "~/yocto";
85
86 protected static final String GIT_CLONE = "Git Clone";
87 public static final String VALIDATION_FILE = DEFAULT_INIT_SCRIPT;
88
89 private Map model;
90 private MessageConsole myConsole;
91 private OptionsPage optionsPage;
92
93 public InstallWizard() {
94 this.model = new Hashtable();
95 model.put(INSTALL_DIRECTORY, DEFAULT_INSTALL_DIR);
96 model.put(INIT_SCRIPT, DEFAULT_INIT_SCRIPT);
97
98 setWindowTitle("Yocto Project BitBake Commander");
99 setNeedsProgressMonitor(true);
100 }
101
102
103
104 public InstallWizard(IStructuredSelection selection) {
105 model = new Hashtable();
106 }
107
108 /*
109 * @Override public IWizardPage getNextPage(IWizardPage page) { if (page
110 * instanceof WelcomePage) { if (model.containsKey(WelcomePage.ACTION_USE))
111 * { return bbcProjectPage; } } else if (page instanceof ProgressPage) {
112 * return bitbakePage; }
113 *
114 * if (super.getNextPage(page) != null) { System.out.println("next page: " +
115 * super.getNextPage(page).getClass().getName()); } else {
116 * System.out.println("end page"); }
117 *
118 * return super.getNextPage(page); }
119 *
120 * @Override public boolean canFinish() { System.out.println("can finish: "
121 * + super.canFinish()); return super.canFinish(); }
122 */
123 @Override
124 public void addPages() {
125 optionsPage = new OptionsPage(model);
126 addPage(optionsPage);
127 }
128
129 @Override
130 public Map getModel() {
131 return model;
132 }
133
134 @Override
135 public boolean performFinish() {
136 WizardPage page = (WizardPage) getPage("Options");
137 page.setPageComplete(true);
138 Map<String, Object> options = model;
139
140 try {
141 URI uri = new URI("");
142 if (options.containsKey(INSTALL_DIRECTORY)) {
143 uri = (URI) options.get(INSTALL_DIRECTORY);
144 }
145 IRemoteConnection remoteConnection = ((IRemoteConnection)model.get(InstallWizard.SELECTED_CONNECTION));
146 IRemoteServices remoteServices = ((IRemoteServices)model.get(InstallWizard.SELECTED_REMOTE_SERVICE));
147 IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName());
148 CommandResponseHandler cmdHandler = new CommandResponseHandler(RemoteHelper.getConsole(connection));
149 IWizardContainer container = this.getContainer();
150 if (((Boolean)options.get(GIT_CLONE)).booleanValue()) {
151 String cmd = "git clone --progress git://git.yoctoproject.org/poky.git " + uri.getPath();
152 String taskName = "Checking out Yocto git repository";
153
154 YoctoRunnableWithProgress adapter = new YoctoRunnableWithProgress(new YoctoCommand(cmd, "", ""));
155
156 adapter.setRemoteConnection(remoteConnection);
157 adapter.setRemoteServices(remoteServices);
158 adapter.setTaskName(taskName);
159 try {
160 container.run(true, true, adapter);
161 } catch (InvocationTargetException e) {
162 e.printStackTrace();
163 } catch (InterruptedException e) {
164 e.printStackTrace();
165 }
166 }
167 if (!cmdHandler.hasError()) {
168 String initPath = "";
169 if (uri.getPath() != null) {
170 initPath = uri.getPath() + "/" + (String) options.get(INIT_SCRIPT);
171 } else {
172 initPath = uri.getFragment() + "/" + (String) options.get(INIT_SCRIPT);
173 }
174 String prjName = (String) options.get(PROJECT_NAME);
175 ProjectInfo pinfo = new ProjectInfo();
176 pinfo.setInitScriptPath(initPath);
177 pinfo.setLocationURI(uri);
178 pinfo.setName(prjName);
179 pinfo.setConnection(connection);
180 pinfo.setRemoteServices(remoteServices);
181
182 final ConsoleWriter cw = new ConsoleWriter();
183 BBConfigurationInitializeOperation configInitOp = new BBConfigurationInitializeOperation(pinfo, null);
184 container.run(false, false, configInitOp);
185 myConsole = RemoteHelper.getConsole(connection);
186 myConsole.newMessageStream().println(cw.getContents());
187
188 if (configInitOp.hasErrorOccured()) {
189 optionsPage.setErrorMessage(configInitOp.getErrorMessage());
190 return false;
191 }
192
193 model.put(InstallWizard.KEY_PINFO, pinfo);
194 Activator.putProjInfo(pinfo.getOEFSURI(), pinfo);
195
196 container.run(false, false, new CreateBBCProjectOperation(pinfo));
197 RemoteHelper.storeURIInMetaArea(pinfo.getProjectName(), uri);
198 RemoteHelper.storeProjDescrInMetaArea(pinfo.getConnection(), pinfo.getProjectName(), pinfo.getOriginalURI().getPath());
199 return true;
200 }
201 } catch (Exception e) {
202 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
203 IStatus.ERROR, e.getMessage(), e));
204 this.getContainer().getCurrentPage().setDescription(
205 "Failed to create project: " + e.getMessage());
206 }
207 return false;
208 }
209
210 public void init(IWorkbench workbench, IStructuredSelection selection) {
211 }
212
213}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java
new file mode 100644
index 0000000..75d9f99
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java
@@ -0,0 +1,327 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards.install;
13
14import java.io.IOException;
15import java.io.File;
16import java.net.URI;
17import java.net.URISyntaxException;
18import java.util.ArrayList;
19import java.util.Hashtable;
20import java.util.Iterator;
21import java.util.List;
22import java.util.Map;
23import java.util.regex.Matcher;
24import java.util.regex.Pattern;
25
26import org.eclipse.core.resources.IProject;
27import org.eclipse.core.resources.IProjectDescription;
28import org.eclipse.core.resources.IResource;
29import org.eclipse.core.resources.IWorkspaceRoot;
30import org.eclipse.core.resources.ResourcesPlugin;
31import org.eclipse.core.runtime.CoreException;
32import org.eclipse.core.runtime.IStatus;
33import org.eclipse.core.runtime.NullProgressMonitor;
34import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea;
35import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea.IErrorMessageReporter;
36import org.eclipse.ptp.remote.core.IRemoteConnection;
37import org.eclipse.ptp.internal.remote.rse.core.RSEConnection;
38import org.eclipse.rse.core.model.IHost;
39import org.eclipse.rse.services.files.IFileService;
40import org.eclipse.rse.services.files.IHostFile;
41import org.eclipse.swt.SWT;
42import org.eclipse.swt.events.SelectionAdapter;
43import org.eclipse.swt.events.SelectionEvent;
44import org.eclipse.swt.layout.GridData;
45import org.eclipse.swt.layout.GridLayout;
46import org.eclipse.swt.widgets.Button;
47import org.eclipse.swt.widgets.Composite;
48import org.eclipse.swt.widgets.Control;
49import org.eclipse.swt.widgets.DirectoryDialog;
50import org.eclipse.swt.widgets.FileDialog;
51import org.eclipse.swt.widgets.Label;
52import org.eclipse.swt.widgets.Text;
53import org.eclipse.ui.PlatformUI;
54
55import org.yocto.bc.ui.wizards.FiniteStateWizard;
56import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
57import org.yocto.bc.ui.wizards.FiniteStateWizardPage.ValidationListener;
58import org.yocto.remote.utils.RemoteHelper;
59
60/**
61 * Select which flavor of OE is to be installed.
62 *
63 * @author kgilmer
64 *
65 * Setting up the parameters for creating the new Yocto Bitbake project
66 *
67 * @modified jzhang
68 */
69public class OptionsPage extends FiniteStateWizardPage {
70
71 public static final String URI_SEPARATOR = "/";
72 public static final String LOCALHOST = "LOCALHOST";
73
74 private Composite top;
75
76 private RemoteProjectContentsLocationArea locationArea;
77
78 private ValidationListener validationListener;
79 private Text txtProjectName;
80 private Button btnGit;
81
82 protected OptionsPage(Map model) {
83 super("Options", model);
84 //setTitle("Create new yocto bitbake project");
85 setMessage("Enter these parameters to create new Yocto Project BitBake commander project");
86 }
87
88 @Override
89 public void createControl(Composite parent) {
90 top = new Composite(parent, SWT.None);
91 top.setLayout(new GridLayout());
92 top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
93
94 GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL);
95
96 Composite projectNameComp = new Composite(top, SWT.NONE);
97 GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL);
98 projectNameComp.setLayoutData(gdProjName);
99 projectNameComp.setLayout(new GridLayout(2, false));
100 Label lblProjectName = new Label(projectNameComp, SWT.NONE);
101 lblProjectName.setText("Project N&ame:");
102
103 txtProjectName = new Text(projectNameComp, SWT.BORDER);
104 txtProjectName.setLayoutData(gdFillH);
105 txtProjectName.setFocus();
106 validationListener = new ValidationListener();
107
108 txtProjectName.addModifyListener(validationListener);
109
110 IErrorMessageReporter errorReporter = new IErrorMessageReporter() {
111
112 @Override
113 public void reportError(String errorMessage, boolean infoOnly) {
114 setMessage(errorMessage);
115 if (validatePage()) {
116 updateModel();
117 setPageComplete(true);
118 return;
119 }
120
121 setPageComplete(false);
122 }
123 };
124
125 locationArea = new RemoteProjectContentsLocationArea(errorReporter, top, null);
126
127 btnGit = new Button(top, SWT.CHECK);
128 btnGit.setText("Clone from Yocto Project &Git Repository into new location");
129 btnGit.setEnabled(true);
130 btnGit.setSelection(true);
131 btnGit.addSelectionListener(validationListener);
132 GridData gd = new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_HORIZONTAL);
133 btnGit.setLayoutData(gd);
134
135 setControl(top);
136 }
137
138 @Override
139 public void pageCleanup() {
140
141 }
142
143 @Override
144 public void pageDisplay() {
145 }
146
147 @Override
148
149 protected void updateModel() {
150 try {
151 URI uri = getProjectLocationURI();
152 if (uri != null)
153 model.put(InstallWizard.INSTALL_DIRECTORY, getProjectLocationURI());
154 } catch (Exception e){
155 e.printStackTrace();
156 }
157 model.put(InstallWizard.PROJECT_NAME, txtProjectName.getText());
158 model.put(InstallWizard.GIT_CLONE, new Boolean(btnGit.getSelection()));
159 model.put(InstallWizard.SELECTED_CONNECTION, locationArea.getRemoteConnection());
160 model.put(InstallWizard.SELECTED_REMOTE_SERVICE, locationArea.getRemoteServices());
161 }
162
163 public URI getProjectLocationURI() throws URISyntaxException {
164 URI uri = locationArea.getProjectLocationURI();
165
166 if (uri != null) {
167 String location = locationArea.getProjectLocation();
168 if (!uri.getPath().isEmpty()) {
169 String separator = uri.getPath().endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR;
170
171 return new URI( uri.getScheme(),
172 uri.getHost(),
173 uri.getPath() + separator + txtProjectName.getText(),
174 uri.getFragment());
175 } else {
176 return null;
177 }
178 } else {
179 String location = locationArea.getProjectLocation();
180 String separator = location.endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR;
181
182 IRemoteConnection conn = locationArea.getConnection();
183 if (conn instanceof RSEConnection) {
184 RSEConnection rseConn = (RSEConnection)conn;
185 return new URI("rse", rseConn.getHost().getHostName(), location);
186 } else {
187 return new URI( "file", location + separator + txtProjectName.getText(),"");
188 }
189 }
190 }
191
192 private boolean isValidProjectName(String projectName) {
193 if (projectName.indexOf('$') > -1) {
194 return false;
195 }
196
197 return true;
198 }
199
200 private boolean validateProjectName() {
201 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
202
203 IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT);
204
205 if (txtProjectName.getText().trim().isEmpty()) {
206 setErrorMessage("Project name cannot be empty!");
207 return false;
208 }
209
210 if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) {
211 setErrorMessage("Invalid project name: " + txtProjectName.getText());
212 return false;
213 }
214
215 IProject proj = wsroot.getProject(txtProjectName.getText());
216 if (proj.exists()) {
217 setErrorMessage("A project with the name " + txtProjectName.getText() + " already exists");
218 return false;
219 }
220 return true;
221 }
222 private String convertToRealPath(String path) {
223 String patternStr = File.separator + File.separator;
224 if (patternStr.equals(URI_SEPARATOR))
225 return path;
226 String replaceStr = URI_SEPARATOR;
227 String convertedpath;
228
229 //Compile regular expression
230 Pattern pattern = Pattern.compile(patternStr); //pattern to look for
231
232 //replace all occurance of percentage character to file separator
233 Matcher matcher = pattern.matcher(path);
234 convertedpath = matcher.replaceAll(replaceStr);
235
236 return convertedpath;
237 }
238
239 public String getProjectName(){
240 return txtProjectName.getText().trim();
241 }
242
243 protected boolean validateProjectLocation() {
244
245 String projectLoc = locationArea.getProjectLocation().trim();
246
247 IRemoteConnection remoteConnection = locationArea.getRemoteConnection();
248 if (remoteConnection == null)
249 return false;
250
251 if (projectLoc.isEmpty())
252 return true;
253
254 IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName());
255
256 projectLoc = convertToRealPath(projectLoc);
257 String separator = projectLoc.endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR;
258 String projectPath = projectLoc + separator + getProjectName();
259 IHostFile repoDest = RemoteHelper.getRemoteHostFile(connection, projectPath, new NullProgressMonitor());
260
261 if(!btnGit.getSelection()) {
262 if (repoDest == null || !repoDest.exists()) {
263 setErrorMessage("Directory " + projectPath + " does not exist, please select git clone.");
264 return false;
265 }
266
267 IHostFile validationFile = RemoteHelper.getRemoteHostFile(connection, projectPath + URI_SEPARATOR + InstallWizard.VALIDATION_FILE, new NullProgressMonitor());
268 if (validationFile == null || !validationFile.exists()) {
269 setErrorMessage("Directory " + projectPath + " seems invalid, please use other directory or project name.");
270 return false;
271 }
272 } else { //git clone
273 if (repoDest != null && repoDest.exists() && repoDest.isDirectory()) {
274 IHostFile[] hostFiles = RemoteHelper.getRemoteDirContent(connection, repoDest.getAbsolutePath(), "", IFileService.FILE_TYPE_FILES_AND_FOLDERS, new NullProgressMonitor());
275 if (hostFiles.length != 0) {
276 setErrorMessage("Directory " + projectPath + " is not empty, please choose another location.");
277 return false;
278 }
279 IHostFile gitDescr = RemoteHelper.getRemoteHostFile(connection, projectPath + "/.git", new NullProgressMonitor());
280 if (gitDescr != null && gitDescr.exists()) {
281 setErrorMessage("Directory " + projectPath + " contains a repository, please choose another location or skip cloning the repository.");
282 return false;
283 }
284 }
285 }
286
287 try {
288 String projName = txtProjectName.getText();
289 if (!projName.trim().isEmpty() && validateProjectName()) {
290 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
291 IProject proj = wsroot.getProject();
292 if (proj != null && proj.exists()) {
293 setErrorMessage("A project with the name " + projName + " already exists");
294 return false;
295 }
296 URI location = new URI("file:" + URI_SEPARATOR + URI_SEPARATOR + convertToRealPath(projectLoc) + URI_SEPARATOR + txtProjectName.getText());
297
298 IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocationURI(proj, location);
299 if (!status.isOK()) {
300 setErrorMessage(status.getMessage());
301 return false;
302 }
303 }
304 } catch (Exception e) {
305 e.printStackTrace();
306 setErrorMessage("Run into error while trying to validate entries!");
307 return false;
308 }
309
310 setErrorMessage(null);
311 return true;
312 }
313 @Override
314 protected boolean validatePage() {
315 if (!validateProjectName())
316 return false;
317
318 if (!validateProjectLocation())
319 return false;
320
321 setErrorMessage(null);
322 setMessage("All the entries are valid, press \"Finish\" to start the process, "+
323 "this will take a while. Please don't interrupt till there's output in the Yocto Console window...");
324 return true;
325 }
326
327}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java
new file mode 100644
index 0000000..c44b7b5
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java
@@ -0,0 +1,69 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards.newproject;
13
14import java.io.Writer;
15import java.lang.reflect.InvocationTargetException;
16
17import org.eclipse.core.runtime.IProgressMonitor;
18import org.eclipse.jface.operation.IRunnableWithProgress;
19
20import org.yocto.bc.bitbake.BBSession;
21import org.yocto.bc.bitbake.ProjectInfoHelper;
22import org.yocto.bc.ui.Activator;
23import org.yocto.bc.ui.model.ProjectInfo;
24import org.yocto.remote.utils.RemoteHelper;
25
26public class BBConfigurationInitializeOperation implements IRunnableWithProgress {
27
28 private final ProjectInfo pinfo;
29 private final Writer writer;
30 private boolean errorOccured = false;
31 private String errorMessage = "";
32
33 public BBConfigurationInitializeOperation(ProjectInfo pinfo) {
34 this.pinfo = pinfo;
35 writer = null;
36 }
37 public boolean hasErrorOccured() {
38 return errorOccured;
39 }
40 public BBConfigurationInitializeOperation(ProjectInfo pinfo, Writer writer) {
41 this.pinfo = pinfo;
42 this.writer = writer;
43 }
44
45 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
46 BBSession session;
47 try {
48 System.out.println("Initialize bitbake session ...");
49 monitor.beginTask("Initialize bitbake session ...", RemoteHelper.TOTALWORKLOAD);
50 session = Activator.getBBSession(pinfo, writer, monitor);
51 session.initialize();
52 monitor.worked(90);
53 monitor.done();
54 errorOccured = session.hasErrorOccured();
55 errorMessage = session.getErrorLines();
56 if (!errorOccured) {
57 System.out.println("Bitbake session initialized successfully.");
58 errorMessage = "";
59 } else
60 System.out.println("An error occured and Bitbake session was not initialized.");
61 } catch (Exception e) {
62 throw new InvocationTargetException(e);
63 }
64 }
65
66 public String getErrorMessage() {
67 return errorMessage;
68 }
69}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java
new file mode 100644
index 0000000..54f16c3
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java
@@ -0,0 +1,93 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, 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 * Ken Gilmer - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards.newproject;
13
14import java.io.IOException;
15import java.lang.reflect.InvocationTargetException;
16import java.net.URI;
17import java.net.URISyntaxException;
18import java.util.Arrays;
19import java.util.Vector;
20
21import org.eclipse.core.resources.IProject;
22import org.eclipse.core.resources.IProjectDescription;
23import org.eclipse.core.resources.IWorkspace;
24import org.eclipse.core.resources.IWorkspaceRoot;
25import org.eclipse.core.resources.ResourcesPlugin;
26import org.eclipse.core.runtime.CoreException;
27import org.eclipse.core.runtime.IProgressMonitor;
28import org.eclipse.core.runtime.IStatus;
29import org.eclipse.core.runtime.QualifiedName;
30import org.eclipse.core.runtime.Status;
31import org.eclipse.ui.actions.WorkspaceModifyOperation;
32
33import org.yocto.bc.bitbake.ProjectInfoHelper;
34import org.yocto.bc.ui.Activator;
35import org.yocto.bc.ui.builder.BitbakeCommanderNature;
36import org.yocto.bc.ui.model.ProjectInfo;
37
38
39/**
40 * Creates a bbc project
41 * @author kgilmer
42 *
43 */
44public class CreateBBCProjectOperation extends WorkspaceModifyOperation {
45
46 public static final String OEFS_SCHEME = "OEFS://";
47 public static final QualifiedName BBC_PROJECT_INIT = new QualifiedName(null, "BBC_PROJECT_INIT");
48 public static void addNatureToProject(IProject proj, String nature_id, IProgressMonitor monitor) throws CoreException {
49 IProjectDescription desc = proj.getDescription();
50 Vector natureIds = new Vector();
51
52 natureIds.add(nature_id);
53 natureIds.addAll(Arrays.asList(desc.getNatureIds()));
54 desc.setNatureIds((String[]) natureIds.toArray(new String[natureIds.size()]));
55
56 proj.setDescription(desc, monitor);
57 }
58
59 private ProjectInfo projInfo;
60
61 public CreateBBCProjectOperation(ProjectInfo projInfo) {
62 this.projInfo = projInfo;
63 }
64
65 protected void addNatures(IProject proj, IProgressMonitor monitor) throws CoreException {
66 addNatureToProject(proj, BitbakeCommanderNature.NATURE_ID, monitor);
67 }
68
69 private IProjectDescription createProjectDescription(IWorkspace workspace, ProjectInfo projInfo) throws CoreException {
70 IProjectDescription desc = workspace.newProjectDescription(projInfo.getProjectName());
71
72 desc.setLocationURI(projInfo.getOEFSURI());
73 return desc;
74 }
75
76 @Override
77 protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
78 IProjectDescription desc = createProjectDescription(ResourcesPlugin.getWorkspace(), projInfo);
79
80 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
81
82 IProject proj = wsroot.getProject(projInfo.getProjectName());
83 proj.create(desc, monitor);
84
85 proj.open(monitor);
86
87 addNatures(proj, monitor);
88 }
89
90 public ProjectInfo getProjectInfo() {
91 return projInfo;
92 }
93}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java
new file mode 100644
index 0000000..810a014
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java
@@ -0,0 +1,262 @@
1package org.yocto.bc.ui.wizards.variable;
2
3import java.util.Comparator;
4import java.util.Map;
5
6import org.eclipse.jface.viewers.ILabelProviderListener;
7import org.eclipse.jface.viewers.IStructuredContentProvider;
8import org.eclipse.jface.viewers.ITableLabelProvider;
9import org.eclipse.jface.viewers.TableViewer;
10import org.eclipse.jface.viewers.Viewer;
11import org.eclipse.jface.viewers.ViewerFilter;
12import org.eclipse.jface.viewers.ViewerSorter;
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.events.SelectionAdapter;
15import org.eclipse.swt.events.SelectionEvent;
16import org.eclipse.swt.graphics.Image;
17import org.eclipse.swt.layout.GridData;
18import org.eclipse.swt.layout.GridLayout;
19import org.eclipse.swt.widgets.Composite;
20import org.eclipse.swt.widgets.Table;
21import org.eclipse.swt.widgets.TableColumn;
22import org.eclipse.swt.widgets.Text;
23
24import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
25
26/**
27 * The wizard page for the Variable Wizard.
28 * @author kgilmer
29 *
30 */
31public class VariablePage extends FiniteStateWizardPage {
32
33 private Text txtName;
34 private Text txtValue;
35 private TableViewer viewer;
36 private TableColumn c1;
37 private TableColumn c2;
38
39 protected VariablePage(Map model) {
40 super("Yocto Project BitBake Commander", model);
41 setTitle("Yocto Project BitBake Variable Viewer");
42 setDescription("Sort and fitler global BitBake variables by name or value.");
43 }
44
45 @Override
46 public void createControl(Composite parent) {
47 Composite top = new Composite(parent, SWT.None);
48 top.setLayout(new GridLayout(2, true));
49 top.setLayoutData(new GridData(GridData.FILL_BOTH));
50
51 ValidationListener listener = new ValidationListener();
52
53 txtName = new Text(top, SWT.BORDER);
54 txtName.addModifyListener(listener);
55 txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
56
57 txtValue = new Text(top, SWT.BORDER);
58 txtValue.addModifyListener(listener);
59 txtValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
60
61 viewer = new TableViewer(top);
62
63 Table table = viewer.getTable();
64 table.setLinesVisible(true);
65 table.setHeaderVisible(true);
66 GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
67 data.heightHint = 200;
68 data.horizontalSpan = 2;
69 table.setLayoutData(data);
70 c1 = new TableColumn(table, SWT.NONE);
71 c1.setText("Name");
72 c1.setWidth(200);
73 c1.addSelectionListener(new SelectionAdapter() {
74 public void widgetSelected(SelectionEvent event) {
75 ((VariableViewerSorter) viewer.getSorter()).doSort(0);
76 viewer.refresh();
77 }
78 });
79
80 c2 = new TableColumn(table, SWT.NONE);
81 c2.setText("Value");
82 c2.setWidth(200);
83 c2.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent event) {
85 ((VariableViewerSorter) viewer.getSorter()).doSort(1);
86 viewer.refresh();
87 }
88 });
89
90 viewer.setContentProvider(new VariableContentProvider());
91 viewer.setLabelProvider(new VariableLabelProvider());
92 viewer.setSorter(new VariableViewerSorter());
93
94 viewer.setFilters(new ViewerFilter[] {new MapViewerFilter()});
95 setControl(top);
96 }
97
98 @Override
99 public void pageCleanup() {
100
101 }
102
103 @Override
104 public void pageDisplay() {
105 viewer.setInput(model);
106 }
107
108 @Override
109 protected void updateModel() {
110 viewer.refresh();
111 }
112
113 @Override
114 protected boolean validatePage() {
115 return true;
116 }
117
118 /**
119 * A content provider for the variable wizard dialog.
120 * @author kgilmer
121 *
122 */
123 private class VariableContentProvider implements IStructuredContentProvider {
124
125 public Object[] getElements(Object inputElement) {
126 return model.keySet().toArray();
127 }
128
129 public void dispose() {
130
131 }
132
133 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
134
135 }
136 }
137
138 /**
139 * A label provider for variable wizard dialog.
140 * @author kgilmer
141 *
142 */
143 private class VariableLabelProvider implements ITableLabelProvider {
144
145 public Image getColumnImage(Object element, int columnIndex) {
146 return null;
147 }
148
149 public String getColumnText(Object element, int columnIndex) {
150 String val;
151
152 switch (columnIndex) {
153 case 0:
154 val = element.toString();
155 break;
156 case 1:
157 val = (String) model.get(element);
158 break;
159 default:
160 val = "";
161 break;
162 }
163
164 return val;
165 }
166
167 public void addListener(ILabelProviderListener listener) {
168
169 }
170
171 public void dispose() {
172
173 }
174
175 public boolean isLabelProperty(Object element, String property) {
176 return false;
177 }
178
179 public void removeListener(ILabelProviderListener listener) {
180
181 }
182
183 }
184
185 /**
186 *
187 * A tableviewer sorter found on the internet.
188 *
189 */
190 class VariableViewerSorter extends ViewerSorter {
191 private static final int ASCENDING = 0;
192
193 private static final int DESCENDING = 1;
194
195 private int column;
196
197 private int direction;
198
199 public void doSort(int column) {
200 if (column == this.column) {
201 // Same column as last sort; toggle the direction
202 direction = 1 - direction;
203 } else {
204 // New column; do an ascending sort
205 this.column = column;
206 direction = ASCENDING;
207 }
208 }
209
210 public int compare(Viewer viewer, Object e1, Object e2) {
211 int rc = 0;
212 Comparator c = this.getComparator();
213 // Determine which column and do the appropriate sort
214 switch (column) {
215 case 0:
216 rc = c.compare(e1, e2);
217 break;
218 case 1:
219 rc = c.compare(model.get(e1), model.get(e2));
220 break;
221 }
222
223 // If descending order, flip the direction
224 if (direction == DESCENDING)
225 rc = -rc;
226
227 return rc;
228 }
229 }
230
231 /**
232 * A filter for the name/value model.
233 * @author kgilmer
234 *
235 */
236 private class MapViewerFilter extends ViewerFilter {
237
238 public MapViewerFilter() {
239 }
240
241 @Override
242 public boolean select(Viewer viewer, Object parentElement, Object element) {
243 String keyFilter = txtName.getText();
244 String valFilter = txtValue.getText();
245
246 String elem = (String) element;
247 String val = (String) model.get(element);
248
249 if (keyFilter.length() > 0 && elem.indexOf(keyFilter) == -1 ) {
250 return false;
251 }
252
253 if (valFilter.length() > 0 && val.indexOf(valFilter) == -1 ) {
254 return false;
255 }
256
257 return true;
258 }
259
260 }
261
262}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java
new file mode 100644
index 0000000..d1bee1a
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java
@@ -0,0 +1,43 @@
1package org.yocto.bc.ui.wizards.variable;
2
3import java.util.Hashtable;
4import java.util.Map;
5
6import org.eclipse.jface.viewers.IStructuredSelection;
7
8import org.yocto.bc.ui.wizards.FiniteStateWizard;
9
10/**
11 * This wizard is used to view, filter, and search for BitBake variables and variable contents.
12 * @author kgilmer
13 *
14 */
15public class VariableWizard extends FiniteStateWizard {
16
17 private Map model;
18
19 public VariableWizard(Map model) {
20 this.model = model;
21 setWindowTitle("Yocto Project BitBake Commander");
22 }
23
24 public VariableWizard(IStructuredSelection selection) {
25 model = new Hashtable();
26 }
27
28 @Override
29 public void addPages() {
30 addPage(new VariablePage(model));
31 }
32
33 @Override
34 public Map getModel() {
35 return model;
36 }
37
38 @Override
39 public boolean performFinish() {
40 return true;
41 }
42
43}