Skip to content

Commit

Permalink
JDK 11 compile target reverted (#645)
Browse files Browse the repository at this point in the history
JDK 11 compile target reverted

Signed-off-by: David Kral <david.k.kral@oracle.com>
  • Loading branch information
Verdent authored Jul 10, 2024
1 parent 5fcac65 commit 14e68b6
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

strategy:
matrix:
java_version: [ 17, 21 ]
java_version: [ 11, 17, 21 ]

steps:
- name: Checkout for build
Expand All @@ -30,9 +30,9 @@ jobs:
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
Expand Down
83 changes: 81 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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-->
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -449,7 +528,7 @@
<configuration>
<rules>
<requireJavaVersion>
<version>[17,)</version>
<version>[11,)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.6.0,)</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,38 +34,25 @@ private ClassMultiReleaseExtension() {
}

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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
4 changes: 2 additions & 2 deletions yasson-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down

0 comments on commit 14e68b6

Please sign in to comment.