JDK 11 compile target reverted (#645)
JDK 11 compile target reverted
Signed-off-by: David Kral <david.k.kral@oracle.com>
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index ca961de..3b21094 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -21,7 +21,7 @@
strategy:
matrix:
- java_version: [ 17, 21 ]
+ java_version: [ 11, 17, 21 ]
steps:
- name: Checkout for build
@@ -30,9 +30,9 @@
fetch-depth: 0
- name: Set up compile JDK
uses: actions/setup-java@v4
- with:
+ with: #Compile java needs to be the highest to ensure proper compilation of the multi-release jar
distribution: 'temurin'
- java-version: ${{ matrix.java_version }}
+ java-version: 17
cache: 'maven'
- name: Copyright
run: bash etc/copyright.sh
diff --git a/pom.xml b/pom.xml
index 1116c76..a97891c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.compiler.release>17</maven.compiler.release>
+ <maven.compiler.release>11</maven.compiler.release>
<maven.compiler.testRelease>${maven.compiler.release}</maven.compiler.testRelease>
<!--Dependencies-->
@@ -298,6 +298,50 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>jdk16</id>
+ <activation>
+ <jdk>[16,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-testCompile</id>
+ <configuration>
+ <release>16</release>
+ <testRelease>16</testRelease>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/test/java</compileSourceRoot>
+ <compileSourceRoot>${project.basedir}/src/test/java16</compileSourceRoot>
+ </compileSourceRoots>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <includes>
+ <include>**/RecordTest.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
<build>
@@ -309,6 +353,38 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<!-- defaults for compile and testCompile -->
+ <executions>
+ <execution>
+ <id>default-compile</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>11</release>
+ <source>11</source>
+ <target>11</target>
+ </configuration>
+ </execution>
+ <execution>
+ <id>default-testCompile</id>
+ <configuration>
+ <release>11</release>
+ </configuration>
+ </execution>
+ <execution>
+ <id>multi-release-compile-16</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>16</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java16</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ </executions>
<configuration>
<compilerArgs>
<arg>-Xlint:all</arg>
@@ -322,6 +398,9 @@
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ <manifestEntries>
+ <Multi-Release>true</Multi-Release>
+ </manifestEntries>
</archive>
</configuration>
</plugin>
@@ -449,7 +528,7 @@
<configuration>
<rules>
<requireJavaVersion>
- <version>[17,)</version>
+ <version>[11,)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.6.0,)</version>
diff --git a/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java b/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java
index 2f3d2dc..72653cf 100644
--- a/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java
+++ b/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java
@@ -22,8 +22,6 @@
import org.eclipse.yasson.internal.model.JsonbCreator;
import org.eclipse.yasson.internal.model.Property;
-import org.eclipse.yasson.internal.properties.MessageKeys;
-import org.eclipse.yasson.internal.properties.Messages;
/**
* Search for instance creator from other sources.
@@ -36,38 +34,25 @@
}
static boolean shouldTransformToPropertyName(Method method) {
- return !method.getDeclaringClass().isRecord();
+ return true;
}
static boolean isSpecialAccessorMethod(Method method, Map<String, Property> classProperties) {
- return isRecord(method.getDeclaringClass())
- && method.getParameterCount() == 0
- && !void.class.equals(method.getReturnType())
- && classProperties.containsKey(method.getName());
+ return false;
}
static JsonbCreator findCreator(Class<?> clazz,
Constructor<?>[] declaredConstructors,
AnnotationIntrospector introspector,
PropertyNamingStrategy propertyNamingStrategy) {
- if (clazz.isRecord()) {
- if (declaredConstructors.length == 1) {
- return introspector.createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy);
- }
- }
return null;
}
public static boolean isRecord(Class<?> clazz) {
- return clazz.isRecord();
+ return false;
}
public static Optional<JsonbException> exceptionToThrow(Class<?> clazz) {
- if (clazz.isRecord()) {
- if (clazz.getDeclaredConstructors().length > 1) {
- return Optional.of(new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz)));
- }
- }
return Optional.empty();
}
diff --git a/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java b/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java
new file mode 100644
index 0000000..2f3d2dc
--- /dev/null
+++ b/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0,
+ * or the Eclipse Distribution License v. 1.0 which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
+ */
+
+package org.eclipse.yasson.internal;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Optional;
+
+import jakarta.json.bind.JsonbException;
+import jakarta.json.bind.config.PropertyNamingStrategy;
+
+import org.eclipse.yasson.internal.model.JsonbCreator;
+import org.eclipse.yasson.internal.model.Property;
+import org.eclipse.yasson.internal.properties.MessageKeys;
+import org.eclipse.yasson.internal.properties.Messages;
+
+/**
+ * Search for instance creator from other sources.
+ * Mainly intended to add extensibility for different java versions and new features.
+ */
+public class ClassMultiReleaseExtension {
+
+ private ClassMultiReleaseExtension() {
+ throw new IllegalStateException("This class cannot be instantiated");
+ }
+
+ static boolean shouldTransformToPropertyName(Method method) {
+ return !method.getDeclaringClass().isRecord();
+ }
+
+ static boolean isSpecialAccessorMethod(Method method, Map<String, Property> classProperties) {
+ return isRecord(method.getDeclaringClass())
+ && method.getParameterCount() == 0
+ && !void.class.equals(method.getReturnType())
+ && classProperties.containsKey(method.getName());
+ }
+
+ static JsonbCreator findCreator(Class<?> clazz,
+ Constructor<?>[] declaredConstructors,
+ AnnotationIntrospector introspector,
+ PropertyNamingStrategy propertyNamingStrategy) {
+ if (clazz.isRecord()) {
+ if (declaredConstructors.length == 1) {
+ return introspector.createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy);
+ }
+ }
+ return null;
+ }
+
+ public static boolean isRecord(Class<?> clazz) {
+ return clazz.isRecord();
+ }
+
+ public static Optional<JsonbException> exceptionToThrow(Class<?> clazz) {
+ if (clazz.isRecord()) {
+ if (clazz.getDeclaredConstructors().length > 1) {
+ return Optional.of(new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz)));
+ }
+ }
+ return Optional.empty();
+ }
+
+}
diff --git a/yasson-tck/pom.xml b/yasson-tck/pom.xml
index 1abbd05..bd0d76e 100644
--- a/yasson-tck/pom.xml
+++ b/yasson-tck/pom.xml
@@ -14,8 +14,8 @@
<yasson.version>3.0.4-SNAPSHOT</yasson.version>
<jakarta.json.bind.version>3.0.1</jakarta.json.bind.version>
<jakarta.json.version>2.1.3</jakarta.json.version>
- <maven.compiler.source>17</maven.compiler.source>
- <maven.compiler.target>17</maven.compiler.target>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
</properties>
<!-- TODO: Temporarily enable snapshot repository -->