forked from Mirrors/flatpak-builder
builder: Make the builder manifest objects serializable to json
parent
f7b20fad85
commit
3fb4226c81
|
@ -411,6 +411,43 @@ builder_manifest_init (BuilderManifest *self)
|
|||
self->strip = TRUE;
|
||||
}
|
||||
|
||||
static JsonNode *
|
||||
builder_manifest_serialize_property (JsonSerializable *serializable,
|
||||
const gchar *property_name,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
if (strcmp (property_name, "modules") == 0)
|
||||
{
|
||||
BuilderManifest *self = BUILDER_MANIFEST (serializable);
|
||||
JsonNode *retval = NULL;
|
||||
GList *l;
|
||||
|
||||
if (self->modules)
|
||||
{
|
||||
JsonArray *array;
|
||||
|
||||
array = json_array_sized_new (g_list_length (self->modules));
|
||||
|
||||
for (l = self->modules; l != NULL; l = l->next)
|
||||
{
|
||||
JsonNode *child = json_gobject_serialize (l->data);
|
||||
json_array_add_element (array, child);
|
||||
}
|
||||
|
||||
retval = json_node_init_array (json_node_alloc (), array);
|
||||
json_array_unref (array);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else
|
||||
return json_serializable_default_serialize_property (serializable,
|
||||
property_name,
|
||||
value,
|
||||
pspec);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
builder_manifest_deserialize_property (JsonSerializable *serializable,
|
||||
const gchar *property_name,
|
||||
|
@ -469,6 +506,7 @@ builder_manifest_deserialize_property (JsonSerializable *serializable,
|
|||
static void
|
||||
serializable_iface_init (JsonSerializableIface *serializable_iface)
|
||||
{
|
||||
serializable_iface->serialize_property = builder_manifest_serialize_property;
|
||||
serializable_iface->deserialize_property = builder_manifest_deserialize_property;
|
||||
}
|
||||
|
||||
|
|
|
@ -357,6 +357,43 @@ builder_module_init (BuilderModule *self)
|
|||
{
|
||||
}
|
||||
|
||||
static JsonNode *
|
||||
builder_module_serialize_property (JsonSerializable *serializable,
|
||||
const gchar *property_name,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
if (strcmp (property_name, "sources") == 0)
|
||||
{
|
||||
BuilderModule *self = BUILDER_MODULE (serializable);
|
||||
JsonNode *retval = NULL;
|
||||
GList *l;
|
||||
|
||||
if (self->sources)
|
||||
{
|
||||
JsonArray *array;
|
||||
|
||||
array = json_array_sized_new (g_list_length (self->sources));
|
||||
|
||||
for (l = self->sources; l != NULL; l = l->next)
|
||||
{
|
||||
JsonNode *child = builder_source_to_json (BUILDER_SOURCE (l->data));
|
||||
json_array_add_element (array, child);
|
||||
}
|
||||
|
||||
retval = json_node_init_array (json_node_alloc (), array);
|
||||
json_array_unref (array);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else
|
||||
return json_serializable_default_serialize_property (serializable,
|
||||
property_name,
|
||||
value,
|
||||
pspec);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
builder_module_deserialize_property (JsonSerializable *serializable,
|
||||
const gchar *property_name,
|
||||
|
@ -415,6 +452,7 @@ builder_module_deserialize_property (JsonSerializable *serializable,
|
|||
static void
|
||||
serializable_iface_init (JsonSerializableIface *serializable_iface)
|
||||
{
|
||||
serializable_iface->serialize_property = builder_module_serialize_property;
|
||||
serializable_iface->deserialize_property = builder_module_deserialize_property;
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,84 @@ builder_options_init (BuilderOptions *self)
|
|||
self->arch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
||||
}
|
||||
|
||||
static JsonNode *
|
||||
builder_options_serialize_property (JsonSerializable *serializable,
|
||||
const gchar *property_name,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
if (strcmp (property_name, "arch") == 0)
|
||||
{
|
||||
BuilderOptions *self = BUILDER_OPTIONS (serializable);
|
||||
JsonNode *retval = NULL;
|
||||
|
||||
if (self->arch && g_hash_table_size (self->arch) > 0)
|
||||
{
|
||||
JsonObject *object;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
|
||||
object = json_object_new ();
|
||||
|
||||
g_hash_table_iter_init (&iter, self->arch);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
JsonNode *child = json_gobject_serialize (value);
|
||||
json_object_set_member (object, (char *)key, child);
|
||||
}
|
||||
|
||||
retval = json_node_init_object (json_node_alloc (), object);
|
||||
json_object_unref (object);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else if (strcmp (property_name, "env") == 0)
|
||||
{
|
||||
BuilderOptions *self = BUILDER_OPTIONS (serializable);
|
||||
JsonNode *retval = NULL;
|
||||
|
||||
if (self->env && g_strv_length (self->env) > 0)
|
||||
{
|
||||
JsonObject *object;
|
||||
int i;
|
||||
|
||||
object = json_object_new ();
|
||||
|
||||
for (i = 0; self->env[i] != NULL; i++)
|
||||
{
|
||||
JsonNode *str = json_node_new (JSON_NODE_VALUE);
|
||||
const char *equal;
|
||||
g_autofree char *member = NULL;
|
||||
|
||||
equal = strchr (self->env[i], '=');
|
||||
if (equal)
|
||||
{
|
||||
json_node_set_string (str, equal + 1);
|
||||
member = g_strndup (self->env[i], equal - self->env[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
json_node_set_string (str, "");
|
||||
member = g_strdup (self->env[i]);
|
||||
}
|
||||
|
||||
json_object_set_member (object, member, str);
|
||||
}
|
||||
|
||||
retval = json_node_init_object (json_node_alloc (), object);
|
||||
json_object_unref (object);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else
|
||||
return json_serializable_default_serialize_property (serializable,
|
||||
property_name,
|
||||
value,
|
||||
pspec);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
builder_options_deserialize_property (JsonSerializable *serializable,
|
||||
const gchar *property_name,
|
||||
|
@ -295,6 +373,7 @@ builder_options_deserialize_property (JsonSerializable *serializable,
|
|||
static void
|
||||
serializable_iface_init (JsonSerializableIface *serializable_iface)
|
||||
{
|
||||
serializable_iface->serialize_property = builder_options_serialize_property;
|
||||
serializable_iface->deserialize_property = builder_options_deserialize_property;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,6 +149,37 @@ serializable_iface_init (JsonSerializableIface *serializable_iface)
|
|||
{
|
||||
}
|
||||
|
||||
JsonNode *
|
||||
builder_source_to_json (BuilderSource *self)
|
||||
{
|
||||
JsonNode *node;
|
||||
JsonObject *object;
|
||||
const gchar *type = NULL;
|
||||
|
||||
node = json_gobject_serialize (G_OBJECT (self));
|
||||
object = json_node_get_object (node);
|
||||
|
||||
if (BUILDER_IS_SOURCE_ARCHIVE (self))
|
||||
type = "archive";
|
||||
else if (BUILDER_IS_SOURCE_FILE (self))
|
||||
type = "file";
|
||||
else if (BUILDER_IS_SOURCE_SCRIPT (self))
|
||||
type = "script";
|
||||
else if (BUILDER_IS_SOURCE_PATCH (self))
|
||||
type = "patch";
|
||||
else if (BUILDER_IS_SOURCE_GIT (self))
|
||||
type = "git";
|
||||
else if (BUILDER_IS_SOURCE_BZR (self))
|
||||
type = "bzr";
|
||||
else
|
||||
g_warning ("Unknown source type");
|
||||
|
||||
if (type)
|
||||
json_object_set_string_member (object, "type", type);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
BuilderSource *
|
||||
builder_source_from_json (JsonNode *node)
|
||||
{
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef struct {
|
|||
GType builder_source_get_type (void);
|
||||
|
||||
BuilderSource * builder_source_from_json (JsonNode *node);
|
||||
JsonNode * builder_source_to_json (BuilderSource *self);
|
||||
|
||||
gboolean builder_source_download (BuilderSource *self,
|
||||
BuilderContext *context,
|
||||
|
|
Loading…
Reference in New Issue