From 4af52c160fcb17bfd56bfae99a6d6d517e40a185 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 31 Jan 2018 06:41:24 -0600 Subject: [PATCH] Try to get HAPI building on JDK9 --- .travis.yml | 2 +- appveyor.yml | 2 +- hapi-fhir-cli/hapi-fhir-cli-app/pom.xml | 8 ++-- hapi-fhir-jpaserver-base/pom.xml | 21 +++++++++ .../tinder/parser/BaseStructureParser.java | 46 +++++++++++++----- pom.xml | 47 ++++++++++++++++--- src/changes/changes.xml | 5 ++ 7 files changed, 109 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index bec09c5d1cd..5d6fca80e68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,5 +25,5 @@ before_script: script: # - mvn -e -B clean install && cd hapi-fhir-ra && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID clean test jacoco:report coveralls:report # - mvn -Dci=true -e -B -P ALLMODULES,NOPARALLEL,ERRORPRONE clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report - - mvn -Dci=true -e -B -P ALLMODULES,REDUCED_JPA_TESTS,ERRORPRONE clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report + - mvn -Dci=true -e -B -P ALLMODULES,REDUCED_JPA_TESTS,ERRORPRONE_JDK8 clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report diff --git a/appveyor.yml b/appveyor.yml index afb21a48371..a08ed7500ff 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,4 +4,4 @@ cache: - C:\maven\ - C:\Users\appveyor\.m2\repository build_script: - - cmd: mvn -P MINPARALLEL,ALLMODULES install + - cmd: mvn -P MINPARALLEL,ALLMODULES,ERRORPRONE_JDK8 install diff --git a/hapi-fhir-cli/hapi-fhir-cli-app/pom.xml b/hapi-fhir-cli/hapi-fhir-cli-app/pom.xml index c7348883b47..10348db39f7 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-app/pom.xml +++ b/hapi-fhir-cli/hapi-fhir-cli-app/pom.xml @@ -190,20 +190,22 @@ com.phloc phloc-commons + + javax.xml.bind jaxb-api - 2.3.0 com.sun.xml.bind jaxb-core - 2.3.0 com.sun.xml.bind jaxb-impl - 2.3.0 diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml index b103623a495..bbe19c60c6f 100644 --- a/hapi-fhir-jpaserver-base/pom.xml +++ b/hapi-fhir-jpaserver-base/pom.xml @@ -550,6 +550,27 @@ + + + + javax.xml.bind + jaxb-api + ${jaxb_api_version} + + + com.sun.xml.bind + jaxb-core + ${jaxb_core_version} + + + com.sun.xml.bind + jaxb-impl + ${jaxb_core_version} + + org.jacoco diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java index f01ada1bc59..63f9d423d23 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java @@ -13,6 +13,9 @@ import ca.uhn.fhir.tinder.ValueSetGenerator; import ca.uhn.fhir.tinder.VelocityHelper; import ca.uhn.fhir.tinder.model.*; import ca.uhn.fhir.tinder.model.SimpleSetter.Parameter; +import com.google.common.base.Charsets; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.WordUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -455,8 +458,8 @@ public abstract class BaseStructureParser { scanForTypeNameConflicts(theNext, typeNames); } - public void setExtensions(ArrayList theExts) { - myExtensions = theExts; + public void setExtensions(ArrayList theExtensions) { + myExtensions = theExtensions; } public void setVelocityProperties(String theVelocityProperties) { @@ -464,12 +467,7 @@ public abstract class BaseStructureParser { } private void write(BaseRootType theResource, File theFile, String thePackageBase) throws IOException, MojoFailureException { - FileOutputStream fos = new FileOutputStream(theFile, false); - OutputStreamWriter w = new OutputStreamWriter(fos, "UTF-8"); - - ourLog.debug("Writing file: {}", theFile.getAbsolutePath()); - - ArrayList imports = new ArrayList(); + ArrayList imports = new ArrayList<>(); for (String next : myImports) { next = Resource.correctName(next); if (next.contains(".")) { @@ -535,10 +533,36 @@ public abstract class BaseStructureParser { } InputStreamReader templateReader = new InputStreamReader(templateIs); - v.evaluate(ctx, w, "", templateReader); + ByteArrayOutputStream byteArrayWriter = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayWriter, Charsets.UTF_8); + v.evaluate(ctx, outputStreamWriter, "", templateReader); + outputStreamWriter.flush(); - w.close(); - fos.close(); + byte[] bytesToWrite = byteArrayWriter.toByteArray(); + + boolean actuallyWrite = false; + if (!theFile.exists()) { + actuallyWrite = true; + } else if (FileUtils.sizeOf(theFile) != bytesToWrite.length) { + actuallyWrite = true; + } else { + byte[] existingBytes = IOUtils.toByteArray(new FileInputStream(theFile)); + if (!Arrays.equals(existingBytes, bytesToWrite)) { + actuallyWrite = true; + } + } + + if (!actuallyWrite) { + ourLog.info("Skipping writing already up-to-date file: {}", theFile.getAbsolutePath()); + return; + } + + ourLog.debug("Writing file: {}", theFile.getAbsolutePath()); + + try (FileOutputStream fos = new FileOutputStream(theFile, false)) { + fos.write(bytesToWrite); + fos.flush(); + } } public void writeAll(File theOutputDirectory, File theResourceOutputDirectory, String thePackageBase) throws MojoFailureException { diff --git a/pom.xml b/pom.xml index e9ab94ec679..e27fe80b8c1 100644 --- a/pom.xml +++ b/pom.xml @@ -408,6 +408,8 @@ 10.14.1.0 + 2.3.0 + 2.3.0 2.25.1 9.4.8.v20171121 @@ -580,11 +582,26 @@ javax.json-api 1.1 + + javax.xml.bind + jaxb-api + ${jaxb_api_version} + com.google.code.gson gson 2.8.1 + + com.sun.xml.bind + jaxb-core + ${jaxb_core_version} + + + com.sun.xml.bind + jaxb-impl + ${jaxb_core_version} + javax.mail javax.mail-api @@ -1063,9 +1080,9 @@ de.juplo hibernate-maven-plugin - 2.0.0 + 2.1.1 - false + false false false false @@ -1972,10 +1989,7 @@ - ERRORPRONE - - true - + ERRORPRONE_JDK8 @@ -1988,6 +2002,27 @@ + + ERRORPRONE_JDK9 + + + + org.apache.maven.plugins + maven-compiler-plugin + + javac-with-errorprone + + + + com.google.errorprone + error_prone_core + 2.2.0 + + + + + + diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 13734fc55d3..d7eba0a841e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -93,6 +93,11 @@ not respect any chained method parameters (e.g. MedicationRequest?medication.code=123). Thanks to @manjusampath for reporting! + + A few fixes went into the build which should now allow HAPI FHIR + to build correctly on JDK 9.0. Currently building is supported on + JDK 8.x and 9.x only. +