diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ProjectInfoHelper.java | |
download | eclipse-poky-juno-41ac47d732eed8392d60d0f6773e5a279d49b999.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
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.java | 105 |
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.bitbake; | ||
12 | |||
13 | import java.io.BufferedReader; | ||
14 | import java.io.File; | ||
15 | import java.io.FileOutputStream; | ||
16 | import java.io.FileReader; | ||
17 | import java.io.IOException; | ||
18 | |||
19 | import org.eclipse.core.resources.IProject; | ||
20 | import org.eclipse.core.resources.ResourcesPlugin; | ||
21 | |||
22 | import org.yocto.bc.ui.model.ProjectInfo; | ||
23 | |||
24 | /** | ||
25 | * A helper class for ProjectInfo related tasks. | ||
26 | * | ||
27 | * @author kgilmer | ||
28 | * | ||
29 | */ | ||
30 | public 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 | } | ||