123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using Invercargill;
- namespace Usm {
- public class CachedPackage {
- public string state_path { get; private set; }
- public string package_path { get; private set; }
- public string package_name { get; private set; }
- public CachedPackage(string path) {
- this.state_path = path;
- this.package_path = Path.build_filename(path, "package.usmc");
- this.package_name = Path.get_basename(path);
- }
- public Manifest get_manifest() throws Error {
- return new Manifest.from_package(package_path);
- }
- public OriginInformation get_origin_information() throws Error {
- return new OriginInformation.from_file(Path.build_filename(state_path, "origin-info"));
- }
- public bool has_build_directory() {
- return File.new_for_path(build_directory_path()).query_exists();
- }
- public bool has_build_archive() {
- return File.new_for_path(build_archive_path()).query_exists();
- }
- public string create_build_directory() throws Error {
- var path = build_directory_path();
- File.new_for_path(path).make_directory();
- return path;
- }
- public string get_build_directory() throws Error {
- var path = build_directory_path();
- if(File.new_for_path(path).query_exists()) {
- return path;
- }
- var archive_path = build_archive_path();
- if(!File.new_for_path(path).query_exists()) {
- throw new StateError.NO_BUILD_ARTIFACT(@"The package \"$package_name\" has no build artifact");
- }
- Util.unarchive(archive_path, path);
- return path;
- }
- public string get_build_archive() throws Error {
- var path = build_archive_path();
- if(File.new_for_path(path).query_exists()) {
- return path;
- }
- var dir_path = build_directory_path();
- if(!File.new_for_path(dir_path).query_exists()) {
- throw new StateError.NO_BUILD_ARTIFACT(@"The package \"$package_name\" has no build artifact");
- }
- Util.archive(dir_path, path);
- return path;
- }
- public void archive_build() throws Error {
- var build_dir = get_build_directory();
- // Delete existing archive, if it exists
- var archive_file = File.new_for_path(build_archive_path());
- if(archive_file.query_exists()) {
- archive_file.delete();
- }
- Util.archive(build_dir, archive_file.get_path());
- clean_build_directory();
- }
- public void unarchive_build() throws Error {
- clean_build_directory();
- get_build_directory();
- }
- public void clean_build_directory() throws Error {
- var path = build_directory_path();
- if(File.new_for_path(path).query_exists()) {
- Util.delete_tree(path);
- }
- }
- public string get_source_directory() throws Error {
- var path = source_directory_path();
- if(File.new_for_path(path).query_exists()) {
- return path;
- }
- print(@"Extracting $(package_path) to $(path)\n");
- Util.unarchive(package_path, path);
- return path;
- }
- public void clean_source() throws Error {
- var path = source_directory_path();
- if(File.new_for_path(path).query_exists()) {
- Util.delete_tree(path);
- }
- }
- public string create_install_directory() throws Error {
- var path = install_directory_path();
- File.new_for_path(path).make_directory();
- return path;
- }
- public void clean_install() throws Error {
- var path = install_directory_path();
- if(File.new_for_path(path).query_exists()) {
- Util.delete_tree(path);
- }
- }
- public void update_origin_information(OriginInformation info) throws Error {
- var properties = OriginInformation.get_mapper().map_from(info);
- var json = new InvercargillJson.JsonElement.from_properties(properties);
- json.write_to_file(Path.build_filename(state_path, "origin-info"));
- }
- private string build_directory_path() {
- return Path.build_filename(state_path, "build");
- }
- private string build_archive_path() {
- return Path.build_filename(state_path, "build.tar.xz");
- }
- private string source_directory_path() {
- return Path.build_filename(state_path, "package");
- }
- private string install_directory_path() {
- return Path.build_filename(state_path, "install");
- }
- }
- public class CachedPackageManifest {
- public CachedPackage package { get; private set; }
- public Manifest manifest { get; private set; }
- public CachedPackageManifest(CachedPackage package) throws Error {
- this.package = package;
- this.manifest = package.get_manifest();
- }
- }
- }
|