Ejemplo n.º 1
0
    /// <summary>
    /// Moves along the build chain skipping units until it finds the matching unit.
    /// If it is the target unit, returns build actions for it, if no, pass the rest of the chain to each child and returns merged actions.
    /// </summary>
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(SkipTillUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                for (var i = 0; i < buildChain.Length; i++)
                {
                    var unitInfo = buildChain[i];

                    var isPatternMatches = UnitPattern.Matches(unitInfo);
                    if (isPatternMatches)
                    {
                        Log.WriteLine(LogLevel.Verbose, LogConst.Matched, true);
                        hasActions = GetOwnOrChildrenBuildActions(buildChain.GetTail(i), inputWeight, out actionBag);
                        return(hasActions);
                    }
                }

                Log.WriteLine(LogLevel.Trace, LogConst.Matched, false);
            }

        actionBag = null;
        return(false);
    }
Ejemplo n.º 2
0
        public void should_not_match_if_tag_differs([Values(null, "kind")] object kind)
        {
            var unitInfo = new UnitId(kind, "tag1");
            var target   = new UnitPattern(kind, "tag2");

            // --assert
            target.Matches(unitInfo).Should().BeFalse();
        }
Ejemplo n.º 3
0
        public void should_not_match_if_kind_differs([Values(null, "tag")] object tag)
        {
            var unitInfo = new UnitId("kind1", tag);
            var target   = new UnitPattern("kind2", tag);

            // --assert
            target.Matches(unitInfo).Should().BeFalse();
        }
Ejemplo n.º 4
0
        public void should_match_if_tag_any_provided([Values(null, "tag")] object tag)
        {
            var unitInfo = new UnitId("kind", tag);
            var target   = new UnitPattern("kind", SpecialTag.Any);

            // --assert
            target.Matches(unitInfo).Should().BeTrue();
        }
Ejemplo n.º 5
0
        public void should_match([Values(null, "kind")] string?kind, [Values(null, "tag")] string?tag)
        {
            if (kind is null && tag is null)
            {
                Assert.Ignore("Impossible arguments combination");
            }

            var unitInfo = new UnitId(kind, tag);
            var target   = new UnitPattern(kind, tag);

            // --assert
            target.Matches(unitInfo).Should().BeTrue();
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Checks if the first unit in the build chain matches the specified patter.
    /// If it is the target unit, returns build actions for it, if no, pass the rest of the build chain to each child and returns all actions from children merged
    /// </summary>
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        actionBag = null;

        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(IfFirstUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                var isPatternMatches = UnitPattern.Matches(buildChain[0]);
                Log.WriteLine(LogLevel.Verbose, LogConst.Matched, isPatternMatches);

                hasActions = isPatternMatches && GetOwnOrChildrenBuildActions(buildChain, inputWeight, out actionBag);
                return(hasActions);
            }
    }
Ejemplo n.º 7
0
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(SkipWhileUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                var i = 0;
                for (; i < buildChain.Length - 1; i++) // target unit is not the subject of skipping
                {
                    if (!UnitPattern.Matches(buildChain[i]))
                    {
                        break;
                    }
                }

                hasActions = GetChildrenActions(buildChain.GetTail(i), inputWeight, out actionBag);
                return(hasActions);
            }
    }