From c7da892cb23d50d4d85746c9a0b6b14bf570989d Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 26 Jun 2014 13:23:09 +0200 Subject: initial commit for Enea Linux 4.0 Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau --- .../org/yocto/sdk/remotetools/YoctoJSONHelper.java | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.java (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/YoctoJSONHelper.java') 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 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * 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: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools; + +import java.io.IOException; +import java.io.FileWriter; +import java.util.Iterator; +import java.util.Set; +import java.util.HashSet; +import java.io.FileReader; + +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +public class YoctoJSONHelper { + private static final String PROPERTIES_FILE = "/tmp/properties.json"; + private static final String PROPERTY_VALUE_FILE = "/tmp/propertyvalues.json"; + + private static HashSet properties; + + public static HashSet getProperties() throws Exception { + + properties = new HashSet(); + try { + + JSONObject obj = (JSONObject)JSONValue.parse(new FileReader(PROPERTIES_FILE)); + Set keys = obj.keySet(); + if (!keys.isEmpty()) { + Iterator iter = keys.iterator(); + while (iter.hasNext()) { + String key = (String)iter.next(); + if (validKey(key)) { + JSONObject value_obj = (JSONObject)obj.get(key); + YoctoBspPropertyElement elem = new YoctoBspPropertyElement(); + elem.setName(key); + String type = (String)value_obj.get("type"); + elem.setType(type); + if (type.contentEquals("boolean")) { + elem.setDefaultValue((String)value_obj.get("default")); + } + properties.add(elem); + } + } + } + + } catch (Exception e) { + throw e; + } + return properties; + } + + public static void createBspJSONFile(HashSet properties) { + try { + JSONObject obj = new JSONObject(); + if (!properties.isEmpty()) { + Iterator it = properties.iterator(); + while (it.hasNext()) { + // Get property + YoctoBspPropertyElement propElem = (YoctoBspPropertyElement)it.next(); + obj.put(propElem.getName(), propElem.getValue()); + } + } + + FileWriter file = new FileWriter(PROPERTY_VALUE_FILE); + file.write(obj.toJSONString()); + file.flush(); + file.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static boolean validKey(String key) { + if (key.contains("kernel")) + return false; + if (key.contentEquals("qemuarch")) + return false; + return true; + } +} -- cgit v1.2.3-54-g00ecf