From e5f846af06bc6f1b88e658d56fc9520dc36a6d1c Mon Sep 17 00:00:00 2001 From: Jens Pots Date: Sat, 20 Jul 2024 15:57:35 +0200 Subject: [PATCH] fix: preparation commands as rdf collection --- processors/file-utils-ts/index.ttl | 7 ++++--- processors/shacl-validator-ts/index.ttl | 7 ++++--- runners/nodejs/index.ttl | 7 ++++--- src/main/kotlin/parser/impl/JenaParser.kt | 20 +++++++++++++++++++- src/test/kotlin/parser/ParserTest.kt | 5 ++++- src/test/resources/packages/dummy/index.ttl | 7 ++++++- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/processors/file-utils-ts/index.ttl b/processors/file-utils-ts/index.ttl index 1918211..b3ef96f 100644 --- a/processors/file-utils-ts/index.ttl +++ b/processors/file-utils-ts/index.ttl @@ -10,9 +10,10 @@ rdfc:FileUtilsTS rdfc:description "Utility processors for interacting with the file system." ; rdfc:repo "https://github.com/rdf-connect/orchestrator.git" ; rdfc:license "MIT" ; - rdfc:prepare - "npm install" , - "npm run build" ; + rdfc:prepare ( + "npm install" + "npm run build" + ) ; rdfc:processors rdfc:FileReaderTS , rdfc:FileWriterTS . diff --git a/processors/shacl-validator-ts/index.ttl b/processors/shacl-validator-ts/index.ttl index 748431c..6d8163c 100644 --- a/processors/shacl-validator-ts/index.ttl +++ b/processors/shacl-validator-ts/index.ttl @@ -10,9 +10,10 @@ rdfc:description "A SHACL Validator processor, written in TypeScript." ; rdfc:repo "https://github.com/rdf-connect/orchestrator.git" ; rdfc:license "MIT" ; - rdfc:prepare - "npm install" , - "npm run build" ; + rdfc:prepare ( + "npm install" + "npm run build" + ) ; rdfc:processors rdfc:SHACLValidatorTS . rdfc:SHACLValidatorTS diff --git a/runners/nodejs/index.ttl b/runners/nodejs/index.ttl index 02f5f62..ef78289 100644 --- a/runners/nodejs/index.ttl +++ b/runners/nodejs/index.ttl @@ -7,9 +7,10 @@ rdfc:NodePackage rdfc:description "A gRPC based Node.js runner." ; rdfc:repo "https://github.com/rdf-connect/orchestrator" ; rdfc:license "MIT" ; - rdfc:prepare - "npm install" , - "npm run build" ; + rdfc:prepare ( + "npm install" + "npm run build" + ) ; rdfc:runners rdfc:NodeRunner . rdfc:NodeRunner diff --git a/src/main/kotlin/parser/impl/JenaParser.kt b/src/main/kotlin/parser/impl/JenaParser.kt index f8420ba..30a5c0e 100644 --- a/src/main/kotlin/parser/impl/JenaParser.kt +++ b/src/main/kotlin/parser/impl/JenaParser.kt @@ -299,6 +299,18 @@ private fun Model.parseDependencies(pipeline: Resource?): List { } } +private fun Model.getCollection(resource: Resource): List { + val first = + objectOfProperty(resource, RDF.first) ?: Log.shared.fatal("No first element: $resource") + val rest = objectOfProperty(resource, RDF.rest) ?: Log.shared.fatal("No rest element: $resource") + + return if (rest != RDF.nil) { + listOf(first) + getCollection(rest.asResource()) + } else { + listOf(first) + } +} + private fun Model.parsePackage(directory: File, pkg: Resource): IRPackage { Log.shared.debug("Parsing package: $pkg") @@ -315,7 +327,13 @@ private fun Model.parsePackage(directory: File, pkg: Resource): IRPackage { parseRunner(directory, it.asResource()) } - val prepare = listObjectsOfProperty(pkg, RDFC.prepare).toList().map { it.toString() } + val prepareCollection = objectOfProperty(pkg, RDFC.prepare) + val prepare = + if (prepareCollection != null) { + getCollection(prepareCollection.asResource()).map { it.toString() } + } else { + emptyList() + } // Parse the properties to strings if required, and return the package IR. return IRPackage( diff --git a/src/test/kotlin/parser/ParserTest.kt b/src/test/kotlin/parser/ParserTest.kt index 79ec102..2d6e947 100644 --- a/src/test/kotlin/parser/ParserTest.kt +++ b/src/test/kotlin/parser/ParserTest.kt @@ -37,8 +37,11 @@ class ParserTest { assertEquals("A simple description.", pkg.description) assertEquals("https://example.com.git", pkg.repo) assertEquals("MIT", pkg.license) - assertEquals(1, pkg.prepare?.size) + assertEquals(4, pkg.prepare?.size) assertEquals("make", pkg.prepare?.get(0)) + assertEquals("make install", pkg.prepare?.get(1)) + assertEquals("make test", pkg.prepare?.get(2)) + assertEquals("make clean", pkg.prepare?.get(3)) // Check the processors. assertEquals(1, pkg.processors.size) diff --git a/src/test/resources/packages/dummy/index.ttl b/src/test/resources/packages/dummy/index.ttl index 68761ec..c2583f7 100644 --- a/src/test/resources/packages/dummy/index.ttl +++ b/src/test/resources/packages/dummy/index.ttl @@ -16,6 +16,11 @@ test:DummyPackage rdfc:description "A simple description." ; rdfc:repo "https://example.com.git" ; rdfc:license "MIT" ; - rdfc:prepare "make" ; + rdfc:prepare ( + "make" + "make install" + "make test" + "make clean" + ) ; rdfc:processors test:DummyProcessor ; rdfc:runners test:DummyRunner .