Skip to content

Commit

Permalink
Use jakarta (#25)
Browse files Browse the repository at this point in the history
- Uses an xjc gradle plugin that has been updated recently (previous is
basically dead)
- Does as much as possible in groovy, rather than via the plugin, which
hopefully means we can drop-in replacement since no special
functionality is required
- jakarta is now used

---------

Co-authored-by: Lars-Olav Vågene <42863501+LarsV123@users.noreply.github.com>
  • Loading branch information
brinxmat and LarsV123 authored Dec 5, 2024
1 parent c8c45af commit e2d7046
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 83 deletions.
38 changes: 0 additions & 38 deletions .github/gradle.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build

on:
push:
branches: [main]
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
uses: BIBSYSDEV/nva-github-workflows/.github/workflows/java.yml@v1
with:
lint_openapi: false
lint_cloudformation: false
secrets:
codacy_token: ${{ secrets.CODACY_PROJECT_TOKEN }}
44 changes: 34 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
plugins {
id 'nebula.lint' version '18.1.0'
id 'nebula.lint' version '20.3.0'
id 'jacoco-report-aggregation'
}

dependencies {
subprojects.forEach {
jacocoAggregation it
}
}

allprojects {
Expand All @@ -14,23 +21,27 @@ allprojects {
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'nebula.lint'
apply plugin: 'jacoco-report-aggregation'

group 'no.unit.nva'
version '0.5.8'
version '0.5.9'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}


gradleLint.rules = ['unused-dependency']

def junit5Version = '5.9.3'
def junit5Version = '5.11.3'

dependencies {
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '4.0.2'
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '3.0'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit5Version
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit5Version
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit5Version
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.11.3'
}

test {
Expand All @@ -52,9 +63,10 @@ allprojects {
ruleSetConfig = rootProject.resources.text.fromFile('config/pmd/ruleset.xml')
ruleSets = []
ignoreFailures = false
toolVersion = "7.8.0"
}

tasks.withType(Pmd) {
tasks.withType(Pmd).configureEach {
exclude '**/org/datacite/schema/**'
}

Expand All @@ -63,11 +75,11 @@ allprojects {
showViolations = true
}

tasks.withType(Checkstyle) {
tasks.withType(Checkstyle).configureEach {
exclude '**/org/datacite/schema/**'
}

tasks.withType(Checkstyle) {
tasks.withType(Checkstyle).configureEach {
reports {
xml.required = false
html.required = true
Expand Down Expand Up @@ -100,6 +112,18 @@ allprojects {
}
}

tasks.named('check') {
dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
}

reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
testType = TestSuiteType.UNIT_TEST
}
}
}

java {
withSourcesJar()
}
Expand Down
6 changes: 1 addition & 5 deletions config/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<exclude-pattern>.*/datacite-data/.*</exclude-pattern>

<rule ref="category/java/errorprone.xml">
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="MissingSerialVersionUID"/>
<exclude name="BeanMembersShouldSerialize"/>
</rule>

<rule ref="category/java/multithreading.xml"/>
Expand All @@ -38,9 +36,7 @@
<exclude name="TooManyStaticImports"/>
<exclude name="ClassNamingConventions"/>
<exclude name="UnnecessaryConstructor"/>

<!--<exclude name="BeanMembersShouldSerialize"/>-->

<exclude name="UseExplicitTypes"/>
<exclude name="ConfusingTernary"/>

<!-- printStackTrace is used in the Default Amazon handler in a static clause
Expand Down
77 changes: 58 additions & 19 deletions datacite-transform/build.gradle
Original file line number Diff line number Diff line change
@@ -1,41 +1,80 @@
import java.nio.file.Files
import java.nio.file.Paths

plugins {
id 'java'
id "org.unbroken-dome.xjc" version "2.0.0"
id("com.github.bjornvester.xjc") version "1.8.1"
id "de.undercouch.download" version "5.6.0"
}

group 'no.unit.nva'

dependencies {
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '2.3.2'
runtimeOnly group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '4.0.2'
runtimeOnly group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '4.0.5'
}

def schemaDir = "${buildDir}/tmp/schema/"
ext.SCHEMA_VERSION = '4.5'
ext.SCHEMA_DIR = file(layout.buildDirectory.asFile.get().toURI().toString() + '/tmp/schema')
ext.METADATA_XSD = 'metadata.xsd'
ext.DID_DOWNLOAD = new HashMap<String, Boolean>()

tasks.register('fetchSchema') {
doLast {
getUris().forEach {
downloadFile(it.toString())
}
if (DID_DOWNLOAD.any { it.value == false }) {
System.out.println("WARN: Some XSD files were cached from a previous run, to avoid this, run ./gradlew clean")
}
}
}

task fetchSchema() {
def schemaVersion = '4.4'
private List<String> getUris() {

mkdir(schemaDir)
def source = downloadFile(METADATA_XSD)

def urlFile = "datacite.url"
def xml = new groovy.xml.XmlSlurper().parseText(source.getText())

if (!file(schemaDir + urlFile).exists()) {
Files.createFile(Paths.get(schemaDir + urlFile))
.text = "https://schema.datacite.org/meta/kernel-${schemaVersion}/metadata.xsd"
return xml.'**'.findAll {
it.name() == 'include' || it.name() == 'import'
}.collect {
it.@'schemaLocation'
}
}

private File downloadFile(String path) {
def uri = "https://schema.datacite.org/meta/kernel-${SCHEMA_VERSION}/${path}"
def file = file(SCHEMA_DIR.toURI().toString() + '/' + path)

if (!file.exists()) {
def destination = path.contains("/") ? file.parentFile : SCHEMA_DIR
destination.mkdirs()
download.run {
src uri
dest destination
}
DID_DOWNLOAD.put(path, true)
} else {
DID_DOWNLOAD.put(path, false)
}
return file;
}

jar {
from "$buildDir/classes/java/main"
from "${layout.buildDirectory}/classes/java/main"
}

tasks.named('sourcesJar') {
dependsOn('xjc')
}

System.setProperty('javax.xml.accessExternalSchema', 'all')

xjc {
srcDirName = schemaDir
xsdDir.set(layout.projectDirectory.dir(SCHEMA_DIR.toURI().toString()))
}

tasks.named('xjc') {
dependsOn('fetchSchema')
}

build.dependsOn("fetchSchema")
tasks.named('compileJava') {
dependsOn('xjc')
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package no.unit.nva.transformer;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import java.io.StringWriter;
import java.util.List;
import java.util.stream.Collectors;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import no.unit.nva.transformer.dto.AlternateIdentifierDto;
import no.unit.nva.transformer.dto.CreatorDto;
import no.unit.nva.transformer.dto.DataCiteMetadataDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.unit.nva.transformer.dto;

import static java.util.Objects.isNull;
import jakarta.xml.bind.JAXBException;
import java.util.List;
import javax.xml.bind.JAXBException;
import no.unit.nva.transformer.Transformer;

public final class DataCiteMetadataDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum IdentifierType {
}

public static IdentifierType fromValue(String v) {
for (IdentifierType c : IdentifierType.values()) {
for (IdentifierType c : values()) {
if (c.getValue().equalsIgnoreCase(v)) {
return c;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.unit.nva.transformer;

import jakarta.xml.bind.JAXBException;
import no.unit.nva.transformer.dto.AlternateIdentifierDto;
import no.unit.nva.transformer.dto.CreatorDto;
import no.unit.nva.transformer.dto.DataCiteMetadataDto;
Expand All @@ -10,7 +11,6 @@
import no.unit.nva.transformer.dto.TitleDto;
import org.junit.jupiter.api.Test;

import javax.xml.bind.JAXBException;
import java.util.List;

import static java.util.Objects.nonNull;
Expand Down Expand Up @@ -132,8 +132,8 @@ private DataCiteMetadataDto generateRecord(String doi,
}

private List<AlternateIdentifierDto> getAlternateIdentifiers(String resourceIdentifier) {
return nonNull(resourceIdentifier) ?
List.of(new AlternateIdentifierDto.Builder().withValue(resourceIdentifier).build())
return nonNull(resourceIdentifier)
? List.of(new AlternateIdentifierDto.Builder().withValue(resourceIdentifier).build())
: List.of();
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jdk:
- openjdk11
- openjdk21
install:
- ./gradlew build
- ./gradlew -Pgroup=com.github.BIBSYSDEV -Pversion=v0.5.8 -xtest assemble publishToMavenLocal
- ./gradlew -Pgroup=com.github.BIBSYSDEV -Pversion=v0.5.9 -xtest assemble publishToMavenLocal

0 comments on commit e2d7046

Please sign in to comment.