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
|
/*
* Copyright (c) 2008
* Embedded Brains GmbH
* Obere Lagerstr. 30
* D-82178 Puchheim
* Germany
* rtems@embedded-brains.de
*
* The license and distribution terms for this file may be found in the file
* LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
*/
package org.rtems.cdt;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;
import org.rtems.cdt.Activator;
public class Storage {
public static String getPristineProperty( IProject project, String key) {
String value = null;
try {
value = project.getPersistentProperty( new QualifiedName( "", key));
} catch (CoreException e) {
e.printStackTrace();
}
return value;
}
public static String getProperty( IProject project, String key) {
String value = getPristineProperty( project, key);
if (value == null) {
if (key.startsWith( Constants.TOOL_KEY_PREFIX)) {
reloadBSPInformation( project);
} else {
value = Activator.getDefault().getPreferenceStore().getString( key);
setProperty( project, key, value);
}
}
return value;
}
public static void setProperty( IProject project, String key, String value) {
try {
project.setPersistentProperty( new QualifiedName( "", key), value);
} catch (CoreException e) {
e.printStackTrace();
}
}
public static void reloadBSPInformation( IProject project) {
// Create make process builder
ProcessBuilder pb = new ProcessBuilder( "make");
// Prepend RTEMS base binary path to PATH environment variable
Map<String, String> env = pb.environment();
IPath binPath = new Path( getProperty( project, Constants.BASE_PATH_KEY)).append( "bin");
env.put( "PATH", binPath.toOSString() + Constants.PATH_SEPERATOR + env.get( "PATH"));
// Provide RTEMS_MAKEFILE_PATH environment variable
env.put( "RTEMS_MAKEFILE_PATH", getProperty( project, Constants.BSP_PATH_KEY));
// Change working directory to the Makefile location
pb.directory( Activator.getDefault().getMakefileLocation().toFile());
// Start make process and parse its output
try {
Process p = pb.start();
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader( new InputStreamReader( is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private Storage() {
// Do nothing
}
}
|