Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Groovy 4.0 #1114

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
org.gradle.daemon=true
groovyVersion=3.0.9
groovyVersion=4.0.14
spockVersion=2.3
jettyVersion = 9.4.44.v20210927
prometheusVersion = 0.15.0
log4jVersion = 2.17.0
resilience4jVersion = 1.7.1
httpComponentsCoreVersion = 4.4.14
httpComponentsClientVersion = 4.5.13
systemProp.https.protocols=TLSv1.1,TLSv1.2
spockVersion=2.1-groovy-3.0
guavaVersion=31.1-jre
jacocoVersion=0.8.8
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
8 changes: 3 additions & 5 deletions gretty.plugin
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// SOURCE: https://raw.githubusercontent.com/gretty-gradle-plugin/gretty/master/pluginScripts/gretty-3.0.3.plugin
// SOURCE: https://raw.githubusercontent.com/gretty-gradle-plugin/gretty/master/pluginScripts/gretty-4.1.0.plugin

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'org.gretty:gretty:3.0.6'
classpath 'org.gretty:gretty:4.1.0'
}
}

repositories {
mavenCentral()
}

if (!project.plugins.findPlugin(org.akhikhl.gretty.GrettyPlugin)) {
if (!project.plugins.findPlugin(org.akhikhl.gretty.GrettyPlugin))
project.apply(plugin: org.akhikhl.gretty.GrettyPlugin)
project.gretty.servletContainer = 'jetty9.4'
}
8 changes: 4 additions & 4 deletions importers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies {

// Common tools
providedCompile 'javax.servlet:servlet-api:2.5'
implementation "org.codehaus.groovy:groovy-all:${groovyVersion}"
implementation "org.apache.groovy:groovy-all:${groovyVersion}"
implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'

// Integration
Expand All @@ -83,9 +83,9 @@ dependencies {
// profiling and test
testImplementation "org.spockframework:spock-core:${spockVersion}"
testImplementation 'cglib:cglib-nodep:3.1'
implementation "org.codehaus.groovy:groovy-json:${groovyVersion}"
implementation "org.codehaus.groovy:groovy-sql:${groovyVersion}"
implementation "org.codehaus.groovy:groovy:${groovyVersion}"
implementation "org.apache.groovy:groovy-json:${groovyVersion}"
implementation "org.apache.groovy:groovy-sql:${groovyVersion}"
implementation "org.apache.groovy:groovy:${groovyVersion}"
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'org.slf4j:slf4j-simple:1.7.32'
}
Expand Down
3 changes: 2 additions & 1 deletion librisxl-tools/examples/ExerciseOaipmh.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import groovy.xml.XmlSlurper
import groovy.xml.StreamingMarkupBuilder
import groovy.util.slurpersupport.GPathResult
import groovy.xml.slurpersupport.GPathResult

class ExerciseOaipmh {

Expand Down
2 changes: 1 addition & 1 deletion marc_export/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
}
implementation group: 'xml-apis', name: 'xml-apis', version: '1.4.01'
implementation 'org.apache.commons:commons-lang3:3.3.2'
implementation "org.codehaus.groovy:groovy:${groovyVersion}"
implementation "org.apache.groovy:groovy:${groovyVersion}"
}

gretty {
Expand Down
10 changes: 5 additions & 5 deletions rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ dependencies {
implementation(project(':whelk-core'))

// Common tools
implementation "org.codehaus.groovy:groovy-all:${groovyVersion}"
implementation "org.codehaus.groovy:groovy-dateutil:${groovyVersion}"
implementation "org.apache.groovy:groovy-all:${groovyVersion}"
implementation "org.apache.groovy:groovy-dateutil:${groovyVersion}"
implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
implementation 'commons-io:commons-io:2.11.0'
implementation "com.google.guava:guava:${guavaVersion}"
Expand Down Expand Up @@ -101,10 +101,10 @@ dependencies {
// Standalone
executableWarDeps "org.eclipse.jetty:jetty-server:${jettyVersion}"
executableWarDeps "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
executableWarDeps "org.codehaus.groovy:groovy-all:${groovyVersion}"
executableWarDeps "org.apache.groovy:groovy-all:${groovyVersion}"
executableWarDeps 'commons-cli:commons-cli:1.2'
implementation "org.codehaus.groovy:groovy-xml:${groovyVersion}"
implementation "org.codehaus.groovy:groovy:${groovyVersion}"
implementation "org.apache.groovy:groovy-xml:${groovyVersion}"
implementation "org.apache.groovy:groovy:${groovyVersion}"
implementation 'org.codehaus.jackson:jackson-core-asl:1.9.13'
implementation 'xml-apis:xml-apis:1.4.01'
}
Expand Down
8 changes: 4 additions & 4 deletions rest/src/main/groovy/whelk/rest/api/Crud.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import whelk.exception.UnexpectedHttpStatusException
import whelk.exception.WhelkRuntimeException
import whelk.history.History
import whelk.rest.api.CrudGetRequest.Lens
import whelk.rest.api.HttpTools
import whelk.rest.security.AccessControl
import whelk.util.WhelkFactory

Expand All @@ -32,7 +33,6 @@ import java.lang.management.ManagementFactory

import static whelk.rest.api.CrudUtils.ETag
import static whelk.rest.api.HttpTools.getBaseUri
import static whelk.rest.api.HttpTools.sendError
import static whelk.rest.api.HttpTools.sendResponse
import static whelk.util.Jackson.mapper

Expand Down Expand Up @@ -225,12 +225,12 @@ class Crud extends HttpServlet {
setVary(response)
response.setHeader("ETag", eTag.toString())
response.setHeader("Server-Start-Time", "" + ManagementFactory.getRuntimeMXBean().getStartTime())
sendError(response, HttpServletResponse.SC_NOT_MODIFIED, "Document has not been modified.")
HttpTools.sendError(response, HttpServletResponse.SC_NOT_MODIFIED, "Document has not been modified.")
}

private static void sendNotFound(HttpServletRequest request, HttpServletResponse response) {
metrics.failedRequests.labels(request.getMethod(), HttpServletResponse.SC_NOT_FOUND.toString()).inc()
sendError(response, HttpServletResponse.SC_NOT_FOUND, "Document not found.")
HttpTools.sendError(response, HttpServletResponse.SC_NOT_FOUND, "Document not found.")
}

private Object getFormattedResponseBody(CrudGetRequest request, Document doc, String profileId) {
Expand Down Expand Up @@ -843,7 +843,7 @@ class Crud extends HttpServlet {
if (log.isDebugEnabled()) {
log.debug("Sending error $code : ${e.getMessage()} for ${request.getRequestURI()}")
}
sendError(response, code, e.getMessage(), e)
HttpTools.sendError(response, code, e.getMessage(), e)
}

static private int mapError(Exception e) {
Expand Down
3 changes: 2 additions & 1 deletion rest/src/main/groovy/whelk/rest/api/RemoteSearchAPI.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package whelk.rest.api

import groovy.util.logging.Log4j2 as Log
import groovy.util.slurpersupport.GPathResult
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult
import groovy.xml.StreamingMarkupBuilder
import se.kb.libris.util.marc.Field
import se.kb.libris.util.marc.MarcRecord
Expand Down
10 changes: 5 additions & 5 deletions whelk-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ dependencies {
implementation "io.github.resilience4j:resilience4j-circuitbreaker:${resilience4jVersion}"
implementation "io.github.resilience4j:resilience4j-prometheus:${resilience4jVersion}"
implementation "io.github.resilience4j:resilience4j-retry:${resilience4jVersion}"
implementation "org.codehaus.groovy:groovy-all:${groovyVersion}"
implementation "org.apache.groovy:groovy-all:${groovyVersion}"
implementation 'com.damnhandy:handy-uri-templates:2.0.4'
implementation 'com.zaxxer:HikariCP:4.0.3'
implementation 'commons-codec:commons-codec:1.7'
Expand All @@ -96,10 +96,10 @@ dependencies {
implementation "org.apache.httpcomponents:httpclient:${httpComponentsClientVersion}"
implementation "org.apache.httpcomponents:httpcore:${httpComponentsCoreVersion}"
api 'org.apache.jena:apache-jena-libs:3.0.1'
api "org.codehaus.groovy:groovy-json:${groovyVersion}"
api "org.codehaus.groovy:groovy-xml:${groovyVersion}"
api "org.codehaus.groovy:groovy-yaml:${groovyVersion}"
api "org.codehaus.groovy:groovy:${groovyVersion}"
api "org.apache.groovy:groovy-json:${groovyVersion}"
api "org.apache.groovy:groovy-xml:${groovyVersion}"
api "org.apache.groovy:groovy-yaml:${groovyVersion}"
api "org.apache.groovy:groovy:${groovyVersion}"
api 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
implementation 'xerces:xercesImpl:2.11.0' //KP

Expand Down
18 changes: 6 additions & 12 deletions whelk-core/src/main/groovy/se/kb/libris/Normalizers.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@ import whelk.component.DocumentNormalizer
import whelk.exception.InvalidQueryException
import whelk.filter.BlankNodeLinker
import whelk.filter.LanguageLinker
import whelk.util.DocumentUtil
import whelk.util.DocumentUtil.Remove
import whelk.util.Romanizer

import static whelk.JsonLd.GRAPH_KEY
import static whelk.JsonLd.ID_KEY
import static whelk.JsonLd.TYPE_KEY
import static whelk.JsonLd.asList
import static whelk.util.DocumentUtil.traverse

/*
TODO: add support for linking blank nodes based on owl:hasKey
example:
Expand Down Expand Up @@ -99,12 +92,13 @@ class Normalizers {

return new Normalizer({ Document doc ->
def (_record, thing) = doc.data[GRAPH_KEY]

thing.identifiedBy?.with {
asList(it).forEach { Map id ->
id.typeNote?.with { String tn ->
OBSOLETE_TYPE_NOTES[tn.toLowerCase()]
}?.with { type ->
id[TYPE_KEY] = type
id[JsonLd.TYPE_KEY] = type
id.remove('typeNote')
}
}
Expand All @@ -124,13 +118,13 @@ class Normalizers {
static DocumentNormalizer workPosition(JsonLd jsonLd) {
return new Normalizer({ Document doc ->
def (_record, thing, legacyWork) = doc.data[GRAPH_KEY]

boolean shouldMove = (legacyWork && isInstanceOf(jsonLd, legacyWork, 'Work')
&& thing && thing['instanceOf'] && thing['instanceOf'][ID_KEY]
&& thing['instanceOf'][ID_KEY] == legacyWork[ID_KEY])
&& thing && thing['instanceOf'] && thing['instanceOf'][JsonLd.ID_KEY]
&& thing['instanceOf'][JsonLd.ID_KEY] == legacyWork[JsonLd.ID_KEY])

if (shouldMove) {
def work = doc.data[GRAPH_KEY].remove(2)
def work = doc.data[JsonLd.GRAPH_KEY].remove(2)
work.remove(ID_KEY)
thing['instanceOf'] = work
}
Expand Down
32 changes: 18 additions & 14 deletions whelk-core/src/main/groovy/whelk/JsonLd.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ class JsonLd {
}

static List<List<String>> findPaths(Map obj, String key, Set<String> values) {
List paths = []
List<List<String>> paths = []
new DFS().search(obj, { List path, v ->
if (v in values && key == path[-1]) {
paths << new ArrayList(path)
Expand Down Expand Up @@ -728,7 +728,7 @@ class JsonLd {
if (type == null)
return

List subTerms = (List) (superTermOf[type])
List<String> subTerms = (List<String>) (superTermOf[type])
if (subTerms == null)
return

Expand All @@ -747,7 +747,7 @@ class JsonLd {
return jsonLd
}

List graphItems = jsonLd.get(GRAPH_KEY)
List graphItems = (List) jsonLd.get(GRAPH_KEY)

additionalObjects.each { object ->
if (object instanceof Map) {
Expand Down Expand Up @@ -868,8 +868,8 @@ class JsonLd {
* [<language>, <property value>] pairs.
*/
private List applyLensAsListByLang(Map thing, Set<String> languagesToKeep, List<String> removableBaseUris, String lensToUse) {
Map lensGroups = displayData.get('lensGroups')
Map lensGroup = lensGroups.get(lensToUse)
Map lensGroups = (Map) displayData.get('lensGroups')
Map lensGroup = (Map) lensGroups.get(lensToUse)
Map lens = getLensFor((Map)thing, lensGroup)
List parts = []

Expand Down Expand Up @@ -956,12 +956,13 @@ class JsonLd {
be displayed on the frontend. Mainly for use as search keys.
*/
Map applyLensAsMapByLang(Map thing, Set<String> languagesToKeep, List<String> removableBaseUris, List<String> lensesToTry) {
Map lensGroups = displayData.get('lensGroups')
Map lensGroups = (Map) displayData.get('lensGroups')
Map lens = null
String initialLens
String initialLens = null

for (String lensToTry : lensesToTry) {
Map lensGroup = lensGroups?.get(lensToTry)
Map lensGroup = (Map) lensGroups?.get(lensToTry)

lens = getLensFor((Map)thing, lensGroup)
if (lens) {
initialLens = lensToTry
Expand Down Expand Up @@ -1020,8 +1021,9 @@ class JsonLd {
}

List makeSearchKeyParts(Map object) {
Map lensGroups = displayData.get('lensGroups')
Map lensGroup = lensGroups?.get('chips')
Map lensGroups = (Map) displayData.get('lensGroups')
Map lensGroup = (Map) lensGroups?.get('chips')

Map lens = getLensFor(object, lensGroup)
List parts = []
def type = object.get(TYPE_KEY)
Expand Down Expand Up @@ -1065,9 +1067,10 @@ class JsonLd {
if (data[GRAPH_KEY]) {
return new LinkedHashSet(((List) data[GRAPH_KEY]).collect{ getInverseProperties((Map) it, lensType) }.flatten())
}

Map lensGroups = (Map) displayData.get('lensGroups')
Map lensGroup = (Map)lensGroups?.get(lensType)

Map lensGroups = displayData.get('lensGroups')
Map lensGroup = lensGroups?.get(lensType)
Map lens = getLensFor(data, lensGroup)
return new LinkedHashSet((List) lens?.get('inverseProperties') ?: [])
}
Expand All @@ -1090,10 +1093,11 @@ class JsonLd {
}

private Map getLens(Map thing, List<String> lensTypes) {
Map lensGroups = displayData.get('lensGroups')
Map lensGroups = (Map) displayData.get('lensGroups')
if (lensGroups == null) {
return
}

lensTypes.findResult { lensType ->
lensGroups.get(lensType)?.with { getLensFor(thing, (Map) it) }
}
Expand Down Expand Up @@ -1160,7 +1164,7 @@ class JsonLd {

private Map findLensForType(String typeKey, Map lensGroup) {
def lenses = lensGroup['lenses']
Map lens = ((Map)lenses).get(typeKey)
Map lens = (Map) ((Map)lenses).get(typeKey)
if (lens)
return lens
def typedfn = vocabIndex.get(typeKey)
Expand Down
Loading
Loading