コード例 #1
0
        protected override void OnAfterPackageWalk(IPackage package)
        {
            PackageWalkInfo info = GetPackageInfo(package);

            if (AcceptedTargets.HasFlag(info.Target))
            {
                base.OnAfterPackageWalk(package);
            }
        }
コード例 #2
0
        protected internal PackageWalkInfo GetPackageInfo(IPackage package)
        {
            PackageWalkInfo info;

            if (!_packageLookup.TryGetValue(package, out info))
            {
                info = new PackageWalkInfo(GetPackageTarget(package));
                _packageLookup.Add(package, info);
            }
            return(info);
        }
コード例 #3
0
 protected override void OnAfterPackageWalk(IPackage package)
 {
     if (base.DisableWalkInfo)
     {
         base.OnAfterPackageWalk(package);
     }
     else
     {
         PackageWalkInfo packageInfo = base.GetPackageInfo(package);
         if (this.AcceptedTargets.HasFlag(packageInfo.Target))
         {
             base.OnAfterPackageWalk(package);
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Resolve the package target (i.e. if the parent package was a meta package then set the parent to the current project type)
        /// </summary>
        private void ProcessPackageTarget(IPackage package)
        {
            if (IgnoreWalkInfo || SkipPackageTargetCheck)
            {
                return;
            }

            PackageWalkInfo info = GetPackageInfo(package);

            // If our parent is an unknown then we need to bubble up the type
            if (info.Parent != null)
            {
                PackageWalkInfo parentInfo = GetPackageInfo(info.Parent);

                Debug.Assert(parentInfo != null);


                if (parentInfo.InitialTarget == PackageTargets.None)
                {
                    // Update the parent target type
                    parentInfo.Target |= info.Target;

                    // If we ended up with both that means we found a dependency only packages
                    // that has a mix of solution and project level packages
                    //if (parentInfo.Target == PackageTargets.All)
                    //{
                    //    throw new InvalidOperationException(NuGetResources.DependencyOnlyCannotMixDependencies);
                    //}
                }
                // Choco doesn't care about this at all

                //// Solution packages can't depend on project level packages
                //if (parentInfo.Target == PackageTargets.External && info.Target.HasFlag(PackageTargets.Project))
                //{
                //    throw new InvalidOperationException(NuGetResources.ExternalPackagesCannotDependOnProjectLevelPackages);
                //}
            }
        }
コード例 #5
0
        public void Walk(IPackage package)
        {
            CheckPackageMinClientVersion(package);

            // Do nothing if we saw this package already
            if (Marker.IsVisited(package))
            {
                ProcessPackageTarget(package);
                return;
            }

            OnBeforePackageWalk(package);

            // Mark the package as processing
            Marker.MarkProcessing(package);

            if (!IgnoreDependencies)
            {
                foreach (var dependency in package.GetCompatiblePackageDependencies(TargetFramework))
                {
                    // Try to resolve the dependency from the visited packages first
                    IPackage resolvedDependency = DependencyResolveUtility.ResolveDependency(
                        Marker,
                        dependency, constraintProvider: null,
                        allowPrereleaseVersions: AllowPrereleaseVersions,
                        preferListedPackages: false,
                        dependencyVersion: DependencyVersion);
                    if (resolvedDependency == null)
                    {
                        resolvedDependency = ResolveDependency(dependency);
                    }

                    if (resolvedDependency == null)
                    {
                        OnDependencyResolveError(dependency);
                        // If we're skipping dependency resolve errors then move on to the next
                        // dependency
                        if (SkipDependencyResolveError)
                        {
                            continue;
                        }

                        return;
                    }

                    if (!IgnoreWalkInfo)
                    {
                        // Set the parent
                        PackageWalkInfo dependencyInfo = GetPackageInfo(resolvedDependency);
                        dependencyInfo.Parent = package;
                    }

                    Marker.AddDependent(package, resolvedDependency);

                    if (!OnAfterResolveDependency(package, resolvedDependency))
                    {
                        continue;
                    }

                    if (Marker.IsCycle(resolvedDependency) ||
                        Marker.IsVersionCycle(resolvedDependency.Id))
                    {
                        if (RaiseErrorOnCycle)
                        {
                            List <IPackage> packages = Marker.Packages.ToList();
                            packages.Add(resolvedDependency);

                            throw new InvalidOperationException(
                                      String.Format(CultureInfo.CurrentCulture,
                                                    NuGetResources.CircularDependencyDetected, String.Join(" => ",
                                                                                                           packages.Select(p => p.GetFullName()))));
                        }

                        continue;
                    }

                    Walk(resolvedDependency);
                }
            }

            // Mark the package as visited
            Marker.MarkVisited(package);

            ProcessPackageTarget(package);

            OnAfterPackageWalk(package);
        }
コード例 #6
0
ファイル: PackageWalker.cs プロジェクト: sistoimenov/NuGet2
 protected internal PackageWalkInfo GetPackageInfo(IPackage package)
 {
     PackageWalkInfo info;
     if (!_packageLookup.TryGetValue(package, out info))
     {
         info = new PackageWalkInfo(GetPackageTarget(package));
         _packageLookup.Add(package, info);
     }
     return info;
 }
コード例 #7
0
        public void Walk(IPackage package)
        {
            // Do nothing if we saw this package already
            if (Marker.IsVisited(package))
            {
                return;
            }

            OnBeforePackageWalk(package);

            // Mark the package as processing
            Marker.MarkProcessing(package);

            if (!IgnoreDependencies)
            {
                foreach (var dependency in package.Dependencies)
                {
                    // Try to resolve the dependency from the visited packages first
                    IPackage resolvedDependency = Marker.FindDependency(dependency) ??
                                                  ResolveDependency(dependency);

                    if (resolvedDependency == null)
                    {
                        OnDependencyResolveError(dependency);
                        // If we're skipping dependency resolve errros then move on to the next
                        // dependency
                        if (SkipDependencyResolveError)
                        {
                            continue;
                        }

                        return;
                    }

                    if (!IgnoreWalkInfo)
                    {
                        // Set the parent
                        PackageWalkInfo dependencyInfo = GetPackageInfo(resolvedDependency);
                        dependencyInfo.Parent = package;
                    }

                    Marker.AddDependent(package, resolvedDependency);

                    if (!OnAfterResolveDependency(package, resolvedDependency))
                    {
                        continue;
                    }

                    if (Marker.IsCycle(resolvedDependency) ||
                        Marker.IsVersionCycle(resolvedDependency.Id))
                    {
                        if (RaiseErrorOnCycle)
                        {
                            List <IPackage> packages = Marker.Packages.ToList();
                            packages.Add(resolvedDependency);

                            throw new InvalidOperationException(
                                      String.Format(CultureInfo.CurrentCulture,
                                                    NuGetResources.CircularDependencyDetected, String.Join(" => ",
                                                                                                           packages.Select(p => p.GetFullName()))));
                        }

                        continue;
                    }

                    Walk(resolvedDependency);
                }
            }

            // Mark the package as visited
            Marker.MarkVisited(package);

            if (!IgnoreWalkInfo)
            {
                PackageWalkInfo info = GetPackageInfo(package);

                // If our parent is an unknown then we need to bubble up the type
                if (info.Parent != null)
                {
                    PackageWalkInfo parentInfo = GetPackageInfo(info.Parent);

                    Debug.Assert(parentInfo != null);

                    if (parentInfo.InitialTarget == PackageTargets.None)
                    {
                        // Update the parent target type
                        parentInfo.Target |= info.Target;

                        // If we ended up with both that means we found a dependency only packges
                        // that has a mix of solution and project level packages
                        if (parentInfo.Target == PackageTargets.Both)
                        {
                            throw new InvalidOperationException(NuGetResources.DependencyOnlyCannotMixDependencies);
                        }
                    }

                    // Solution packages can't depend on project level packages
                    if (parentInfo.Target == PackageTargets.External && info.Target.HasFlag(PackageTargets.Project))
                    {
                        throw new InvalidOperationException(NuGetResources.ExternalPackagesCannotDependOnProjectLevelPackages);
                    }
                }
            }

            OnAfterPackageWalk(package);
        }