Exemplo n.º 1
0
 public static List<Wish> CloneAndFillInBlanksFrom(IEnumerable<Wish> deps, Wish defaultDep)
 {
     var merged = new List<Wish>();
     foreach (var dep in deps) {
         merged.Add(dep.CloneAndFillInBlanksFrom(defaultDep));
     }
     return merged;
 }
Exemplo n.º 2
0
 public void AddOrFailIfExists(Wish wish)
 {
     var key = wish.Key;
     if (m_wishesByKey.ContainsKey(key)) {
         throw new ResolverException("Duplicate wish :" + wish);
     }
     m_wishesByKey[key] = wish;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Add a wish unless there is already a matching constraint
 /// </summary>
 /// <returns>true if added, false if there was already a wish matching the same requirements</returns>
 public bool AddWish(Wish wish)
 {
     if (FilterExistsFor(wish)) {
         return false;
     }
     Log.Trace("Adding " + wish.ToSummary());
     return LocalWishSetFor(wish).AddIfNotExists(wish);
 }
Exemplo n.º 4
0
        public void MergeInChild(Wish wish)
        {
            var key = wish.Key;

            Wish existing;
            if (m_wishesByKey.TryGetValue(key, out existing)) {
                m_wishesByKey[key] = wish.CloneAndFillInBlanksFrom(existing);
            } else {
                m_wishesByKey[key] = wish;
            }
        }
Exemplo n.º 5
0
        public override void AfterLoad()
        {
            if (ProjectFormat != SupportedVersion) {
                throw new ArgumentException("This solution only supports format version " + SupportedVersion + ". Instead got " + ProjectFormat);
            }
            base.AfterLoad();

            //Apply defaults
            WishDefaults = WishDefaults == null ? DefaultWishValues.Clone() : WishDefaults.CloneAndFillInBlanksFrom(DefaultWishValues);
            WishDefaults.Scope = Scopes.Transitive;

            //CompileWishes = Wish.CloneAndFillInBlanksFrom(CompileWishes, WishDefaults);
            RuntimeWishes = PostProcess(RuntimeWishes, WishDefaults, Scopes.Runtime);
            ProvidedWishes = PostProcess(ProvidedWishes, WishDefaults, Scopes.Provided);
            OptionalWishes = PostProcess(OptionalWishes, WishDefaults, Scopes.Transitive);
            TransitiveWishes = PostProcess(TransitiveWishes, WishDefaults, Scopes.Transitive);

            ValidateReadyForMerge(RuntimeWishes);
            ValidateReadyForMerge(ProvidedWishes);
            ValidateReadyForMerge(OptionalWishes);
            ValidateReadyForMerge(TransitiveWishes);
        }
Exemplo n.º 6
0
 public NewModule RuntimeWishWith(Wish wish)
 {
     base.RuntimeWishes.Add(wish);
     return this;
 }
Exemplo n.º 7
0
 public NewModule TransitiveWishWith(Wish wish)
 {
     base.TransitiveWishes.Add(wish);
     return this;
 }
Exemplo n.º 8
0
 private static Key Key(Wish wish)
 {
     return wish.Key;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Parse from  group:name:version:ext:classifiers:scope
 /// </summary>
 /// <param name="fullString">Full string.</param>
 public static Wish Parse(String fullString)
 {
     var wish = new Wish();
     wish.SetAllFromParse(fullString);
     return wish;
 }
Exemplo n.º 10
0
 private void InternalFillInBlanksFrom(Wish wish)
 {
     if (wish == null) {
         return;
     }
     InternalFillInSimpleBlanksFrom(wish);
 }
Exemplo n.º 11
0
        private void InternalFillInSimpleBlanksFrom(Wish fromWish)
        {
            if (fromWish == null) {
                return;
            }
            var modified = false;
            if (String.IsNullOrWhiteSpace(this.Group) && !String.IsNullOrWhiteSpace(fromWish.Group)) {
                this.Group = fromWish.Group;
                modified = true;
            }
            if (String.IsNullOrWhiteSpace(this.Name) && !String.IsNullOrWhiteSpace(fromWish.Name)) {
                this.Name = fromWish.Name;
                modified = true;
            }
            if (String.IsNullOrWhiteSpace(this.Ext) && !String.IsNullOrWhiteSpace(fromWish.Ext)) {
                this.Ext = fromWish.Ext;
                modified = true;
            }
            if (this.Url == null && fromWish.Url != null) {
                this.Url = fromWish.Url;
                modified = true;
            }
            if (String.IsNullOrWhiteSpace(this.CopyTo) && !String.IsNullOrWhiteSpace(fromWish.CopyTo)) {
                this.CopyTo = fromWish.CopyTo;
                modified = true;
            }
            if (this.Version == null && fromWish.Version != null) {
                this.Version = fromWish.Version;
                modified = true;
            }
            if (this.Classifiers.Count == 0 && fromWish.Classifiers.Count > 0 ) {
                this.Classifiers = fromWish.Classifiers.Clone();
                modified = true;
            }
            if (String.IsNullOrWhiteSpace(this.Arch) && !String.IsNullOrWhiteSpace(fromWish.Arch)) {
                this.Arch = fromWish.Arch;
                modified = true;
            }
            if (String.IsNullOrWhiteSpace(this.Runtime) && !String.IsNullOrWhiteSpace(fromWish.Runtime)) {
                this.Runtime = fromWish.Runtime;
                modified = true;
            }

            if (fromWish.Scope > Scope) {
                this.Scope = fromWish.Scope;
                modified = true;
            }

            //TODO:also set sources on the merged lists
            this.TransitiveWishes = MergeLists(fromWish.TransitiveWishes, this.TransitiveWishes);

            if (modified) {
                SourceLocations.AddToSourceLocations(this, fromWish.Source);
            }
        }
Exemplo n.º 12
0
 public bool FilterExistsFor(Wish wish)
 {
     var set = GetWishSetForOrNull(wish);
     return set != null && set.ContainsVersion(wish.Version) && set.HighestScope >= wish.Scope;
 }
Exemplo n.º 13
0
 public NewProject TransitiveWish(Wish d)
 {
     base.TransitiveWishes.Add(d.Clone());
     return this;
 }
Exemplo n.º 14
0
 public NewModule OptionalWishWith(Wish wish)
 {
     base.OptionalWishes.Add(wish);
     return this;
 }
Exemplo n.º 15
0
 private ResolverWishSet GetWishSetForOrNull(Wish wish)
 {
     ResolverWishSet set;
     if(m_wishSetsByKey.TryGetValue(wish.Key, out set)){
         return set;
     }
     return null;
 }
Exemplo n.º 16
0
        private List<Wish> PostProcess(List<Wish> wishes, Wish defaults, Scopes scope)
        {
            wishes = Wish.CloneAndFillInBlanksFrom(wishes, defaults);
            wishes.ForEach(w => {
                w.Scope = scope;
                if( w.Version==null ){
                    w.Version = VersionMatcher.AnyMatcher;
                }
                //TODO:recursive?
                SetChildTransitivies(w);
            });

            SourceLocations.AddToSourceLocations(wishes, Source);
            return wishes;
        }
Exemplo n.º 17
0
 private void IncludeTransitivesOf(WishList addTo, int depth, Wish wish)
 {
     foreach (var child in wish.TransitiveWishes) {
         addTo.AddOrFailIfExists(child);
         IncludeTransitivesOf(addTo, depth + 1, child);
     }
 }
Exemplo n.º 18
0
 private static void SetChildTransitivies(Wish wish)
 {
     foreach (var child in wish.TransitiveWishes) {
         child.Scope = Scopes.Transitive;
         SetChildTransitivies(child);
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Pick the next child line where one more dependency is picked and any resolution without picking another aribitrary version
 /// is also performed
 /// </summary>
 /// <returns>Pick the next line with atleast one wish resolved by picking some version. More wishes could be resolved due to this
 /// adding additional wishes for the picked version which causes other wishes to resolve to a fixed dep</returns>
 internal ResolverLine PickNextLine()
 {
     Log.Trace("PickNextLine");
     m_wishSets.PrintResolvedSoFar();
     m_wishSets.PrintNeedResolving();
     //TODO:introduce a strategy here to allow different pick strategies
     //pick a version of each requirement. Pick versions with the least amount of change first
     //a.k.a build incr first, then minor, then major
     foreach (var unfixed in m_wishSets.FindAllUnfixedWishSets().Where(w => !w.HasOnlyTransitive())) {
         Dependency fixedDep;
         do {
             var nextWishSetToBeFixed = m_wishSets.LocalWishSetFor(unfixed.FirstWish);
             Log.Debug("picking dep for wishes : " + nextWishSetToBeFixed.ToSummary());
             fixedDep = nextWishSetToBeFixed.PickNextFixedDependency();
             Log.Debug("picked dep : " + fixedDep.SafeToSummary());
             if (fixedDep == null) {
                 Log.Debug("no more options for : " + nextWishSetToBeFixed.SafeToSummary());
                 //no more deps to pick from, lets try to pick another wish to fix tos a set dependency
                 continue;
             }
             var nextLine = NewChildLine();
             var fixedWish = new Wish(fixedDep){Scope = unfixed.HighestScope};
             Log.Debug("fixing dep using wish : " + fixedWish.SafeToSummary());
             nextLine.AddWish(fixedWish);
             nextLine.ResolveWhatCanBe();
             if (nextLine.CanMatch()) {
                 Log.Debug("returning next line");
                 return nextLine;
             } else {
                 Log.Debug("Can't match next line, trying next new line");
             }
         } while( fixedDep != null );
     }
     Log.Trace("no next candidates, returning null");
     return null;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Add a wish unless there is already a matching constraint
 /// </summary>
 /// <returns>true if added, false if there was already a wish matching the same requirements</returns>
 internal bool AddWish(Wish wish)
 {
     return m_wishSets.AddWish(wish);
 }
Exemplo n.º 21
0
 public ResolverWishSet LocalWishSetFor(Wish wish)
 {
     var key = wish.Key;
     //already added our filter
     if (m_localModifiedKeys.Contains(key)) {
         return m_wishSetsByKey[key];
     }
     m_localModifiedKeys.Add(key);
     ResolverWishSet existingWishes;
     if (m_wishSetsByKey.TryGetValue(key, out existingWishes)) { //if we already have a wishlist for this type then add another version constraint on to it
         var wrappingSet = new ResolverWishSet(wish, existingWishes);
         m_wishSetsByKey[key] = wrappingSet;
         Log.Trace("Wrapped existing wishset : " + existingWishes.ToSummary());
         return wrappingSet;
     } else { //a new key and therefore wishlist
         var newSet = new ResolverWishSet(wish, m_cache);
         m_wishSetsByKey[key] = newSet;
         Log.Trace("Added new wishset : " + newSet.ToSummary());
         return newSet;
     }
 }
Exemplo n.º 22
0
 public NewSolution Wish(Wish wish)
 {
     base.Wishes.Add(wish.Clone());
     return this;
 }
Exemplo n.º 23
0
 public Wish Clone()
 {
     var clone = new Wish();
     Clone(clone);
     clone.Version = Version;
     clone.Scope = Scope;
     clone.CopyTo = CopyTo;
     clone.TransitiveWishes = TransitiveWishes==null?new List<Wish>():new List<Wish>(TransitiveWishes);
     return clone;
 }
Exemplo n.º 24
0
 public Wish CloneAndFillInBlanksFrom(Wish parent)
 {
     var clone = Clone();
     clone.InternalFillInBlanksFrom(parent);
     return clone;
 }
Exemplo n.º 25
0
 public IList<Dependency> FindDependenciesMatching(Wish wish)
 {
     return m_cache.FindDependenciesMatching(wish);
 }
Exemplo n.º 26
0
 public NewProject RuntimeWish(Wish d)
 {
     base.RuntimeWishes.Add(d.Clone());
     return this;
 }