diff --git a/build.gradle b/build.gradle index 99ae975..b13fe4f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,12 @@ + plugins { - id "de.marcphilipp.nexus-publish" version "0.4.0" - id "io.codearte.nexus-staging" version "0.21.1" + id "checkstyle" + id "pmd" + id 'maven-publish' + id 'signing' + id "io.github.gradle-nexus.publish-plugin" version "1.3.0" + id "com.github.spotbugs" version "5.0.14" + id "org.cyclonedx.bom" version "1.7.2" } wrapper { @@ -13,10 +19,10 @@ ext { name = 'oai' description = 'Open Archive Initiative library for Java' inceptionYear = '2016' - url = 'https://github.com/' + user + '/' + name - scmUrl = 'https://github.com/' + user + '/' + name - scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' - scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git' + url = 'https://xbib.org/' + user + '/' + name + scmUrl = 'https://xbib.org/' + user + '/' + name + scmConnection = 'scm:git:git://xbib.org/' + user + '/' + name + '.git' + scmDeveloperConnection = 'scm:git:ssh://forgejo@xbib.org:' + user + '/' + name + '.git' issueManagementSystem = 'Github' issueManagementUrl = ext.scmUrl + '/issues' licenseName = 'The Apache License, Version 2.0' @@ -24,11 +30,14 @@ ext { } subprojects { - apply plugin: 'java-library' apply from: rootProject.file('gradle/ide/idea.gradle') + apply from: rootProject.file('gradle/repositories/maven.gradle') apply from: rootProject.file('gradle/compile/java.gradle') apply from: rootProject.file('gradle/test/junit5.gradle') - apply from: rootProject.file('gradle/publishing/publication.gradle') + apply from: rootProject.file('gradle/publish/maven.gradle') + apply from: rootProject.file('gradle/quality/checkstyle.gradle') + apply from: rootProject.file('gradle/quality/pmd.gradle') + apply from: rootProject.file('gradle/quality/spotbugs.gradle') } - -apply from: rootProject.file('gradle/publishing/sonatype.gradle') +apply from: rootProject.file('gradle/publish/sonatype.gradle') +apply from: rootProject.file('gradle/publish/forgejo.gradle') diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml deleted file mode 100644 index 9b7e458..0000000 --- a/config/checkstyle/suppressions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/gradle/compile/java.gradle b/gradle/compile/java.gradle index 9016125..5f54d0b 100644 --- a/gradle/compile/java.gradle +++ b/gradle/compile/java.gradle @@ -3,6 +3,8 @@ apply plugin: 'java-library' java { modularity.inferModulePath.set(true) + withSourcesJar() + withJavadocJar() } compileJava { @@ -21,18 +23,12 @@ jar { } } -task sourcesJar(type: Jar) { - dependsOn classes - classifier 'sources' - from sourceSets.main.allSource +tasks.withType(JavaCompile) { + options.compilerArgs << '-Xlint:all' + options.encoding = 'UTF-8' } -task javadocJar(type: Jar) { - dependsOn javadoc - classifier 'javadoc' - from javadoc.destinationDir +tasks.withType(Javadoc) { + options.addStringOption('Xdoclint:none', '-quiet') + options.encoding = 'UTF-8' } - -artifacts { - archives sourcesJar, javadocJar -} \ No newline at end of file diff --git a/gradle/publish/forgejo.gradle b/gradle/publish/forgejo.gradle new file mode 100644 index 0000000..18d18c2 --- /dev/null +++ b/gradle/publish/forgejo.gradle @@ -0,0 +1,16 @@ +if (project.hasProperty('forgeJoToken')) { + publishing { + repositories { + maven { + url 'https://xbib.org/api/packages/xbib/maven' + credentials(HttpHeaderCredentials) { + name = "Authorization" + value = "token ${project.property('forgeJoToken')}" + } + authentication { + header(HttpHeaderAuthentication) + } + } + } + } +} diff --git a/gradle/publish/ivy.gradle b/gradle/publish/ivy.gradle new file mode 100644 index 0000000..fe0a848 --- /dev/null +++ b/gradle/publish/ivy.gradle @@ -0,0 +1,27 @@ +apply plugin: 'ivy-publish' + +publishing { + repositories { + ivy { + url = "https://xbib.org/repo" + } + } + publications { + ivy(IvyPublication) { + from components.java + descriptor { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + author { + name = 'Jörg Prante' + url = 'http://example.com/users/jane' + } + descriptor.description { + text = rootProject.ext.description + } + } + } + } +} \ No newline at end of file diff --git a/gradle/publishing/publication.gradle b/gradle/publish/maven.gradle similarity index 78% rename from gradle/publishing/publication.gradle rename to gradle/publish/maven.gradle index c35fcb9..ce6a26f 100644 --- a/gradle/publishing/publication.gradle +++ b/gradle/publish/maven.gradle @@ -1,13 +1,10 @@ -apply plugin: "de.marcphilipp.nexus-publish" - publishing { publications { - mavenJava(MavenPublication) { + "${project.name}"(MavenPublication) { from components.java - artifact sourcesJar - artifact javadocJar pom { + artifactId = project.name name = project.name description = rootProject.ext.description url = rootProject.ext.url @@ -49,16 +46,6 @@ publishing { if (project.hasProperty("signing.keyId")) { apply plugin: 'signing' signing { - sign publishing.publications.mavenJava - } -} - -nexusPublishing { - repositories { - sonatype { - username = project.property('ossrhUsername') - password = project.property('ossrhPassword') - packageGroup = "org.xbib" - } + sign publishing.publications."${project.name}" } } diff --git a/gradle/publish/sonatype.gradle b/gradle/publish/sonatype.gradle new file mode 100644 index 0000000..5d739de --- /dev/null +++ b/gradle/publish/sonatype.gradle @@ -0,0 +1,11 @@ +if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { + nexusPublishing { + repositories { + sonatype { + username = project.property('ossrhUsername') + password = project.property('ossrhPassword') + packageGroup = "org.xbib" + } + } + } +} diff --git a/gradle/publishing/sonatype.gradle b/gradle/publishing/sonatype.gradle deleted file mode 100644 index e1813f3..0000000 --- a/gradle/publishing/sonatype.gradle +++ /dev/null @@ -1,11 +0,0 @@ - -if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { - - apply plugin: 'io.codearte.nexus-staging' - - nexusStaging { - username = project.property('ossrhUsername') - password = project.property('ossrhPassword') - packageGroup = "org.xbib" - } -} diff --git a/gradle/quality/checkstyle.gradle b/gradle/quality/checkstyle.gradle new file mode 100644 index 0000000..85b8bd8 --- /dev/null +++ b/gradle/quality/checkstyle.gradle @@ -0,0 +1,19 @@ + +apply plugin: 'checkstyle' + +tasks.withType(Checkstyle) { + ignoreFailures = true + reports { + xml.getRequired().set(true) + html.getRequired().set(true) + } +} + +checkstyle { + configFile = rootProject.file('gradle/quality/checkstyle.xml') + ignoreFailures = true + showViolations = true + checkstyleMain { + source = sourceSets.main.allSource + } +} diff --git a/config/checkstyle/checkstyle.xml b/gradle/quality/checkstyle.xml similarity index 87% rename from config/checkstyle/checkstyle.xml rename to gradle/quality/checkstyle.xml index 52fe33c..66a9aae 100644 --- a/config/checkstyle/checkstyle.xml +++ b/gradle/quality/checkstyle.xml @@ -9,6 +9,10 @@ page at http://checkstyle.sourceforge.net/config.html --> + + + + @@ -56,10 +60,19 @@ page at http://checkstyle.sourceforge.net/config.html --> - - - - + + + + + + + + + + + + + - + - - - - @@ -184,21 +193,6 @@ page at http://checkstyle.sourceforge.net/config.html --> --> - - - - - - - - - @@ -319,5 +313,21 @@ page at http://checkstyle.sourceforge.net/config.html --> + + + + + + + + + + diff --git a/gradle/quality/cyclonedx.gradle b/gradle/quality/cyclonedx.gradle new file mode 100644 index 0000000..a6bf41b --- /dev/null +++ b/gradle/quality/cyclonedx.gradle @@ -0,0 +1,11 @@ +cyclonedxBom { + includeConfigs = [ 'runtimeClasspath' ] + skipConfigs = [ 'compileClasspath', 'testCompileClasspath' ] + projectType = "library" + schemaVersion = "1.4" + destination = file("build/reports") + outputName = "bom" + outputFormat = "json" + includeBomSerialNumber = true + componentVersion = "2.0.0" +} diff --git a/gradle/quality/pmd.gradle b/gradle/quality/pmd.gradle new file mode 100644 index 0000000..55fcfda --- /dev/null +++ b/gradle/quality/pmd.gradle @@ -0,0 +1,17 @@ + +apply plugin: 'pmd' + +tasks.withType(Pmd) { + ignoreFailures = true + reports { + xml.getRequired().set(true) + html.getRequired().set(true) + } +} + +pmd { + ignoreFailures = true + consoleOutput = false + toolVersion = "6.51.0" + ruleSetFiles = rootProject.files('gradle/quality/pmd/category/java/bestpractices.xml') +} diff --git a/config/pmd/category/java/bestpractices.xml b/gradle/quality/pmd/category/java/bestpractices.xml similarity index 98% rename from config/pmd/category/java/bestpractices.xml rename to gradle/quality/pmd/category/java/bestpractices.xml index 816e8cc..6bf15a0 100644 --- a/config/pmd/category/java/bestpractices.xml +++ b/gradle/quality/pmd/category/java/bestpractices.xml @@ -48,6 +48,7 @@ public abstract class Foo { @@ -535,7 +540,7 @@ public class GoodTest { diff --git a/config/pmd/category/java/categories.properties b/gradle/quality/pmd/category/java/categories.properties similarity index 78% rename from config/pmd/category/java/categories.properties rename to gradle/quality/pmd/category/java/categories.properties index 3189fd3..8ef5eac 100644 --- a/config/pmd/category/java/categories.properties +++ b/gradle/quality/pmd/category/java/categories.properties @@ -1,6 +1,3 @@ -# -# BSD-style license; for more info see http://pmd.sourceforge.net/license.html -# rulesets.filenames=\ category/java/bestpractices.xml,\ diff --git a/config/pmd/category/java/codestyle.xml b/gradle/quality/pmd/category/java/codestyle.xml similarity index 99% rename from config/pmd/category/java/codestyle.xml rename to gradle/quality/pmd/category/java/codestyle.xml index ac2f0a0..186ea4b 100644 --- a/config/pmd/category/java/codestyle.xml +++ b/gradle/quality/pmd/category/java/codestyle.xml @@ -760,7 +760,7 @@ public class HelloWorldBean { diff --git a/config/pmd/category/java/design.xml b/gradle/quality/pmd/category/java/design.xml similarity index 100% rename from config/pmd/category/java/design.xml rename to gradle/quality/pmd/category/java/design.xml diff --git a/config/pmd/category/java/documentation.xml b/gradle/quality/pmd/category/java/documentation.xml similarity index 100% rename from config/pmd/category/java/documentation.xml rename to gradle/quality/pmd/category/java/documentation.xml diff --git a/config/pmd/category/java/errorprone.xml b/gradle/quality/pmd/category/java/errorprone.xml similarity index 99% rename from config/pmd/category/java/errorprone.xml rename to gradle/quality/pmd/category/java/errorprone.xml index cf289c3..5ee4e89 100644 --- a/config/pmd/category/java/errorprone.xml +++ b/gradle/quality/pmd/category/java/errorprone.xml @@ -158,7 +158,7 @@ public class A { message="Avoid using a branching statement as the last in a loop." externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidbranchingstatementaslastinloop"> - Using a branching statement as the last part of a loop may be a bug, and/or is confusing. + Using a branching statement as the last message of a loop may be a bug, and/or is confusing. Ensure that the usage is not a bug, or consider using another approach. 2 @@ -1554,7 +1554,7 @@ public class Foo { diff --git a/config/pmd/category/java/multithreading.xml b/gradle/quality/pmd/category/java/multithreading.xml similarity index 100% rename from config/pmd/category/java/multithreading.xml rename to gradle/quality/pmd/category/java/multithreading.xml diff --git a/config/pmd/category/java/performance.xml b/gradle/quality/pmd/category/java/performance.xml similarity index 100% rename from config/pmd/category/java/performance.xml rename to gradle/quality/pmd/category/java/performance.xml diff --git a/config/pmd/category/java/security.xml b/gradle/quality/pmd/category/java/security.xml similarity index 100% rename from config/pmd/category/java/security.xml rename to gradle/quality/pmd/category/java/security.xml diff --git a/gradle/quality/sonarqube.gradle b/gradle/quality/sonarqube.gradle new file mode 100644 index 0000000..fe66cd0 --- /dev/null +++ b/gradle/quality/sonarqube.gradle @@ -0,0 +1,37 @@ + +subprojects { + + sonarqube { + properties { + property "sonar.projectName", "${project.group} ${project.name}" + property "sonar.sourceEncoding", "UTF-8" + property "sonar.tests", "src/test/java" + property "sonar.scm.provider", "git" + property "sonar.junit.reportsPath", "build/test-results/test/" + } + } + + + tasks.withType(Pmd) { + ignoreFailures = true + reports { + xml.enabled = true + html.enabled = true + } + } + + + spotbugs { + effort = "max" + reportLevel = "low" + //includeFilter = file("findbugs-exclude.xml") + } + + tasks.withType(com.github.spotbugs.SpotBugsTask) { + ignoreFailures = true + reports { + xml.enabled = false + html.enabled = true + } + } +} \ No newline at end of file diff --git a/gradle/quality/spotbugs.gradle b/gradle/quality/spotbugs.gradle new file mode 100644 index 0000000..2e5b0cd --- /dev/null +++ b/gradle/quality/spotbugs.gradle @@ -0,0 +1,15 @@ + +apply plugin: 'com.github.spotbugs' + +spotbugs { + effort = "max" + reportLevel = "low" + ignoreFailures = true +} + +spotbugsMain { + reports { + xml.getRequired().set(false) + html.getRequired().set(true) + } +} diff --git a/gradle/repositories/maven.gradle b/gradle/repositories/maven.gradle new file mode 100644 index 0000000..ec58acb --- /dev/null +++ b/gradle/repositories/maven.gradle @@ -0,0 +1,4 @@ +repositories { + mavenLocal() + mavenCentral() +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..c1962a7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8fad3f5..8707e8b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb..aeb74cb 100755 --- a/gradlew +++ b/gradlew @@ -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/. @@ -80,13 +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##*/} - -# 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"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -143,12 +140,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 @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then done fi + +# 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"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in diff --git a/gradlew.bat b/gradlew.bat index 53a6b23..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -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% diff --git a/oai-client/src/test/java/org/xbib/oai/client/BundeskunsthalleTest.java b/oai-client/src/test/java/org/xbib/oai/client/BundeskunsthalleTest.java index fb2c5f8..fda959a 100644 --- a/oai-client/src/test/java/org/xbib/oai/client/BundeskunsthalleTest.java +++ b/oai-client/src/test/java/org/xbib/oai/client/BundeskunsthalleTest.java @@ -16,12 +16,12 @@ import java.util.EnumSet; import java.util.logging.Level; import java.util.logging.Logger; +@Disabled("takes long time") class BundeskunsthalleTest { private static final Logger logger = Logger.getLogger(BundeskunsthalleTest.class.getName()); @Test - @Disabled("takes long time") void testListRecords() throws Exception { OAIClient oaiClient = new OAIClient("https://www.bundeskunsthalle.de/cgi-bin/bib/oai-pmh"); IdentifyResponse identifyResponse = oaiClient.identify(); @@ -29,8 +29,8 @@ class BundeskunsthalleTest { logger.log(Level.INFO, "granularity = " + granularity); DateTimeFormatter dateTimeFormatter = "YYYY-MM-DD".equals(granularity) ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.of("UTC")) : null; - try (MarcJsonWriter writer = new MarcJsonWriter("build/bk-bulk%d.jsonl", 1000, - EnumSet.of(MarcJsonWriter.Style.ELASTICSEARCH_BULK), 8192, false) + try (MarcJsonWriter writer = new MarcJsonWriter("build/bk-bulk%d.jsonl", 1000, 8192, false) + .setStyle(EnumSet.of(MarcJsonWriter.Style.ELASTICSEARCH_BULK)) .setIndex("bk", "type")) { writer.startDocument(); writer.beginCollection(); diff --git a/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java b/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java index ede402a..51c9541 100644 --- a/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java +++ b/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java @@ -1,21 +1,13 @@ package org.xbib.oai.client; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.xbib.oai.client.identify.IdentifyResponse; -import org.xbib.oai.xml.SimpleMetadataHandler; import java.time.Instant; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Level; -import java.util.logging.Logger; +@Disabled("port is locked") class DNBClientTest { - private static final Logger logger = Logger.getLogger(DNBClientTest.class.getName()); - @Test void testBibdatFileDump() throws Exception { OAIClient oaiClient = new OAIClient("http://services.dnb.de/oai/repository"); @@ -35,39 +27,12 @@ class DNBClientTest { oaiClient.setUserAgent("Hochschulbibliothekszentrum Nordrhein-Westfalen (prante@hbz-nrw.de)"); Instant base = Instant.parse("2010-01-01T00:00:00Z"); - //IdentifyResponse identifyResponse = oaiClient.identify(); - //String granularity = identifyResponse.getGranularity(); - //logger.log(Level.INFO, "granularity = " + granularity); - //DateTimeFormatter dateTimeFormatter = "YYYY-MM-DD".equals(granularity) ? - // DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.of("UTC")) : null; SplitWriter splitWriter = new SplitWriter("build/bibdat-test-%d.xml", -1, 8192, false); oaiClient.setSplitWriter(splitWriter); - // Handler handler = new Handler(); oaiClient.listRecords("PicaPlus-xml", "bib", null, Instant.parse("2016-01-01T00:00:00Z"), Instant.parse("2016-02-01T00:00:00Z"), base, null, null); - //logger.log(Level.INFO, "count=" + handler.count()); - //assertTrue(handler.count() > 0); } - static class Handler extends SimpleMetadataHandler { - - final AtomicLong count = new AtomicLong(0L); - - @Override - public void startDocument() { - logger.log(Level.INFO, "start doc"); - } - - @Override - public void endDocument() { - logger.log(Level.INFO, "end doc"); - count.incrementAndGet(); - } - - long count() { - return count.get(); - } - } } diff --git a/settings.gradle b/settings.gradle index 01a2985..b40cd6d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,9 +1,9 @@ dependencyResolutionManagement { versionCatalogs { libs { - version('gradle', '7.5.1') - version('junit', '5.9.1') - version('content', '5.0.1') + version('gradle', '8.1.1') + version('junit', '5.9.3') + version('content', '5.0.3') library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit') library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit') library('junit-jupiter-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit') @@ -12,8 +12,8 @@ dependencyResolutionManagement { library('content-rdf', 'org.xbib', 'content-rdf').versionRef('content') library('content-resource', 'org.xbib', 'content-resource').versionRef('content') library('content-xml', 'org.xbib', 'content-xml').versionRef('content') - library('marc', 'org.xbib', 'marc').version('2.7.1') - library('charactersets', 'org.xbib', 'bibliographic-character-sets').version('2.0.0') + library('marc', 'org.xbib', 'marc').version('2.11.0') + library('charactersets', 'org.xbib', 'bibliographic-character-sets').version('3.0.0') } } }