Exemplo n.º 1
0
        private static void CheckDependencies()
        {
            using (LogAggregator LA = LogAggregator.InUnity(
                       "Dependencies state:",
                       "Dependencies state:",
                       "Dependencies state:"
                       ))
            {
                UpliftManager.DependencyState[] states = UpliftManager.Instance().GetDependenciesState();

                foreach (UpliftManager.DependencyState state in states)
                {
                    string message = string.Format("Package {0} ({1}) ", state.definition.Name, state.definition.Version);
                    if (state.installed != null)
                    {
                        if (state.installed.Version != state.bestMatch.Package.PackageVersion)
                        {
                            message += string.Format(
                                "is outdated. Best available version is {0} (from {1})",
                                state.bestMatch.Package.PackageVersion,
                                state.bestMatch.Repository.ToString()
                                );
                        }
                        else
                        {
                            message += "is up to date.";
                        }

                        if (!state.definition.Requirement.IsMetBy(state.installed.Version))
                        {
                            message += "\nWarning: the package currently installed does not match your requirements";
                        }
                    }
                    else
                    {
                        message += string.Format(
                            "is not installed. Best available version is {0} (from {1})",
                            state.bestMatch.Package.PackageVersion,
                            state.bestMatch.Repository.ToString()
                            );
                    }

                    if (state.latest.Package.PackageVersion != state.bestMatch.Package.PackageVersion)
                    {
                        message += string.Format(
                            "\nNote: there is a more recent version of the package ({0} from {1}), but it doesn't match your requirement",
                            state.latest.Package.PackageVersion,
                            state.bestMatch.Repository.ToString()
                            );
                    }

                    if (state.transitive)
                    {
                        message = "`--> " + string.Join("    \n", message.Split('\n'));
                    }

                    Debug.Log(message);
                }
            }
        }
Exemplo n.º 2
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.º 3
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.º 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.
        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();
            }
        }