From 63b5d935c053bc7ffa969b90249e41e7de544588 Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Sun, 8 Nov 2020 21:13:08 +0100 Subject: [PATCH 1/2] Update fmi4j and replace use of JAXB --- build.gradle | 2 +- fmu-wrapper/build.gradle | 1 + .../kotlin/no/ntnu/ihb/fmuproxy/FmuWrapper.kt | 12 +++++---- .../fmuproxy/misc/MockupModelDescription.kt | 21 ---------------- .../no/ntnu/ihb/fmuproxy/misc/helpers.kt | 25 ------------------- 5 files changed, 9 insertions(+), 52 deletions(-) delete mode 100644 fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/MockupModelDescription.kt diff --git a/build.gradle b/build.gradle index 720003d8..c4b53882 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ println "Gradle version is ${gradle.getGradleVersion()}" ext.slf4j_version = '1.7.25' ext.picocli_version = '4.5.0' -ext.fmi4j_version = '0.33.4' +ext.fmi4j_version = '0.34.0' wrapper { distributionType = Wrapper.DistributionType.ALL diff --git a/fmu-wrapper/build.gradle b/fmu-wrapper/build.gradle index 760e2dd1..6f6aeafe 100644 --- a/fmu-wrapper/build.gradle +++ b/fmu-wrapper/build.gradle @@ -10,6 +10,7 @@ dependencies { implementation project(":rpc-gen") implementation "no.ntnu.ihb.fmi4j:fmi-md:$fmi4j_version" implementation "no.ntnu.ihb.fmi4j:fmi-export:$fmi4j_version" + implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.3" def slf4j_version = '1.7.25' implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4j_version diff --git a/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/FmuWrapper.kt b/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/FmuWrapper.kt index b7350049..f4a8579e 100644 --- a/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/FmuWrapper.kt +++ b/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/FmuWrapper.kt @@ -1,8 +1,10 @@ package no.ntnu.ihb.fmuproxy +import com.fasterxml.jackson.dataformat.xml.XmlMapper import no.ntnu.ihb.fmi4j.export.fmi2.Fmi2Slave import no.ntnu.ihb.fmi4j.modeldescription.fmi1.FmiModelDescription import no.ntnu.ihb.fmi4j.modeldescription.fmi2.Fmi2ModelDescription +import no.ntnu.ihb.fmi4j.modeldescription.util.FmiModelDescriptionUtil import no.ntnu.ihb.fmuproxy.misc.* import no.ntnu.ihb.fmuproxy.thrift.ModelDescription import no.ntnu.ihb.fmuproxy.thrift.internal.InternalFmuService @@ -11,7 +13,6 @@ import org.apache.thrift.transport.TFramedTransport import org.apache.thrift.transport.TSocket import java.io.* import java.util.concurrent.TimeUnit -import javax.xml.bind.JAXB class FmuWrapper( @@ -107,10 +108,11 @@ class FmuWrapper( override fun registerVariables() { - val xml = extractModelDescriptionXml(FileInputStream(fmu)) - when (val version = extractFmiVersion(xml)) { - "1.0" -> processFmi1ModelDescription(JAXB.unmarshal(StringReader(xml), FmiModelDescription::class.java)) - "2.0" -> processFmi2ModelDescription(JAXB.unmarshal(StringReader(xml), Fmi2ModelDescription::class.java)) + val mapper = XmlMapper() + val xml = FmiModelDescriptionUtil.extractModelDescriptionXml(FileInputStream(fmu)) + when (val version = FmiModelDescriptionUtil.extractVersion(xml)) { + "1.0" -> processFmi1ModelDescription(mapper.readValue(xml, FmiModelDescription::class.java)) + "2.0" -> processFmi2ModelDescription(mapper.readValue(xml, Fmi2ModelDescription::class.java)) else -> throw IllegalArgumentException("Unknown FMI version: $version") } diff --git a/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/MockupModelDescription.kt b/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/MockupModelDescription.kt deleted file mode 100644 index 80fb6380..00000000 --- a/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/MockupModelDescription.kt +++ /dev/null @@ -1,21 +0,0 @@ -package no.ntnu.ihb.fmuproxy.misc - -import javax.xml.bind.annotation.XmlAttribute -import javax.xml.bind.annotation.XmlRootElement - -@XmlRootElement(name = "fmiModelDescription") -internal class MockupModelDescription { - - @XmlAttribute(name = "fmiVersion", required = true) - private val fmiVersion_: String? = null - - @XmlAttribute(name = "guid", required = true) - private val guid_: String? = null - - val fmiVersion: String - get() = fmiVersion_!! - - val guid: String - get() = guid_!! - -} diff --git a/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/helpers.kt b/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/helpers.kt index c13f79bb..5d6d9666 100644 --- a/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/helpers.kt +++ b/fmu-wrapper/src/main/kotlin/no/ntnu/ihb/fmuproxy/misc/helpers.kt @@ -2,7 +2,6 @@ package no.ntnu.ihb.fmuproxy.misc import no.ntnu.ihb.fmi4j.modeldescription.fmi1.FmiCausality import no.ntnu.ihb.fmi4j.modeldescription.fmi1.FmiModelDescription -import no.ntnu.ihb.fmi4j.modeldescription.fmi1.FmiScalarVariable import no.ntnu.ihb.fmi4j.modeldescription.fmi1.FmiVariability import no.ntnu.ihb.fmi4j.modeldescription.fmi2.Fmi2Causality import no.ntnu.ihb.fmi4j.modeldescription.fmi2.Fmi2ModelDescription @@ -13,13 +12,8 @@ import org.apache.thrift.transport.TFramedTransport import org.apache.thrift.transport.TSocket import java.io.File import java.io.FileInputStream -import java.io.InputStream -import java.io.StringReader import java.net.ServerSocket import java.nio.ByteBuffer -import java.util.zip.ZipEntry -import java.util.zip.ZipInputStream -import javax.xml.bind.JAXB import kotlin.concurrent.thread internal fun String.isLoopback(): Boolean { @@ -80,25 +74,6 @@ internal fun startLocalProxy(proxyFile: File, fmuFile: File): Pair return process to port } -internal fun extractModelDescriptionXml(stream: InputStream): String { - val xmlFile = "modelDescription.xml" - ZipInputStream(stream).use { zis -> - var nextEntry: ZipEntry? = zis.nextEntry - while (nextEntry != null) { - if (nextEntry.name == xmlFile) { - return zis.bufferedReader().use { it.readText() } - } - nextEntry = zis.nextEntry - } - } - throw IllegalArgumentException("Input is not an valid FMU! No $xmlFile present!") -} - - -internal fun extractFmiVersion(xml: String): String { - return JAXB.unmarshal(StringReader(xml), MockupModelDescription::class.java).fmiVersion -} - internal fun parseSettings(settings: File): ProxySettings { require(settings.exists()) { "No such file: $settings" } return parseSettings(settings.readText()) From a59796fd69a37e508c46f3512865cf29495b87fe Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Sun, 8 Nov 2020 21:15:42 +0100 Subject: [PATCH 2/2] Build with JDK 11 on CI server --- .github/workflows/gradle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 1dee6af1..31b6e112 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - uses: actions/cache@v2 with: