Example #1
0
        public void Valid_FullyGenerated_FilesAry()
        {
            Directory.CreateDirectory(OutputPath);
            string targetPath = Path.Combine(OutputPath, nameof(Valid_FullyGenerated_FilesAry) + ".json");
            var    task       = new GenerateManifest()
            {
                Id          = "TestPlugin",
                Name        = "Test Plugin",
                Author      = "Zingabopp",
                Version     = "1.0.0",
                GameVersion = "1.14.0",
                Description = "Description of a test plugin.",
                DependsOn   =
                    MockTaskItem.FromDictString("DependsOn", "BSIPA|^4.3.0", "TestDepend1|^2.0.1", "TestDepend2|^1.0.0"),
                ConflictsWith =
                    MockTaskItem.FromDictString("ConflictsWith", "TestConflict1|^2.0.1", "TestConflict2|^1.0.0"),
                Files         = new string[] { "Libs/TestLib1.dll", "Libs/TestLib2.dll" },
                Donate        = "http://donate.com",
                ProjectHome   = "http://project.home",
                ProjectSource = "http://project.source",
                PluginHint    = "Namespace.Plugin.Type",
                RequiresBsipa = false,
                TargetPath    = targetPath
            };

            Assert.IsTrue(task.Execute());
            BsipaManifest manifest = BsipaManifest.FromJson(File.ReadAllText(targetPath));

            TestManifest(task, manifest);
            Assert.AreEqual(task.Donate, manifest.Donate);
            Assert.AreEqual(task.ProjectHome, manifest.ProjectHome);
            Assert.AreEqual(task.ProjectSource, manifest.ProjectSource);
            Assert.AreEqual(task.PluginHint, manifest.PluginHint);
        }
Example #2
0
        public void Valid_WithBaseManifest_DependsOnSingle()
        {
            Directory.CreateDirectory(OutputPath);
            string basePath      = Path.Combine(Data, "manifest.json");
            int    baseDepends   = 2;
            int    baseConflicts = 0;
            string targetPath    = Path.Combine(OutputPath, nameof(Valid_WithBaseManifest_DependsOnSingle) + ".json");
            var    task          = new GenerateManifest()
            {
                Id          = "TestPlugin",
                Name        = "Test Plugin",
                Author      = "Zingabopp",
                Version     = "1.0.0",
                GameVersion = "1.14.0",
                Description = "Description of a test plugin.",
                DependsOn   =
                    MockTaskItem.FromDictString("DependsOn", "BSIPA|^4.3.0", "TestDepend1|^2.0.1", "TestDepend2|^1.0.0"),
                ConflictsWith =
                    MockTaskItem.FromDictString("ConflictsWith", "TestConflict1|^2.0.1", "TestConflict2|^1.0.0"),
                RequiresBsipa    = true,
                BaseManifestPath = basePath,
                TargetPath       = targetPath
            };

            Assert.IsTrue(task.Execute());
            BsipaManifest manifest = BsipaManifest.FromJson(File.ReadAllText(targetPath));

            TestManifest(task, manifest, baseDepends, baseConflicts);
        }
Example #3
0
 private void SetOptionalProperties(BsipaManifest manifest)
 {
     manifest.Files         = ParseUtil.ParseStringArray(Files);
     manifest.DependsOn     = ParseUtil.ParseModIds(DependsOn, manifest.DependsOn, "DependsOn");
     manifest.ConflictsWith = ParseUtil.ParseModIds(ConflictsWith, manifest.ConflictsWith, "ConflictsWith");
     manifest.LoadBefore    = ParseUtil.ParseStringArray(LoadBefore);
     manifest.LoadAfter     = ParseUtil.ParseStringArray(LoadAfter);
     if (!string.IsNullOrWhiteSpace(Icon))
     {
         manifest.Icon = Icon;
     }
     manifest.ProjectHome   = ProjectHome;
     manifest.ProjectSource = ProjectSource;
     manifest.Donate        = Donate;
     if (!string.IsNullOrWhiteSpace(Features))
     {
         manifest.Features = SimpleJSON.JSON.Parse(Features) as SimpleJSON.JSONObject;
     }
     if (!string.IsNullOrWhiteSpace(Misc))
     {
         manifest.Misc = SimpleJSON.JSON.Parse(Misc) as SimpleJSON.JSONObject;
     }
     if (!string.IsNullOrWhiteSpace(PluginHint))
     {
         manifest.PluginHint = PluginHint;
     }
     manifest.GeneratedBy = $"BSMT.Tasks/{Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
 }
Example #4
0
 private void SetRequiredProperties(BsipaManifest manifest)
 {
     if (!string.IsNullOrWhiteSpace(Id))
     {
         manifest.Id = Id;
     }
     if (!string.IsNullOrWhiteSpace(Name))
     {
         manifest.Name = Name;
     }
     if (!string.IsNullOrWhiteSpace(Author))
     {
         manifest.Author = Author;
     }
     if (!string.IsNullOrWhiteSpace(Version))
     {
         manifest.Version = Version;
     }
     if (!string.IsNullOrWhiteSpace(GameVersion))
     {
         manifest.GameVersion = GameVersion;
     }
     if (!string.IsNullOrWhiteSpace(Description))
     {
         manifest.Description = Description;
     }
 }
Example #5
0
 public void TestManifest(GenerateManifest task, BsipaManifest manifest, int baseDepends = 0, int baseConflicts = 0)
 {
     Assert.AreEqual(task.Id, manifest.Id);
     Assert.AreEqual(task.Name, manifest.Name);
     Assert.AreEqual(task.Author, manifest.Author);
     Assert.AreEqual(task.Version, manifest.Version);
     Assert.AreEqual(task.GameVersion, manifest.GameVersion);
     Assert.AreEqual(task.Description, manifest.Description);
     Assert.AreEqual(task.Icon, manifest.Icon);
     CompareDictionary(ParseUtil.ParseModIds(task.DependsOn, null, "DependsOn"), manifest.DependsOn, baseDepends);
     CompareDictionary(ParseUtil.ParseModIds(task.ConflictsWith, null, "ConflictsWith"), manifest.ConflictsWith, baseConflicts);
     CompareStringArrays(ParseUtil.ParseStringArray(task.Files), manifest.Files, 0);
 }
Example #6
0
        public void SimpleJSONTest()
        {
            Directory.CreateDirectory(OutputPath);
            string        targetPath = Path.Combine(OutputPath, nameof(SimpleJSONTest) + ".json");
            BsipaManifest manifest   = new BsipaManifest()
            {
                Id          = "TestPlugin",
                Name        = "Test Plugin",
                Author      = "Zingabopp",
                Version     = "1.0.0",
                GameVersion = "1.14.0",
                Description = "Description of a test plugin."
            };

            manifest.DependsOn = ParseUtil.ParseDictString(new string[] { "TestDepend1|^2.0.1;TestDepend2|^1.0.0" }, "DependsOn");
            manifest.Validate(false);
            File.WriteAllText(targetPath, manifest.ToJson());
        }
Example #7
0
 private void WriteManifest(BsipaManifest manifest, string path)
 {
     try
     {
         FileInfo fileInfo = new FileInfo(path);
         path = fileInfo.FullName;
         if (!fileInfo.Directory.Exists)
         {
             Logger.LogMessage(MessageImportance.High, $"Creating manifest target directory '${fileInfo.Directory.FullName}'...");
         }
         fileInfo.Directory.Create();
         File.WriteAllText(path, manifest.ToJson());
     }
     catch (Exception ex)
     {
         throw new IOException($"Failed to write manifest to '${path}': {ex.Message}");
     }
 }
Example #8
0
        public void Valid_FullyGenerated_FilesStr()
        {
            Directory.CreateDirectory(OutputPath);
            string targetPath = Path.Combine(OutputPath, nameof(Valid_FullyGenerated_FilesStr) + ".json");
            var    task       = new GenerateManifest()
            {
                Id            = "TestPlugin",
                Name          = "Test Plugin",
                Author        = "Zingabopp",
                Version       = "1.0.0",
                GameVersion   = "1.14.0",
                Description   = "Description of a test plugin.",
                Files         = new string[] { "Libs/TestLib1.dll;Libs/TestLib2.dll" },
                RequiresBsipa = false,
                TargetPath    = targetPath
            };

            Assert.IsTrue(task.Execute());
            BsipaManifest manifest = BsipaManifest.FromJson(File.ReadAllText(targetPath));

            TestManifest(task, manifest);
        }
Example #9
0
        public void Valid_FullyGenerated_DependsOnArray()
        {
            Directory.CreateDirectory(OutputPath);
            string targetPath = Path.Combine(OutputPath, nameof(Valid_FullyGenerated_DependsOnArray) + ".json");
            var    task       = new GenerateManifest()
            {
                Id          = "TestPlugin",
                Name        = "Test Plugin",
                Author      = "Zingabopp",
                Version     = "1.0.0",
                GameVersion = "1.14.0",
                Description = "Description of a test plugin.",
                DependsOn   =
                    MockTaskItem.FromDictString("DependsOn", "BSIPA|^4.3.0", "TestDepend1|^2.0.1", "TestDepend2|^1.0.0"),
                RequiresBsipa = true,
                TargetPath    = targetPath
            };

            Assert.IsTrue(task.Execute());
            BsipaManifest manifest = BsipaManifest.FromJson(File.ReadAllText(targetPath));

            TestManifest(task, manifest);
        }
Example #10
0
        private BsipaManifest MakeManifest()
        {
            BsipaManifest manifest;

            if (!string.IsNullOrWhiteSpace(BaseManifestPath))
            {
                string manifestPath = Path.GetFullPath(BaseManifestPath);
                if (File.Exists(manifestPath))
                {
                    try
                    {
                        manifest = BsipaManifest.FromJson(File.ReadAllText(manifestPath));
                    }
                    catch (Exception ex)
                    {
                        throw new IOException($"Failed to read JSON at '${manifestPath}': {ex.Message}");
                    }
                }
                else
                {
                    throw new ArgumentException($"A BaseManifestFile '${manifestPath}' does not exist."
                                                , nameof(BaseManifestPath));
                }
            }
            else
            {
                manifest = new BsipaManifest();
            }
            if (string.IsNullOrWhiteSpace(TargetPath))
            {
                TargetPath = "manifest.json";
            }
            SetRequiredProperties(manifest);
            SetOptionalProperties(manifest);
            return(manifest);
        }