Skip to content

Commit

Permalink
Merge branch 'jakarta' into test-java-21
Browse files Browse the repository at this point in the history
* jakarta:
  fix: warning message about "not eligible ..." (#73)
  ci: update bump-spring pipeline
  style: switch formatter (#72)
  • Loading branch information
shihyuho committed Dec 20, 2023
2 parents edfba3e + 48549de commit 1eaac1d
Show file tree
Hide file tree
Showing 112 changed files with 1,098 additions and 1,615 deletions.
10 changes: 9 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
Expand All @@ -9,8 +10,15 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false

[*.{properties,yml,yaml}]
trim_trailing_whitespace = false

[*.mustache]
insert_final_newline = false

[Makefile]
indent_style = tab
intent_size = 4
indent_size = 4
14 changes: 13 additions & 1 deletion .github/workflows/bump-spring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ jobs:
outputs:
spring-boot: ${{ steps.get-latest-version.outputs.spring-boot }}

compare-version:
runs-on: ubuntu-latest
needs: [latest-version, current-version]
steps:
- id: semver-compare
uses: madhead/semver-utils@latest
with:
version: ${{ needs.latest-version.outputs.spring-boot }}
compare-to: ${{ needs.current-version.outputs.spring-boot }}
outputs:
comparison-result: ${{ steps.semver-compare.outputs.comparison-result }}

bump-spring:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
needs: [current-version, latest-version]
needs: [current-version, latest-version, compare-version]
if: "${{ needs.current-version.outputs.spring-boot != needs.latest-version.outputs.spring-boot }}"
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ help: ## Display this help.
##@ Develop

format: ## Format the source code.
mvn process-sources -e
mvn validate -e

clean: ## Remove files generated at build-time.
mvn clean -e
Expand Down
321 changes: 0 additions & 321 deletions ide-config/eclipse-format.xml

This file was deleted.

4 changes: 0 additions & 4 deletions ide-config/eclipse.importorder

This file was deleted.

14 changes: 4 additions & 10 deletions mapper/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tw.com.softleader.data.jakarta</groupId>
<artifactId>specification-mapper-parent</artifactId>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>specification-mapper</artifactId>
<name>specification-mapper</name>
Expand Down Expand Up @@ -74,12 +72,8 @@
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
31 changes: 17 additions & 14 deletions mapper/src/main/java/tw/com/softleader/data/jpa/spec/ASTNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,33 @@
*/
package tw.com.softleader.data.jpa.spec;

import lombok.NonNull;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.lang.Nullable;

import lombok.NonNull;

/**
* @author Matt Ho
*/
public interface ASTNode {

default void preVisit(@NonNull SpecInvocation node) {
node.getAst().add(node.getDepth(), "| +-[%s.%s]: %s (%s)",
node.getTargetType().getSimpleName(),
node.getFieldName(),
node.getFieldType().getName(),
node.getResolverType().getSimpleName());
node.getAst()
.add(
node.getDepth(),
"| +-[%s.%s]: %s (%s)",
node.getTargetType().getSimpleName(),
node.getFieldName(),
node.getFieldType().getName(),
node.getResolverType().getSimpleName());
}

default void postVisit(
@NonNull SpecInvocation node,
@Nullable Specification<Object> resolved) {
node.getAst().add(node.getDepth(), "| \\-[%s.%s]: %s",
node.getTargetType().getSimpleName(),
node.getFieldName(),
resolved);
default void postVisit(@NonNull SpecInvocation node, @Nullable Specification<Object> resolved) {
node.getAst()
.add(
node.getDepth(),
"| \\-[%s.%s]: %s",
node.getTargetType().getSimpleName(),
node.getFieldName(),
resolved);
}
}
13 changes: 3 additions & 10 deletions mapper/src/main/java/tw/com/softleader/data/jpa/spec/Databind.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.lang.reflect.Field;
import java.util.Optional;

import org.springframework.lang.NonNull;

/**
Expand All @@ -32,20 +31,14 @@
*/
public interface Databind {

/**
* 欄位所在的物件
*/
/** 欄位所在的物件 */
@NonNull
Object getTarget();

/**
* 欄位
*/
/** 欄位 */
@NonNull
Field getField();

/**
* 欄位值
*/
/** 欄位值 */
Optional<Object> getFieldValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

import java.util.Objects;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.lang.NonNull;

import lombok.extern.slf4j.Slf4j;
import tw.com.softleader.data.jpa.spec.annotation.JoinFetch;
import tw.com.softleader.data.jpa.spec.annotation.JoinFetch.JoinFetches;
import tw.com.softleader.data.jpa.spec.domain.Conjunction;
Expand All @@ -48,19 +46,18 @@ public boolean supports(@NonNull Databind databind) {
}

@Override
public Specification<Object> buildSpecification(@NonNull Context context,
@NonNull Databind databind) {
public Specification<Object> buildSpecification(
@NonNull Context context, @NonNull Databind databind) {
var handled = handledKey(databind);
if (context.containsKey(handled)) {
log.trace("Already handled [{}], skipping", handled);
return null;
}
try {
var specs = Stream.concat(
joinFetchDef(databind.getTarget()),
joinFetchesDef(databind.getTarget()))
.filter(Objects::nonNull)
.collect(toList());
var specs =
Stream.concat(joinFetchDef(databind.getTarget()), joinFetchesDef(databind.getTarget()))
.filter(Objects::nonNull)
.collect(toList());
if (specs.size() == 1) {
return specs.get(0);
}
Expand All @@ -74,8 +71,7 @@ private Stream<Specification<Object>> joinFetchesDef(Object obj) {
if (!obj.getClass().isAnnotationPresent(JoinFetches.class)) {
return Stream.empty();
}
return stream(obj.getClass().getAnnotation(JoinFetches.class).value())
.map(this::newJoinFetch);
return stream(obj.getClass().getAnnotation(JoinFetches.class).value()).map(this::newJoinFetch);
}

private Stream<Specification<Object>> joinFetchDef(Object obj) {
Expand All @@ -87,13 +83,12 @@ private Stream<Specification<Object>> joinFetchDef(Object obj) {

Specification<Object> newJoinFetch(@NonNull JoinFetch def) {
return new tw.com.softleader.data.jpa.spec.domain.JoinFetch<>(
def.paths(),
def.joinType(),
def.distinct());
def.paths(), def.joinType(), def.distinct());
}

private String handledKey(Databind databind) {
return String.join("/",
return String.join(
"/",
JoinFetchSpecificationResolver.class.getName(),
databind.getField().getDeclaringClass().getName(),
"" + databind.getTarget().hashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import java.lang.reflect.Field;
import java.util.Objects;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.lang.NonNull;

import lombok.extern.slf4j.Slf4j;
import tw.com.softleader.data.jpa.spec.annotation.Join;
import tw.com.softleader.data.jpa.spec.annotation.Join.Joins;
import tw.com.softleader.data.jpa.spec.domain.Conjunction;
Expand All @@ -49,45 +47,43 @@ public boolean supports(@NonNull Databind databind) {
}

@Override
public Specification<Object> buildSpecification(@NonNull Context context,
@NonNull Databind databind) {
return databind.getFieldValue()
.map(value -> {
var specs = Stream.concat(
joinDef(context, databind.getField()),
joinsDef(context, databind.getField()))
.filter(Objects::nonNull)
.collect(toList());
if (specs.size() == 1) {
return specs.get(0);
}
return new Conjunction<>(specs);
}).orElse(null);
public Specification<Object> buildSpecification(
@NonNull Context context, @NonNull Databind databind) {
return databind
.getFieldValue()
.map(
value -> {
var specs =
Stream.concat(
joinDef(context, databind.getField()),
joinsDef(context, databind.getField()))
.filter(Objects::nonNull)
.collect(toList());
if (specs.size() == 1) {
return specs.get(0);
}
return new Conjunction<>(specs);
})
.orElse(null);
}

private Stream<Specification<Object>> joinsDef(Context context, Field field) {
if (!field.isAnnotationPresent(Joins.class)) {
return Stream.empty();
}
return stream(field.getAnnotation(Joins.class).value())
.map(def -> newJoin(context, def));
return stream(field.getAnnotation(Joins.class).value()).map(def -> newJoin(context, def));
}

private Stream<Specification<Object>> joinDef(Context context, Field field) {
if (!field.isAnnotationPresent(Join.class)) {
return Stream.empty();
}
return Stream.of(
newJoin(context, field.getAnnotation(Join.class)));
return Stream.of(newJoin(context, field.getAnnotation(Join.class)));
}

Specification<Object> newJoin(@NonNull Context context, @NonNull Join def) {
return new tw.com.softleader.data.jpa.spec.domain.Join<>(
context,
def.path(),
def.alias(),
def.joinType(),
def.distinct());
context, def.path(), def.alias(), def.joinType(), def.distinct());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

import static tw.com.softleader.data.jpa.spec.AST.CTX_DEPTH;

import org.springframework.data.jpa.domain.Specification;
import org.springframework.lang.NonNull;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.lang.NonNull;
import tw.com.softleader.data.jpa.spec.annotation.And;
import tw.com.softleader.data.jpa.spec.annotation.NestedSpec;
import tw.com.softleader.data.jpa.spec.annotation.Or;
Expand All @@ -47,25 +46,27 @@ public boolean supports(@NonNull Databind databind) {
}

@Override
public Specification<Object> buildSpecification(@NonNull Context context,
@NonNull Databind databind) {
return databind.getFieldValue()
.map(nested -> {
var depth = (int) context.get(CTX_DEPTH).get();
context.put(CTX_DEPTH, depth + 1);
var spec = codec.toSpec(context, nested);
if (spec == null) {
return null;
}
var field = databind.getField();
if (field.isAnnotationPresent(And.class)) {
return new tw.com.softleader.data.jpa.spec.domain.And<>(spec);
}
if (field.isAnnotationPresent(Or.class)) {
return new tw.com.softleader.data.jpa.spec.domain.Or<>(spec);
}
return spec;
})
public Specification<Object> buildSpecification(
@NonNull Context context, @NonNull Databind databind) {
return databind
.getFieldValue()
.map(
nested -> {
var depth = (int) context.get(CTX_DEPTH).get();
context.put(CTX_DEPTH, depth + 1);
var spec = codec.toSpec(context, nested);
if (spec == null) {
return null;
}
var field = databind.getField();
if (field.isAnnotationPresent(And.class)) {
return new tw.com.softleader.data.jpa.spec.domain.And<>(spec);
}
if (field.isAnnotationPresent(Or.class)) {
return new tw.com.softleader.data.jpa.spec.domain.Or<>(spec);
}
return spec;
})
.orElse(null);
}
}
Loading

0 comments on commit 1eaac1d

Please sign in to comment.