Skip to content

Commit

Permalink
Merge pull request #18 from gchq/javax-to-jakarta-jaxb2
Browse files Browse the repository at this point in the history
Javax to jakarta with jaxb2
  • Loading branch information
at055612 authored Jun 19, 2024
2 parents 606c227 + ad7f27d commit eaec5f2
Show file tree
Hide file tree
Showing 45 changed files with 702 additions and 543 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ jobs:
# Set this so it gets the annotated commit, not the commit being tagged.
# Which means we can get the release msg
# See https://github.com/actions/runner/issues/712
ref: ${{ github.ref }}
ref: ${{ github.ref }}

- name: Setup Java
id: setup_java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8.0.312+7'
distribution: 'temurin'
java-version: '11.0.23+9'
cache: 'gradle'

# Make sure the wrapper jar has not been tampered with
- name: Validate gradle wrapper jar
id: validate_gradle_wrapper
uses: gradle/wrapper-validation-action@v1

# Set variables in github's special env file which are then automatically
# Set variables in github's special env file which are then automatically
# read into env vars in each subsequent step
- name: Set Environment Variables
id: set_env_var
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The Javadoc for the latest release of the library is available [here](https://gc
This library requires Java 8 as a minimum.
The only dependencies it brings with it are:

* `javax.xml.bind:jaxb-api`
* `org.glassfish.jaxb:jaxb-runtime`
* `jakarta.xml.bind:jakarta.xml.bind-api`
* `com.sun.xml.bind:jaxb-impl`
* `org.slf4j:slf4j-api`

By default the created events are serialised to XML and passed to an SLF4J logger which would typically be linked to a rolling file appender.
Expand Down
43 changes: 19 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
plugins {
//plugin for downloading content from the 'net
id "de.undercouch.download" version "3.4.3"
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
id "io.github.gradle-nexus.publish-plugin" version "1.2.0"
//plugin for producing a tree of task dependencies, run task 'taskTree'
id "com.dorongold.task-tree" version "1.5"
id "signing"
Expand All @@ -36,7 +36,7 @@ ext.isPropertySet = { propName ->
}
}

ext.ensurePropertyIsSet = { propName ->
ext.ensurePropertyIsSet = { propName ->
if (!isPropertySet(propName)) {
throw new GradleException(
"Expecting project property [${propName}] or env var [ORG_GRADLE_PROJECT_${propName}] to be set.")
Expand All @@ -45,7 +45,7 @@ ext.ensurePropertyIsSet = { propName ->

//if the project has a value for the passed property (i.e from the cmd line via -PpropName=xxx)
//use that, else use a default value
ext.getPropertyOrDefault = { propName, defaultValue ->
ext.getPropertyOrDefault = { propName, defaultValue ->
def val;
if (isPropertySet(propName)) {
val = project.getProperty(propName)
Expand All @@ -67,15 +67,15 @@ ext.getMajorVersion = { versionStr ->

// Set this to the desired release version of the event-logging XML schema on github
// *****************************************************************************
def eventLoggingSchemaVer = "v4.0.0"
def eventLoggingSchemaVer = "v4.1.0"
// *****************************************************************************

// Set this to the last release of this repo on this branch, or earlier branches
// It is used to diff the current jaxb code against the last release so you can
// see if/how the java model has changed following schema changes or changes
// to the jaxb code generation.
// *****************************************************************************
ext.previousReleaseVersion = "v5.0-beta.32_schema-v4.0-beta.10"
ext.previousReleaseVersion = "v5.0.3_schema-v4.0.0"
// *****************************************************************************


Expand Down Expand Up @@ -165,24 +165,20 @@ ext.versions = [
]

// NOTE
// Using beta versions of jaxb libs as they resolve the split pkg problem between jaxb-core and jaxb-runtime
// for running on j9+
// >= v2.3.2 of the jaxb bom pull in the jakarta.xml.bind deps where as the v2.4.0-b one & <v2.3.2 use the old
// javax.xml.bind one.
// XJC code gen is still being done using JAXB 2, but we find/replace javax.xml => jakarta.xml
// so the published -api module can have JAXB 4 deps. Thus there is a mix of JAXB 2/4 deps
// below. Once jaxb-rich-contract-plugin is fixed so we can use its v4.2.0.0+ we can switch
// to all JAXB 4 deps (see https://github.com/mklemm/jaxb-rich-contract-plugin/issues/78)

ext.libs = [
assertj_core : "org.assertj:assertj-core:3.20.2",
classgraph : "io.github.classgraph:classgraph:4.8.146",
jackson_annotations : "com.fasterxml.jackson.core:jackson-annotations:2.13.3",
jackson_databind : "com.fasterxml.jackson.core:jackson-databind:2.13.3",
jakarta_servlet_api : "jakarta.servlet:jakarta.servlet-api:4.0.4",
jakarta_ws_rs_api : "jakarta.ws.rs:jakarta.ws.rs-api:2.1.6",
jaxb_api : "javax.xml.bind:jaxb-api", // Version set by jaxb_bom
jaxb_api : "jakarta.xml.bind:jakarta.xml.bind-api:4.0.2",
jaxb_basics : "org.jvnet.jaxb2_commons:jaxb2-basics:0.12.0",
jaxb_rich_contract_plugin : "net.codesup.util:jaxb2-rich-contract-plugin:2.1.0",
jaxb_runtime : "org.glassfish.jaxb:jaxb-runtime", // Version set by jaxb_bom
jaxb_runtime_2 : "org.glassfish.jaxb:jaxb-runtime", // Version set by jaxb_bom
jaxb_impl : "com.sun.xml.bind:jaxb-impl:4.0.4",
jaxb_xjc : "org.glassfish.jaxb:jaxb-xjc", // Version set by jaxb_bom
jaxb_bom : "org.glassfish.jaxb:jaxb-bom:2.4.0-b180830.0438",
jaxb_bom_2 : "org.glassfish.jaxb:jaxb-bom:2.4.0-b180830.0438",
junit_bom : "org.junit:junit-bom:5.10.0",
junit_jupiter_api : "org.junit.jupiter:junit-jupiter-api", // ver controlled by junit_bom
junit_jupiter_engine : "org.junit.jupiter:junit-jupiter-engine", // ver controlled by junit_bom
Expand All @@ -193,12 +189,11 @@ ext.libs = [
mockito_core : "org.mockito:mockito-core:$versions.mockito",
mockito_junit_jupiter : "org.mockito:mockito-junit-jupiter:$versions.mockito",
saxon_he : "net.sf.saxon:Saxon-HE:9.7.0-21",
slf4j_api : "org.slf4j:slf4j-api:1.7.30",
swagger_annotations : "io.swagger.core.v3:swagger-annotations:$versions.swagger",
slf4j_api : "org.slf4j:slf4j-api:1.7.36",
]

// NOTE
//
//

allprojects {
group "uk.gov.gchq.eventlogging" // no spaces as java pkg name convention
Expand All @@ -217,13 +212,13 @@ subprojects {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
languageVersion = JavaLanguageVersion.of(11)
vendor = JvmVendorSpec.ADOPTIUM
}
}

dependencies {
implementation platform(libs.jaxb_bom)
implementation platform(libs.jaxb_bom_2)
}

//configurations {
Expand Down Expand Up @@ -251,9 +246,9 @@ subprojects {

// This means the reports from our integration tests won't over-write the reports from our unit tests.
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
reports.html.outputLocation = file("${reporting.baseDir}/${name}")

//Use full logging for test exceptions so we can see where the failure occurred
//Use full logging for test exceptions so we can see where the failure occurred
testLogging {
events "failed"
exceptionFormat = 'full'
Expand Down
22 changes: 9 additions & 13 deletions event-logging-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@ apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'io.swagger.core.v3.swagger-gradle-plugin'

ext.moduleName = 'event.logging.api'
ext.moduleName = 'uk.gov.gchq.eventlogging'

def schemaDir = project.file('schema')

// We want a jar like event-logging-5.0-beta.16_schema-v4.0-beta.3.jar,
// not event-logging-api-5.0-beta.16_schema-v4.0-beta.3.jar
archivesBaseName = "event-logging"
base.archivesName = "event-logging"

dependencies {
implementation libs.jackson_annotations
implementation libs.jackson_databind
compileOnly libs.jakarta_servlet_api
implementation libs.jakarta_ws_rs_api
implementation libs.jaxb_api
implementation libs.swagger_annotations
// The JAXB implementation required for event serialisation to XML
runtimeOnly libs.jaxb_impl

// The production code uses the SLF4J logging API at compile time
implementation libs.slf4j_api

// The JAXB implementation required for event serialisation to XML
runtimeOnly libs.jaxb_runtime

testImplementation libs.classgraph
testImplementation(platform(libs.junit_bom))
testImplementation libs.junit_jupiter_api
testImplementation libs.junit_jupiter_params
Expand Down Expand Up @@ -68,6 +61,8 @@ jar {
)
}
version versions.eventLogging
// We want a jar like event-logging-5.0-beta.16_schema-v4.0-beta.3.jar,
// not event-logging-api-5.0-beta.16_schema-v4.0-beta.3.jar
}

javadoc {
Expand Down Expand Up @@ -195,12 +190,13 @@ tasks.build.dependsOn diffAgainstLatest
task runExampleAppBuild(type: GradleBuild) {
dependsOn publishToMavenLocal

buildFile = '../example-logged-application/build.gradle'
// Defaults to build.gradle
dir = '../example-logged-application'
tasks = ['clean', 'build']
startParameter.projectProperties = [mavenVersion: projectVersionForMaven]

doFirst {
println "Running separate example application build [$buildFile]"
println "Running separate example application build [$dir]"
}
}

Expand Down
26 changes: 0 additions & 26 deletions event-logging-api/openapi.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions event-logging-api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module uk.gov.gchq.eventlogging {

exports event.logging;
exports event.logging.impl;
exports event.logging.jaxb;
exports event.logging.jaxb.fluent;
exports event.logging.util;

requires transitive jakarta.xml.bind;
requires java.xml;
requires org.slf4j;

opens event.logging to jakarta.xml.bind;
}
7 changes: 1 addition & 6 deletions event-logging-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ dependencies {
implementation project(':event-logging-api')

// The production code uses the SLF4J logging API at compile time
implementation libs.jackson_annotations
implementation libs.jackson_databind
compileOnly libs.jakarta_servlet_api
implementation libs.jakarta_ws_rs_api
implementation libs.jaxb_api
implementation libs.slf4j_api
implementation libs.swagger_annotations
runtimeOnly libs.jaxb_impl

testImplementation libs.classgraph
testImplementation(platform(libs.junit_bom))
testImplementation libs.junit_jupiter_api
testImplementation libs.junit_jupiter_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import event.logging.EventTime;
import event.logging.Purpose;

import java.util.Date;
import java.time.Instant;
import java.util.function.Supplier;

/**
Expand All @@ -34,7 +34,7 @@ public interface EventLoggingService {
* implementation being used. If this method is not implemented it will return an empty event by default.
*
* Using {@link EventLoggingService#createEvent(String, String, EventAction)} should be preferred.
*
*
* @return An event that is ready to have additional properties set.
*/

Expand Down Expand Up @@ -77,7 +77,7 @@ default Event createEvent(final String typeId,
final EventAction eventAction) {
return Event.builder()
.withEventTime(EventTime.builder()
.withTimeCreated(new Date())
.withTimeCreated(Instant.now())
.build())
.withEventDetail(EventDetail.builder()
.withTypeId(typeId)
Expand All @@ -90,7 +90,7 @@ default Event createEvent(final String typeId,

/**
* Logs an event.
*
*
* @param event The event to log.
*/
void log(Event event);
Expand Down Expand Up @@ -139,17 +139,17 @@ default void log(final String typeId,
* Set to true if the event logging service should validate the output XML against the schema. This option helps
* identify areas of code that are producing invalid data. For performance reasons it is recommended that
* validation is not performed in production.
*
*
* If validate is set to null then the system property shall be used to determine if validation is performed.
*
*
* @param validate
* The validation flag.
*/
void setValidate(Boolean validate);

/**
* Use to determine if the event logging service is set to validate output data against the XML schema.
*
*
* @return True if the validate flag is set.
*/
boolean isValidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public DefaultEventLoggingService(ErrorHandler schemaValidationErrorHandler,
public void log(final Event event) {
final String data = eventSerializer.serialize(event);
final String trimmed = data.trim();
if (trimmed.length() > 0) {
if (!trimmed.isEmpty()) {
// Validate data here if the configuration option is set.
if (checkValidating()) {
xmlValidator.validate(trimmed);
Expand All @@ -109,7 +109,7 @@ private boolean checkValidating() {

// If we aren't setting validate on .
final String val = System.getProperty(VALIDATE);
return Boolean.valueOf(val);
return Boolean.parseBoolean(val);
}

/**
Expand Down
Loading

0 comments on commit eaec5f2

Please sign in to comment.