Ejemplo n.º 1
0
 private static string ConstraintToText(IConstraint constraint)
 {
     return(constraint != null ? Str.Space + constraint.GetPrettyString() : string.Empty);
 }
Ejemplo n.º 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);
        }