aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/bitbake/ProjectInfoHelper.java
diff options
context:
space:
mode:
authorKen Gilmer <kgilmer@gmail.com>2010-05-18 21:53:22 -0400
committerKen Gilmer <kgilmer@gmail.com>2010-05-18 21:53:22 -0400
commita7e84830627e50adac5c81ae4dad69aa350933fb (patch)
tree219aa86f4d5f03b29d7bc56f8cdba2702d67082c /org.openembedded.bc.ui/src/org/openembedded/bc/bitbake/ProjectInfoHelper.java
parente27a6dcce13930bfa711a6e72992597a8d1d07c5 (diff)
downloadeclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.tar.gz
eclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.tar.bz2
eclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.zip
org.openembedded.bc.ui: initial commit
Diffstat (limited to 'org.openembedded.bc.ui/src/org/openembedded/bc/bitbake/ProjectInfoHelper.java')
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/bitbake/ProjectInfoHelper.java102
1 files changed, 102 insertions, 0 deletions
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/bitbake/ProjectInfoHelper.java b/org.openembedded.bc.ui/src/org/openembedded/bc/bitbake/ProjectInfoHelper.java
new file mode 100644
index 0000000..37cc28b
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/bitbake/ProjectInfoHelper.java
@@ -0,0 +1,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();
+ }
+
+}