Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 21 support #509

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ inherited from the parent poms):
<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 Expand Up @@ -504,7 +504,7 @@ repositories {

```groovy
ext {
redisOmVersion = '0.9.5'
redisOmVersion = '0.9.6-SNAPSHOT'
}

dependencies {
Expand Down
16 changes: 8 additions & 8 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 All @@ -31,7 +31,7 @@
<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 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
14 changes: 7 additions & 7 deletions demos/roms-hashes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
<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>

<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
14 changes: 7 additions & 7 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 All @@ -34,7 +34,7 @@
<dependency>
<groupId>com.redis.om</groupId>
<artifactId>redis-om-spring</artifactId>
<version>0.9.5</version>
<version>0.9.6-SNAPSHOT</version>
</dependency>

<dependency>
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
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.redis.om</groupId>
<artifactId>redis-om-spring-parent</artifactId>
<version>0.9.5</version>
<version>0.9.6-SNAPSHOT</version>
<name>redis-om-spring-parent</name>
<packaging>pom</packaging>

<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 @@ -12,7 +12,7 @@
prefix = "redis.om.spring", ignoreInvalidFields = true
)
public class RedisOMProperties {
public static final String ROMS_VERSION = "0.9.5";
public static final String ROMS_VERSION = "0.9.6-SNAPSHOT";
public static final int MAX_SEARCH_RESULTS = 10000;
public static final double DEFAULT_DISTANCE = 0.0005;
public static final Metrics DEFAULT_DISTANCE_METRIC = Metrics.MILES;
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
Loading