Skip to content

Commit

Permalink
Moving from javax packages to jakarta and supporting Boot 3 (#23)
Browse files Browse the repository at this point in the history
* Moving from `javax` packages to `jakarta` and starting to support Boot 3.
  • Loading branch information
onukristo authored May 9, 2023
1 parent acb08a6 commit fb4e51d
Show file tree
Hide file tree
Showing 41 changed files with 149 additions and 95 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ jobs:
max-parallel: 100
matrix:
spring_boot_version:
- 2.7.8
- 2.6.14
- 2.5.14
- 3.0.6
env:
SPRING_BOOT_VERSION: ${{ matrix.spring_boot_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'zulu'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: "8.0"
gradle-home-cache-cleanup: true
# Comment out when you are upgrading gradle in a branch and doing tons of commits you would need to test.
# cache-read-only: false
Expand Down Expand Up @@ -102,7 +104,6 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: "8.0"
gradle-home-cache-cleanup: true
# Comment out when you are upgrading gradle in a branch and doing tons of commits you would need to test.
# cache-read-only: false
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2023-05-06

### Changed

* Moving from `javax` packages to `jakarta`.
That means we will start supporting JDK 17 and Spring Boot 3 only from now on.
Cloned `javax` version to `transferwise/tw-gaffer-jta-javax` repository, for case we need to do urgent changes for older services.

* Jakarta Validation is done now programmatically.
Somehow the `@Validated` annotation based validation considerable slowed down the application startup.

## [2.2.0] - 2023-03-30

### Changed
Expand Down
28 changes: 10 additions & 18 deletions build.common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ configurations {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}
Expand All @@ -60,9 +60,14 @@ jar {
}

dependencies {
local platform(libraries.springBootDependencies + '!!')
local libraries.lombok
local libraries.spotbugsAnnotations
local platform(libraries.springBootDependencies)

compileOnly libraries.lombok
annotationProcessor libraries.lombok
testCompileOnly libraries.lombok
testAnnotationProcessor libraries.lombok

compileOnly libraries.spotbugsAnnotations
}

compileJava {
Expand All @@ -73,19 +78,9 @@ compileJava {

options.fork = true
options.forkOptions.jvmArgs << '-Xmx256m'

javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(11)
}
}

compileTestJava {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}

options.fork = true
options.forkOptions.jvmArgs << '-Xmx256m'
}
Expand Down Expand Up @@ -117,9 +112,6 @@ jar {
}

test {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
useJUnitPlatform()
jvmArgs("-Xmx512m")
testLogging {
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import org.eclipse.jgit.api.errors.RefAlreadyExistsException

plugins {
id "idea"
id 'com.github.spotbugs' version '5.0.13'
id 'org.ajoberstar.grgit' version '5.0.0'
id 'com.github.spotbugs' version '5.0.14'
id 'org.ajoberstar.grgit' version '5.2.0'
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
}

ext.projectName = 'TransferWise Gaffer 1PC JTA'
ext.projectDescription = 'Transferwise Gaffer 1PC JTA - efficient 1PC JTA for enterprise services'
ext.projectGitHubRepoName = 'tw-gaffer-jta'
ext.projectArtifactName = 'tw-gaffer-jta'
ext.projectArtifactName = 'tw-gaffer-jta-jakarta'

apply from: 'build.common.gradle'

Expand Down
8 changes: 4 additions & 4 deletions build.libraries.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
ext {
springBootVersion = System.getenv("SPRING_BOOT_VERSION") ?: "2.6.14"
springBootVersion = System.getenv("SPRING_BOOT_VERSION") ?: "3.0.6"

libraries = [
// explicit versions
guava : 'com.google.guava:guava:31.1-jre',
spotbugsAnnotations : "com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}",
springBootDependencies : "org.springframework.boot:spring-boot-dependencies:${springBootVersion}",
twBaseUtils : 'com.transferwise.common:tw-base-utils:1.9.0',
twBaseUtils : 'com.transferwise.common:tw-base-utils:1.10.1',

// versions managed by spring-boot-dependencies platform
commonsLang3 : 'org.apache.commons:commons-lang3',
hamcrestCore : 'org.hamcrest:hamcrest-core',
hibernateCore : 'org.hibernate:hibernate-core',
hibernateCore : 'org.hibernate.orm:hibernate-core',
hikariCp : "com.zaxxer:HikariCP",
hsqldb : 'org.hsqldb:hsqldb',
jakartaAnnotationApi : 'jakarta.annotation:jakarta.annotation-api',
jakartaValidationApi : 'jakarta.validation:jakarta.validation-api',
javaxTransactionApi : "javax.transaction:javax.transaction-api",
jakartaTransactionApi : "jakarta.transaction:jakarta.transaction-api",
lombok : 'org.projectlombok:lombok',
mariadbJavaClient : 'org.mariadb.jdbc:mariadb-java-client',
slf4jApi : 'org.slf4j:slf4j-api',
Expand Down
5 changes: 5 additions & 0 deletions build.library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ publishing {
developerConnection = projectScmConnection
url = projectScmUrl
}
withXml {
if (!asNode().dependencyManagement.isEmpty()){
throw new IllegalStateException("There should not be any `dependencyManagement` block in POM.")
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.2.0
version=3.0.0
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
4 changes: 2 additions & 2 deletions tw-gaffer-jta-starter/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ext.projectName = "tw-gaffer-jta-starter"
ext.projectDescription = "tw-gaffer-jta-starter"
ext.projectArtifactName = "tw-gaffer-jta-starter"
ext.projectArtifactName = "tw-gaffer-jta-jakarta-starter"

apply from: "${project.rootDir}/build.common.gradle"
apply from: "${project.rootDir}/build.library.gradle"

dependencies {
api libraries.javaxTransactionApi
api libraries.jakartaTransactionApi
api project(":tw-gaffer-jta")

annotationProcessor libraries.springBootConfigurationProcessor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.transferwise.common.gaffer.starter;

import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;

public class DefaultEnvironmentValidator implements EnvironmentValidator, ApplicationListener<ApplicationPreparedEvent> {

@Autowired
private GafferJtaProperties properties;

@Autowired
private Validator validator;

public void validate() {
var violations = validator.validate(properties);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}

@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
validate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.transferwise.common.gaffer.starter;

public interface EnvironmentValidator {

void validate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.transferwise.common.gaffer.ServiceRegistry;
import com.transferwise.common.gaffer.ServiceRegistryHolder;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import jakarta.transaction.TransactionManager;
import jakarta.transaction.UserTransaction;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -52,4 +52,11 @@ public GafferJtaProperties gafferJtaProperties() {
public GafferJtaDataSourceBeanProcessor gafferJtaDataSourceBeanProcessor() {
return new GafferJtaDataSourceBeanProcessor();
}

@Bean
@ConditionalOnMissingBean(EnvironmentValidator.class)
public DefaultEnvironmentValidator gafferJtaEnvironmentValidator() {
return new DefaultEnvironmentValidator();
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.transferwise.common.gaffer.starter;

import com.transferwise.common.gaffer.jdbc.AutoCommitStrategy;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.validation.annotation.Validated;

@Data
@Accessors(chain = true)
@Validated
public class GafferJtaProperties {

@Valid
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.transferwise.common.gaffer.starter.GafferJtaAutoConfiguration
4 changes: 2 additions & 2 deletions tw-gaffer-jta/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ext.projectName = "tw-gaffer-jta"
ext.projectDescription = "tw-gaffer-jta"
ext.projectArtifactName = "tw-gaffer-jta"
ext.projectArtifactName = "tw-gaffer-jta-jakarta"

apply from: "${project.rootDir}/build.common.gradle"
apply from: "${project.rootDir}/build.library.gradle"

dependencies {
api libraries.javaxTransactionApi
api libraries.jakartaTransactionApi

implementation libraries.slf4jApi
implementation libraries.commonsLang3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.transferwise.common.gaffer.util.Clock;
import com.transferwise.common.gaffer.util.MonotonicClock;
import javax.transaction.TransactionSynchronizationRegistry;
import jakarta.transaction.TransactionSynchronizationRegistry;

public class ServiceRegistry {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import com.transferwise.common.gaffer.util.TransactionStatuses;
import com.transferwise.common.gaffer.util.Uid;
import com.transferwise.common.gaffer.util.UidImpl;
import jakarta.transaction.RollbackException;
import jakarta.transaction.Status;
import jakarta.transaction.Synchronization;
import jakarta.transaction.Transaction;
import java.lang.ref.Cleaner;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.transferwise.common.gaffer.util.ExceptionThrower;
import com.transferwise.common.gaffer.util.FormatLogger;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import jakarta.transaction.NotSupportedException;
import jakarta.transaction.RollbackException;
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import jakarta.transaction.TransactionManager;

public class TransactionManagerImpl implements TransactionManager {

Expand Down
Loading

0 comments on commit fb4e51d

Please sign in to comment.