using openrewrite to migrate to java 17

master
Markus Kreth 5 months ago
parent dceda9dd3c
commit 533640b583
  1. 2
      .github/workflows/maven.yml
  2. 27
      pom.xml
  3. 3
      src/main/java/de/kreth/property2java/GeneratorException.java
  4. 3
      src/main/java/de/kreth/property2java/processor/ProcessorConfiguration.java
  5. 45
      src/test/java/de/kreth/property2java/TestPropertiesSource.java
  6. 3
      src/test/java/de/kreth/property2java/generated/GenerateTheTest.java

@ -19,6 +19,6 @@ jobs:
- name: Set up JDK 1.8 - name: Set up JDK 1.8
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 11 java-version: 17
- name: Build with Maven - name: Build with Maven
run: mvn -B package --file pom.xml run: mvn -B package --file pom.xml

@ -10,7 +10,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version> <java.version>17</java.version>
<org.junit.jupiter>5.3.0-M1</org.junit.jupiter> <org.junit.jupiter>5.3.0-M1</org.junit.jupiter>
<org.slf4j>1.7.36</org.slf4j> <org.slf4j>1.7.36</org.slf4j>
<org.apache.logging.log4j>2.17.2</org.apache.logging.log4j> <org.apache.logging.log4j>2.17.2</org.apache.logging.log4j>
@ -47,6 +47,12 @@
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>${org.slf4j}</version> <version>${org.slf4j}</version>
</dependency> </dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
@ -140,12 +146,29 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.14.0</version>
<configuration> <configuration>
<release>${java.version}</release> <release>${java.version}</release>
<compilerArgs>-proc:none</compilerArgs> <compilerArgs>-proc:none</compilerArgs>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.15.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>3.14.1</version>
</dependency>
</dependencies>
</plugin>
</plugins> </plugins>
</build> </build>
<scm> <scm>

@ -1,7 +1,10 @@
package de.kreth.property2java; package de.kreth.property2java;
import java.io.Serial;
public class GeneratorException extends Exception { public class GeneratorException extends Exception {
@Serial
private static final long serialVersionUID = -7319030228448260990L; private static final long serialVersionUID = -7319030228448260990L;
public GeneratorException(String message, Throwable cause) { public GeneratorException(String message, Throwable cause) {

@ -49,8 +49,7 @@ public class ProcessorConfiguration implements Configuration {
public String getPackage() { public String getPackage() {
String packageName = ""; String packageName = "";
if (element instanceof TypeElement) { if (element instanceof TypeElement typeElement) {
TypeElement typeElement = (TypeElement) element;
PackageElement packageElement = (PackageElement) typeElement.getEnclosingElement(); PackageElement packageElement = (PackageElement) typeElement.getEnclosingElement();
packageName = packageElement.getQualifiedName().toString(); packageName = packageElement.getQualifiedName().toString();
} }

@ -10,23 +10,34 @@ import de.kreth.property2java.generated.GenerateTheTest;
public class TestPropertiesSource { public class TestPropertiesSource {
public static StringReader testProperties() { public static StringReader testProperties() {
return new StringReader("\r\n" + "label = \r\n" + "\r\n" + "label.addarticle = Add Article\r\n" return new StringReader("""
+ "label.cancel = Cancel\r\n" + "label.close = Close\r\n"
+ "label.delete = Delete\r\n" + "label.discart = Discart\r\n" label =
+ "label.loggedin = Logged in:\r\n" + "label.logout = Logout\r\n"
+ "label.ok = OK\r\n" + "label.store = Store\r\n" label.addarticle = Add Article
+ "label.preview = Preview\r\n" + "label.open = Open\r\n" label.cancel = Cancel
+ "label.user.register = Register\r\n" + "\r\n" label.close = Close
+ "message.article.priceerror = Please set the price.\r\n" label.delete = Delete
+ "message.delete.text = Delete {0}?\r\n" label.discart = Discart
+ "message.delete.title = Really delete?\r\n" label.loggedin = Logged in:
+ "message.invoiceitem.allfieldsmustbeset = Start, end and article must not be \\r\\n" label.logout = Logout
+ " empty!\r\n" label.ok = OK
+ "message.invoiceitem.startbeforeend = End must be later than start.\r\n" label.store = Store
+ "message.user.create.success = Thanks {0} created!\r\n" label.preview = Preview
+ "message.user.loginfailure = Login Error! Wrong user or password?\r\n" label.open = Open
+ "message.user.passwordmissmatch = Passwords don't match.\r\n" label.user.register = Register
+ "message.with.five.placeholders = Third is first{2}, then last \"{4}\", second={1}, fourth={3} and first is last={0}\r\n");
message.article.priceerror = Please set the price.
message.delete.text = Delete {0}?
message.delete.title = Really delete?
message.invoiceitem.allfieldsmustbeset = Start, end and article must not be \\r\\n\
empty!
message.invoiceitem.startbeforeend = End must be later than start.
message.user.create.success = Thanks {0} created!
message.user.loginfailure = Login Error! Wrong user or password?
message.user.passwordmissmatch = Passwords don't match.
message.with.five.placeholders = Third is first{2}, then last "{4}", second={1}, fourth={3} and first is last={0}
""");
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {

@ -3,7 +3,6 @@ package de.kreth.property2java.generated;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -25,7 +24,7 @@ public class GenerateTheTest {
public static final String RESOURCE_BUNDLE = "resource_bundle.properties"; public static final String RESOURCE_BUNDLE = "resource_bundle.properties";
public static void main(String[] args) throws IOException, GeneratorException { public static void main(String[] args) throws IOException, GeneratorException {
Path current = Paths.get(".", "src", "test", "java", "de", "kreth", "property2java", "generated").toAbsolutePath().normalize(); Path current = Path.of(".", "src", "test", "java", "de", "kreth", "property2java", "generated").toAbsolutePath().normalize();
System.out.println(current); System.out.println(current);
withUnaryOperatorParameter(current); withUnaryOperatorParameter(current);

Loading…
Cancel
Save