summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java105
1 files changed, 105 insertions, 0 deletions
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..25dac97
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java
@@ -0,0 +1,105 @@
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
13import java.io.BufferedReader;
14import java.io.File;
15import java.io.FileOutputStream;
16import java.io.FileReader;
17import java.io.IOException;
18
19import org.eclipse.core.resources.IProject;
20import org.eclipse.core.resources.ResourcesPlugin;
21
22import org.yocto.bc.ui.model.ProjectInfo;
23
24/**
25 * A helper class for ProjectInfo related tasks.
26 *
27 * @author kgilmer
28 *
29 */
30public class ProjectInfoHelper {
31
32 protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
33 /**
34 * @param path
35 * @return The path to bitbake init script
36 * @throws IOException
37 */
38 public static String getInitScriptPath(String path) throws IOException {
39 String val = path + File.separator + DEFAULT_INIT_SCRIPT;
40
41 File inFile = new File(path, ".eclipse-data");
42 if(inFile.exists()) {
43 BufferedReader br = new BufferedReader(new FileReader(inFile));
44 val = br.readLine();
45 br.close();
46 }
47
48 return val;
49 }
50
51 public static String getInitScript(String path) throws IOException {
52 File inFile = new File(path);
53 BufferedReader br = new BufferedReader(new FileReader(inFile));
54 StringBuffer sb = new StringBuffer();
55 String line = null;
56
57 while ((line = br.readLine()) != null) {
58 sb.append(line);
59 }
60
61 br.close();
62
63 return sb.toString();
64 }
65
66 public static String getProjectName(String projectRoot) {
67 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
68 for (int i = 0; i < projects.length; ++i) {
69 try {
70 if (projects[i].getLocationURI().getPath().equals(projectRoot)) {
71 return projects[i].getName();
72 }
73
74 } catch (Exception e) {
75 // TODO Auto-generated catch block
76 e.printStackTrace();
77 }
78 }
79
80 return null;
81 }
82
83 /**
84 * This method will store the path to the bitbake init script for future
85 * reference.
86 *
87 * @param path
88 * @param projInfo
89 * @throws IOException
90 */
91 public static void store(String path, ProjectInfo projInfo) throws IOException {
92 writeToFile(path, projInfo.getInitScriptPath());
93 }
94
95 private static void writeToFile(String path, String init) throws IOException {
96 File outFile = new File(path, ".eclipse-data");
97 FileOutputStream fos = new FileOutputStream(outFile);
98
99 fos.write(init.getBytes());
100
101 fos.flush();
102 fos.close();
103 }
104
105}