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

Replace xjc with custom XSD Kotlin code gen #1479

Merged
merged 13 commits into from
Dec 29, 2024
Merged
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
2 changes: 2 additions & 0 deletions Src/java/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies {
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.7.2")
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.14")
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")
implementation("com.github.node-gradle:gradle-node-plugin:7.1.0")
implementation("org.jetbrains.kotlin:kotlin-serialization:2.0.20")
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spotless {
palantirJavaFormat()
}
kotlin {
targetExclude("**/generated/**")
ktfmt().kotlinlangStyle()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
}

val xjc: Configuration by configurations.creating

dependencies {
xjc("codes.rafael.jaxb2_commons:jaxb2-basics-ant:3.0.0")
xjc("codes.rafael.jaxb2_commons:jaxb2-basics:3.0.0")
xjc("codes.rafael.jaxb2_commons:jaxb2-fluent-api:3.0.0")
// Eclipse has taken over all Java EE reference components
// https://www.infoworld.com/article/3310042/eclipse-takes-over-all-java-ee-reference-components.html
// https://wiki.eclipse.org/Jakarta_EE_Maven_Coordinates
xjc("jakarta.xml.bind:jakarta.xml.bind-api:4.0.1")
xjc("org.glassfish.jaxb:jaxb-xjc:3.0.2")
xjc("org.glassfish.jaxb:jaxb-runtime:4.0.3")
xjc("org.eclipse.persistence:org.eclipse.persistence.moxy:4.0.2")
xjc("org.slf4j:slf4j-simple:1.7.36")
xjc("org.apache.ant:ant:1.10.14")
}

var buildDir = project.layout.buildDirectory.get().toString()
val destDir = "${buildDir}/generated/sources/$name-xjc-temp/main/java"

tasks.withType<KotlinCompile>().configureEach {
dependsOn(tasks.withType<XjcTask>())
}

tasks.withType<JavaCompile>().configureEach {
dependsOn(tasks.withType<XjcTask>())
}

tasks.withType<XjcTask>().configureEach {
outputDir = destDir
outputs.dir(outputDir)
}

tasks.withType<Delete>().configureEach {
delete(destDir)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.github.gradle.node.task.NodeTask
import org.gradle.kotlin.dsl.kotlin

plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("com.github.node-gradle.node")
}

dependencies {
implementation("io.github.pdvrieze.xmlutil:core:0.90.3")
implementation("io.github.pdvrieze.xmlutil:serialization:0.90.3")
implementation("io.github.pdvrieze.xmlutil:serialization-jvm:0.90.3")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
}

node {
download = true
nodeProjectDir.set(file("../../js/xsd-kotlin-gen"))
}

val buildDir = project.layout.buildDirectory.get().toString()
val destDir = "${buildDir}/generated/sources/$name/main/java"

val runXsdKotlinGenTask = tasks.register<NodeTask>("runXsdKotlinGen") {
dependsOn(tasks.npmInstall)
script.set(file("../../js/xsd-kotlin-gen/generate.js"))
}

tasks.withType<KotlinCompile>().configureEach {
dependsOn(runXsdKotlinGenTask)
}

tasks.withType<JavaCompile>().configureEach {
dependsOn(runXsdKotlinGenTask)
}

tasks.withType<Delete>().configureEach {
delete(destDir)
}

sourceSets {
main {
java {
srcDir(destDir)
}
}
}
1 change: 1 addition & 0 deletions Src/java/cqf-fhir-npm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
dependencies {
implementation(project(":cql-to-elm"))
implementation(project(":cqf-fhir"))
implementation(project(":model-xmlutil"))
implementation("com.google.code.gson:gson:2.9.1")
implementation("org.apache.commons:commons-compress:1.24.0")
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.cqframework.fhir.npm;

import jakarta.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.hl7.cql.model.ModelIdentifier;
import org.hl7.cql.model.ModelInfoProvider;
import org.hl7.elm_modelinfo.r1.ModelInfo;
import org.hl7.elm_modelinfo.r1.serializing.xmlutil.XmlModelInfoReader;
import org.hl7.fhir.r5.context.ILoggingService;
import org.hl7.fhir.r5.model.Library;
import org.hl7.fhir.utilities.npm.NpmPackage;
Expand Down Expand Up @@ -51,7 +51,8 @@ public ModelInfo load(ModelIdentifier modelIdentifier) {
modelIdentifier.setSystem(identifier.getSystem());
}
InputStream is = new ByteArrayInputStream(a.getData());
return JAXB.unmarshal(is, ModelInfo.class);
var reader = new XmlModelInfoReader();
return reader.read(is);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions Src/java/cql-to-elm-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ application {

dependencies {
implementation(project(":cql-to-elm"))
implementation(project(":cql-to-elm-jackson"))
// Is this needed once JAXB and Jackson are replaced with XmlUtil?
// implementation(project(":cql-to-elm-jackson"))
implementation(project(":quick"))
implementation(project(":qdm"))
implementation(project(":model-jaxb"))
implementation(project(":elm-jaxb"))
implementation(project(":model-xmlutil"))
implementation(project(":elm-xmlutil"))
implementation(project(":ucum"))
implementation("net.sf.jopt-simple:jopt-simple:4.7")
implementation("org.slf4j:slf4j-simple:2.0.13")
implementation("org.glassfish.jaxb:jaxb-runtime:4.0.5")
implementation("org.eclipse.persistence:org.eclipse.persistence.moxy:4.0.2")
testImplementation(project(":model-jaxb"))
testImplementation(project(":elm-jaxb"))
testImplementation(project(":model-xmlutil"))
testImplementation(project(":elm-xmlutil"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import org.junit.jupiter.api.Test;

class CqlTranslatorOptionsToJsonSchema {
Expand Down
9 changes: 7 additions & 2 deletions Src/java/cql-to-elm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ dependencies {
api(project(":cql"))
api(project(":model"))
api(project(":elm"))
testImplementation(project(":elm-jaxb"))
testImplementation(project(":model-jaxb"))

// Temporary until we can get rid of the dependency on wrapping
// the CQL annotations in a JAXBElement for narrative generation
implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.1")

testImplementation(project(":elm-xmlutil"))
testImplementation(project(":model-xmlutil"))
testImplementation(project(":quick"))
testImplementation(project(":qdm"))
testImplementation(project(":ucum"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object CompilerOptions {
*/
@JvmStatic
fun getCompilerOptions(library: Library): Set<CqlCompilerOptions.Options>? {
if (library.annotation.isNullOrEmpty()) {
if (library.annotation.isEmpty()) {
return null
}
val compilerOptions = getCompilerOptions(library.annotation)
Expand All @@ -38,7 +38,7 @@ object CompilerOptions {

/**
* Parses a string representing CQL compiler Options into an EnumSet. The string is expected to
* be a comma delimited list of values from the CqlCompiler.Options enumeration. For example
* be a comma-delimited list of values from the CqlCompiler.Options enumeration. For example
* "EnableListPromotion, EnableListDemotion".
*
* @param compilerOptions the string to parse
Expand All @@ -52,11 +52,7 @@ object CompilerOptions {
val optionSet: EnumSet<CqlCompilerOptions.Options> =
EnumSet.noneOf(CqlCompilerOptions.Options::class.java)
val options =
compilerOptions
.trim { it <= ' ' }
.split(",".toRegex())
.dropLastWhile { it.isEmpty() }
.toTypedArray()
compilerOptions.trim { it <= ' ' }.split(",".toRegex()).dropLastWhile { it.isEmpty() }
for (option in options) {
optionSet.add(CqlCompilerOptions.Options.valueOf(option))
}
Expand All @@ -74,7 +70,7 @@ object CompilerOptions {
*/
@JvmStatic
fun getCompilerVersion(library: Library): String? {
if (library.annotation.isNullOrEmpty()) {
if (library.annotation.isEmpty()) {
return null
}
return getCompilerVersion(library.annotation)
Expand Down
Loading
Loading