You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/07/02 02:43:21 UTC
groovy git commit: GROOVY-8671: Move JaxbGroovyMethods into their own
optional groovy-jaxb "module"
Repository: groovy
Updated Branches:
refs/heads/master d38a5ef2a -> 8255a2910
GROOVY-8671: Move JaxbGroovyMethods into their own optional groovy-jaxb "module"
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8255a291
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8255a291
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8255a291
Branch: refs/heads/master
Commit: 8255a29103b5533d00f9c2e134ae091d14d18cf8
Parents: d38a5ef
Author: Paul King <pa...@asert.com.au>
Authored: Sun Jul 1 22:54:01 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Jul 2 12:42:10 2018 +1000
----------------------------------------------------------------------
gradle/binarycompatibility.gradle | 5 +-
gradle/docs.gradle | 1 +
gradle/pomconfigurer.gradle | 3 +
gradle/upload.gradle | 7 +-
settings.gradle | 1 +
subprojects/groovy-jaxb/build.gradle | 27 +++++++
.../groovy/jaxb/extensions/JaxbExtensions.java | 83 ++++++++++++++++++++
.../jaxb/extensions/JaxbExtensionsTest.groovy | 39 +++++++++
.../apache/groovy/jaxb/extensions/Person.groovy | 36 +++++++++
subprojects/groovy-xml/build.gradle | 2 +-
.../groovy/xml/jaxb/JaxbGroovyMethods.groovy | 7 +-
.../xml/jaxb/JaxbGroovyMethodsTest.groovy | 41 ----------
.../test/groovy/groovy/xml/jaxb/Person.groovy | 38 ---------
13 files changed, 207 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/gradle/binarycompatibility.gradle
----------------------------------------------------------------------
diff --git a/gradle/binarycompatibility.gradle b/gradle/binarycompatibility.gradle
index 184a2e0..45b951d 100644
--- a/gradle/binarycompatibility.gradle
+++ b/gradle/binarycompatibility.gradle
@@ -35,7 +35,10 @@ task checkBinaryCompatibility {
check.dependsOn(checkBinaryCompatibility)
// for comparing between versions with different modules, set excludeModules to differing modules, e.g.
-def excludeModules = ['groovy-cli-picocli', 'groovy-cli-commons', 'groovy-dateutil', 'groovy-datetime', 'performance', 'groovy-macro', 'tests-vm8', 'groovy-json-direct', 'groovy-test-junit5']
+def excludeModules = [
+ 'groovy-cli-picocli', 'groovy-cli-commons', 'groovy-dateutil', 'groovy-datetime', 'groovy-jaxb',
+ 'groovy-macro', 'groovy-json-direct', 'groovy-test-junit5', 'performance', 'tests-vm8'
+]
//def excludeModules = []
Set projectsToCheck = allprojects.findAll{ !(it.name in excludeModules) }
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/gradle/docs.gradle
----------------------------------------------------------------------
diff --git a/gradle/docs.gradle b/gradle/docs.gradle
index c302216..3472e3c 100644
--- a/gradle/docs.gradle
+++ b/gradle/docs.gradle
@@ -156,6 +156,7 @@ task docGDK {
arg(value: 'subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java')
arg(value: 'subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeExtensions.java')
arg(value: 'subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeStaticExtensions.java')
+ arg(value: 'subprojects/groovy-jaxb/src/main/groovy/org/apache/groovy/jaxb/extensions/JaxbExtensions.java')
arg(value: 'subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java')
arg(value: 'subprojects/groovy-swing/src/main/java/org/codehaus/groovy/runtime/SwingGroovyMethods.java')
arg(value: 'subprojects/groovy-xml/src/main/java/org/codehaus/groovy/runtime/XmlGroovyMethods.java')
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/gradle/pomconfigurer.gradle
----------------------------------------------------------------------
diff --git a/gradle/pomconfigurer.gradle b/gradle/pomconfigurer.gradle
index 33c62d3..401f38d 100644
--- a/gradle/pomconfigurer.gradle
+++ b/gradle/pomconfigurer.gradle
@@ -633,6 +633,9 @@ project.ext.pomConfigureClosureWithoutTweaks = {
contributor {
name 'mgroovy'
}
+ contributor {
+ name 'Dominik Przybysz'
+ }
}
mailingLists {
mailingList {
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/gradle/upload.gradle
----------------------------------------------------------------------
diff --git a/gradle/upload.gradle b/gradle/upload.gradle
index 5c7e07b..ad984d9 100644
--- a/gradle/upload.gradle
+++ b/gradle/upload.gradle
@@ -201,7 +201,12 @@ allprojects {
}
}
-def optionalModules = ['groovy-dateutil', 'groovy-cli-commons', 'groovy-json-direct']
+def optionalModules = [
+ 'groovy-cli-commons',
+ 'groovy-dateutil',
+ 'groovy-jaxb',
+ 'groovy-json-direct'
+]
ext.pomAll = {
addFilter('groovy') { artifact, file ->
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index f726532..4e4958f 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -26,6 +26,7 @@ def subprojects = ['groovy-ant',
'groovy-docgenerator',
'groovy-groovydoc',
'groovy-groovysh',
+ 'groovy-jaxb',
'groovy-jmx',
'groovy-json',
'groovy-json-direct',
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-jaxb/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/groovy-jaxb/build.gradle b/subprojects/groovy-jaxb/build.gradle
new file mode 100644
index 0000000..4a27164
--- /dev/null
+++ b/subprojects/groovy-jaxb/build.gradle
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+dependencies {
+ compile rootProject
+ testCompile project(':groovy-test')
+}
+
+task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
+ extensionClasses = 'org.apache.groovy.jaxb.extensions.JaxbExtensions'
+}
+compileJava.dependsOn moduleDescriptor
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-jaxb/src/main/java/org/apache/groovy/jaxb/extensions/JaxbExtensions.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-jaxb/src/main/java/org/apache/groovy/jaxb/extensions/JaxbExtensions.java b/subprojects/groovy-jaxb/src/main/java/org/apache/groovy/jaxb/extensions/JaxbExtensions.java
new file mode 100644
index 0000000..76fe261
--- /dev/null
+++ b/subprojects/groovy-jaxb/src/main/java/org/apache/groovy/jaxb/extensions/JaxbExtensions.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.jaxb.extensions;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+/**
+ * This class defines new groovy methods which appear on Jaxb-related JDK
+ * classes ({@code JAXBContext}, {@code Marshaller}) inside the Groovy environment.
+ * Static methods are used with the first parameter being the destination class.
+ */
+public class JaxbExtensions {
+
+ /**
+ * Marshall an object to a xml {@code String}.
+ *
+ * @param self a Marshaller which can marshall the type of the given object
+ * @param jaxbElement object to marshall to a {@code String}
+ * @return {@code String} representing the object as xml
+ */
+ public static <T> String marshal(Marshaller self, T jaxbElement) throws JAXBException {
+ StringWriter sw = new StringWriter();
+ self.marshal(jaxbElement, sw);
+ return sw.toString();
+ }
+
+ /**
+ * Marshall an object to a xml {@code String}.
+ *
+ * @param self a JaxbContext, which recognizes the type of the given object
+ * @param jaxbElement object to marshall to a {@code String}
+ * @return String representing the object as xml
+ */
+ public static <T> String marshal(JAXBContext self, T jaxbElement) throws JAXBException {
+ return marshal(self.createMarshaller(), jaxbElement);
+ }
+
+ /**
+ * Unmarshal xml data from the given {@code String} to object of the given type.
+ *
+ * @param self Unmarshaller, a Unmarshaller which can unmarshall the type of the given object
+ * @param xml xml data as a {@link String}
+ * @param declaredType appropriate JAXB mapped class to hold node's xml data
+ * @return instance of destination class unmarshalled from xml
+ */
+ public static <T> T unmarshal(Unmarshaller self, String xml, Class<T> declaredType) throws JAXBException {
+ StringReader sr = new StringReader(xml);
+ return declaredType.cast(self.unmarshal(sr));
+ }
+
+ /**
+ * Unmarshal xml data from the given {@code String} to object of the given type.
+ *
+ * @param self a JaxbContext, which recognizes the type of the given object
+ * @param xml xml data as a {@link String}
+ * @param declaredType appropriate JAXB mapped class to hold node's xml data
+ * @return instance of destination class unmarshalled from xml
+ */
+ public static <T> T unmarshal(JAXBContext self, String xml, Class<T> declaredType) throws JAXBException {
+ return unmarshal(self.createUnmarshaller(), xml, declaredType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/JaxbExtensionsTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/JaxbExtensionsTest.groovy b/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/JaxbExtensionsTest.groovy
new file mode 100644
index 0000000..87ac31c
--- /dev/null
+++ b/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/JaxbExtensionsTest.groovy
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.jaxb.extensions
+
+import javax.xml.bind.JAXBContext
+
+/**
+ * Test cases for {@link JaxbExtensions}
+ */
+class JaxbExtensionsTest extends GroovyTestCase {
+ JAXBContext jaxbContext = JAXBContext.newInstance(Person)
+ Person p = new Person(name: 'JT', age: 20)
+
+ void testMarshallAndUnmarshallObjectUsingExtensionMethodsForMarshallerAndUnmarshaller() {
+ String xml = jaxbContext.createMarshaller().marshal(p)
+ assert jaxbContext.createUnmarshaller().unmarshal(xml, Person) == p
+ }
+
+ void testMarshallAndUnmarshallObjectUsingExtensionMethodsForJaxbContext() {
+ String xml = jaxbContext.marshal(p)
+ assert jaxbContext.unmarshal(xml, Person) == p
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/Person.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/Person.groovy b/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/Person.groovy
new file mode 100644
index 0000000..a76b3a0
--- /dev/null
+++ b/subprojects/groovy-jaxb/src/test/groovy/org/apache/groovy/jaxb/extensions/Person.groovy
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.jaxb.extensions
+
+import groovy.transform.EqualsAndHashCode
+
+import javax.xml.bind.annotation.XmlAccessType
+import javax.xml.bind.annotation.XmlAccessorType
+import javax.xml.bind.annotation.XmlRootElement
+
+/**
+ * DTO class for {@link JaxbExtensionsTest}
+ */
+@EqualsAndHashCode
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement
+class Person {
+ String name
+ int age
+}
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-xml/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/build.gradle b/subprojects/groovy-xml/build.gradle
index c5c2848..cf514dd 100644
--- a/subprojects/groovy-xml/build.gradle
+++ b/subprojects/groovy-xml/build.gradle
@@ -24,6 +24,6 @@ dependencies {
}
task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
- extensionClasses = 'org.codehaus.groovy.runtime.XmlGroovyMethods,groovy.xml.jaxb.JaxbGroovyMethods'
+ extensionClasses = 'org.codehaus.groovy.runtime.XmlGroovyMethods'
}
compileJava.dependsOn moduleDescriptor
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-xml/src/main/groovy/groovy/xml/jaxb/JaxbGroovyMethods.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/main/groovy/groovy/xml/jaxb/JaxbGroovyMethods.groovy b/subprojects/groovy-xml/src/main/groovy/groovy/xml/jaxb/JaxbGroovyMethods.groovy
index 0323300..a544b2e 100644
--- a/subprojects/groovy-xml/src/main/groovy/groovy/xml/jaxb/JaxbGroovyMethods.groovy
+++ b/subprojects/groovy-xml/src/main/groovy/groovy/xml/jaxb/JaxbGroovyMethods.groovy
@@ -29,9 +29,10 @@ import javax.xml.bind.Unmarshaller
* classes ({@code JAXBContext}, {@code Marshaller}) inside the Groovy environment.
* Static methods are used with the first parameter being the destination class.
*
- * @author Dominik Przybysz
+ * @deprecated use org.apache.groovy.jaxb.extensions.JaxbExtensions
*/
@CompileStatic
+@Deprecated
class JaxbGroovyMethods {
/**
@@ -41,6 +42,7 @@ class JaxbGroovyMethods {
* @param jaxbElement object to marshall to a {@code String}
* @return {@code String} representing the object as xml
*/
+ @Deprecated
static <T> String marshal(Marshaller self, T jaxbElement) {
StringWriter sw = new StringWriter()
self.marshal(jaxbElement, sw)
@@ -54,6 +56,7 @@ class JaxbGroovyMethods {
* @param jaxbElement object to marshall to a {@code String}
* @return String representing the object as xml
*/
+ @Deprecated
static <T> String marshal(JAXBContext self, T jaxbElement) {
marshal(self.createMarshaller(), jaxbElement)
}
@@ -66,6 +69,7 @@ class JaxbGroovyMethods {
* @param declaredType appropriate JAXB mapped class to hold node's xml data
* @return instance of destination class unmarshalled from xml
*/
+ @Deprecated
static <T> T unmarshal(Unmarshaller self, String xml, Class<T> declaredType) {
StringReader sr = new StringReader(xml)
declaredType.cast(self.unmarshal(sr))
@@ -79,6 +83,7 @@ class JaxbGroovyMethods {
* @param declaredType appropriate JAXB mapped class to hold node's xml data
* @return instance of destination class unmarshalled from xml
*/
+ @Deprecated
static <T> T unmarshal(JAXBContext self, String xml, Class<T> declaredType) {
unmarshal(self.createUnmarshaller(), xml, declaredType)
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/JaxbGroovyMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/JaxbGroovyMethodsTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/JaxbGroovyMethodsTest.groovy
deleted file mode 100644
index 04bc500..0000000
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/JaxbGroovyMethodsTest.groovy
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package groovy.xml.jaxb
-
-import javax.xml.bind.JAXBContext
-
-/**
- * Test cases for {@link JaxbGroovyMethods}
- *
- * @author Dominik Przybysz
- */
-class JaxbGroovyMethodsTest extends GroovyTestCase {
- JAXBContext jaxbContext = JAXBContext.newInstance(Person)
- Person p = new Person(name: 'JT', age: 20)
-
- void testMarshallAndUnmarshallObjectUsingExtensionMethodsForMarshallerAndUnmarshaller() {
- String xml = jaxbContext.createMarshaller().marshal(p)
- assert jaxbContext.createUnmarshaller().unmarshal(xml, Person) == p
- }
-
- void testMarshallAndUnmarshallObjectUsingExtensionMethodsForJaxbContext() {
- String xml = jaxbContext.marshal(p)
- assert jaxbContext.unmarshal(xml, Person) == p
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/8255a291/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/Person.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/Person.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/Person.groovy
deleted file mode 100644
index 862c071..0000000
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/jaxb/Person.groovy
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package groovy.xml.jaxb
-
-import groovy.transform.EqualsAndHashCode
-
-import javax.xml.bind.annotation.XmlAccessType
-import javax.xml.bind.annotation.XmlAccessorType
-import javax.xml.bind.annotation.XmlRootElement
-
-/**
- * DTO class for {@link JaxbGroovyMethodsTest}
- *
- * @author Dominik Przybysz
- */
-@EqualsAndHashCode
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlRootElement
-public class Person {
- String name
- int age
-}