public void InstanceUnicityTest() { Upfile upA = Upfile.Instance(); Upfile upB = Upfile.Instance(); Assert.AreSame(upA, upB); }
protected void Given() { UpliftManagerExposer.ClearAllInstances(); pwd = Directory.GetCurrentDirectory(); Helper.InitializeRunDirectory(); try { Directory.SetCurrentDirectory(Helper.testRunDirectoryName); // Upfile Setup upfile_path = Helper.GetLocalFilePath("..", "TestData", "PackageUpdating", "Upfile.xml"); try { UpfileExposer.SetInstance(UpfileExposer.LoadTestXml(upfile_path)); } catch (FileNotFoundException) { Console.WriteLine("Make sure you are running the test from UpliftTesting/TestResults. The Upfile.xml uses the current path to register the repositories."); } upfile = Upfile.Instance(); manager = UpliftManager.Instance(); upfile.Dependencies[0].Version = "1.0.0"; manager.InstallDependencies(); upfile.Dependencies[0].Version = "1.0.1"; } finally { Directory.SetCurrentDirectory(pwd); } }
private void UpdatePackage(Upset package, TemporaryDirectory td) { NukePackage(package.PackageName); DependencyDefinition definition = Upfile.Instance().Dependencies.First(dep => dep.Name == package.PackageName); InstallPackage(package, td, definition, true); }
public void WhenUpfileModifiedNoSkip() { // Upfile Setup upfile_path = Helper.GetLocalFilePath(new string[] { "..", "TestData", "CustomizedFileLocation", "Upfile_Modified_NoSkip.xml" }); try { UpfileExposer.SetInstance(UpfileExposer.LoadTestXml(upfile_path)); } catch (FileNotFoundException) { Console.WriteLine("Make sure you are running the test from UpliftTesting/TestResults. The Upfile.xml uses the current path to register the repositories."); Assert.IsTrue(false, "The test could not run correctly. See console message."); } upfile = Upfile.Instance(); manager.InstallDependencies(); // Directories existence Assert.IsTrue(Directory.Exists("UPackages"), "Directory UPackages does not exist"); Assert.IsTrue(Directory.Exists("UPackages/package_c~1.3.5"), "Package directory does not exist under UPackages"); Assert.IsTrue(Directory.Exists("UPackages/package_c~1.3.5/Media"), "Media directory does not exist under UPackages/package_c~1.3.5"); Assert.IsTrue(Directory.Exists("UPackages/package_c~1.3.5/Example"), "Example directory does not exist under UPackages/package_c~1.3.5"); Assert.IsTrue(Directory.Exists("UPackages/package_c~1.3.5/Example/Adv"), "Example advanced directory does not exist under UPackages/package_c~1.3.5"); Assert.IsTrue(Directory.Exists("Assets"), "Directory Assets does not exist"); Assert.IsTrue(Directory.Exists("Assets/UPackages"), "Directory UPackages under Assets does not exist"); Assert.IsTrue(Directory.Exists("Assets/UPackages/package_c~1.3.5"), "Package directory does not exist under Assets/UPackages"); Assert.IsTrue(Directory.Exists("Assets/Media"), "Media directory does not exist under Assets"); Assert.IsTrue(Directory.Exists("Assets/Media/package_c~1.3.5"), "Package directory does not exist under Assets/Media"); Assert.IsTrue(Directory.Exists("Examples"), "Examples directory does not exist"); Assert.IsTrue(Directory.Exists("Examples/package_c~1.3.5"), "Package directory does not exist under Examples"); Assert.IsTrue(Directory.Exists("Examples/package_c~1.3.5/Adv"), "Advanced directory does not exist under Examples/package_c~1.3.5"); // Files under Assets Assert.IsTrue(File.Exists("Assets/UPackages/package_c~1.3.5/C1.cs"), "File C1 did not get copied to Assets/UPackages/package_c~1.3.5"); Assert.IsTrue(File.Exists("Assets/UPackages/package_c~1.3.5/C2.cs"), "File C2 did not get copied to Assets/UPackages/package_c~1.3.5"); Assert.IsTrue(File.Exists("Assets/Media/package_c~1.3.5/M1.txt"), "File M1 did not get copied to Assets/Media/package_c~1.3.5"); Assert.IsTrue(File.Exists("Assets/Media/package_c~1.3.5/M2.txt"), "File M2 did not get copied to Assets/Media/package_c~1.3.5"); Assert.IsTrue(File.Exists("Examples/package_c~1.3.5/E1.txt"), "File E1 did not get copied to Examples/package_c~1.3.5"); Assert.IsTrue(File.Exists("Examples/package_c~1.3.5/E2.txt"), "File E2 did not get copied to Examples/package_c~1.3.5"); Assert.IsTrue(File.Exists("Examples/package_c~1.3.5/Adv/E3.txt"), "File E2 did not get copied to Examples/package_c~1.3.5/Adv"); // Files under UPackages Assert.IsTrue(File.Exists("UPackages/package_c~1.3.5/C1.cs"), "File C1 did not get copied to UPackages/package_c~1.3.5"); Assert.IsTrue(File.Exists("UPackages/package_c~1.3.5/C2.cs"), "File C2 did not get copied to UPackages/package_c~1.3.5"); Assert.IsTrue(File.Exists("UPackages/package_c~1.3.5/Media/M1.txt"), "File M1 did not get copied to UPackages/package_c~1.3.5/Media"); Assert.IsTrue(File.Exists("UPackages/package_c~1.3.5/Media/M2.txt"), "File M2 did not get copied to UPackages/package_c~1.3.5/Media"); Assert.IsTrue(File.Exists("UPackages/package_c~1.3.5/Example/E1.txt"), "File E1 did not get copied to UPackages/package_c~1.3.5/Example"); Assert.IsTrue(File.Exists("UPackages/package_c~1.3.5/Example/E2.txt"), "File E2 did not get copied to UPackages/package_c~1.3.5/Example"); Assert.IsTrue(File.Exists("UPackages/package_c~1.3.5/Example/Adv/E3.txt"), "File E2 did not get copied to UPackages/package_c~1.3.5/Example/Adv"); }
public void UpdatePackage(Upset package, TemporaryDirectory td) { Upbring upbring = Upbring.Instance(); // Nuking previous version InstalledPackage installedPackage = upbring.GetInstalledPackage(package.PackageName); installedPackage.Nuke(); DependencyDefinition definition = Upfile.Instance().Dependencies.First(dep => dep.Name == package.PackageName); InstallPackage(package, td, definition); }
private void UpdatePackage(Upset package, TemporaryDirectory td, bool updateLockfile) { NukePackage(package.PackageName); // First or default returns the first DependencyDefinition which satistfies dep.Name == package.PackageName // If no elements meets this condition a Default value for DependencyDefinition is returned which, for our implementation, is null. DependencyDefinition definition = Upfile.Instance().Dependencies.FirstOrDefault(dep => dep.Name == package.PackageName); if (definition == null) { definition = new DependencyDefinition() { Name = package.PackageName, Version = package.PackageVersion }; } InstallPackage(package, td, definition, updateLockfile); }
public void InstallDependencies(IDependencySolver dependencySolver) { //FIXME: We should check for all repositories, not the first one //FileRepository rt = (FileRepository) Upfile.Repositories[0]; upfile = Upfile.Instance(); PackageList pList = PackageList.Instance(); DependencyDefinition[] dependencies = dependencySolver.SolveDependencies(upfile.Dependencies); foreach (DependencyDefinition packageDefinition in dependencies) { PackageRepo result = pList.FindPackageAndRepository(packageDefinition); if (result.Repository != null) { using (TemporaryDirectory td = result.Repository.DownloadPackage(result.Package)) { InstallPackage(result.Package, td, packageDefinition); } } } }
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)); } } }
static Initialize() { Upfile.Instance(); }
protected void Given() { UpliftManagerExposer.ClearAllInstances(); pwd = Directory.GetCurrentDirectory(); Helper.InitializeRunDirectory(); try { Directory.SetCurrentDirectory(Helper.testRunDirectoryName); // Upfile Setup for filler package upfile_path = Helper.GetLocalFilePath("..", "TestData", "PackageNuking", "Init_Upfile.xml"); try { UpfileExposer.SetInstance(UpfileExposer.LoadTestXml(upfile_path)); } catch (FileNotFoundException) { Console.WriteLine("Make sure you are running the test from UpliftTesting/TestResults. The Upfile.xml uses the current path to register the repositories."); Assert.Fail("The test could not run correctly. See console message."); } UpfileExposer.TestingInstance(); manager = UpliftManager.Instance(); // Creating original state Directory.CreateDirectory("Assets"); Directory.CreateDirectory("Assets/Media"); File.Create("Assets/scriptA.cs").Dispose(); File.Create("Assets/scriptB.cs").Dispose(); File.Create("Assets/Media/mediaA.txt").Dispose(); File.Create("Assets/Media/mediaB.txt").Dispose(); // Install Filler Package manager.InstallDependencies(); // Save the snapshot original_snapshot = GetSnapshot(); // Proper Upfile Setup UpliftManagerExposer.ClearAllInstances(); UpfileExposer.ClearInstance(); upfile_path = Helper.GetLocalFilePath("..", "TestData", "PackageNuking", "Upfile.xml"); try { UpfileExposer.SetInstance(UpfileExposer.LoadTestXml(upfile_path)); } catch (FileNotFoundException) { Console.WriteLine("Make sure you are running the test from UpliftTesting/TestResults. The Upfile.xml uses the current path to register the repositories."); Assert.IsTrue(false, "The test could not run correctly. See console message."); } Upfile.Instance(); manager = UpliftManager.Instance(); } finally { Directory.SetCurrentDirectory(pwd); } }
public void WhenInstalling() { upfile_path = Helper.GetLocalFilePath("..", "TestData", "BasicPackageInstallation", "Upfile.xml"); try { UpfileExposer.SetInstance(UpfileExposer.LoadTestXml(upfile_path)); } catch (FileNotFoundException) { UnityEngine.Debug.LogError("The Upfile.xml uses the current path to register the repositories."); } Upfile.Instance(); manager = UpliftManager.Instance(); manager.InstallDependencies(); // Directories existence Assert.IsTrue(Directory.Exists("UPackages"), "Directory UPackages does not exist"); Assert.IsTrue(Directory.Exists("UPackages/package_a~1.0.0"), "Package directory does not exist under UPackages"); Assert.IsTrue(Directory.Exists("Assets"), "Directory Assets does not exist"); Assert.IsTrue(Directory.Exists("Assets/UPackages"), "Directory UPackages under Assets does not exist"); Assert.IsTrue(Directory.Exists("Assets/UPackages/package_a~1.0.0"), "Package directory does not exist under Assets/UPackages"); // Files under Assets/UPackages Assert.IsTrue(File.Exists("Assets/UPackages/package_a~1.0.0/A1.cs"), "File A1 did not get copied to Assets/UPackages/package_a~1.0.0"); Assert.IsTrue(File.Exists("Assets/UPackages/package_a~1.0.0/A2.cs"), "File A2 did not get copied to Assets/UPackages/package_a~1.0.0"); Assert.IsTrue(File.Exists("Assets/UPackages/package_a~1.0.0/A3.cs"), "File A3 did not get copied to Assets/UPackages/package_a~1.0.0"); Assert.IsTrue(File.Exists("Assets/UPackages/package_a~1.0.0/Upset.xml"), "Upset file did not get copied to Assets/UPackages/package_a~1.0.0"); // Files under UPackages Assert.IsTrue(File.Exists("UPackages/Upbring.xml"), "Upbring file has not been created"); Assert.IsTrue(File.Exists("UPackages/package_a~1.0.0/A1.cs"), "File A1 did not get copied to UPackages/package_a~1.0.0"); Assert.IsTrue(File.Exists("UPackages/package_a~1.0.0/A2.cs"), "File A2 did not get copied to UPackages/package_a~1.0.0"); Assert.IsTrue(File.Exists("UPackages/package_a~1.0.0/A3.cs"), "File A3 did not get copied to UPackages/package_a~1.0.0"); Assert.IsTrue(File.Exists("UPackages/package_a~1.0.0/Upset.xml"), "Upset file did not get copied to UPackages/package_a~1.0.0"); // Upbring validity Upbring upbring = Upbring.Instance(); Assert.IsNotEmpty(upbring.InstalledPackage, "Upbring file did not registered the installation"); Assert.That(upbring.InstalledPackage.Any(p => p.Name == "package_a" && p.Version == "1.0.0" ), "Upbring did not register an installation with the proper package Name and Version"); Assert.IsNotEmpty(upbring.InstalledPackage[0].Install, "Upbring file did not register file dependencies"); Assert.That(upbring.InstalledPackage[0].Install.Any(i => i is InstallSpecPath && (i as InstallSpecPath).Path == "UPackages/package_a~1.0.0" && i.Type == InstallSpecType.Root ), "Root installation did not get registered"); Assert.That(upbring.InstalledPackage[0].Install.Any(i => i is InstallSpecPath && (i as InstallSpecPath).Path == "Assets/UPackages/package_a~1.0.0/A1.cs" && i.Type == InstallSpecType.Base ), "Base installation of A1.cs did not get registered"); Assert.That(upbring.InstalledPackage[0].Install.Any(i => i is InstallSpecPath && (i as InstallSpecPath).Path == "Assets/UPackages/package_a~1.0.0/A2.cs" && i.Type == InstallSpecType.Base ), "Base installation of A2.cs did not get registered"); Assert.That(upbring.InstalledPackage[0].Install.Any(i => i is InstallSpecPath && (i as InstallSpecPath).Path == "Assets/UPackages/package_a~1.0.0/A3.cs" && i.Type == InstallSpecType.Base ), "Base installation of A3.cs did not get registered"); Assert.That(upbring.InstalledPackage[0].Install.Any(i => i is InstallSpecPath && (i as InstallSpecPath).Path == "Assets/UPackages/package_a~1.0.0/Upset.xml" && i.Type == InstallSpecType.Base ), "Base installation of Upset.xml did not get registered"); }
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(); } } }
internal static void InitializeInstance() { instance = new UpliftManager(); instance.upfile = Upfile.Instance(); }
protected void OnGUI() { #if UNITY_5_1_OR_NEWER titleContent.text = "Edit Upfile"; #endif upfile = Upfile.Instance(); EditorGUILayout.Space(); scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); upfile.UnityVersion = EditorGUILayout.TextField("Unity version:", upfile.UnityVersion); EditorGUILayout.Separator(); if (upfile.Repositories != null) { EditorGUILayout.LabelField("Repositories:", EditorStyles.boldLabel); EditorGUILayout.HelpBox("This sections specifies where Uplift will fetch the packages from.", MessageType.Info); // FIXME: Do not care about Upfile Override repositories upfile.Repositories = ArrayField <Repository>( upfile.Repositories, "Remove repository", "Add another repository", new FileRepository { Path = "Enter a path " }, repo => RepositoryField(repo) ); } else { upfile.Repositories = new Repository[0]; Repaint(); } EditorGUILayout.Separator(); if (upfile.Configuration != null) { EditorGUILayout.LabelField("Configuration:", EditorStyles.boldLabel); EditorGUILayout.HelpBox("This sections specifies where Uplift will install the packages into your project.", MessageType.Info); upfile.Configuration.RepositoryPath = PathField("Repository path:", upfile.Configuration.RepositoryPath); upfile.Configuration.DocsPath = PathField("Documentation path:", upfile.Configuration.DocsPath); upfile.Configuration.ExamplesPath = PathField("Examples path:", upfile.Configuration.ExamplesPath); upfile.Configuration.BaseInstallPath = PathField("Base install path:", upfile.Configuration.BaseInstallPath); upfile.Configuration.MediaPath = PathField("Media path:", upfile.Configuration.MediaPath); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Warning: the following path have special behaviours in Unity. Modify them at your own risk!"); upfile.Configuration.GizmoPath = PathField("Gizmo path:", upfile.Configuration.GizmoPath); upfile.Configuration.PluginPath = PathField("Plugin path:", upfile.Configuration.PluginPath); upfile.Configuration.EditorPluginPath = PathField("Plugin path for the Editor:", upfile.Configuration.EditorPluginPath); } EditorGUILayout.Separator(); if (upfile.Dependencies != null) { EditorGUILayout.LabelField("Dependencies:", EditorStyles.boldLabel); EditorGUILayout.HelpBox("This sections specifies which packages your project depends on.", MessageType.Info); upfile.Dependencies = ArrayField <DependencyDefinition>( upfile.Dependencies, "Remove dependency", "Declare another dependency", new DependencyDefinition { Name = "Enter a package name", Version = "Enter a version" }, def => DependencyField(def) ); } else { upfile.Dependencies = new DependencyDefinition[0]; Repaint(); } EditorGUILayout.EndScrollView(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Refresh Upfile")) { Upfile.InitializeInstance(); } if (GUILayout.Button("Edit raw Upfile")) { EditorWindow.GetWindow(typeof(RawUpfileEditor)); } if (GUILayout.Button("Save Upfile")) { upfile.SaveFile(); } EditorGUILayout.EndHorizontal(); }