Skip to content

Commit 66536f4

Browse files
authored
Merge branch 'master' into master
2 parents 324cf9a + ce16c49 commit 66536f4

File tree

71 files changed

+778
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+778
-362
lines changed

.github/workflows/comment-pr.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Description: This workflow is triggered when the `receive-pr` workflow completes to post suggestions on the PR.
2+
# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code.
3+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
4+
---
5+
name: comment-pr
6+
7+
on:
8+
workflow_run:
9+
workflows: ["receive-pr"]
10+
types:
11+
- completed
12+
13+
jobs:
14+
post-suggestions:
15+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow
16+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
17+
runs-on: ubuntu-latest
18+
env:
19+
# https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token
20+
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
timeout-minutes: 10
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
ref: ${{github.event.workflow_run.head_branch}}
26+
repository: ${{github.event.workflow_run.head_repository.full_name}}
27+
28+
# Download the patch
29+
- uses: actions/download-artifact@v4
30+
with:
31+
name: patch
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
run-id: ${{ github.event.workflow_run.id }}
34+
- name: Apply patch
35+
run: |
36+
git apply git-diff.patch --allow-empty
37+
rm git-diff.patch
38+
39+
# Download the PR number
40+
- uses: actions/download-artifact@v4
41+
with:
42+
name: pr_number
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
run-id: ${{ github.event.workflow_run.id }}
45+
- name: Read pr_number.txt
46+
run: |
47+
PR_NUMBER=$(cat pr_number.txt)
48+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
49+
rm pr_number.txt
50+
51+
# Post suggestions as a comment on the PR
52+
- uses: googleapis/code-suggester@v4
53+
with:
54+
command: review
55+
pull_number: ${{ env.PR_NUMBER }}
56+
git_dir: '.'

.github/workflows/receive-pr.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Description: This workflow runs OpenRewrite recipes against opened pull request and upload the patch.
2+
# Since this pull request receives untrusted code, we should **NOT** have any secrets in the environment.
3+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
4+
---
5+
name: receive-pr
6+
7+
on:
8+
pull_request:
9+
types: [opened, synchronize]
10+
branches:
11+
- master
12+
13+
concurrency:
14+
group: '${{ github.workflow }} @ ${{ github.ref }}'
15+
cancel-in-progress: true
16+
17+
jobs:
18+
upload-patch:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 10
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
ref: ${{github.event.pull_request.head.ref}}
25+
repository: ${{github.event.pull_request.head.repo.full_name}}
26+
- uses: actions/setup-java@v4
27+
with:
28+
java-version: '21'
29+
distribution: 'temurin'
30+
cache: 'maven'
31+
32+
# Capture the PR number
33+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
34+
- name: Create pr_number.txt
35+
run: echo "${{ github.event.number }}" > pr_number.txt
36+
- uses: actions/upload-artifact@v4
37+
with:
38+
name: pr_number
39+
path: pr_number.txt
40+
- name: Remove pr_number.txt
41+
run: rm -f pr_number.txt
42+
43+
# Execute recipes
44+
- name: Apply OpenRewrite recipes
45+
run: ./mvnw -Dtoolchain.skip=true -P examples,quickbuild,openrewrite,dev clean install
46+
# Capture the diff
47+
- name: Create patch
48+
run: |
49+
git diff | tee git-diff.patch
50+
- uses: actions/upload-artifact@v4
51+
with:
52+
name: patch
53+
path: git-diff.patch

pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@
943943
</plugins>
944944
</build>
945945
</profile>
946+
946947
<profile>
947948
<id>no-databases</id>
948949

@@ -991,6 +992,68 @@
991992
</build>
992993
</profile>
993994

995+
<profile>
996+
<id>openrewrite</id>
997+
<build>
998+
<plugins>
999+
<plugin>
1000+
<groupId>org.openrewrite.maven</groupId>
1001+
<artifactId>rewrite-maven-plugin</artifactId>
1002+
<version>5.36.0</version>
1003+
1004+
<dependencies>
1005+
<dependency>
1006+
<groupId>org.openrewrite.recipe</groupId>
1007+
<artifactId>rewrite-testing-frameworks</artifactId>
1008+
<version>2.14.0</version>
1009+
</dependency>
1010+
<dependency>
1011+
<groupId>org.openrewrite.recipe</groupId>
1012+
<artifactId>rewrite-migrate-java</artifactId>
1013+
<version>2.20.0</version>
1014+
</dependency>
1015+
</dependencies>
1016+
1017+
<executions>
1018+
<execution>
1019+
<id>tests</id>
1020+
<goals>
1021+
<goal>runNoFork</goal>
1022+
</goals>
1023+
<phase>verify</phase>
1024+
<configuration>
1025+
<exportDatatables>true</exportDatatables>
1026+
<activeRecipes>
1027+
<recipe>org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ</recipe>
1028+
<recipe>org.openrewrite.java.testing.assertj.JUnitToAssertj</recipe>
1029+
<recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
1030+
<recipe>org.openrewrite.java.migrate.UpgradeToJava21</recipe>
1031+
</activeRecipes>
1032+
<exclusions>
1033+
<exclusion>**/src/main/java/**</exclusion>
1034+
<exclusion>pom.xml</exclusion>
1035+
</exclusions>
1036+
</configuration>
1037+
</execution>
1038+
<execution>
1039+
<id>sources</id>
1040+
<goals>
1041+
<goal>runNoFork</goal>
1042+
</goals>
1043+
<phase>verify</phase>
1044+
<configuration>
1045+
<exportDatatables>true</exportDatatables>
1046+
<activeRecipes>
1047+
<recipe>org.openrewrite.java.migrate.Java8toJava11</recipe>
1048+
</activeRecipes>
1049+
</configuration>
1050+
</execution>
1051+
</executions>
1052+
</plugin>
1053+
</plugins>
1054+
</build>
1055+
</profile>
1056+
9941057
<profile>
9951058
<id>toolchain</id>
9961059
<activation>

querydsl-examples/querydsl-example-r2dbc-sql-codegen/src/test/java/com/querydsl/example/config/TestDataService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ public void removeTestData() {
149149
// Idem for sequences
150150
s =
151151
c.createStatement(
152-
"SELECT SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES WHERE"
153-
+ " SEQUENCE_SCHEMA='PUBLIC'");
152+
"""
153+
SELECT SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES WHERE\
154+
SEQUENCE_SCHEMA='PUBLIC'\
155+
""");
154156
List<String> sequences =
155157
Flux.from(s.execute())
156158
.flatMap(result -> result.map((row, meta) -> row.get(0, String.class)))

querydsl-examples/querydsl-example-sql-guice/src/test/java/com/querydsl/example/sql/repository/TweetRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void save_with_mentions() {
5656
tweet.setPosterId(posterId);
5757
Long tweetId = repository.save(tweet, otherId);
5858

59-
assertThat(repository.findWithMentioned(otherId).get(0).getId()).isEqualTo(tweetId);
59+
assertThat(repository.findWithMentioned(otherId).getFirst().getId()).isEqualTo(tweetId);
6060
}
6161

6262
@Test

querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/AliasTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void alias3() {
8383

8484
// 4
8585
from(c, cats)
86-
.where($(c.getKittens().get(0).getBodyWeight()).gt(12))
86+
.where($(c.getKittens().getFirst().getBodyWeight()).gt(12))
8787
.select($(c.getName()))
8888
.iterate();
8989

querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/CollQueryStandardTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected Fetchable<?> createQuery(Predicate filter) {
7373

7474
@Test
7575
public void test() {
76-
Cat kitten = data.getFirst().getKittens().get(0);
76+
Cat kitten = data.getFirst().getKittens().getFirst();
7777
standardTest.runArrayTests(cat.kittenArray, otherCat.kittenArray, kitten, new Cat());
7878
standardTest.runBooleanTests(cat.name.isNull(), otherCat.kittens.isEmpty());
7979
standardTest.runCollectionTests(cat.kittens, otherCat.kittens, kitten, new Cat());

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/MethodType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public enum MethodType {
3030
/** __mappedPath invocation */
3131
GET_MAPPED_PATH("__mappedPath", Path.class, ManagedObject.class),
3232
/** getter invocation */
33+
LIST_GET_FIRST("getFirst", Object.class, List.class),
34+
/** getter invocation */
3335
GETTER("(get|is).+", Object.class, Object.class),
3436
/** hashCode invocation */
3537
HASH_CODE("hashCode", int.class, Object.class),

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/PropertyAccessInvocationHandler.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,27 @@ public Object intercept(
8484
MethodType methodType = MethodType.get(method);
8585

8686
if (methodType == MethodType.GETTER) {
87-
String ptyName = propertyNameForGetter(method);
87+
var ptyName = propertyNameForGetter(method);
8888
Class<?> ptyClass = method.getReturnType();
89-
Type genericType = method.getGenericReturnType();
89+
var genericType = method.getGenericReturnType();
9090

9191
if (propToObj.containsKey(ptyName)) {
9292
rv = propToObj.get(ptyName);
9393
} else {
94-
PathMetadata pm = createPropertyPath((Path<?>) hostExpression, ptyName);
94+
var pm = createPropertyPath((Path<?>) hostExpression, ptyName);
9595
rv = newInstance(ptyClass, genericType, proxy, ptyName, pm);
9696
}
9797
aliasFactory.setCurrent(propToExpr.get(ptyName));
9898

9999
} else if (methodType == MethodType.SCALA_GETTER) {
100-
String ptyName = method.getName();
100+
var ptyName = method.getName();
101101
Class<?> ptyClass = method.getReturnType();
102-
Type genericType = method.getGenericReturnType();
102+
var genericType = method.getGenericReturnType();
103103

104104
if (propToObj.containsKey(ptyName)) {
105105
rv = propToObj.get(ptyName);
106106
} else {
107-
PathMetadata pm = createPropertyPath((Path<?>) hostExpression, ptyName);
107+
var pm = createPropertyPath((Path<?>) hostExpression, ptyName);
108108
rv = newInstance(ptyClass, genericType, proxy, ptyName, pm);
109109
}
110110
aliasFactory.setCurrent(propToExpr.get(ptyName));
@@ -115,7 +115,18 @@ public Object intercept(
115115
if (propToObj.containsKey(propKey)) {
116116
rv = propToObj.get(propKey);
117117
} else {
118-
PathMetadata pm = createListAccessPath((Path<?>) hostExpression, (Integer) args[0]);
118+
var pm = createListAccessPath((Path<?>) hostExpression, (Integer) args[0]);
119+
Class<?> elementType = ((ParameterizedExpression<?>) hostExpression).getParameter(0);
120+
rv = newInstance(elementType, elementType, proxy, propKey, pm);
121+
}
122+
aliasFactory.setCurrent(propToExpr.get(propKey));
123+
} else if (methodType == MethodType.LIST_GET_FIRST) {
124+
// TODO : manage cases where the argument is based on a property invocation
125+
Object propKey = Arrays.asList(MethodType.LIST_GET_FIRST);
126+
if (propToObj.containsKey(propKey)) {
127+
rv = propToObj.get(propKey);
128+
} else {
129+
var pm = PathMetadataFactory.forListFirst((Path<?>) hostExpression);
119130
Class<?> elementType = ((ParameterizedExpression<?>) hostExpression).getParameter(0);
120131
rv = newInstance(elementType, elementType, proxy, propKey, pm);
121132
}
@@ -126,7 +137,7 @@ public Object intercept(
126137
if (propToObj.containsKey(propKey)) {
127138
rv = propToObj.get(propKey);
128139
} else {
129-
PathMetadata pm = createMapAccessPath((Path<?>) hostExpression, args[0]);
140+
var pm = createMapAccessPath((Path<?>) hostExpression, args[0]);
130141
Class<?> valueType = ((ParameterizedExpression<?>) hostExpression).getParameter(1);
131142
rv = newInstance(valueType, valueType, proxy, propKey, pm);
132143
}
@@ -270,7 +281,7 @@ protected <T> T newInstance(
270281
}
271282

272283
protected String propertyNameForGetter(Method method) {
273-
String name = method.getName();
284+
var name = method.getName();
274285
name = name.startsWith("is") ? name.substring(2) : name.substring(3);
275286
return BeanUtils.uncapitalize(name);
276287
}

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadataFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public static PathMetadata forCollectionAny(Path<?> parent) {
5555
return new PathMetadata(parent, "", PathType.COLLECTION_ANY);
5656
}
5757

58+
/**
59+
* Create a new PathMetadata instance for list first element
60+
*
61+
* @param parent parent path
62+
* @return collection any path
63+
*/
64+
public static PathMetadata forListFirst(Path<?> parent) {
65+
return new PathMetadata(parent, "", PathType.LIST_FIRST);
66+
}
67+
5868
/**
5969
* Create a new PathMetadata instance for delegate access
6070
*

0 commit comments

Comments
 (0)