Example #1
0
        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);
                    }
                }
            }
        }
Example #2
0
        private PackageRepo[] GetTargets(IDependencySolver solver, InstallStrategy strategy, bool updateLockfile = true)
        {
            DependencyDefinition[] upfileDependencies      = upfile.Dependencies;
            DependencyDefinition[] solvedDependencies      = solver.SolveDependencies(upfileDependencies);
            PackageRepo[]          installableDependencies = IdentifyInstallable(solvedDependencies);
            PackageRepo[]          targets = new PackageRepo[0];
            bool present = File.Exists(lockfilePath);

            if (strategy == InstallStrategy.UPDATE_LOCKFILE || (strategy == InstallStrategy.INCOMPLETE_LOCKFILE && !present))
            {
                if (updateLockfile)
                {
                    GenerateLockfile(new LockfileSnapshot
                    {
                        upfileDependencies      = upfileDependencies,
                        installableDependencies = installableDependencies
                    });
                }
                targets = installableDependencies;
            }
            else if (strategy == InstallStrategy.INCOMPLETE_LOCKFILE)
            {
                // Case where the file does not exist is already covered
                LockfileSnapshot snapshot = LoadLockfile();

                DependencyDefinition[] modifiedDependencies =
                    upfileDependencies
                    .Where(def => !snapshot.upfileDependencies.Any(
                               d => d.Name == def.Name && d.Version == def.Version
                               ))
                    .ToArray();
                if (modifiedDependencies.Length == 0)
                {
                    targets = installableDependencies;
                }
                else
                {
                    // Fetch all the PackageRepo for the unmodified packages
                    List <PackageRepo>  unmodifiableList = new List <PackageRepo>();
                    Queue <PackageRepo> scanningQueue    = new Queue <PackageRepo>();
                    foreach (DependencyDefinition def in snapshot.upfileDependencies.Where(directDepency => !modifiedDependencies.Any(d => d.Name == directDepency.Name)))
                    {
                        scanningQueue.Enqueue(snapshot.installableDependencies.First(pr => pr.Package.PackageName == def.Name));
                    }

                    while (scanningQueue.Count != 0)
                    {
                        PackageRepo top = scanningQueue.Dequeue();
                        unmodifiableList.Add(top);
                        if (top.Package.Dependencies != null)
                        {
                            foreach (DependencyDefinition def in top.Package.Dependencies)
                            {
                                scanningQueue.Enqueue(snapshot.installableDependencies.First(pr => pr.Package.PackageName == def.Name));
                            }
                        }
                    }
                    PackageRepo[] unmodifiable =
                        snapshot.installableDependencies
                        .Where(pr => unmodifiableList.Any(unmodpr =>
                                                          unmodpr.Package.PackageName == pr.Package.PackageName &&
                                                          unmodpr.Package.PackageVersion == pr.Package.PackageVersion
                                                          ))
                        .ToArray();

                    DependencyDefinition[] solvedModified = solver.SolveDependencies(modifiedDependencies);
                    DependencyDefinition[] conflicting    = solvedModified.Where(def => unmodifiable.Any(pr => pr.Package.PackageName == def.Name)).ToArray();
                    if (conflicting.Length != 0)
                    {
                        foreach (DependencyDefinition def in conflicting)
                        {
                            if (!def.Requirement.IsMetBy(unmodifiable.First(pr => pr.Package.PackageName == def.Name).Package.PackageVersion))
                            {
                                throw new ApplicationException("Existing dependency on " + def.Name + " would be broken when installing. Please update it manually.");
                            }
                        }

                        solvedModified = solvedModified.Where(def => !conflicting.Contains(def)).ToArray();
                    }
                    PackageRepo[] installableModified = IdentifyInstallable(solvedModified);
                    targets = new PackageRepo[unmodifiable.Length + installableModified.Length];
                    Array.Copy(unmodifiable, targets, unmodifiable.Length);
                    Array.Copy(installableModified, 0, targets, unmodifiable.Length, installableModified.Length);
                }

                if (updateLockfile)
                {
                    GenerateLockfile(new LockfileSnapshot
                    {
                        upfileDependencies      = upfileDependencies,
                        installableDependencies = targets
                    });
                }
            }
            else if (strategy == InstallStrategy.ONLY_LOCKFILE)
            {
                if (!present)
                {
                    throw new ApplicationException("Uplift cannot install dependencies in strategy ONLY_LOCKFILE if there is no lockfile");
                }

                targets = LoadLockfile().installableDependencies;
            }
            else
            {
                throw new ArgumentException("Unknown install strategy: " + strategy);
            }

            return(targets);
        }