Skip to content

Commit

Permalink
feature: Java 21 support
Browse files Browse the repository at this point in the history
  • Loading branch information
bsbodden committed Sep 11, 2024
1 parent 02add23 commit 2e797b6
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ jobs:

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: 17
java-version: 21
distribution: 'zulu'
- name: Autobuild
uses: github/codeql-action/autobuild@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
~/.mv2/repository
key: om-${{hashFiles('**/pom.xml')}}

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: 17
java-version: 21
distribution: 'zulu'
- run: mvn dependency:go-offline
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
path: |
~/.mv2/repository
key: om-${{hashFiles('**/pom.xml')}}
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: 17
java-version: 21
distribution: 'zulu'
server-id: ossrh
server-username: MAVEN_USERNAME
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up publishing to maven central
uses: actions/setup-java@v2
with:
java-version: 17
java-version: 21
distribution: 'zulu'
server-id: ossrh
server-username: MAVEN_USERNAME
Expand Down
14 changes: 7 additions & 7 deletions demos/roms-documents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<description>Redis OM Spring Document Demo</description>

<properties>
<java.version>17</java.version>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.test.source>17</maven.test.source>
<maven.test.target>17</maven.test.target>
<java.version>21</java.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.test.source>21</maven.test.source>
<maven.test.target>21</maven.test.target>
<maven.deploy.skip>true</maven.deploy.skip>
<testcontainers.redis.version>2.2.2</testcontainers.redis.version>
</properties>
Expand Down Expand Up @@ -141,7 +141,7 @@
<path>
<groupId>com.redis.om</groupId>
<artifactId>redis-om-spring</artifactId>
<version>0.9.5</version>
<version>0.9.6-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
12 changes: 6 additions & 6 deletions demos/roms-hashes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<description>Redis OM Spring Enhanced RedisHash Demo</description>

<properties>
<java.version>17</java.version>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.test.source>17</maven.test.source>
<maven.test.target>17</maven.test.target>
<java.version>21</java.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.test.source>21</maven.test.source>
<maven.test.target>21</maven.test.target>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

Expand Down
12 changes: 6 additions & 6 deletions demos/roms-permits/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<description>Demo project for Spring Boot</description>

<properties>
<java.version>17</java.version>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.test.source>17</maven.test.source>
<maven.test.target>17</maven.test.target>
<java.version>21</java.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.test.source>21</maven.test.source>
<maven.test.target>21</maven.test.target>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

Expand Down
14 changes: 7 additions & 7 deletions demos/roms-vss/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
<description>Redis OM Spring Vector Similarity Search Demo</description>

<properties>
<java.version>17</java.version>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.test.source>17</maven.test.source>
<maven.test.target>17</maven.test.target>
<java.version>21</java.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.test.source>21</maven.test.source>
<maven.test.target>21</maven.test.target>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.redis.om</groupId>
<artifactId>redis-om-spring</artifactId>
<version>0.9.5</version>
<version>0.9.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.test.source>17</maven.test.source>
<maven.test.target>17</maven.test.target>
<java.version>17</java.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.test.source>21</maven.test.source>
<maven.test.target>21</maven.test.target>
<java.version>21</java.version>
</properties>

<modules>
Expand Down
18 changes: 9 additions & 9 deletions redis-om-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.redis.om</groupId>
<artifactId>redis-om-spring</artifactId>
<version>0.9.5</version>
<version>0.9.6-SNAPSHOT</version>
<packaging>jar</packaging>

<name>redis-om-spring</name>
Expand Down Expand Up @@ -55,12 +55,12 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.test.source>17</maven.test.source>
<maven.test.target>17</maven.test.target>
<java.version>17</java.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.test.source>21</maven.test.source>
<maven.test.target>21</maven.test.target>
<java.version>21</java.version>
<spring.version>3.3.2</spring.version>
<sdr.version>3.3.2</sdr.version>
<jedis.version>5.0.2</jedis.version>
Expand Down Expand Up @@ -374,8 +374,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<source>21</source>
<target>21</target>
<encoding>${project.build.sourceEncoding}</encoding>
<parameters>true</parameters>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
@SupportedAnnotationTypes(
value = { "com.redis.om.spring.annotations.Document", "org.springframework.data.redis.core.RedisHash" }
)
@SupportedSourceVersion(SourceVersion.RELEASE_17)
@AutoService(Processor.class)
public final class MetamodelGenerator extends AbstractProcessor {

Expand All @@ -60,6 +59,11 @@ public final class MetamodelGenerator extends AbstractProcessor {
public MetamodelGenerator() {
}

@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}

private static TypeSpec getTypeSpecForMetamodelClass(String genEntityName, List<FieldSpec> interceptors,
List<ObjectGraphFieldSpec> fields, List<FieldSpec> nestedFieldsConstants, CodeBlock staticBlock) {
return TypeSpec.classBuilder(genEntityName) //
Expand Down Expand Up @@ -242,7 +246,7 @@ private List<Triple<ObjectGraphFieldSpec, FieldSpec, CodeBlock>> processFieldMet
TypeName entityField = TypeName.get(field.asType());

TypeMirror fieldType = field.asType();
String fullTypeClassName = fieldType.toString();
String fullTypeClassName = fieldType.toString().replace("@lombok.NonNull ", "").trim();
String cls = ObjectUtils.getTargetClassName(fullTypeClassName);

if (field.asType().getKind().isPrimitive()) {
Expand Down Expand Up @@ -575,20 +579,26 @@ private Map<? extends Element, String> getInstanceFields(Element element) {
// Only consider methods with no parameters
.filter(ee -> ee.getEnclosedElements().stream().noneMatch(eee -> eee.getKind() == ElementKind.PARAMETER))
// Todo: Filter out methods that returns void or Void
.collect(Collectors.toMap(e -> e.getSimpleName().toString(), Function.identity()));
.collect(Collectors.toMap(
e -> e.getSimpleName().toString(),
Function.identity(),
(v1, v2) -> v1 // Merge function to handle duplicate keys
));

final Set<String> isGetters = getters.values().stream()
// todo: Filter out methods only returning boolean or Boolean
.map(Element::getSimpleName).map(Object::toString).filter(n -> n.startsWith(IS_PREFIX)).map(n -> n.substring(2))
.map(ObjectUtils::toLowercaseFirstCharacter).collect(Collectors.toSet());

// Use a mutable map to collect the results
Map<Element, String> results = new HashMap<>();

// Retrieve all declared non-final instance fields of the annotated class
Map<Element, String> results = element.getEnclosedElements().stream()
.filter(ee -> ee.getKind().isField() && !ee.getModifiers().contains(Modifier.STATIC) // Ignore static
// fields
element.getEnclosedElements().stream()
.filter(ee -> ee.getKind().isField() && !ee.getModifiers().contains(Modifier.STATIC) // Ignore static fields
&& !ee.getModifiers().contains(Modifier.FINAL)) // Ignore final fields
.collect(Collectors.toMap(Function.identity(),
ee -> findGetter(ee, getters, isGetters, element.toString(), lombokGetterAvailable(element, ee))));
.forEach(ee -> results.put(ee,
findGetter(ee, getters, isGetters, element.toString(), lombokGetterAvailable(element, ee))));

Types types = processingEnvironment.getTypeUtils();
List<? extends TypeMirror> superTypes = types.directSupertypes(element.asType());
Expand Down Expand Up @@ -679,6 +689,23 @@ private String findGetter(final Element field, final Map<String, Element> getter
return lambdaName + " -> " + lambdaName + "." + fieldName;
}

// Handle specific cases for java.lang.String, java.lang.Enum, and java.util.Date
if (field.getEnclosingElement().toString().equals("java.lang.String")) {
if (fieldName.equals("hash") || fieldName.equals("hashIsZero")) {
return lambdaName + " -> 0"; // Return a default value for hash and hashIsZero
}
} else if (field.getEnclosingElement().toString().equals("java.lang.Enum")) {
if (fieldName.equals("hash")) {
return lambdaName + " -> 0"; // Return a default value for hash
}
} else if (field.getEnclosingElement().toString().equals("java.util.Date")) {
if (fieldName.equals("fastTime")) {
return lambdaName + " -> " + lambdaName + ".getTime()"; // Use getTime() as a fallback for fastTime
} else if (fieldName.equals("cdate")) {
return lambdaName + " -> " + lambdaName + ".getTime()"; // Use getTime() as a fallback for cdate
}
}

// default to thrower
messager.printMessage(Diagnostic.Kind.ERROR,
"Class " + entityName + " is not a proper JavaBean because " + field.getSimpleName()
Expand Down

0 comments on commit 2e797b6

Please sign in to comment.