public void GetLatestPackageTest() { Mock <Repository> repo_mock = new Mock <Repository>(); Upset package_dummy_1 = new Upset(); package_dummy_1.PackageName = "package 1"; package_dummy_1.PackageVersion = "0.0.0"; Upset package_dummy_2 = new Upset(); package_dummy_2.PackageName = "package 1"; package_dummy_2.PackageVersion = "1.1.1"; Upset package_dummy_3 = new Upset(); package_dummy_3.PackageName = "not package 1"; package_dummy_3.PackageVersion = "2.0.0"; repo_mock.Setup(repo => repo.ListPackages()).Returns(new Upset[] { package_dummy_1, package_dummy_2, package_dummy_3 }); (pl as PackageListTester).SetPackages(new List <PackageRepo> { new PackageRepo { Package = package_dummy_1, Repository = repo_mock.Object }, new PackageRepo { Package = package_dummy_2, Repository = repo_mock.Object }, new PackageRepo { Package = package_dummy_3, Repository = repo_mock.Object } }); PackageRepo result = pl.GetLatestPackage("package 1"); Assert.AreEqual(new PackageRepo { Package = package_dummy_2, Repository = repo_mock.Object }, result); }
private static void CheckDependencies() { Upbring upbring = Upbring.Instance(); Upfile upfile = Upfile.Instance(); PackageList packageList = PackageList.Instance(); PackageRepo[] packageRepos = packageList.GetAllPackages(); bool any_installed = upbring.InstalledPackage != null && upbring.InstalledPackage.Length != 0; foreach (DependencyDefinition dependency in upfile.Dependencies) { string name = dependency.Name; bool installed = any_installed && upbring.InstalledPackage.Any(ip => ip.Name == name); bool installable = packageRepos.Any(pr => pr.Package.PackageName == name); string latest = installable ? packageList.GetLatestPackage(name).Package.PackageVersion : ""; string string_latest = string.IsNullOrEmpty(latest) ? "No version available in any repository" : "Latest version is " + latest; if (installed) { string installed_version = upbring.GetInstalledPackage(name).Version; if (installed_version != latest) { Debug.Log(string.Format("Package {0} is outdated: installed version is {1}, latest is {2}", name, installed_version, string_latest)); } else { Debug.Log(string.Format("Package {0} is up-to-date ({1})", name, installed_version)); } } else { Debug.Log(string.Format("Package {0} is not installed ({1})", name, string_latest)); } } }
public void LoadDependencies(DependencyDefinition dependency, PackageList packageList, DependencyHelper.ConflictChecker checkConflict, out DependencyNode node) { node = new DependencyNode(dependency.Name, dependency.Version, dependency.Repository); if (Contains(dependency.Name)) { DependencyNode existing = FindByName(dependency.Name); checkConflict(ref existing, node); } else { nodeList.Add(node); Upset package = packageList.GetLatestPackage(dependency.Name).Package; if (package == null) { throw new MissingDependencyException(string.Format(" depends on {0} but it is not present in any of your specified repository", dependency.Name)); } if (package.Dependencies != null) { DependencyNode child; foreach (DependencyDefinition packageDependency in package.Dependencies) { child = null; try { LoadDependencies(packageDependency, packageList, checkConflict, out child); AddDependency(node, child); } catch (MissingDependencyException e) { throw new MissingDependencyException(dependency.Name + e.Message); } } } } }
protected void OnGUI() { titleContent.text = "Update Utility"; UpliftManager manager = UpliftManager.Instance(); Upbring upbring = Upbring.Instance(); Upfile upfile = Upfile.Instance(); PackageList packageList = PackageList.Instance(); PackageRepo[] packageRepos = packageList.GetAllPackages(); DependencyDefinition[] dependencies = upfile.Dependencies; bool any_installed = upbring.InstalledPackage != null && upbring.InstalledPackage.Length != 0; if (dependencies.Length == 0) { EditorGUILayout.HelpBox("It seems that you didn't specify any dependency in the Upfile. Try refreshing it if you did.", MessageType.Warning); } else { foreach (DependencyDefinition dependency in dependencies) { string name = dependency.Name; EditorGUILayout.LabelField(name + ":", EditorStyles.boldLabel); bool installable = packageRepos.Any(pr => pr.Package.PackageName == name); bool installed = any_installed && upbring.InstalledPackage.Any(ip => ip.Name == name); string installed_version = installed ? upbring.GetInstalledPackage(name).Version : ""; if (installed) { EditorGUILayout.LabelField("- Installed version is " + installed_version); } else { EditorGUILayout.LabelField("- Not yet installed"); } if (!installable) { EditorGUILayout.HelpBox("No repository contains this package. Try specifying one whith this package in.", MessageType.Warning); } else { PackageRepo latestPackageRepo = packageList.GetLatestPackage(name); string latest_version = latestPackageRepo.Package.PackageVersion; EditorGUILayout.LabelField(string.Format("- Latest version is: {0} (from {1})", latest_version, latestPackageRepo.Repository.ToString())); GUI.enabled = installed && installed_version != latest_version; if (GUILayout.Button("Update to " + latest_version)) { Debug.Log(string.Format("Updating package {0} (to {1})", name, latest_version)); manager.UpdatePackage(latestPackageRepo); AssetDatabase.Refresh(); Repaint(); } GUI.enabled = true; } EditorGUILayout.Space(); } if (GUILayout.Button("Install all dependencies")) { manager.InstallDependencies(); AssetDatabase.Refresh(); Repaint(); } GUI.enabled = any_installed; if (GUILayout.Button("Update all installed packages")) { foreach (InstalledPackage package in upbring.InstalledPackage) { PackageRepo latestPackageRepo = packageList.GetLatestPackage(package.Name); if (package.Version != latestPackageRepo.Package.PackageVersion) { Debug.Log(string.Format("Updating package {0} (to {1})", package.Name, latestPackageRepo.Package.PackageVersion)); manager.UpdatePackage(latestPackageRepo); } } AssetDatabase.Refresh(); Repaint(); } GUI.enabled = true; if (GUILayout.Button("Refresh Upfile")) { Upfile.Instance(); Repaint(); } } }