Commit 7163d1a2 authored by Bat's avatar Bat
Browse files

Merge branch 'issue-32' into 'develop'

Issue 32

Closes #32

See merge request !19
parents a81a593c c02c465f
Pipeline #12482 failed with stages
in 1 minute and 47 seconds
......@@ -19,10 +19,10 @@ deprecated = true
[dependencies]
"gee-0.8" = "*"
"gio-2.0" = "*"
"json-glib-1.0" = "*"
json-vala = "1.7.x"
"libsoup-2.4" = "*"
semver = "*"
toml-glib = "^0.1.0"
semver = "1.x.x"
toml-glib = "~0.1.0"
[scripts]
install = [
......
......@@ -151,8 +151,8 @@ libdir=%s
Name: %s
Description: %s
Version: %s
CFlags: -I$${includedir}%s
Libs: -L$${libdir} -l %s
CFlags: -I${includedir}%s
Libs: -L${libdir} -l%s
""".printf (include_dir, lib_dir, output.name, desc, this.manifest.version.to_string (), this.manifest.name, this.manifest.name);
if (this.manifest.dependencies.size > 0) {
pc += "Requires:";
......
......@@ -54,23 +54,23 @@ namespace Poulp.Commands {
bool tmpl_found = false;
// we iterate over the different registered file templates
parser.get_root ().get_array ().foreach_element ((arr, index, _elt) => {
Json.Object elt = _elt.get_object ();
foreach (var elt in parser.root.as_array ()) {
Json.Object tmpl = elt.as_object ();
// if the ID of the template or its name is the one we choose
if (elt.get_string_member ("id") == template || elt.get_string_member ("name") == template) {
if (tmpl["id"].as<string> () == template || tmpl["name"].as<string> () == template) {
// We copy the files of the template
elt.get_array_member ("files").foreach_element ((array, i, file) => {
foreach (var file in tmpl["files"].as_array ()) {
try {
File origin = File.new_for_path (Path.build_filename (get_poulp_dir (), "files", file.get_string ()));
File dest = File.new_for_commandline_arg (output + "." + new ArrayList<string>.wrap (file.get_string ().split (".")).last ());
File origin = File.new_for_path (Path.build_filename (get_poulp_dir (), "files", file.as<string> ()));
File dest = File.new_for_commandline_arg (output + "." + new ArrayList<string>.wrap (file.as<string> ().split (".")).last ());
origin.copy (dest, FileCopyFlags.OVERWRITE);
} catch (Error err) {
Logger.log_error (err.message);
}
});
}
tmpl_found = true;
}
});
}
if (!tmpl_found) {
Logger.log_error ("Can't find the specified template.");
......
......@@ -12,14 +12,14 @@ namespace Poulp.Commands {
*
* @param toml The JSON representation of this template
*/
public ProjectTemplate (Json.Object toml) {
public ProjectTemplate (Json.Object json) {
// we get data from the JSON to initialize the instance
this.id = toml.get_string_member ("id");
this.name = toml.get_string_member ("name");
this.description = toml.get_string_member ("description");
toml.get_array_member ("files").foreach_element ((arr, index, elt) => {
this.files.add (elt.get_string ());
});
this.id = json.get_string_member ("id");
this.name = json.get_string_member ("name");
this.description = json.get_string_member ("description");
foreach (var file in json["files"].as_array ()) {
this.files.add (file.as<string> ());
}
}
/**
......@@ -126,16 +126,16 @@ namespace Poulp.Commands {
// we read the templates from `projects.toml` and we display them
try {
string projects_path = Path.build_filename (get_poulp_dir (), "projects", "projects.toml");
string projects_path = Path.build_filename (get_poulp_dir (), "projects", "projects.json");
string projects;
FileUtils.get_contents (projects_path, out projects);
Json.Parser parser = new Json.Parser ();
parser.load_from_data (projects);
parser.get_root ().get_array ().foreach_element ((arr, index, elt) => {
foreach (var elt in parser.root.as_array ()) {
// ad the template to the list
ProjectTemplate tmpl = new ProjectTemplate (elt.get_object ());
ProjectTemplate tmpl = new ProjectTemplate (elt.as_object ());
prjs.add (tmpl);
});
};
} catch (Error err) {
Logger.log_error (err.message);
return false;
......
......@@ -55,7 +55,7 @@ namespace Poulp {
*/
public override async bool install () {
try {
Manifest man = new Manifest.for_path (Path.build_filename (this.project_path, "poulp.json"));
Manifest man = new Manifest.for_path (Path.build_filename (this.project_path, "poulp.toml"));
if (man.scripts.has_key ("pre-install")) {
return yield new ScriptRunner ().run (man.scripts["pre-install"]);
......
......@@ -43,7 +43,7 @@ namespace Poulp {
} catch (TomlError terr) {
Logger.log_error (terr.message);
} catch (Error err) {
throw new PoulpError.NO_MANIFEST ("This project doesn't contain a `poulp.toml` file.");
throw new PoulpError.NO_MANIFEST ("Can't read %s, the project probably doesn't contain a `poulp.toml` file.\nDetails: %s".printf (path, err.message));
}
}
......
......@@ -23,10 +23,10 @@ namespace Poulp {
* @param root The packages.json of this repository
*/
public Repository.from_json (Json.Object root) {
this.name = root.get_string_member ("name");
root.get_object_member ("packages").foreach_member ((obj, key, value) => {
this.packages[key] = value.get_string ();
});
this.name = root["name"].as<string> ();
foreach (var pkg in root["packages"].as_object ().properties) {
this.packages[pkg.name] = pkg.value.as<string> ();
}
}
/**
......@@ -38,12 +38,11 @@ namespace Poulp {
try {
FileUtils.get_contents (Path.build_filename (get_poulp_dir (), "repos"), out repo_list);
foreach (string url in repo_list.split ("\n")) {
print (@"gettin $url\n");
if (url.length != 0) {
var repo_content = yield download (Path.build_path ("/", url, "packages.json"));
Json.Parser parser = new Json.Parser ();
parser.load_from_data ((string)repo_content);
var repo = new Repository.from_json (parser.get_root ().get_object ());
var repo = new Repository.from_json (parser.root.as_object ());
known.add (repo);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment