blob: 37cc28b234a4098e69532230304bf33475607a25 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*****************************************************************************
* Copyright (c) 2009 Ken Gilmer
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ken Gilmer - initial API and implementation
*******************************************************************************/
package org.openembedded.bc.bitbake;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.openembedded.bc.ui.model.ProjectInfo;
/**
* A helper class for ProjectInfo related tasks.
*
* @author kgilmer
*
*/
public class ProjectInfoHelper {
/**
* @param path
* @return The path to bitbake init script
* @throws IOException
*/
public static String getInitScriptPath(String path) throws IOException {
File inFile = new File(path, ".eclipse-data");
BufferedReader br = new BufferedReader(new FileReader(inFile));
String val = br.readLine();
br.close();
return val;
}
public static String getInitScript(String path) throws IOException {
File inFile = new File(path);
BufferedReader br = new BufferedReader(new FileReader(inFile));
StringBuffer sb = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
return sb.toString();
}
public static String getProjectName(String projectRoot) {
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (int i = 0; i < projects.length; ++i) {
try {
if (projects[i].getLocationURI().getPath().equals(projectRoot)) {
return projects[i].getName();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
/**
* This method will store the path to the bitbake init script for future
* reference.
*
* @param path
* @param projInfo
* @throws IOException
*/
public static void store(String path, ProjectInfo projInfo) throws IOException {
writeToFile(path, projInfo.getInitScriptPath());
}
private static void writeToFile(String path, String init) throws IOException {
File outFile = new File(path, ".eclipse-data");
FileOutputStream fos = new FileOutputStream(outFile);
fos.write(init.getBytes());
fos.flush();
fos.close();
}
}
|