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.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.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.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.java new file mode 100644 index 0000000..37ce54d --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.java | |||
@@ -0,0 +1,89 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools; | ||
12 | |||
13 | import java.io.IOException; | ||
14 | import java.io.FileWriter; | ||
15 | import java.util.Iterator; | ||
16 | import java.util.Set; | ||
17 | import java.util.HashSet; | ||
18 | import java.io.FileReader; | ||
19 | |||
20 | import org.json.simple.JSONObject; | ||
21 | import org.json.simple.JSONValue; | ||
22 | |||
23 | public class YoctoJSONHelper { | ||
24 | private static final String PROPERTIES_FILE = "/tmp/properties.json"; | ||
25 | private static final String PROPERTY_VALUE_FILE = "/tmp/propertyvalues.json"; | ||
26 | |||
27 | private static HashSet<YoctoBspPropertyElement> properties; | ||
28 | |||
29 | public static HashSet<YoctoBspPropertyElement> getProperties() throws Exception { | ||
30 | |||
31 | properties = new HashSet<YoctoBspPropertyElement>(); | ||
32 | try { | ||
33 | |||
34 | JSONObject obj = (JSONObject)JSONValue.parse(new FileReader(PROPERTIES_FILE)); | ||
35 | Set<String> keys = obj.keySet(); | ||
36 | if (!keys.isEmpty()) { | ||
37 | Iterator<String> iter = keys.iterator(); | ||
38 | while (iter.hasNext()) { | ||
39 | String key = (String)iter.next(); | ||
40 | if (validKey(key)) { | ||
41 | JSONObject value_obj = (JSONObject)obj.get(key); | ||
42 | YoctoBspPropertyElement elem = new YoctoBspPropertyElement(); | ||
43 | elem.setName(key); | ||
44 | String type = (String)value_obj.get("type"); | ||
45 | elem.setType(type); | ||
46 | if (type.contentEquals("boolean")) { | ||
47 | elem.setDefaultValue((String)value_obj.get("default")); | ||
48 | } | ||
49 | properties.add(elem); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | } catch (Exception e) { | ||
55 | throw e; | ||
56 | } | ||
57 | return properties; | ||
58 | } | ||
59 | |||
60 | public static void createBspJSONFile(HashSet<YoctoBspPropertyElement> properties) { | ||
61 | try { | ||
62 | JSONObject obj = new JSONObject(); | ||
63 | if (!properties.isEmpty()) { | ||
64 | Iterator<YoctoBspPropertyElement> it = properties.iterator(); | ||
65 | while (it.hasNext()) { | ||
66 | // Get property | ||
67 | YoctoBspPropertyElement propElem = (YoctoBspPropertyElement)it.next(); | ||
68 | obj.put(propElem.getName(), propElem.getValue()); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | FileWriter file = new FileWriter(PROPERTY_VALUE_FILE); | ||
73 | file.write(obj.toJSONString()); | ||
74 | file.flush(); | ||
75 | file.close(); | ||
76 | |||
77 | } catch (IOException e) { | ||
78 | e.printStackTrace(); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | private static boolean validKey(String key) { | ||
83 | if (key.contains("kernel")) | ||
84 | return false; | ||
85 | if (key.contentEquals("qemuarch")) | ||
86 | return false; | ||
87 | return true; | ||
88 | } | ||
89 | } | ||