コード例 #1
0
 private void HandleCompileConflict(ConflictItem conflictItem)
 {
     if (conflictItem.ItemType == ConflictItemType.Reference)
     {
         referenceConflicts.Add(conflictItem.OriginalItem);
     }
     allConflicts.Add(conflictItem);
 }
コード例 #2
0
        private ITaskItem CreateConflictTaskItem(ConflictItem conflict)
        {
            var item = new TaskItem(conflict.SourcePath);

            if (conflict.PackageId != null)
            {
                item.SetMetadata(nameof(ConflictItemType), conflict.ItemType.ToString());
            }

            return(item);
        }
コード例 #3
0
ファイル: ConflictResolver.cs プロジェクト: NathanG/standard
        public void ResolveConflicts(IEnumerable<ConflictItem> conflictItems, Func<ConflictItem, string> getItemKey, Action<ConflictItem> foundConflict, bool commitWinner = true)
        {
            if (conflictItems == null)
            {
                return;
            }

            foreach (var conflictItem in conflictItems)
            {
                var itemKey = getItemKey(conflictItem);

                if (String.IsNullOrEmpty(itemKey))
                {
                    continue;
                }

                ConflictItem existingItem;

                if (winningItemsByKey.TryGetValue(itemKey, out existingItem))
                {
                    // a conflict was found, determine the winner.
                    var winner = ResolveConflict(existingItem, conflictItem);

                    if (winner == null)
                    {
                        // no winner, skip it.
                        // don't add to conflict list and just use the existing item for future conflicts.
                        continue;
                    }

                    ConflictItem loser = conflictItem;
                    if (!ReferenceEquals(winner, existingItem))
                    {
                        // replace existing item
                        if (commitWinner)
                        {
                            winningItemsByKey[itemKey] = conflictItem;
                        }
                        else
                        {
                            winningItemsByKey.Remove(itemKey);
                        }
                        loser = existingItem;

                    }

                    foundConflict(loser);
                }
                else if (commitWinner)
                {
                    winningItemsByKey[itemKey] = conflictItem;
                }
            }
        }
コード例 #4
0
 private void HandleRuntimeConflict(ConflictItem conflictItem)
 {
     if (conflictItem.ItemType == ConflictItemType.Reference)
     {
         conflictItem.OriginalItem.SetMetadata(MetadataNames.Private, "False");
     }
     else if (conflictItem.ItemType == ConflictItemType.CopyLocal)
     {
         copyLocalConflicts.Add(conflictItem.OriginalItem);
     }
     allConflicts.Add(conflictItem);
 }
コード例 #5
0
        private ConflictItem ResolveConflict(ConflictItem item1, ConflictItem item2)
        {
            var conflictMessage = $"Encountered conflict between {item1.DisplayName} and {item2.DisplayName}.";

            var forcedPackageRank1 = forcedPackageRank.GetPackageRank(item1.PackageId);
            var forcedPackageRank2 = forcedPackageRank.GetPackageRank(item2.PackageId);

            if (forcedPackageRank1 < forcedPackageRank2)
            {
                log.LogMessage($"{conflictMessage}.  Choosing {item1.DisplayName} because package it comes from a package that is forced.");
                return(item1);
            }

            if (forcedPackageRank1 < forcedPackageRank2)
            {
                log.LogMessage($"{conflictMessage}.  Choosing {item2.DisplayName} because package it comes from a package that is forced.");
                return(item2);
            }

            var exists1 = item1.Exists;
            var exists2 = item2.Exists;

            if (!exists1 || !exists2)
            {
                var fileMessage = !exists1 ?
                                  !exists2 ?
                                  "both files do" :
                                  $"{item1.DisplayName} does" :
                                  $"{item2.DisplayName} does";

                log.LogMessage($"{conflictMessage}.  Could not determine winner because {fileMessage} not exist.");
                return(null);
            }

            var assemblyVersion1 = item1.AssemblyVersion;
            var assemblyVersion2 = item2.AssemblyVersion;

            // if only one is missing version stop: something is wrong when we have a conflict between assembly and non-assembly
            if (assemblyVersion1 == null ^ assemblyVersion2 == null)
            {
                var nonAssembly = assemblyVersion1 == null ? item1.DisplayName : item2.DisplayName;
                log.LogMessage($"{conflictMessage}. Could not determine a winner because {nonAssembly} is not an assembly.");
                return(null);
            }

            // only handle cases where assembly version is different, and not null (implicit here due to xor above)
            if (assemblyVersion1 != assemblyVersion2)
            {
                if (assemblyVersion1 > assemblyVersion2)
                {
                    log.LogMessage($"{conflictMessage}.  Choosing {item1.DisplayName} because AssemblyVersion {assemblyVersion1} is greater than {assemblyVersion2}.");
                    return(item1);
                }

                if (assemblyVersion2 > assemblyVersion1)
                {
                    log.LogMessage($"{conflictMessage}.  Choosing {item2.DisplayName} because AssemblyVersion {assemblyVersion2} is greater than {assemblyVersion1}.");
                    return(item2);
                }
            }

            var fileVersion1 = item1.FileVersion;
            var fileVersion2 = item2.FileVersion;

            // if only one is missing version
            if (fileVersion1 == null ^ fileVersion2 == null)
            {
                var nonVersion = fileVersion1 == null ? item1.DisplayName : item2.DisplayName;
                log.LogMessage($"{conflictMessage}. Could not determine a winner because {nonVersion} has no file version.");
                return(null);
            }

            if (fileVersion1 != fileVersion2)
            {
                if (fileVersion1 > fileVersion2)
                {
                    log.LogMessage($"{conflictMessage}.  Choosing {item1.DisplayName} because file version {fileVersion1} is greater than {fileVersion2}.");
                    return(item1);
                }

                if (fileVersion2 > fileVersion1)
                {
                    log.LogMessage($"{conflictMessage}.  Choosing {item2.DisplayName} because file version {fileVersion2} is greater than {fileVersion1}.");
                    return(item2);
                }
            }

            var preferredPackageRank1 = preferredPackageRank.GetPackageRank(item1.PackageId);
            var preferredPackageRank2 = preferredPackageRank.GetPackageRank(item2.PackageId);

            if (preferredPackageRank1 < preferredPackageRank2)
            {
                log.LogMessage($"{conflictMessage}.  Choosing {item1.DisplayName} because package it comes from a package that is preferred.");
                return(item1);
            }

            if (preferredPackageRank2 < preferredPackageRank1)
            {
                log.LogMessage($"{conflictMessage}.  Choosing {item2.DisplayName} because package it comes from a package that is preferred.");
                return(item2);
            }

            var isPlatform1 = item1.ItemType == ConflictItemType.Platform;
            var isPlatform2 = item2.ItemType == ConflictItemType.Platform;

            if (isPlatform1 && !isPlatform2)
            {
                log.LogMessage($"{conflictMessage}.  Choosing {item1.DisplayName} because it is a platform item.");
                return(item1);
            }

            if (!isPlatform1 && isPlatform2)
            {
                log.LogMessage($"{conflictMessage}.  Choosing {item2.DisplayName} because it is a platform item.");
                return(item1);
            }

            log.LogMessage($"{conflictMessage}.  Could not determine winner due to equal file and assembly versions.");
            return(null);
        }