Пример #1
0
        private IEnumerable <IPackage> FilterPackages(IEnumerable <IPackage> packages, IConstraint constraint = null, bool returnFirstMatch = false)
        {
            if (constraint == null)
            {
                foreach (var package in packages)
                {
                    yield return(package);

                    if (returnFirstMatch)
                    {
                        yield break;
                    }
                }

                yield break;
            }

            foreach (var package in packages)
            {
                var packageConstraint = new Constraint("==", package.GetVersion());

                if (!constraint.Matches(packageConstraint))
                {
                    continue;
                }

                yield return(package);

                if (returnFirstMatch)
                {
                    yield break;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Assert whether the plugin api version matches the current bucket.
        /// </summary>
        protected virtual bool AssertPluginApiVersion(IPackage package)
        {
            if (package.GetPackageType() != PluginType)
            {
                return(false);
            }

            IConstraint requireConstraint = null;

            foreach (var link in package.GetRequires())
            {
                if (link.GetTarget() == PluginRequire)
                {
                    requireConstraint = link.GetConstraint();
                    break;
                }
            }

            if (requireConstraint == null)
            {
                throw new RuntimeException(
                          $"Plugin \"{package.GetName()}\" is missing a require statement for a version of the \"{PluginRequire}\" package.");
            }

            var currentPluginApiVersion    = GetPluginApiVersion();
            var currentPluginApiConstraint = new Constraint("==", versionParser.Normalize(currentPluginApiVersion));

            if (!requireConstraint.Matches(currentPluginApiConstraint))
            {
                io.WriteError($"<warning>The \"{package.GetName()}\" plugin was skipped because it requires a Plugin API version (\"{requireConstraint.GetPrettyString()}\") that does not match your Bucket installation (\"{currentPluginApiVersion}\"). You may need to run bucket update with the \"--no-plugins\" option.</warning>");
                return(false);
            }

            return(true);
        }
Пример #3
0
        /// <inheritdoc />
        public virtual IPackage FindPackage(string name, IConstraint constraint)
        {
            name = name.ToLower();
            foreach (var package in GetPackages())
            {
                if (package.GetName() != name)
                {
                    continue;
                }

                var packageConstraint = new Constraint("==", package.GetVersion());
                if (constraint.Matches(packageConstraint))
                {
                    return(package);
                }
            }

            return(null);
        }
Пример #4
0
        /// <inheritdoc />
        public virtual IPackage[] FindPackages(string name, IConstraint constraint = null)
        {
            name = name.ToLower();
            var collection = new LinkedList <IPackage>();

            foreach (var package in GetPackages())
            {
                if (package.GetName() != name)
                {
                    continue;
                }

                if (constraint == null || constraint.Matches(new Constraint("==", package.GetVersion())))
                {
                    collection.AddLast(package);
                }
            }

            return(collection.ToArray());
        }
Пример #5
0
        private static bool IsVersionAcceptable(PredicatePackageAcceptable predicatePackageAcceptable, IConstraint constraint, string name, ConfigPackageBucket config)
        {
            // todo: to load aliase package.
            var versions = new[] { config.VersionNormalized };

            foreach (var version in versions)
            {
                if (predicatePackageAcceptable != null &&
                    !predicatePackageAcceptable(VersionParser.ParseStability(version), name))
                {
                    continue;
                }

                if (constraint != null && !constraint.Matches(new Constraint("==", version)))
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
Пример #6
0
 /// <summary>
 /// Apply a constraint to an actual value, succeedingt if the constraint
 /// is satisfied and throwing an assertion exception on failure.
 /// </summary>
 /// <param name="constraint">An IConstraint to be applied</param>
 /// <param name="actual">The actual value to test</param>
 /// <param name="message">The message that will be displayed on failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 public static void That( object actual, IConstraint constraint, string message, params object[] args )
 {
     Assert.IncrementAssertCount();
     if ( !constraint.Matches( actual ) )
     {
         MessageWriter writer = new TextMessageWriter( message, args );
         constraint.WriteMessageTo( writer );
         throw new AssertionException( writer.ToString() );
     }
 }