Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

feat: add package model #9

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
de8a049
work in progress
naipotato Oct 5, 2021
63d9a2d
fix: lint errors
dar5hak Oct 5, 2021
3a7f9d1
Disable space-before-paren on the regex
dar5hak Oct 5, 2021
07311b9
remove .vscode directory
naipotato Oct 5, 2021
07728da
move Person parsing logic to its own method
naipotato Oct 5, 2021
d874997
add a missing check
naipotato Oct 5, 2021
b83f482
fix the missing check
naipotato Oct 5, 2021
135d3e9
some more progress
naipotato Oct 6, 2021
6c2b7f4
Start working on file test
colinkiama Mar 12, 2022
4702f75
Test package config file can be parsed
colinkiama Mar 12, 2022
6a71777
Add references to npm and drakkar package config specs
colinkiama Mar 12, 2022
18f2672
Full package config file test
colinkiama Mar 12, 2022
4027429
Fix: HashMap properties failing to be deserialized
colinkiama Mar 12, 2022
68192a6
Fix: string_list_from_json method not adding string values
colinkiama Mar 12, 2022
0b917ee
Add "equals" methods to package models
colinkiama Mar 12, 2022
7569274
Check if contributors are parsed correctly
colinkiama Mar 13, 2022
f514b0d
Handle parsing of "type" property names
colinkiama Mar 13, 2022
8bd0913
Fix: Respository property object parsing
colinkiama Mar 13, 2022
b7f3453
Test full package configuration file deserialization
colinkiama Mar 13, 2022
536dc71
Serialized keywords
colinkiama Mar 13, 2022
d991974
Fix serialization of "type" properties
colinkiama Mar 13, 2022
e9de045
Serialize "dependencies" properties
colinkiama Mar 13, 2022
b0092a7
Compare serialized content with expecrted content
colinkiama Mar 13, 2022
7fc96a3
Move File test to unit tests file
colinkiama Mar 13, 2022
cd9c2a2
refactor: Move public model classes into their own files
colinkiama Mar 13, 2022
32d981a
test config vapi formatting
colinkiama Mar 13, 2022
537eb95
Formatting
colinkiama Mar 13, 2022
3a8f224
Fix: Missing config header for tests
colinkiama Mar 14, 2022
ab9371c
Replaced assertcmp methods with assert
colinkiama Apr 5, 2022
210b7dd
Explicit disable new lines from being added to test asset files
colinkiama Apr 5, 2022
a81519d
Rename `equals` methods with `equal`
colinkiama Apr 5, 2022
d30362f
Add space between cases
colinkiama Apr 5, 2022
6f24b37
Packages and generators in unit tests now initialised with object ini…
colinkiama Apr 5, 2022
d965c9c
Fix "desrialise_package_config" typo
colinkiama Apr 5, 2022
9072775
Stop checking for errors from boolean value of `FileUtils.get_contents`
colinkiama Apr 5, 2022
87f1a69
Reduce usage of CCode Attributes in config.vapi
colinkiama Apr 5, 2022
b3362d0
Remove double blank line
colinkiama Apr 5, 2022
13dc733
Use literal map in for test configuration files
colinkiama Apr 5, 2022
6d2c4e5
Split project into `cli` and `vamp` directories
colinkiama Apr 5, 2022
c3fe03a
Merge literal strings in test build file to one string
colinkiama Apr 9, 2022
6d8e853
Using full qualifier names for JSON NodeType enums
colinkiama Apr 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.rulers": [80]
}
naipotato marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 6 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
project('vamp', 'vala', 'c',
version: '0.0.1')
version: '0.0.1'
)

dependencies = [
dependency('glib-2.0'),
dependency('gobject-2.0')
dependency('glib-2.0'),
dependency('gobject-2.0'),
dependency('gee-0.8'),
dependency('json-glib-1.0'),
]

add_project_arguments(['--enable-experimental'], language: 'vala')
Expand Down
11 changes: 6 additions & 5 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sources = [
'main.vala'
'models/Package.vala',
'main.vala',
]

executable('vamp',
sources,
dependencies: dependencies,
install: true)
executable('vamp', sources,
dependencies: dependencies,
install: true,
)
165 changes: 165 additions & 0 deletions src/models/Package.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
class Vamp.Package : Object, Json.Serializable {
public string name { get; set; }
public string version { get; set; }
public string description { get; set; }
public Gee.List<string> keywords { get; set; }
public string homepage { get; set; }
public Bugs bugs { get; set; }
public string license { get; set; }
public Person author { get; set; }
public Gee.List<Person> contributors { get; set; }
public Gee.List<FundingInfo> funding { get; set; }
public Gee.List<string> files { get; set; }
public Repository repository { get; set; }
public Gee.Map<string, string> dependencies { get; set; }
public Gee.Map<string, string> dev_dependencies { get; set; }
public Gee.Map<string, string> optional_dependencies { get; set; }

public static Package from_json (Json.Node node) {
assert (node.get_node_type () == OBJECT);
return (Package) Json.gobject_deserialize (typeof (Package), node);
}

public Json.Node to_json () {
return Json.gobject_serialize (this);
}

private bool deserialize_property (
string property_name,
out Value @value,
ParamSpec pspec,
Json.Node property_node
) {
switch (property_name) {
case "keywords":
if (property_node.get_node_type () != ARRAY) {
@value = {};
return false;
}

@value = string_list_from_json (property_node);

return true;

case "bugs":
if (property_node.get_node_type () == OBJECT) {
@value = Bugs.from_json (property_node);
return true;
}

@value = new Bugs () {
url = property_node.get_string (),
};

return true;

case "author":
if (property_node.get_node_type () == OBJECT) {
@value = Person.from_json (property_node);
return true;
}

if (property_node.get_value_type () != Type.STRING) {
return false;
}

var regex = /^(.*)(?:\s)(<.*>)(?:\s)(\(.*\))/;
MatchInfo info;

if (regex.match (property_node.get_string (), 0, out info)) {
@value = new Person () {
name = info.fetch (1),
email = info.fetch (2),
url = info.fetch (3),
};

return true;
}

return false;

default:
return default_deserialize_property (
property_name,
out @value,
pspec,
property_node
);
}
}
}

class Vamp.Repository : Object {
dar5hak marked this conversation as resolved.
Show resolved Hide resolved
public string type { get; set; }
public string url { get; set; }
public string directory { get; set; }

public static Repository from_json (Json.Node node) {
assert (node.get_node_type () == OBJECT);
return (Repository) Json.gobject_deserialize (typeof (Repository), node);
}

public Json.Node to_json () {
return Json.gobject_serialize (this);
}
}

class Vamp.FundingInfo : Object {
public string type { get; set; }
public string url { get; set; }

public static FundingInfo from_json (Json.Node node) {
assert (node.get_node_type () == OBJECT);
return (FundingInfo) Json.gobject_deserialize (typeof (FundingInfo), node);
}

public Json.Node to_json () {
return Json.gobject_serialize (this);
}
}

class Vamp.Person : Object {
public string name { get; set; }
public string email { get; set; }
public string url { get; set; }

public static Person from_json (Json.Node node) {
assert (node.get_node_type () == OBJECT);
return (Person) Json.gobject_deserialize (typeof (Person), node);
}

public Json.Node to_json () {
return Json.gobject_serialize (this);
}
}

class Vamp.Bugs : Object {
public string url { get; set; }
public string email { get; set; }

public static Bugs from_json (Json.Node node) {
assert (node.get_node_type () == OBJECT);
return (Bugs) Json.gobject_deserialize (typeof (Bugs), node);
}

public Json.Node to_json () {
return Json.gobject_serialize (this);
}
}

Gee.List<string> string_list_from_json (Json.Node node) {
assert (node.get_node_type () == ARRAY);

var array = node.get_array ();
var result = new Gee.ArrayList<string> ();

array.foreach_element ((_, __, element_node) => {
if (element_node.get_value_type () == Type.STRING) {
return;
}

result.add(element_node.get_string ());
});

return result;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have one file per public class: https://docs.elementary.io/develop/writing-apps/code-style#classes-and-files

Also: we will have this classes on the Vamp namespace or in a more specific namespace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in another comment, since Vala namespaces have no real advantages (literally not even in terms of member accessibility), my idea was simply not to use them unless strictly necessary: for example, if we are exposing a public API or if we want to simulate static classes.