package com.github.blindpirate.gogradle.util;

import org.gradle.api.internal.DynamicObjectUtil;
import org.gradle.internal.metaobject.DynamicObject;
import org.gradle.internal.metaobject.SetPropertyResult;

import java.util.Map;

public class ConfigureUtils {
    public static <T> T configureByMapQuietly(Map<?, ?> properties, T delegate) {
        DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

        properties.entrySet().forEach(entry -> {
            String name = entry.getKey().toString();
            Object value = entry.getValue();

            SetPropertyResult setterResult = new SetPropertyResult();
            dynamicObject.setProperty(name, value, setterResult);
        });

        return delegate;
    }
}

@@ -143,16 +143,73 @@
 Object;%0A
+import org.gradle.internal.metaobject.GetPropertyResult;%0A
 import o
@@ -279,16 +279,42 @@
 til.Map;
+%0Aimport java.util.Objects;
 %0A%0Apublic
@@ -830,11 +830,882 @@
 e;%0A    %7D
+%0A%0A    public static boolean match(Map%3CString, Object%3E properties, Object target) %7B%0A        if (properties.isEmpty()) %7B%0A            return false;%0A        %7D%0A        DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(target);%0A        return properties.entrySet().stream()%0A                .allMatch((entry) -%3E entryMatch(entry, dynamicObject));%0A    %7D%0A%0A    private static boolean entryMatch(Map.Entry%3CString, Object%3E propertyEntry, DynamicObject dynamicObject) %7B%0A        String name = propertyEntry.getKey();%0A        Object value = propertyEntry.getValue();%0A        GetPropertyResult getPropertyResult = new GetPropertyResult();%0A        dynamicObject.getProperty(name, getPropertyResult);%0A        if (!getPropertyResult.isFound()) %7B%0A            return false;%0A        %7D else %7B%0A            return Objects.equals(getPropertyResult.getValue(), value);%0A        %7D%0A    %7D
 %0A%7D%0A

add match util method