This commit is contained in:
Grahame Grieve 2020-06-26 06:05:25 +10:00
commit c6e424d50d
6 changed files with 557 additions and 704 deletions

View File

@ -1,18 +1,23 @@
# HAPI FHIR - HL7 FHIR Core Artifacts
### CI/CD
| master Branch CI | SNAPSHOT Publisher |
| :---: | :---: |
| [![Build Status][Badge-BuildPipeline]][Link-BuildPipeline] | [![Build Status][Badge-SnapshotPipeline]][Link-SnapshotPipeline] |
| CI Status (master) |
| :---: |
| [![Build Status][Badge-BuildPipeline]][Link-BuildPipeline] |
All intergration and delivery done on Azure pipelines. Every successful merge to master branch will result in a new SNAPSHOT build being published to Sonatype. Azure project can be viewed [here][Link-AzureProject].
### CI/CD
All intergration and delivery done on Azure pipelines. Azure project can be viewed [here][Link-AzureProject].
### Current Versions
| Project | Latest SNAPSHOT | Current Release |
| Project | Current Release | Latest SNAPSHOT |
| :---: | :---: | :---: |
| org.hl7.fhir.validation.cli | [![Snapshot Artifact][Badge-cliSonatypeSnapshot]][Link-cliSonatypeSnapshot] | [![Release Artifacts][Badge-cliSonatypeRelease]][Link-cliSonatypeRelease] |
| org.hl7.fhir.r4 | [![Snapshot Artifact][Badge-r4SonatypeSnapshot]][Link-r4SonatypeSnapshot] | [![Release Artifacts][Badge-r4SonatypeRelease]][Link-r4SonatypeRelease] |
| org.hl7.fhir.r5 | [![Snapshot Artifact][Badge-r5SonatypeSnapshot]][Link-r5SonatypeSnapshot] | [![Release Artifacts][Badge-r5SonatypeRelease]][Link-r5SonatypeRelease] |
| org.hl7.fhir.validation.cli | [![Release Artifacts][Badge-r4SonatypeRelease]][Link-cliSonatypeRelease] | [![Snapshot Artifact][Badge-cliSonatypeSnapshot]][Link-cliSonatypeSnapshot] |
| org.hl7.fhir.validation | [![Release Artifacts][Badge-validationSonatypeRelease]][Link-validationSonatypeRelease] | [![Snapshot Artifact][Badge-validationSonatypeSnapshot]][Link-validationSonatypeSnapshot] |
| org.hl7.fhir.dstu2 | [![Release Artifacts][Badge-dstu2SonatypeRelease]][Link-dstu2SonatypeRelease] | [![Snapshot Artifact][Badge-dstu2SonatypeSnapshot]][Link-dstu2SonatypeSnapshot] |
| org.hl7.fhir.dstu2016may | [![Release Artifacts][Badge-dstu2016maySonatypeRelease]][Link-dstu2016maySonatypeRelease] | [![Snapshot Artifact][Badge-dstu2016maySonatypeSnapshot]][Link-dstu2016maySonatypeSnapshot] |
| org.hl7.fhir.dstu3 | [![Release Artifacts][Badge-dstu3SonatypeRelease]][Link-dstu3SonatypeRelease] | [![Snapshot Artifact][Badge-dstu3SonatypeSnapshot]][Link-dstu3SonatypeSnapshot] |
| org.hl7.fhir.r4 | [![Release Artifacts][Badge-r4SonatypeRelease]][Link-r4SonatypeRelease] | [![Snapshot Artifact][Badge-r4SonatypeSnapshot]][Link-r4SonatypeSnapshot] |
| org.hl7.fhir.r5 | [![Release Artifacts][Badge-r5SonatypeRelease]][Link-r5SonatypeRelease] | [![Snapshot Artifact][Badge-r5SonatypeSnapshot]][Link-r5SonatypeSnapshot] |
### Building this Project
This project uses [Apache Maven](http://maven.apache.org) to build. To build:
@ -25,6 +30,11 @@ To skip unit tests:
```
mvn -Dmaven.test.skip install
```
### Publishing Binaries
An brief overview of our publishing process is [here][Link-Publishing].
For more detailed instructions on cutting a release, please read [the wiki][Link-PublishingRelease]
### Download
##### org.hl7.fhir.validation.cli
@ -42,6 +52,36 @@ mvn -Dmaven.test.skip install
compile group: 'ca.uhn.hapi.fhir', name: 'org.hl7.fhir.validation.cli', version: '(latest version)'
```
##### org.hl7.fhir.dstu2
###### Maven
```xml
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2</artifactId>
<version>(latest version)</version>
</dependency>
```
###### Gradle
```groovy
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-structures-dstu2', version: '(latest version)'
```
##### org.hl7.fhir.dstu3
###### Maven
```xml
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu3</artifactId>
<version>(latest version)</version>
</dependency>
```
###### Gradle
```groovy
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-structures-dstu3', version: '(latest version)'
```
##### org.hl7.fhir.r4
###### Maven
```xml
@ -76,24 +116,41 @@ compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-structures-r5', version: '(l
This project is maintained by [Grahame Grieve][Link-grahameGithub] and [James Agnew][Link-jamesGithub] on behalf of the FHIR community.
[Link-AzureProject]: https://dev.azure.com/fhir-pipelines/fhir-core-library
[Link-BuildPipeline]: https://dev.azure.com/fhir-pipelines/fhir-core-library/_build/latest?definitionId=16&branchName=master
[Link-BuildPipeline]: https://dev.azure.com/fhir-pipelines/fhir-core-library/_build/latest?definitionId=29&branchName=master
[Link-SnapshotPipeline]: https://dev.azure.com/fhir-pipelines/fhir-core-library/_build/latest?definitionId=17&branchName=master
[Link-dstu2SonatypeSnapshot]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.dstu2&v=LATEST "Sonatype Snapshot"
[Link-dstu2SonatypeRelease]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.dstu2&v=LATEST "Sonatype Release"
[Link-dstu2016maySonatypeSnapshot]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.dstu2016may&v=LATEST "Sonatype Snapshot"
[Link-dstu2016maySonatypeRelease]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.dstu2016may&v=LATEST "Sonatype Release"
[Link-dstu3SonatypeSnapshot]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.dstu3&v=LATEST "Sonatype Snapshot"
[Link-dstu3SonatypeRelease]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.dstu3&v=LATEST "Sonatype Release"
[Link-r4SonatypeSnapshot]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.r4&v=LATEST "Sonatype Snapshot"
[Link-r4SonatypeRelease]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.r4&v=LATEST "Sonatype Release"
[Link-r5SonatypeSnapshot]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.r5&v=LATEST "Sonatype Snapshot"
[Link-r5SonatypeRelease]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.r5&v=LATEST "Sonatype Release"
[Link-cliSonatypeSnapshot]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation.cli&v=LATEST "Sonatype Snapshot"
[Link-cliSonatypeRelease]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation.cli&v=LATEST "Sonatype Release"
[Link-cliSonatypeRelease]: https://github.com/hapifhir/org.hl7.fhir.core/releases/latest/download/validator_cli.jar
[Link-validationSonatypeSnapshot]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation&v=LATEST "Sonatype Snapshot"
[Link-validationSonatypeRelease]: https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation&v=LATEST "Sonatype Release"
[Link-grahameGithub]: https://github.com/grahamegrieve
[Link-jamesGithub]: https://github.com/jamesagnew
[Link-Publishing]: https://github.com/FHIR/fhir-test-cases/wiki/Publishing-Binaries
[Link-PublishingRelease]: https://github.com/FHIR/fhir-test-cases/wiki/Detailed-Release-Instructions
[Badge-BuildPipeline]: https://dev.azure.com/fhir-pipelines/fhir-core-library/_apis/build/status/Build%20%26%20Test?branchName=master
[Badge-BuildPipeline]: https://dev.azure.com/fhir-pipelines/fhir-core-library/_apis/build/status/Master%20Branch%20Pipeline?branchName=master
[Badge-SnapshotPipeline]: https://dev.azure.com/fhir-pipelines/fhir-core-library/_apis/build/status/Module%20SNAPSHOT%20Publisher?branchName=master
[Badge-dstu2SonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.dstu2.svg "Sonatype Releases"
[Badge-dstu2SonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.dstu2.svg "Sonatype Snapshots"
[Badge-dstu2016maySonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.dstu2016may.svg "Sonatype Releases"
[Badge-dstu2016maySonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.dstu2016may.svg "Sonatype Snapshots"
[Badge-dstu3SonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.dstu3.svg "Sonatype Releases"
[Badge-dstu3SonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.dstu3.svg "Sonatype Snapshots"
[Badge-r4SonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.r4.svg "Sonatype Releases"
[Badge-r4SonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.r4.svg "Sonatype Snapshots"
[Badge-r5SonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.r5.svg "Sonatype Releases"
[Badge-r5SonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.r5.svg "Sonatype Snapshots"
[Badge-cliSonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.validation.cli.svg "Sonatype Releases"
[Badge-cliSonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.validation.cli.svg "Sonatype Snapshots"
[Badge-validationSonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.validation.svg "Sonatype Releases"
[Badge-validationSonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.validation.svg "Sonatype Snapshots"

View File

@ -1,105 +0,0 @@
trigger: none
pr: none
# Different users have different machine setups, we run the build three times, on ubuntu, osx, and windows
strategy:
matrix:
linux:
imageName: 'ubuntu-latest'
mac:
imageName: "macos-10.15"
windows:
imageName: "windows-2019"
maxParallel: 3
pool:
vmImage: $(imageName)
variables:
currentImage: $(imageName)
codecov: $(CODECOV_TOKEN)
VERSION:
steps:
# This task pulls the <version> value from the org.hl7.fhir.r5 project pom.xml file. All modules are released as
# the same version, at the same time, as defined in the root level pom.xml.
- task: PowerShell@2
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
inputs:
targetType: 'inline'
script: |
[xml]$pomXml = Get-Content -Path .\pom.xml
# version
Write-Host $pomXml.project.version
$version=$pomXml.project.version
Write-Host "##vso[task.setvariable variable=version]$version"
# Prints out the build version, for debugging purposes
- bash: echo Pulled version from pom.xml => $(version)
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
# Azure pipelines cannot pass variables between pipelines, but it can pass files, so we
# pass the build id (ex: 1.1.13-SNAPSHOT) as a string in a file.
# This is used in the release pipeline, so we create it here.
# This is only done for the release branch.
- bash: |
echo $(version)
VERSION=$(version)
echo "$VERSION" > $(System.DefaultWorkingDirectory)/VERSION
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
# Copies the VERSION file containing the build id (ex: 1.1.13-SNAPSHOT) to the staging directory
# This is done for release versions only.
- task: CopyFiles@2
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(System.Defaultworkingdirectory)'
Contents: "$(System.DefaultWorkingDirectory)/VERSION"
TargetFolder: '$(build.artifactstagingdirectory)'
# Runs 'mvn clean package'
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
# Upload test results to codecov
- script: bash <(curl https://codecov.io/bash) -t $(codecov)
displayName: 'codecov Bash Uploader'
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
# Publishes the test results to build artifacts.
- task: PublishCodeCoverageResults@1
displayName: 'Publish JaCoCo test results '
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/org.hl7.fhir.report/target/site/jacoco-aggregate/jacoco.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/org.hl7.fhir.report/target/site/jacoco-aggregate/'
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
# Publishes the built Validator jar to build artifacts. Primarily for testing and debugging builds.
- task: PublishPipelineArtifact@1
displayName: 'Publish Validator jar'
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
inputs:
targetPath: "$(System.DefaultWorkingDirectory)/org.hl7.fhir.validation/target/org.hl7.fhir.validation-$(version).jar"
artifactName: Validator
# Publishes the files we've moved into the staging directory, so they can be accessed by the
# release pipeline. You will notice that we only do this for the ubuntu build, as doing it
# for each of the three release pipelines will cause conflicts.
# This is done for release versions only.
- task: PublishBuildArtifacts@1
condition: and(eq(variables.currentImage, 'ubuntu-latest'), eq(variables['Build.SourceBranch'], 'refs/heads/release'))
displayName: 'Publish Build Artifacts'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'

View File

@ -81,5 +81,5 @@ steps:
inputs:
mavenPomFile: '$(System.DefaultWorkingDirectory)/pom.xml'
goals: deploy
options: '--settings $(System.DefaultWorkingDirectory)/settings.xml'
options: '--settings $(System.DefaultWorkingDirectory)/settings.xml -Pdeploy'
publishJUnitResults: false

View File

@ -1,86 +0,0 @@
# This pipeline produces a SNAPSHOT build for each of the sub modules in
# the core library, and publishes them to ossrh.
trigger: none
pr: none
pool:
vmImage: "ubuntu-16.04"
variables:
currentModule: $(module)
steps:
# Signing, for now, occurs for all builds, SNAPSHOT or release. So we need a valid
# signing key. The next two steps download the public and private keys from the
# secure library files.
- task: DownloadSecureFile@1
displayName: 'Download public key.'
inputs:
secureFile: public.key
- task: DownloadSecureFile@1
displayName: 'Download private key.'
inputs:
secureFile: private.key
# Import both the private and public keys into gpg for signing.
- bash: |
gpg --import --no-tty --batch --yes $(Agent.TempDirectory)/public.key
gpg --import --no-tty --batch --yes $(Agent.TempDirectory)/private.key
gpg --list-keys --keyid-format LONG
gpg --list-secret-keys --keyid-format LONG
displayName: 'Import signing keys.'
# For creating the snapshot release with maven, we need to build a fake settings.xml
# for it to read from. This is done for the master branch merges only.
- bash: |
cat >$(System.DefaultWorkingDirectory)/settings.xml <<EOL
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>ossrh</id>
<username>$(SONATYPE_USER)</username>
<password>$(SONATYPE_PASS)</password>
</server>
<server>
<id>sonatype-nexus-snapshots</id>
<username>$(SONATYPE_USER)</username>
<password>$(SONATYPE_PASS)</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>$(SONATYPE_USER)</username>
<password>$(SONATYPE_PASS)</password>
</server>
<server>
<id>$(PGP_KEYNAME)</id>
<passphrase>$(PGP_PASSPHRASE)</passphrase>
</server>
</servers>
<profiles>
<profile>
<id>release</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.keyname>$(PGP_KEYNAME)</gpg.keyname>
</properties>
</profile>
</profiles>
</settings>
EOL
displayName: 'Create .mvn/settings.xml'
# Deploy the SNAPSHOT artifact to sonatype nexus.
# This is done for the master branch merges only.
- task: Maven@3
displayName: 'Deploy $(module) to Sonatype staging'
inputs:
mavenPomFile: '$(System.DefaultWorkingDirectory)/pom.xml'
goals: deploy
options: '--settings $(System.DefaultWorkingDirectory)/settings.xml'
publishJUnitResults: false

View File

@ -30,10 +30,10 @@ package org.hl7.fhir.utilities;
*/
import org.apache.commons.io.FileUtils;
import org.hl7.fhir.exceptions.FHIRException;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -42,7 +42,6 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
@ -50,27 +49,18 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.hl7.fhir.exceptions.FHIRException;
import net.sf.saxon.TransformerFactoryImpl;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class Utilities {
// private static final String TOKEN_REGEX = "^a-z[A-Za-z0-9]*$";
private static final String OID_REGEX = "[0-2](\\.(0|[1-9][0-9]*))+";
/**
* Returns the plural form of the word in the string.
*
* <p>
* Examples:
*
* <pre>
@ -81,17 +71,16 @@ public class Utilities {
* inflector.pluralize(&quot;the blue mailman&quot;) #=&gt; &quot;the blue mailmen&quot;
* inflector.pluralize(&quot;CamelOctopus&quot;) #=&gt; &quot;CamelOctopi&quot;
* </pre>
*
*
*
* <p>
* <p>
* <p>
* Note that if the {@link Object#toString()} is called on the supplied object, so this method works for non-strings, too.
*
*
* @param word the word that is to be pluralized.
* @return the pluralized form of the word, or the word itself if it could not be pluralized
* @see #singularize(Object)
*/
public static String pluralizeMe( String word ) {
public static String pluralizeMe(String word) {
Inflector inf = new Inflector();
return inf.pluralize(word);
}
@ -153,7 +142,7 @@ public class Utilities {
public static boolean isHex(String string) {
try {
int i = Integer.parseInt(string, 16);
return i != i+1;
return i != i + 1;
} catch (Exception e) {
return false;
}
@ -208,11 +197,11 @@ public class Utilities {
havePeriod = true;
preDecLength = length;
length = 0;
} else if (next == '-' || next == '+' ) {
} else if (next == '-' || next == '+') {
if (haveDigits || haveSign)
return DecimalStatus.SYNTAX;
haveSign = true;
} else if (next == 'e' || next == 'E' ) {
} else if (next == 'e' || next == 'E') {
if (!haveDigits || haveExponent || !allowExponent)
return DecimalStatus.SYNTAX;
haveExponent = true;
@ -285,11 +274,10 @@ public class Utilities {
return b.toString();
}
public static String capitalize(String s)
{
if( s == null ) return null;
if( s.length() == 0 ) return s;
if( s.length() == 1 ) return s.toUpperCase();
public static String capitalize(String s) {
if (s == null) return null;
if (s.length() == 0) return s;
if (s.length() == 1) return s.toUpperCase();
return s.substring(0, 1).toUpperCase() + s.substring(1);
}
@ -297,18 +285,18 @@ public class Utilities {
public static void copyDirectory(String sourceFolder, String destFolder, FileNotifier notifier) throws IOException, FHIRException {
CSFile src = new CSFile(sourceFolder);
if (!src.exists())
throw new FHIRException("Folder " +sourceFolder+" not found");
throw new FHIRException("Folder " + sourceFolder + " not found");
createDirectory(destFolder);
String[] files = src.list();
for (String f : files) {
if (new CSFile(sourceFolder+File.separator+f).isDirectory()) {
if (new CSFile(sourceFolder + File.separator + f).isDirectory()) {
if (!f.startsWith(".")) // ignore .git files...
copyDirectory(sourceFolder+File.separator+f, destFolder+File.separator+f, notifier);
copyDirectory(sourceFolder + File.separator + f, destFolder + File.separator + f, notifier);
} else {
if (notifier != null)
notifier.copyFile(sourceFolder+File.separator+f, destFolder+File.separator+f);
copyFile(new CSFile(sourceFolder+File.separator+f), new CSFile(destFolder+File.separator+f));
notifier.copyFile(sourceFolder + File.separator + f, destFolder + File.separator + f);
copyFile(new CSFile(sourceFolder + File.separator + f), new CSFile(destFolder + File.separator + f));
}
}
}
@ -318,7 +306,7 @@ public class Utilities {
}
public static void copyFile(File sourceFile, File destFile) throws IOException {
if(!destFile.exists()) {
if (!destFile.exists()) {
if (!new CSFile(destFile.getParent()).exists()) {
createDirectory(destFile.getParent());
}
@ -332,22 +320,20 @@ public class Utilities {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally {
if(source != null) {
} finally {
if (source != null) {
source.close();
}
if(destination != null) {
if (destination != null) {
destination.close();
}
}
}
public static boolean checkFolder(String dir, List<String> errors)
throws IOException
{
throws IOException {
if (!new CSFile(dir).exists()) {
errors.add("Unable to find directory "+dir);
errors.add("Unable to find directory " + dir);
return false;
} else {
return true;
@ -355,11 +341,10 @@ public class Utilities {
}
public static boolean checkFile(String purpose, String dir, String file, List<String> errors)
throws IOException
{
if (!new CSFile(dir+file).exists()) {
throws IOException {
if (!new CSFile(dir + file).exists()) {
if (errors != null)
errors.add("Unable to find "+purpose+" file "+file+" in "+dir);
errors.add("Unable to find " + purpose + " file " + file + " in " + dir);
return false;
} else {
return true;
@ -401,7 +386,7 @@ public class Utilities {
if (files != null) {
for (String f : files) {
if (!existsInList(f, exemptions)) {
File fh = new CSFile(folder+File.separatorChar+f);
File fh = new CSFile(folder + File.separatorChar + f);
if (fh.isDirectory())
clearDirectory(fh.getAbsolutePath());
fh.delete();
@ -412,7 +397,7 @@ public class Utilities {
}
}
public static File createDirectory(String path) throws IOException{
public static File createDirectory(String path) throws IOException {
new CSFile(path).mkdirs();
return new File(path);
}
@ -421,12 +406,11 @@ public class Utilities {
if (name.lastIndexOf('.') > -1)
return name.substring(0, name.lastIndexOf('.')) + ext;
else
return name+ext;
return name + ext;
}
public static String cleanupTextString( String contents )
{
if( contents == null || contents.trim().equals("") )
public static String cleanupTextString(String contents) {
if (contents == null || contents.trim().equals(""))
return null;
else
return contents.trim();
@ -438,8 +422,6 @@ public class Utilities {
}
public static void bytesToFile(byte[] content, String filename) throws IOException {
FileOutputStream out = new FileOutputStream(filename);
out.write(content);
@ -448,13 +430,12 @@ public class Utilities {
}
public static String appendSlash(String definitions) {
return definitions.endsWith(File.separator) ? definitions : definitions+File.separator;
return definitions.endsWith(File.separator) ? definitions : definitions + File.separator;
}
public static String appendForwardSlash(String definitions) {
return definitions.endsWith("/") ? definitions : definitions+"/";
return definitions.endsWith("/") ? definitions : definitions + "/";
}
@ -462,12 +443,11 @@ public class Utilities {
if (file == null)
return null;
String s = new File(file).getName();
return s.indexOf(".") == -1? s : s.substring(0, s.indexOf("."));
return s.indexOf(".") == -1 ? s : s.substring(0, s.indexOf("."));
}
public static String systemEol()
{
public static String systemEol() {
return System.getProperty("line.separator");
}
@ -499,9 +479,9 @@ public class Utilities {
else if (e.toString().equals("quot"))
b.append("\"");
else if (e.toString().equals("mu"))
b.append((char)956);
b.append((char) 956);
else
throw new FHIRException("unknown XML entity \""+e.toString()+"\"");
throw new FHIRException("unknown XML entity \"" + e.toString() + "\"");
} else
b.append(xml.charAt(i));
i++;
@ -545,11 +525,11 @@ public class Utilities {
b.append('\t');
break;
case 'u':
String hex = json.substring(i+1, i+5);
String hex = json.substring(i + 1, i + 5);
b.append((char) Integer.parseInt(hex, 16));
break;
default:
throw new FHIRException("Unknown JSON escape \\"+ch);
throw new FHIRException("Unknown JSON escape \\" + ch);
}
} else
b.append(json.charAt(i));
@ -591,7 +571,7 @@ public class Utilities {
StringBuilder s = new StringBuilder();
boolean d = false;
boolean first = true;
for(String arg: args) {
for (String arg : args) {
if (first && arg == null)
continue;
first = false;
@ -609,7 +589,7 @@ public class Utilities {
}
} else if ("[user]".equals(a)) {
a = System.getProperty("user.home");
} else if (a.startsWith("[") && a.endsWith("]")){
} else if (a.startsWith("[") && a.endsWith("]")) {
String ev = System.getenv(a.replace("[", "").replace("]", ""));
if (ev != null) {
a = ev;
@ -623,22 +603,22 @@ public class Utilities {
if (s.length() > 0 && a.startsWith(File.separator))
a = a.substring(File.separator.length());
while (a.startsWith(".."+File.separator)) {
while (a.startsWith(".." + File.separator)) {
if (s.length() == 0) {
s = new StringBuilder(Paths.get(".").toAbsolutePath().normalize().toString());
} else {
String p = s.toString().substring(0, s.length()-1);
String p = s.toString().substring(0, s.length() - 1);
if (!p.contains(File.separator)) {
s = new StringBuilder();
} else {
s = new StringBuilder(p.substring(0, p.lastIndexOf(File.separator))+File.separator);
s = new StringBuilder(p.substring(0, p.lastIndexOf(File.separator)) + File.separator);
}
}
a = a.substring(3);
}
if ("..".equals(a)) {
int i = s.substring(0, s.length()-1).lastIndexOf(File.separator);
s = new StringBuilder(s.substring(0, i+1));
int i = s.substring(0, s.length() - 1).lastIndexOf(File.separator);
s = new StringBuilder(s.substring(0, i + 1));
} else
s.append(a);
}
@ -656,7 +636,7 @@ public class Utilities {
public static String pathURL(String... args) {
StringBuilder s = new StringBuilder();
boolean d = false;
for(String arg: args) {
for (String arg : args) {
if (!d)
d = !noString(arg);
else if (!s.toString().endsWith("/") && !arg.startsWith("/"))
@ -667,7 +647,6 @@ public class Utilities {
}
// public static void checkCase(String filename) {
// File f = new CSFile(filename);
// if (!f.getName().equals(filename))
@ -684,7 +663,7 @@ public class Utilities {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
s.append(c);
else if (c != ' ')
s.append("."+Integer.toString(c));
s.append("." + Integer.toString(c));
}
return s.toString();
}
@ -722,7 +701,7 @@ public class Utilities {
s = s.trim();
if (s.endsWith(".") || s.endsWith("?"))
return s;
return s+".";
return s + ".";
}
@ -730,7 +709,7 @@ public class Utilities {
if (Utilities.noString(s))
return s;
if (s.endsWith("."))
return s.substring(0, s.length()-1);
return s.substring(0, s.length() - 1);
return s;
}
@ -743,7 +722,7 @@ public class Utilities {
public static String oidTail(String id) {
if (id == null || !id.contains("."))
return id;
return id.substring(id.lastIndexOf(".")+1);
return id.substring(id.lastIndexOf(".") + 1);
}
@ -785,7 +764,7 @@ public class Utilities {
b.append(Character.toLowerCase(name.charAt(i)));
}
parts.add(b.toString());
return parts.toArray(new String[] {} );
return parts.toArray(new String[]{});
}
@ -794,7 +773,6 @@ public class Utilities {
}
public static String normalize(String s) {
if (noString(s))
return null;
@ -921,7 +899,7 @@ public class Utilities {
public static File createTempFile(String prefix, String suffix) throws IOException {
// this allows use to eaily identify all our dtemp files and delete them, since delete on Exit doesn't really work.
File file = File.createTempFile("ohfu-"+prefix, suffix);
File file = File.createTempFile("ohfu-" + prefix, suffix);
file.deleteOnExit();
return file;
}
@ -937,7 +915,7 @@ public class Utilities {
}
public static String makeUuidUrn() {
return "urn:uuid:"+UUID.randomUUID().toString().toLowerCase();
return "urn:uuid:" + UUID.randomUUID().toString().toLowerCase();
}
public static boolean isURL(String s) {
@ -963,7 +941,7 @@ public class Utilities {
else if (c == '\\')
b.append("\\\\");
else if (((int) c) < 32)
b.append("\\u"+Utilities.padLeft(String.valueOf((int) c), '0', 4));
b.append("\\u" + Utilities.padLeft(String.valueOf((int) c), '0', 4));
else
b.append(c);
}
@ -996,9 +974,9 @@ public class Utilities {
public static String uncapitalize(String s) {
if( s == null ) return null;
if( s.length() == 0 ) return s;
if( s.length() == 1 ) return s.toLowerCase();
if (s == null) return null;
if (s.length() == 0) return s;
if (s.length() == 1) return s.toLowerCase();
return s.substring(0, 1).toLowerCase() + s.substring(1);
}
@ -1013,8 +991,6 @@ public class Utilities {
}
public static boolean isOid(String cc) {
return cc.matches(OID_REGEX) && cc.lastIndexOf('.') >= 5;
}
@ -1033,10 +1009,10 @@ public class Utilities {
File src = new File(folder);
String[] files = src.list();
for (String f : files) {
if (new File(folder+File.separator+f).isDirectory()) {
deleteAllFiles(folder+File.separator+f, type);
if (new File(folder + File.separator + f).isDirectory()) {
deleteAllFiles(folder + File.separator + f, type);
} else if (f.endsWith(type)) {
new File(folder+File.separator+f).delete();
new File(folder + File.separator + f).delete();
}
}
@ -1074,12 +1050,14 @@ public class Utilities {
if (in1 != null) {
try {
in1.close();
} catch (IOException e) {}
} catch (IOException e) {
}
}
if (in2 != null) {
try {
in2.close();
} catch (IOException e) {}
} catch (IOException e) {
}
}
}
}
@ -1095,7 +1073,7 @@ public class Utilities {
public static boolean isAbsoluteUrl(String ref) {
return ref != null && (ref.startsWith("http:") || ref.startsWith("https:") || ref.startsWith("urn:uuid:") || ref.startsWith("urn:oid:")) ;
return ref != null && (ref.startsWith("http:") || ref.startsWith("https:") || ref.startsWith("urn:uuid:") || ref.startsWith("urn:oid:"));
}
@ -1120,7 +1098,7 @@ public class Utilities {
public static String getFileExtension(String fn) {
return fn.contains(".") ? fn.substring(fn.lastIndexOf(".")+1) : "";
return fn.contains(".") ? fn.substring(fn.lastIndexOf(".") + 1) : "";
}
@ -1162,7 +1140,7 @@ public class Utilities {
if (i == 0)
break;
list.add(line.substring(0, i));
line = line.substring(i+1);
line = line.substring(i + 1);
}
list.add(line);
StringBuilder b = new StringBuilder();
@ -1171,7 +1149,7 @@ public class Utilities {
if (first)
first = false;
else
b.append("\r\n"+padLeft("", ' ', indent));
b.append("\r\n" + padLeft("", ' ', indent));
b.append(s);
}
return b.toString();
@ -1269,14 +1247,14 @@ public class Utilities {
while (i < p.length) {
String s = p[i];
if (s.contains("[")) {
String si = s.substring(s.indexOf("[")+1, s.length()-1);
String si = s.substring(s.indexOf("[") + 1, s.length() - 1);
if (!Utilities.isInteger(si))
throw new FHIRException("The FHIRPath expression '"+path+"' is not valid");
s = s.substring(0, s.indexOf("["))+"["+Integer.toString(Integer.parseInt(si)+1)+"]";
throw new FHIRException("The FHIRPath expression '" + path + "' is not valid");
s = s.substring(0, s.indexOf("[")) + "[" + Integer.toString(Integer.parseInt(si) + 1) + "]";
}
if (i < p.length - 1 && p[i+1].startsWith(".ofType(")) {
if (i < p.length - 1 && p[i + 1].startsWith(".ofType(")) {
i++;
s = s + capitalize(p[i].substring(8, p.length-1));
s = s + capitalize(p[i].substring(8, p.length - 1));
}
b.append(s);
i++;
@ -1309,5 +1287,4 @@ public class Utilities {
}
}

40
pom.xml
View File

@ -311,6 +311,29 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
@ -329,21 +352,8 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>