Skip to content

Commit

Permalink
add converter and test, adjust pom and XStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Julia Boes committed Aug 19, 2020
1 parent 67c2dbb commit a7b38c5
Show file tree
Hide file tree
Showing 4 changed files with 620 additions and 2 deletions.
50 changes: 48 additions & 2 deletions xstream/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!--
Copyright (C) 2006 Joe Walnes.
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2017, 2018, 2019, 2020 XStream committers.
Copyright (C) 2020, Oracle and/or its affiliates.
All rights reserved.
The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -203,6 +204,46 @@
</build>

<profiles>
<!-- Build Record tests using JDK 14 (or greater) if available -->
<profile>
<id>jdk14-ge</id>
<activation>
<jdk>[14,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>jdk14-ge-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<release>${java.vm.specification.version}</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
<testExcludes>
<testExclude>com/**</testExclude>
</testExcludes>
<testIncludes>
<testInclude>jdk14-ge/**</testInclude>
</testIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<preview.arg>--enable-preview</preview.arg>
</properties>
</profile>
<profile>
<id>jdk11-ge</id>
<activation>
Expand All @@ -224,7 +265,7 @@
</plugins>
</build>
<properties>
<surefire.argline>--illegal-access=${surefire.illegal.access}</surefire.argline>
<surefire.argline>${preview.arg} --illegal-access=${surefire.illegal.access}</surefire.argline>
</properties>
</profile>
<profile>
Expand All @@ -233,7 +274,7 @@
<jdk>[9,11)</jdk>
</activation>
<properties>
<surefire.argline>--add-modules java.activation,java.xml.bind --illegal-access=${surefire.illegal.access}</surefire.argline>
<surefire.argline>${preview.arg} --add-modules java.activation,java.xml.bind --illegal-access=${surefire.illegal.access}</surefire.argline>
</properties>
</profile>
<profile>
Expand All @@ -250,6 +291,9 @@
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<testExcludes>
<testExclude>jdk14-ge/**</testExclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -306,6 +350,8 @@
</reporting>

<properties>
<!-- optional preview argument when running with JDK 14+ -->
<preview.arg></preview.arg>
<bundle.export.package>!com.thoughtworks.xstream.core.util,com.thoughtworks.xstream.*;-noimport:=true</bundle.export.package>
<bundle.import.package>
org.xmlpull.mxp1;resolution:=optional,
Expand Down
9 changes: 9 additions & 0 deletions xstream/src/java/com/thoughtworks/xstream/XStream.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 XStream Committers.
* Copyright (C) 2020, Oracle and/or its affiliates.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -992,6 +993,10 @@ protected void setupConverters() {
PRIORITY_NORMAL, new Class[]{Mapper.class, ReflectionProvider.class, ClassLoaderReference.class},
new Object[]{mapper, reflectionProvider, classLoaderReference});
}
if (JVM.isVersion(14)) {
registerConverterDynamically("com.thoughtworks.xstream.converters.extended.RecordConverter",
PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
}

registerConverter(new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
}
Expand Down Expand Up @@ -1087,6 +1092,10 @@ protected void setupImmutableTypes() {
addImmutableTypeDynamically("java.time.temporal.IsoFields$Unit", false);
addImmutableTypeDynamically("java.time.temporal.JulianFields$Field", false);
}

if (JVM.isVersion(14)) {
addImmutableTypeDynamically("java.lang.Record", false);
}
}

private void addImmutableTypeDynamically(final String className, final boolean isReferenceable) {
Expand Down

0 comments on commit a7b38c5

Please sign in to comment.