using Invercargill; namespace Usm { public class ManifestFile { public ManifestFilePathBase path_base { get; set; } public string path { get; set; } public ManifestFileType file_type { get; set; } public string? destination { get; set; } public Vector? keep_on { get; set; } public Vector? skip_for { get; set; } public static PropertyMapper get_mapper() { return PropertyMapper.build_for(cfg => { cfg.map("path", o => o.path, (o, v) => o.path = v); cfg.map("pathBase", o => o.path_base.to_string(), (o, v) => o.path_base = ManifestFilePathBase.from_string(v)); cfg.map("type", o => o.file_type.to_string(), (o, v) => o.file_type = ManifestFileType.from_string(v)); cfg.map("dest", o => o.destination, (o, v) => o.destination = v, false); cfg.map_many("keepOn", o => o.keep_on.select(i => i.to_string()), (o, v) => o.keep_on = v.convert(i => RemoveType.from_string(i)).to_vector(), false); cfg.map_many("skipFor", o => o.skip_for.select(i => i.to_string()), (o, v) => o.skip_for = v.convert(i => InstallType.from_string(i)).to_vector(), false); cfg.set_constructor(() => new ManifestFile()); }); } public ManifestFile.from_string(string str) throws ManifestError { var parts = str.split(":", 2); path_base = ManifestFilePathBase.from_string(parts[0]); file_type = ManifestFileType.REGULAR; if(path_base == ManifestFilePathBase.AS_EXPECTED) { path = ""; return; } if(parts.length != 2) { throw new ManifestError.INVALID_FILE_PATH("No file path provided"); } path = parts[1]; } } public enum ManifestFileType { REGULAR, DIRECTORY, SYMBOLIC_LINK; public string to_string() { switch(this) { case ManifestFileType.REGULAR: return "reg"; case ManifestFileType.DIRECTORY: return "dir"; case ManifestFileType.SYMBOLIC_LINK: return "lnk"; default: assert_not_reached(); } } public static ManifestFileType from_string(string str) throws ManifestError { switch(str) { case "reg": return ManifestFileType.REGULAR; case "dir": return ManifestFileType.DIRECTORY; case "lnk": return ManifestFileType.SYMBOLIC_LINK; default: throw new ManifestError.INVALID_FILE_TYPE(@"Unknown file type \"$str\"."); } } } public enum ManifestFilePathBase { SOURCE, BUILD, INSTALL, AS_EXPECTED; public string to_string() { switch(this) { case ManifestFilePathBase.SOURCE: return "source"; case ManifestFilePathBase.BUILD: return "build"; case ManifestFilePathBase.INSTALL: return "install"; case ManifestFilePathBase.AS_EXPECTED: return "as-expected"; default: assert_not_reached(); } } public static ManifestFilePathBase from_string(string str) throws ManifestError { switch(str) { case "source": return ManifestFilePathBase.SOURCE; case "build": return ManifestFilePathBase.BUILD; case "install": return ManifestFilePathBase.INSTALL; case "as-expected": return ManifestFilePathBase.AS_EXPECTED; default: throw new ManifestError.INVALID_PATH_BASE(@"Unknown path base \"$str\"."); } } } }