Support Groovy 3's QName in GroovyXmlUtil (#379)

This commit is contained in:
modmuss50
2021-04-02 19:30:43 +01:00
committed by GitHub
parent 93afc7574d
commit 98731532d5
3 changed files with 40 additions and 23 deletions

View File

@@ -31,6 +31,8 @@ import java.util.stream.Stream;
import groovy.util.Node;
import groovy.xml.QName;
import net.fabricmc.loom.util.gradle.GradleSupport;
public final class GroovyXmlUtil {
private GroovyXmlUtil() { }
@@ -63,9 +65,19 @@ public final class GroovyXmlUtil {
return ((QName) nodeName).matches(givenName);
}
// New groovy 3 (gradle 7) class
if (GradleSupport.IS_GRADLE_7_OR_NEWER && nodeName.getClass().getName().equals("groovy.namespace.QName")) {
return isSameNameGroovy3(nodeName, givenName);
}
throw new UnsupportedOperationException("Cannot determine if " + nodeName.getClass() + " is the same as a String");
}
// TODO Move out of its own method when requiring gradle 7
private static boolean isSameNameGroovy3(Object nodeName, String givenName) {
return ((groovy.namespace.QName) nodeName).matches(givenName);
}
public static Stream<Node> childrenNodesStream(Node node) {
//noinspection unchecked
return (Stream<Node>) (Stream) (((List<Object>) node.children()).stream().filter((i) -> i instanceof Node));