Skip to content

Commit

Permalink
Create separate artifact for lexicons schemas.
Browse files Browse the repository at this point in the history
  • Loading branch information
christiandeange committed May 23, 2024
1 parent e1c5dbd commit 8817f03
Show file tree
Hide file tree
Showing 186 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bluesky/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ kmmbridge {
}

dependencies {
lexicons(fileTree("lexicons") { include("**/*.json") })
lexicons(project(":lexicons"))
}

lexicons {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import sh.christian.ozone.api.generator.ApiConfiguration
import sh.christian.ozone.api.generator.LexiconApiGenerator
import sh.christian.ozone.api.generator.LexiconClassFileCreator
import sh.christian.ozone.api.generator.LexiconProcessingEnvironment
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Collectors
import kotlin.io.path.extension
import kotlin.io.path.isRegularFile
import kotlin.io.path.readText

@CacheableTask
abstract class LexiconGeneratorTask : DefaultTask() {
Expand All @@ -38,7 +45,9 @@ abstract class LexiconGeneratorTask : DefaultTask() {
outputDir.mkdirs()

val processingEnvironment = LexiconProcessingEnvironment(
allLexiconSchemaJsons = schemasClasspath.map { it.readText() },
allLexiconSchemaJsons = schemasClasspath.flatMap { inputFile ->
inputFile.toPath().findJsonFiles()
},
outputDirectory = outputDir,
)

Expand All @@ -58,4 +67,31 @@ abstract class LexiconGeneratorTask : DefaultTask() {
lexiconClassFileCreator.generateSealedRelationshipMapping()
lexiconApiGenerator.generateApis()
}

private fun Path.findJsonFiles(): List<String> {
return when (extension) {
"json" -> {
logger.info("Including lexicon schema: $this")
listOf(readText())
}

"jar" -> {
// Unzip jar and resolve all json files
logger.info("Including lexicon schemas from: $this")
FileSystems.newFileSystem(this, null as ClassLoader?).use { jar ->
jar.rootDirectories.flatMap { root ->
Files.walk(root)
.filter { it.isRegularFile() }
.collect(Collectors.toList())
.flatMap { it.findJsonFiles() }
}
}
}

else -> {
logger.info("Ignoring non-json file: $this")
emptyList()
}
}
}
}
1 change: 1 addition & 0 deletions lexicons/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
8 changes: 8 additions & 0 deletions lexicons/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id("ozone-publish")
`java-library`
}

tasks.jar.configure {
from(fileTree("schemas") { include("**/*.json") })
}
2 changes: 2 additions & 0 deletions lexicons/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POM_NAME=AT Protocol for Kotlin - Lexicons
POM_DESCRIPTION=Lexicon schema source files
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ include(":app:web")
include(":api-gen-runtime")
include(":api-gen-runtime-internal")
include(":bluesky")
include(":lexicons")

includeBuild("build-logic")
includeBuild("generator")

0 comments on commit 8817f03

Please sign in to comment.