Exemplo n.º 1
0
        public void FromXmlWhenAbsentTest()
        {
            try
            {
                Directory.CreateDirectory(temp_dir);
                Directory.SetCurrentDirectory(temp_dir);
                string repo_path = Path.Combine(temp_dir, Path.GetRandomFileName());
                Directory.CreateDirectory(repo_path);

                Upfile dummy = new Upfile()
                {
                    Configuration = new Configuration()
                    {
                        RepositoryPath = new PathConfiguration()
                        {
                            Location = repo_path
                        }
                    },
                    Dependencies = new DependencyDefinition[0],
                    Repositories = new Repository[0],
                    UnityVersion = "foo"
                };
                UpfileExposer.SetInstance(dummy);

                Upbring.InitializeInstance();

                CollectionAssert.IsEmpty(Upbring.Instance().InstalledPackage);
            }
            finally
            {
                Directory.SetCurrentDirectory(pwd);
                Directory.Delete(temp_dir, true);
            }
        }
Exemplo n.º 2
0
        public DependencyState[] GetDependenciesState(bool refresh = false)
        {
            if (refresh)
            {
                UpliftManager.ResetInstances();
            }
            Upbring upbring = Upbring.Instance();

            PackageRepo[] targets = GetTargets(GetDependencySolver(), InstallStrategy.UPDATE_LOCKFILE, false);

            bool anyInstalled =
                upbring.InstalledPackage != null &&
                upbring.InstalledPackage.Length != 0;

            List <DependencyState> dependenciesState = new List <DependencyState>();

            foreach (DependencyDefinition definition in upfile.Dependencies)
            {
                AppendDependencyState(
                    ref dependenciesState,
                    definition,
                    targets,
                    anyInstalled
                    );
            }

            return(dependenciesState.ToArray());
        }
Exemplo n.º 3
0
        public void InstallPackages(PackageRepo[] targets, bool updateLockfile = true)
        {
            Debug.Log("Install Packages");
            using (LogAggregator LA = LogAggregator.InUnity(
                       "Successfully installed dependencies ({0} actions were done)",
                       "Successfully installed dependencies ({0} actions were done) but warnings were raised",
                       "Some errors occured while installing dependencies",
                       targets.Length
                       ))
            {
                // Remove installed dependencies that are no longer in the dependency tree

                foreach (InstalledPackage ip in Upbring.Instance().InstalledPackage)
                {
                    if (targets.Any(tar => tar.Package.PackageName == ip.Name))
                    {
                        continue;
                    }

                    UnityEngine.Debug.Log("Removing unused dependency on " + ip.Name);

                    NukePackage(ip.Name);
                }

                foreach (PackageRepo pr in targets)
                {
                    if (pr.Repository != null)
                    {
                        if (Upbring.Instance().InstalledPackage.Any(ip => ip.Name == pr.Package.PackageName))
                        {
                            Debug.Log("update " + pr.Package.PackageName);
                            UpdatePackage(pr, updateDependencies: false, updateLockfile: updateLockfile);
                        }
                        else
                        {
                            DependencyDefinition def = upfile.Dependencies.Any(d => d.Name == pr.Package.PackageName) ?
                                                       upfile.Dependencies.First(d => d.Name == pr.Package.PackageName) :
                                                       new DependencyDefinition()
                            {
                                Name = pr.Package.PackageName, Version = pr.Package.PackageVersion
                            };

                            using (TemporaryDirectory td = pr.Repository.DownloadPackage(pr.Package))
                            {
                                Debug.Log("install " + pr.Package.PackageName);
                                InstallPackage(pr.Package, td, def, updateLockfile);
                            }
                        }
                    }
                    else
                    {
                        UnityEngine.Debug.LogError("No repository for package " + pr.Package.PackageName);
                    }
                }
            }
            UnityHacks.BuildSettingsEnforcer.EnforceAssetSave();
        }
Exemplo n.º 4
0
        // What's the difference between Nuke and Uninstall?
        // Nuke doesn't care for dependencies (if present)
        public void NukePackage(string packageName)
        {
            Upbring          upbring = Upbring.Instance();
            InstalledPackage package = upbring.GetInstalledPackage(packageName);

            package.Nuke();
            upbring.RemovePackage(package);
            upbring.SaveFile();
        }
Exemplo n.º 5
0
        // What's the difference between Nuke and Uninstall?
        // Nuke doesn't care for dependencies (if present)
        public void NukePackage(string packageName)
        {
            Upbring          upbring = Upbring.Instance();
            InstalledPackage package = upbring.GetInstalledPackage(packageName);

            package.Nuke();
            upbring.RemovePackage(package);
            upbring.SaveFile();
            UnityHacks.BuildSettingsEnforcer.EnforceAssetSave();
        }
Exemplo n.º 6
0
        public void NukeAllPackages()
        {
            Upbring upbring = Upbring.Instance();

            foreach (InstalledPackage package in upbring.InstalledPackage)
            {
                package.Nuke();
                upbring.RemovePackage(package);
            }

            //TODO: Remove file when Upbring properly removes everything
            Upbring.RemoveFile();
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public void UpdatePackage(PackageRepo newer, bool updateDependencies = true, bool updateLockfile = true)
        {
            InstalledPackage installed = Upbring.Instance().InstalledPackage.First(ip => ip.Name == newer.Package.PackageName);

            // If latest version is greater than the one installed, update to it
            if (string.Equals(newer.Package.PackageVersion, installed.Version))
            {
                UnityEngine.Debug.Log(string.Format("Required version of {0} is already installed ({1})", installed.Name, installed.Version));
                return;
            }
            else
            {
                using (TemporaryDirectory td = newer.Repository.DownloadPackage(newer.Package))
                {
                    Debug.Log("Required version is not installed, updating package");
                    UpdatePackage(newer.Package, td, updateLockfile);
                }
            }

            if (updateDependencies)
            {
                Debug.Log("Update dependencies enabled, starting update :");
                DependencyDefinition[] packageDependencies = PackageList.Instance().ListDependenciesRecursively(
                    GetDependencySolver()
                    .SolveDependencies(upfile.Dependencies)
                    .First(dep => dep.Name == newer.Package.PackageName)
                    );
                foreach (DependencyDefinition def in packageDependencies)
                {
                    PackageRepo dependencyPR = PackageList.Instance().FindPackageAndRepository(def);
                    if (Upbring.Instance().InstalledPackage.Any(ip => ip.Name == def.Name))
                    {
                        UpdatePackage(dependencyPR,
                                      updateDependencies: false,
                                      updateLockfile: updateLockfile
                                      );
                    }
                    else
                    {
                        using (TemporaryDirectory td = dependencyPR.Repository.DownloadPackage(dependencyPR.Package))
                        {
                            InstallPackage(dependencyPR.Package,
                                           td,
                                           def,
                                           updateLockfile: updateLockfile
                                           );
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void FromXmlWhenPresentTest()
        {
            try
            {
                Directory.CreateDirectory(temp_dir);
                Directory.SetCurrentDirectory(temp_dir);
                string repo_path = Path.Combine(temp_dir, Path.GetRandomFileName());
                Directory.CreateDirectory(repo_path);

                Upfile dummy = new Upfile()
                {
                    Configuration = new Configuration()
                    {
                        RepositoryPath = new PathConfiguration()
                        {
                            Location = repo_path
                        }
                    },
                    Dependencies = new DependencyDefinition[0],
                    Repositories = new Repository[0],
                    UnityVersion = "foo"
                };
                UpfileExposer.SetInstance(dummy);

                InstalledPackage package_A = new InstalledPackage()
                {
                    Name = "packageA", Install = new InstallSpec[0], Version = "0.0.0"
                };
                Upbring test = new Upbring()
                {
                    InstalledPackage = new InstalledPackage[] { package_A }
                };
                XmlSerializer serializer = new XmlSerializer(typeof(Upbring));
                using (FileStream fs = new FileStream(Path.Combine(repo_path, "Upbring.xml"), FileMode.Create))
                {
                    serializer.Serialize(fs, test);
                }
                Upbring.InitializeInstance();

                Assert.That(Upbring.Instance().InstalledPackage.Any(p =>
                                                                    p.Name == package_A.Name &&
                                                                    p.Version == package_A.Version
                                                                    ));
            }
            finally
            {
                Directory.SetCurrentDirectory(pwd);
                Directory.Delete(temp_dir, true);
            }
        }
Exemplo n.º 10
0
        public void NukeAllPackages()
        {
            Upbring upbring = Upbring.Instance();

            using (LogAggregator LA = LogAggregator.InUnity(
                       "{0} packages were successfully nuked",
                       "{0} packages were successfully nuked but warnings were raised",
                       "Some errors occured while nuking {0} packages",
                       upbring.InstalledPackage.Length
                       ))
            {
                foreach (InstalledPackage package in upbring.InstalledPackage)
                {
                    package.Nuke();
                    upbring.RemovePackage(package);
                }

                //TODO: Remove file when Upbring properly removes everything
                Upbring.RemoveFile();
            }
        }
Exemplo n.º 11
0
        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));
                }
            }
        }
Exemplo n.º 12
0
        private void AppendDependencyState(
            ref List <DependencyState> dependenciesState,
            DependencyDefinition definition,
            PackageRepo[] targets,
            bool anyInstalled,
            bool transitive = false
            )
        {
            Upbring upbring = Upbring.Instance();

            DependencyState state = new DependencyState
            {
                definition = definition,
                latest     = PackageList.Instance().GetLatestPackage(definition.Name)
            };

            state.bestMatch = targets.First(pr => pr.Package.PackageName == definition.Name);
            if (anyInstalled && upbring.InstalledPackage.Any(ip => ip.Name == definition.Name))
            {
                state.installed = upbring.InstalledPackage.First(ip => ip.Name == definition.Name);
            }
            state.transitive = transitive;

            dependenciesState.Add(state);
            if (state.bestMatch.Package.Dependencies != null)
            {
                foreach (DependencyDefinition dependency in state.bestMatch.Package.Dependencies)
                {
                    AppendDependencyState(
                        ref dependenciesState,
                        dependency,
                        targets,
                        anyInstalled,
                        true
                        );
                }
            }
        }
Exemplo n.º 13
0
        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");
        }
Exemplo n.º 14
0
        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();
                }
            }
        }
Exemplo n.º 15
0
        public void WhenUpdating()
        {
            manager.InstallDependencies();
            Upbring upbring = Upbring.Instance();

            // -- 1.0.0 UNINSTALLATION --
            // Directories absence
            Assert.IsFalse(Directory.Exists("UPackages/package_a~1.0.0"), "Package directory still exists under UPackages");
            Assert.IsFalse(Directory.Exists("Assets/UPackages/package_a~1.0.0"), "Package directory still exists under Assets/UPackages");

            // Upbring validity
            Assert.IsFalse((upbring.InstalledPackage.Any(p =>
                                                         p.Name == "package_a" &&
                                                         p.Version == "1.0.0"
                                                         )), "Upbring did not properly forget the outdated installation");

            // -- 1.0.1 INSTALLATION --
            // Directories existence
            Assert.IsTrue(Directory.Exists("UPackages"), "Directory UPackages does not exist");
            Assert.IsTrue(Directory.Exists("UPackages/package_a~1.0.1"), "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.1"), "Package directory does not exist under Assets/UPackages");

            // 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.1/A1.cs"), "File A1 did not get copied to UPackages/package_a~1.0.1");
            Assert.IsTrue(File.Exists("UPackages/package_a~1.0.1/A2.cs"), "File A2 did not get copied to UPackages/package_a~1.0.1");
            Assert.IsTrue(File.Exists("UPackages/package_a~1.0.1/A3.cs"), "File A3 did not get copied to UPackages/package_a~1.0.1");
            Assert.IsTrue(File.Exists("UPackages/package_a~1.0.1/Upset.xml"), "Upset file did not get copied to UPackages/package_a~1.0.1");

            // Upbring validity
            Assert.IsNotEmpty(upbring.InstalledPackage, "Upbring file did not registered the new installation");
            Assert.That(upbring.InstalledPackage.Any(p =>
                                                     p.Name == "package_a" &&
                                                     p.Version == "1.0.1"
                                                     ), "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");
            // FIXME: Refactor the test to take into account the GUID tracking

            /*
             * Assert.That(upbring.InstalledPackage[0].Install.Any(i =>
             * i.Path == Path.Combine("UPackages", "package_a~1.0.1") &&
             * i.Type == InstallSpecType.Root
             * ), "Root installation did not get registered");
             * Assert.That(upbring.InstalledPackage[0].Install.Any(i =>
             * i.Path == Path.Combine(new string[] { "Assets", "UPackages", "package_a~1.0.1", "A1.cs" }) &&
             * i.Type == InstallSpecType.Base
             * ), "Base installation of A1.cs did not get registered");
             * Assert.That(upbring.InstalledPackage[0].Install.Any(i =>
             * i.Path == Path.Combine(new string[] { "Assets", "UPackages", "package_a~1.0.1", "A2.cs" }) &&
             * i.Type == InstallSpecType.Base
             * ), "Base installation of A2.cs did not get registered");
             * Assert.That(upbring.InstalledPackage[0].Install.Any(i =>
             * i.Path == Path.Combine(new string[] { "Assets", "UPackages", "package_a~1.0.1", "A3.cs" }) &&
             * i.Type == InstallSpecType.Base
             * ), "Base installation of A3.cs did not get registered");
             * Assert.That(upbring.InstalledPackage[0].Install.Any(i =>
             * i.Path == Path.Combine(new string[] { "Assets", "UPackages", "package_a~1.0.1", "Upset.xml" }) &&
             * i.Type == InstallSpecType.Base
             * ), "Base installation of Upset.xml did not get registered");
             */
        }
Exemplo n.º 16
0
        //FIXME: This is super unsafe right now, as we can copy down into the FS.
        // This should be contained using kinds of destinations.
        private void InstallPackage(Upset package, TemporaryDirectory td, DependencyDefinition dependencyDefinition, bool updateLockfile = false)
        {
            GitIgnorer VCSHandler = new GitIgnorer();

            using (LogAggregator LA = LogAggregator.InUnity(
                       "Package {0} was successfully installed",
                       "Package {0} was successfully installed but raised warnings",
                       "An error occured while installing package {0}",
                       package.PackageName
                       ))
            {
                Upbring upbring = Upbring.Instance();

                // Note: Full package is ALWAYS copied to the upackages directory right now
                string localPackagePath = GetRepositoryInstallPath(package);
                upbring.AddPackage(package);
                if (!Directory.Exists(localPackagePath))
                {
                    Directory.CreateDirectory(localPackagePath);
                }

                Uplift.Common.FileSystemUtil.CopyDirectory(td.Path, localPackagePath);
                upbring.AddLocation(package, InstallSpecType.Root, localPackagePath);

                VCSHandler.HandleDirectory(upfile.GetPackagesRootPath());

                InstallSpecPath[] specArray;
                if (package.Configuration == null)
                {
                    // If there is no Configuration present we assume
                    // that the whole package is wrapped in "InstallSpecType.Base"
                    InstallSpecPath wrapSpec = new InstallSpecPath
                    {
                        Path = "",
                        Type = InstallSpecType.Base
                    };

                    specArray = new[] { wrapSpec };
                }
                else
                {
                    specArray = package.Configuration;
                }

                foreach (InstallSpecPath spec in specArray)
                {
                    if (dependencyDefinition.SkipInstall != null && dependencyDefinition.SkipInstall.Any(skip => skip.Type == spec.Type))
                    {
                        continue;
                    }

                    var sourcePath = Uplift.Common.FileSystemUtil.JoinPaths(td.Path, spec.Path);

                    PathConfiguration PH = upfile.GetDestinationFor(spec);
                    if (dependencyDefinition.OverrideDestination != null && dependencyDefinition.OverrideDestination.Any(over => over.Type == spec.Type))
                    {
                        PH.Location = Uplift.Common.FileSystemUtil.MakePathOSFriendly(dependencyDefinition.OverrideDestination.First(over => over.Type == spec.Type).Location);
                    }

                    var packageStructurePrefix =
                        PH.SkipPackageStructure ? "" : GetPackageDirectory(package);

                    var destination = Path.Combine(PH.Location, packageStructurePrefix);

                    // Working with single file
                    if (File.Exists(sourcePath))
                    {
                        // Working with singular file
                        if (!Directory.Exists(destination))
                        {
                            Directory.CreateDirectory(destination);
                            VCSHandler.HandleFile(destination);
                        }
                        if (Directory.Exists(destination))
                        { // we are copying a file into a directory
                            destination = System.IO.Path.Combine(destination, System.IO.Path.GetFileName(sourcePath));
                        }
                        File.Copy(sourcePath, destination);
                        Uplift.Common.FileSystemUtil.TryCopyMeta(sourcePath, destination);

                        if (destination.StartsWith("Assets"))
                        {
                            TryUpringAddGUID(upbring, sourcePath, package, spec.Type, destination);
                        }
                        else
                        {
                            upbring.AddLocation(package, spec.Type, destination);
                        }
                    }

                    // Working with directory
                    if (Directory.Exists(sourcePath))
                    {
                        // Working with directory
                        Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, destination);
                        if (!PH.SkipPackageStructure)
                        {
                            VCSHandler.HandleDirectory(destination);
                        }

                        bool useGuid = destination.StartsWith("Assets");
                        foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true))
                        {
                            if (useGuid)
                            {
                                TryUpringAddGUID(upbring, file, package, spec.Type, destination);
                            }
                            else
                            {
                                upbring.AddLocation(package, spec.Type, Path.Combine(destination, file));
                            }

                            if (PH.SkipPackageStructure)
                            {
                                VCSHandler.HandleFile(Path.Combine(destination, file));
                            }
                        }
                    }
                }

                upbring.SaveFile();

                if (updateLockfile)
                {
                    LockfileSnapshot snapshot = LoadLockfile();
                    int  index;
                    bool found = false;
                    for (index = 0; index < snapshot.installableDependencies.Length; index++)
                    {
                        if (snapshot.installableDependencies[index].Package.PackageName == package.PackageName)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        snapshot.installableDependencies[index].Package = package;
                    }
                    else
                    {
                        Array.Resize <PackageRepo>(ref snapshot.installableDependencies, snapshot.installableDependencies.Length + 1);
                        snapshot.installableDependencies[snapshot.installableDependencies.Length] = new PackageRepo {
                            Package = package
                        };
                    }
                    GenerateLockfile(snapshot);
                }

                td.Dispose();
                UnityHacks.BuildSettingsEnforcer.EnforceAssetSave();
            }
        }
Exemplo n.º 17
0
        //FIXME: This is super unsafe right now, as we can copy down into the FS.
        // This should be contained using kinds of destinations.
        public void InstallPackage(Upset package, TemporaryDirectory td, DependencyDefinition dependencyDefinition)
        {
            Upbring upbring = Upbring.Instance();
            // Note: Full package is ALWAYS copied to the upackages directory right now
            string localPackagePath = GetRepositoryInstallPath(package);

            upbring.AddPackage(package);
            FileSystemUtil.CopyDirectory(td.Path, localPackagePath);
            upbring.AddLocation(package, InstallSpecType.Root, localPackagePath);

            InstallSpecPath[] specArray;
            if (package.Configuration == null)
            {
                // If there is no Configuration present we assume
                // that the whole package is wrapped in "InstallSpecType.Base"
                InstallSpecPath wrapSpec = new InstallSpecPath
                {
                    Path = "",
                    Type = InstallSpecType.Base
                };

                specArray = new[] { wrapSpec };
            }
            else
            {
                specArray = package.Configuration;
            }

            foreach (InstallSpecPath spec in specArray)
            {
                if (dependencyDefinition.SkipInstall != null && dependencyDefinition.SkipInstall.Any(skip => skip.Type == spec.Type))
                {
                    continue;
                }

                var sourcePath = Uplift.Common.FileSystemUtil.JoinPaths(td.Path, spec.Path);

                PathConfiguration PH = upfile.GetDestinationFor(spec);
                if (dependencyDefinition.OverrideDestination != null && dependencyDefinition.OverrideDestination.Any(over => over.Type == spec.Type))
                {
                    PH.Location = Uplift.Common.FileSystemUtil.MakePathOSFriendly(dependencyDefinition.OverrideDestination.First(over => over.Type == spec.Type).Location);
                }

                var packageStructurePrefix =
                    PH.SkipPackageStructure ? "" : GetPackageDirectory(package);

                var destination = Path.Combine(PH.Location, packageStructurePrefix);

                // Working with single file
                if (File.Exists(sourcePath))
                {
                    // Working with singular file
                    if (!Directory.Exists(destination))
                    {
                        Directory.CreateDirectory(destination);
                    }
                    File.Copy(sourcePath, destination);
                    FileSystemUtil.TryCopyMeta(sourcePath, destination);

                    if (destination.StartsWith("Assets"))
                    {
                        TryUpringAddGUID(upbring, sourcePath, package, spec.Type, destination);
                    }
                    else
                    {
                        upbring.AddLocation(package, spec.Type, destination);
                    }
                }

                // Working with directory
                if (Directory.Exists(sourcePath))
                {
                    // Working with directory
                    Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, destination);

                    if (destination.StartsWith("Assets"))
                    {
                        foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true))
                        {
                            TryUpringAddGUID(upbring, file, package, spec.Type, destination);
                        }
                    }
                    else
                    {
                        foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true))
                        {
                            upbring.AddLocation(package, spec.Type, Path.Combine(destination, file));
                        }
                    }
                }
            }

            upbring.SaveFile();

            td.Dispose();
        }