Skip to content

Commit

Permalink
fix: preparation commands as rdf collection
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspots committed Jul 20, 2024
1 parent 5eb55f2 commit e5f846a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
7 changes: 4 additions & 3 deletions processors/file-utils-ts/index.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
7 changes: 4 additions & 3 deletions processors/shacl-validator-ts/index.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions runners/nodejs/index.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion src/main/kotlin/parser/impl/JenaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ private fun Model.parseDependencies(pipeline: Resource?): List<IRDependency> {
}
}

private fun Model.getCollection(resource: Resource): List<RDFNode> {
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")

Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion src/test/kotlin/parser/ParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/test/resources/packages/dummy/index.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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 .

0 comments on commit e5f846a

Please sign in to comment.