From 41a86fd37b4def384083138a8c5819d3c30c1649 Mon Sep 17 00:00:00 2001 From: Anders Jensen-Urstad Date: Thu, 9 Jul 2026 14:34:51 +0200 Subject: [PATCH] chore: upgrade from Groovy 4 to 5 --- gradle.properties | 4 ++-- .../whelk/housekeeping/NotificationSender.groovy | 6 +++--- .../groovy/whelk/importer/DatasetImporter.groovy | 2 +- whelk-core/src/main/groovy/whelk/JsonLd.groovy | 6 +++--- .../groovy/whelk/component/DependencyCache.groovy | 6 +++--- .../groovy/whelk/component/ElasticSearch.groovy | 6 +++--- .../src/main/groovy/whelk/search/ESQuery.groovy | 2 +- .../main/groovy/whelk/search/ElasticFind.groovy | 2 +- .../src/main/groovy/whelk/util/Romanizer.groovy | 14 +++++++------- .../whelk/search2/querytree/QueryTreeSpec.groovy | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6b8cbc9480..e832d3be53 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.daemon=true -groovyVersion=4.0.27 -spockVersion=2.3-groovy-4.0 +groovyVersion=5.0.7 +spockVersion=2.4-groovy-5.0 byteBuddyVersion = 1.17.6 codeNarcVersion=3.6.0-groovy-4.0 servletApiVersion = 4.0.3 diff --git a/housekeeping/src/main/groovy/whelk/housekeeping/NotificationSender.groovy b/housekeeping/src/main/groovy/whelk/housekeeping/NotificationSender.groovy index 97b8e70c03..a042f19f03 100644 --- a/housekeeping/src/main/groovy/whelk/housekeeping/NotificationSender.groovy +++ b/housekeeping/src/main/groovy/whelk/housekeeping/NotificationSender.groovy @@ -191,9 +191,9 @@ class NotificationSender extends HouseKeeper { private Map matches(String trigger, List changeObservationsForInstance) { for (Object obj : changeObservationsForInstance) { Map changeObservationMap = mapper.readValue( (String) obj, Map ) - List graphList = changeObservationMap["@graph"] - Map mainEntity = graphList?[1] - String category = mainEntity?.category["@id"] + List graphList = (List) changeObservationMap["@graph"] + Map mainEntity = (Map) graphList?[1] + String category = (String) mainEntity?.category["@id"] if (category && category == trigger) return changeObservationMap } diff --git a/importers/src/main/groovy/whelk/importer/DatasetImporter.groovy b/importers/src/main/groovy/whelk/importer/DatasetImporter.groovy index 872b964dd8..b56655e347 100644 --- a/importers/src/main/groovy/whelk/importer/DatasetImporter.groovy +++ b/importers/src/main/groovy/whelk/importer/DatasetImporter.groovy @@ -94,7 +94,7 @@ class DatasetImporter { continue } if (item[TYPE] == 'Dataset' && 'sourceData' in item) { - Map sourceRef = item['sourceData'] + Map sourceRef = (Map) item['sourceData'] String sourceUrl = null if (ID in sourceRef) { diff --git a/whelk-core/src/main/groovy/whelk/JsonLd.groovy b/whelk-core/src/main/groovy/whelk/JsonLd.groovy index 0358f80af1..9b917553fe 100644 --- a/whelk-core/src/main/groovy/whelk/JsonLd.groovy +++ b/whelk-core/src/main/groovy/whelk/JsonLd.groovy @@ -187,7 +187,7 @@ class JsonLd { static String getDisplayUri(String vocabUri, Map vocabData) { for (Map node : (List) vocabData[GRAPH_KEY]) { if (node[ID_KEY] == vocabUri) { - Map displayRef = node[DISPLAY_KEY] + Map displayRef = (Map) node[DISPLAY_KEY] if (displayRef) { return displayRef[ID_KEY] } @@ -620,7 +620,7 @@ class JsonLd { else if (graphIndex > 1) { p.add(0, graphIndex) // Normally there should only be @graph,0 and @graph,1 } - result.add(new Link(relation: p.join('.'), iri: value[ID_KEY])) + result.add(new Link(relation: p.join('.'), iri: (String) value[ID_KEY])) } return DocumentUtil.NOP } @@ -1394,7 +1394,7 @@ class JsonLd { static void putRecordReferencesIntoThings(Map idMap) { for (obj in idMap.values()) { - Map thingRef = obj[THING_KEY] + Map thingRef = (Map) obj[THING_KEY] if (thingRef) { String thingId = thingRef[ID_KEY] Map thing = idMap[thingId] diff --git a/whelk-core/src/main/groovy/whelk/component/DependencyCache.groovy b/whelk-core/src/main/groovy/whelk/component/DependencyCache.groovy index 83fcd05c8a..738ae0fdc3 100644 --- a/whelk-core/src/main/groovy/whelk/component/DependencyCache.groovy +++ b/whelk-core/src/main/groovy/whelk/component/DependencyCache.groovy @@ -125,17 +125,17 @@ class DependencyCache { log.info("dependenciesCache: ${dependenciesCache.stats()}") } - private CacheLoader> loader(BiFunction func) { + private CacheLoader> loader(BiFunction> func) { return new CacheLoader>() { @Override Set load(Link link) { try { - def iris = func.apply(storage.getSystemIdByThingId(link.iri), link.relation) + Collection iris = func.apply(storage.getSystemIdByThingId(link.iri), link.relation) .findResults (this.&tryGetThingMainIriBySystemId) return iris.isEmpty() ? Collections.EMPTY_SET - : Collections.unmodifiableSet(new HashSet(iris)) + : Collections.unmodifiableSet(new HashSet(iris)) } catch (MissingMainIriException e) { log.warn("Missing Main IRI: $e") diff --git a/whelk-core/src/main/groovy/whelk/component/ElasticSearch.groovy b/whelk-core/src/main/groovy/whelk/component/ElasticSearch.groovy index 62e664aeff..34371fe2ac 100644 --- a/whelk-core/src/main/groovy/whelk/component/ElasticSearch.groovy +++ b/whelk-core/src/main/groovy/whelk/component/ElasticSearch.groovy @@ -105,13 +105,13 @@ class ElasticSearch { private final JsonLd jsonLd private static final class DerivedLenses { - public static final FresnelUtil.Lens CARD_ONLY = new FresnelUtil.Lens( + public static final Lens CARD_ONLY = new FresnelUtil.Lens( FresnelUtil.CARD_CHAIN, FresnelUtil.Lenses.SEARCH_CHIP, List.of(FresnelUtil.CHIP_CHAIN) ) - public static final FresnelUtil.Lens SEARCH_CARD_ONLY = new FresnelUtil.Lens( + public static final Lens SEARCH_CARD_ONLY = new FresnelUtil.Lens( new FresnelUtil.LensGroupChain(FresnelUtil.SEARCH_CARDS), FresnelUtil.Lenses.SEARCH_CHIP, List.of(FresnelUtil.CHIP_CHAIN, FresnelUtil.CARD_CHAIN) @@ -574,7 +574,7 @@ class ElasticSearch { var embellishedNonIntegralGraphs = fullEmbellishedGraph.drop(mainGraph.size() + embellishedIntegralGraphs.size()) var shapedEmbellishedNonIntegralGraphs = shapeNonIntegralThings(whelk.fresnelUtil, embellishedNonIntegralGraphs) - copy.data[GRAPH_KEY] = shapedMainGraph + shapedEmbellishedIntegralGraphs + shapedEmbellishedNonIntegralGraphs + copy.data[GRAPH_KEY] = (List) shapedMainGraph + shapedEmbellishedIntegralGraphs + shapedEmbellishedNonIntegralGraphs setIdentifiers(copy) copy.setThingMeta(document.getCompleteId()) diff --git a/whelk-core/src/main/groovy/whelk/search/ESQuery.groovy b/whelk-core/src/main/groovy/whelk/search/ESQuery.groovy index 3a0a9b4981..05e5ada478 100644 --- a/whelk-core/src/main/groovy/whelk/search/ESQuery.groovy +++ b/whelk-core/src/main/groovy/whelk/search/ESQuery.groovy @@ -1115,7 +1115,7 @@ class ESQuery { private static Set getFieldsByCondition(Map mappings, Closure cond, String parentName) { Set fields = [] as Set if (mappings) { - (mappings['properties'] as Map)?.each { fieldName, fieldSettings -> + (mappings.get('properties') as Map)?.each { fieldName, fieldSettings -> fields += getFieldsByCondition(fieldName as String, fieldSettings as Map, cond, parentName) } } diff --git a/whelk-core/src/main/groovy/whelk/search/ElasticFind.groovy b/whelk-core/src/main/groovy/whelk/search/ElasticFind.groovy index b68d961260..abeae8a876 100644 --- a/whelk-core/src/main/groovy/whelk/search/ElasticFind.groovy +++ b/whelk-core/src/main/groovy/whelk/search/ElasticFind.groovy @@ -69,7 +69,7 @@ class ElasticFind { private void fetchFirst() { def firstResult = getter(0) - total = firstResult['totalHits'] + total = (int) firstResult['totalHits'] if (total > esQuery.getMaxItems()) { throw new ElasticSearch.TooManyResultsException(total, esQuery.getMaxItems()) } diff --git a/whelk-core/src/main/groovy/whelk/util/Romanizer.groovy b/whelk-core/src/main/groovy/whelk/util/Romanizer.groovy index b71223f99c..a1c320a91c 100644 --- a/whelk-core/src/main/groovy/whelk/util/Romanizer.groovy +++ b/whelk-core/src/main/groovy/whelk/util/Romanizer.groovy @@ -106,14 +106,14 @@ class Romanizer { Romanizer.class.getClassLoader().getResourceAsStream('romanizer/' + filename).getText("UTF-8") } - interface Transform { - String sourceTag() - String targetTag() - String transform(String s) - default String toString() {"${getClass().getSimpleName().take(1)}(${sourceTag()} -> ${targetTag()})"} + static abstract class Transform { + abstract String sourceTag() + abstract String targetTag() + abstract String transform(String s) + String toString() {"${getClass().getSimpleName().take(1)}(${sourceTag()} -> ${targetTag()})"} } - static class Auto implements Transform { + static class Auto extends Transform { private String sourceTag private Transliterator transliterator @@ -138,7 +138,7 @@ class Romanizer { } } - static class Manual implements Transform { + static class Manual extends Transform { private static final var SOURCE = Pattern.compile(".*-t-(.*?)(-\\p{Alpha}\\p{Digit}-.*)?\$") private String sourceTag private String targetTag diff --git a/whelk-core/src/test/groovy/whelk/search2/querytree/QueryTreeSpec.groovy b/whelk-core/src/test/groovy/whelk/search2/querytree/QueryTreeSpec.groovy index a10db5bfbb..2d1f6f724c 100644 --- a/whelk-core/src/test/groovy/whelk/search2/querytree/QueryTreeSpec.groovy +++ b/whelk-core/src/test/groovy/whelk/search2/querytree/QueryTreeSpec.groovy @@ -287,7 +287,7 @@ class QueryTreeSpec extends Specification { given: QueryTree queryTree = new QueryTree(q, disambiguate) Node nodeToMatch = QueryTreeBuilder.buildTree(replace, disambiguate) - Node nodeToReplace = queryTree.allDescendants().find(nodeToMatch::equals) + Node nodeToReplace = queryTree.allDescendants().find { it == nodeToMatch } Node replacementNode = QueryTreeBuilder.buildTree(replacement, disambiguate) expect: