Exemple #1
0
        public void GetDestinationForDefault()
        {
            Upfile upfile = new Upfile();

            upfile.Configuration = new Configuration
            {
                BaseInstallPath = new PathConfiguration {
                    Location = "foo"
                }
            };

            InstallSpec test_spec = new InstallSpecPath();

            Assert.AreEqual("foo", upfile.GetDestinationFor(test_spec).Location);
        }
Exemple #2
0
        public void GetDestinationForPlugin()
        {
            Upfile upfile = new Upfile();

            upfile.Configuration = new Configuration
            {
                PluginPath = new PathConfiguration {
                    Location = "foo"
                }
            };

            InstallSpec test_spec = new InstallSpecPath
            {
                Type = InstallSpecType.Plugin
            };

            Assert.AreEqual("foo", upfile.GetDestinationFor(test_spec).Location);
        }
Exemple #3
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();
            }
        }
Exemple #4
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();
        }