Ejemplo n.º 1
0
        public IEnumerable <Artifact> ResolveArtifacts(Model.Index index, IEnumerable <Artifact> dependencies)
        {
            Console.WriteLine("[index][tree]Solving dependencies...");

            var map = new Dictionary <string, IEnumerable <Artifact> >();

            foreach (var dependency in dependencies)
            {
                var key     = dependency.Group + "/" + dependency.Name;
                var matches = index.FindMatches(dependency);

                if (map.ContainsKey(key))
                {
                    var artifactIds          = map[key].Select(x => x.Id);
                    var matchesIds           = matches.Select(x => x.Id);
                    var intersectedIds       = artifactIds.Intersect(matchesIds);
                    var intersectedArtifacts = intersectedIds.Select(x => new Artifact {
                        Id = x
                    });
                    matches = intersectedArtifacts;

                    if (!matches.Any())
                    {
                        throw new PackDmException("Não foi possível resolver uma versão compatível para o artefato porque existem referências desencontradas: " + dependency);
                    }
                }
                else
                {
                    if (!matches.Any())
                    {
                        throw new PackDmException("Não foi possível resolver uma versão compatível para o artefato: " + dependency);
                    }
                }

                map[key] = matches;
            }

            var artifacts = map.Select(m => m.Value.LastOrDefault());

            return(artifacts);
        }
Ejemplo n.º 2
0
        public static Model.Index Load(SourceReader source)
        {
            using (source)
            {
                var reader = source.GetReader();
                var index  = new Model.Index();

                Artifact artifact = null;

                string line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();

                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    var isDependency = line.StartsWith("+");
                    if (isDependency)
                    {
                        Artifact dependency = line.Split('+').Last().Trim();
                        index.RegisterConstraint(artifact, dependency);
                    }
                    else
                    {
                        artifact = line;
                        index.Add(artifact);
                    }
                }

                return(index);
            }
        }