Support Groovy 3's QName in GroovyXmlUtil (#379)
parent
93afc7574d
commit
98731532d5
|
@ -36,6 +36,9 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation gradleApi()
|
implementation gradleApi()
|
||||||
|
|
||||||
|
// Compile against groovy 3 to aid with gradle 7 support. Remove when updating to gradle 7
|
||||||
|
compileOnly 'org.codehaus.groovy:groovy-all:3.0.7'
|
||||||
|
|
||||||
// libraries
|
// libraries
|
||||||
implementation ('commons-io:commons-io:2.8.0')
|
implementation ('commons-io:commons-io:2.8.0')
|
||||||
implementation ('org.zeroturnaround:zt-zip:1.14')
|
implementation ('org.zeroturnaround:zt-zip:1.14')
|
||||||
|
|
|
@ -31,6 +31,8 @@ import java.util.stream.Stream;
|
||||||
import groovy.util.Node;
|
import groovy.util.Node;
|
||||||
import groovy.xml.QName;
|
import groovy.xml.QName;
|
||||||
|
|
||||||
|
import net.fabricmc.loom.util.gradle.GradleSupport;
|
||||||
|
|
||||||
public final class GroovyXmlUtil {
|
public final class GroovyXmlUtil {
|
||||||
private GroovyXmlUtil() { }
|
private GroovyXmlUtil() { }
|
||||||
|
|
||||||
|
@ -63,9 +65,19 @@ public final class GroovyXmlUtil {
|
||||||
return ((QName) nodeName).matches(givenName);
|
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");
|
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) {
|
public static Stream<Node> childrenNodesStream(Node node) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (Stream<Node>) (Stream) (((List<Object>) node.children()).stream().filter((i) -> i instanceof Node));
|
return (Stream<Node>) (Stream) (((List<Object>) node.children()).stream().filter((i) -> i instanceof Node));
|
||||||
|
|
|
@ -41,49 +41,51 @@ import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
|
||||||
class MavenProjectTest extends Specification implements MockMavenServerTrait, ArchiveAssertionsTrait {
|
class MavenProjectTest extends Specification implements MockMavenServerTrait, ArchiveAssertionsTrait {
|
||||||
@RestoreSystemProperties
|
@RestoreSystemProperties
|
||||||
@Unroll
|
@Unroll
|
||||||
def "publish lib #version"() {
|
def "publish lib #version #gradle"() {
|
||||||
given:
|
given:
|
||||||
setProperty('loom.test.version', version)
|
setProperty('loom.test.version', version)
|
||||||
library = true
|
library = true
|
||||||
when:
|
when:
|
||||||
def result = create("publish")
|
def result = create("publish", gradle)
|
||||||
then:
|
then:
|
||||||
result.task(":publish").outcome == SUCCESS
|
result.task(":publish").outcome == SUCCESS
|
||||||
hasArchiveEntry("fabric-example-lib-${version}.jar", "net/fabricmc/example/ExampleLib.class")
|
hasArchiveEntry("fabric-example-lib-${version}.jar", "net/fabricmc/example/ExampleLib.class")
|
||||||
where:
|
where:
|
||||||
version | _
|
version | gradle
|
||||||
'1.0.0' | _
|
'1.0.0' | DEFAULT_GRADLE
|
||||||
'1.1.0' | _
|
'1.0.0' | PRE_RELEASE_GRADLE
|
||||||
'1.1.1' | _
|
'1.1.0' | DEFAULT_GRADLE
|
||||||
'1.2.0+meta' | _
|
'1.1.1' | DEFAULT_GRADLE
|
||||||
'2.0.0-SNAPSHOT' | _
|
'1.2.0+meta' | DEFAULT_GRADLE
|
||||||
'2.0.0-SNAPSHOT' | _ // Publish this twice to give ourselves a bit of a challenge
|
'2.0.0-SNAPSHOT' | DEFAULT_GRADLE
|
||||||
'master-SNAPSHOT' | _
|
'2.0.0-SNAPSHOT' | DEFAULT_GRADLE // Publish this twice to give ourselves a bit of a challenge
|
||||||
|
'master-SNAPSHOT' | DEFAULT_GRADLE
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestoreSystemProperties
|
@RestoreSystemProperties
|
||||||
@Unroll
|
@Unroll
|
||||||
def "resolve #version"() {
|
def "resolve #version #gradle"() {
|
||||||
given:
|
given:
|
||||||
setProperty('loom.test.resolve', "com.example:fabric-example-lib:${version}")
|
setProperty('loom.test.resolve', "com.example:fabric-example-lib:${version}")
|
||||||
library = false
|
library = false
|
||||||
when:
|
when:
|
||||||
def result = create("build")
|
def result = create("build", gradle)
|
||||||
then:
|
then:
|
||||||
result.task(":build").outcome == SUCCESS
|
result.task(":build").outcome == SUCCESS
|
||||||
hasArchiveEntry("fabric-example-mod-1.0.0.jar", "net/fabricmc/examplemod/ExampleMod.class")
|
hasArchiveEntry("fabric-example-mod-1.0.0.jar", "net/fabricmc/examplemod/ExampleMod.class")
|
||||||
where:
|
where:
|
||||||
version | _
|
version | gradle
|
||||||
'1.0.0' | _
|
'1.0.0' | DEFAULT_GRADLE
|
||||||
'1.1.+' | _
|
'1.0.0' | PRE_RELEASE_GRADLE
|
||||||
'1.2.0+meta' | _
|
'1.1.+' | DEFAULT_GRADLE
|
||||||
'2.0.0-SNAPSHOT' | _
|
'1.2.0+meta' | DEFAULT_GRADLE
|
||||||
'master-SNAPSHOT' | _
|
'2.0.0-SNAPSHOT' | DEFAULT_GRADLE
|
||||||
'1.0.0:classifier' | _
|
'master-SNAPSHOT' | DEFAULT_GRADLE
|
||||||
'1.1.+:classifier' | _
|
'1.0.0:classifier' | DEFAULT_GRADLE
|
||||||
'1.2.0+meta:classifier' | _
|
'1.1.+:classifier' | DEFAULT_GRADLE
|
||||||
'2.0.0-SNAPSHOT:classifier' | _
|
'1.2.0+meta:classifier' | DEFAULT_GRADLE
|
||||||
'master-SNAPSHOT:classifier' | _
|
'2.0.0-SNAPSHOT:classifier' | DEFAULT_GRADLE
|
||||||
|
'master-SNAPSHOT:classifier' | DEFAULT_GRADLE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set to true when to build and publish the mavenLibrary
|
// Set to true when to build and publish the mavenLibrary
|
||||||
|
|
Loading…
Reference in New Issue