Merge branch 'generic-tinder-from-model'
This commit is contained in:
commit
0c0729711f
|
@ -1,187 +1,211 @@
|
||||||
package ca.uhn.fhir.tinder;
|
package ca.uhn.fhir.tinder;
|
||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR Tinder Plug-In
|
* HAPI FHIR Tinder Plug-In
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2016 University Health Network
|
* Copyright (C) 2014 - 2016 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||||
|
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingModel;
|
||||||
import java.io.IOException;
|
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||||
import java.util.*;
|
|
||||||
|
import java.io.IOException;
|
||||||
public abstract class AbstractGenerator {
|
import java.util.*;
|
||||||
|
|
||||||
protected abstract void logDebug (String message);
|
public abstract class AbstractGenerator {
|
||||||
|
|
||||||
protected abstract void logInfo (String message);
|
protected abstract void logDebug (String message);
|
||||||
|
|
||||||
public void prepare (GeneratorContext context) throws ExecutionException, FailureException {
|
protected abstract void logInfo (String message);
|
||||||
|
|
||||||
/*
|
public void prepare (GeneratorContext context) throws ExecutionException, FailureException {
|
||||||
* Deal with the FHIR spec version
|
|
||||||
*/
|
/*
|
||||||
FhirContext fhirContext;
|
* Deal with the FHIR spec version
|
||||||
String packageSuffix = "";
|
*/
|
||||||
if ("dstu2".equals(context.getVersion())) {
|
FhirContext fhirContext;
|
||||||
fhirContext = FhirContext.forDstu2();
|
String packageSuffix = "";
|
||||||
} else if ("dstu3".equals(context.getVersion())) {
|
if ("dstu2".equals(context.getVersion())) {
|
||||||
fhirContext = FhirContext.forDstu3();
|
fhirContext = FhirContext.forDstu2();
|
||||||
packageSuffix = ".dstu3";
|
} else if ("dstu3".equals(context.getVersion())) {
|
||||||
} else {
|
fhirContext = FhirContext.forDstu3();
|
||||||
throw new FailureException("Unknown version configured: " + context.getVersion());
|
packageSuffix = ".dstu3";
|
||||||
}
|
} else if ("r4".equals(context.getVersion())) {
|
||||||
context.setPackageSuffix(packageSuffix);
|
fhirContext = FhirContext.forR4();
|
||||||
|
packageSuffix = ".r4";
|
||||||
/*
|
} else {
|
||||||
* Deal with which resources to process
|
throw new FailureException("Unknown version configured: " + context.getVersion());
|
||||||
*/
|
}
|
||||||
List<String> includeResources = context.getIncludeResources();
|
context.setPackageSuffix(packageSuffix);
|
||||||
List<String> excludeResources = context.getExcludeResources();
|
|
||||||
|
/*
|
||||||
if (includeResources == null || includeResources.isEmpty()) {
|
* Deal with which resources to process
|
||||||
includeResources = new ArrayList<String>();
|
*/
|
||||||
|
List<String> includeResources = context.getIncludeResources();
|
||||||
logInfo("No resource names supplied, going to use all resources from version: "+fhirContext.getVersion().getVersion());
|
List<String> excludeResources = context.getExcludeResources();
|
||||||
|
|
||||||
Properties p = new Properties();
|
if (includeResources == null || includeResources.isEmpty()) {
|
||||||
try {
|
includeResources = new ArrayList<String>();
|
||||||
p.load(fhirContext.getVersion().getFhirVersionPropertiesFile());
|
|
||||||
} catch (IOException e) {
|
logInfo("No resource names supplied, going to use all resources from version: "+fhirContext.getVersion().getVersion());
|
||||||
throw new FailureException("Failed to load version property file", e);
|
|
||||||
}
|
Properties p = new Properties();
|
||||||
|
try {
|
||||||
logDebug("Property file contains: "+p);
|
p.load(fhirContext.getVersion().getFhirVersionPropertiesFile());
|
||||||
|
} catch (IOException e) {
|
||||||
TreeSet<String> keys = new TreeSet<String>();
|
throw new FailureException("Failed to load version property file", e);
|
||||||
for(Object next : p.keySet()) {
|
}
|
||||||
keys.add((String) next);
|
|
||||||
}
|
logDebug("Property file contains: "+p);
|
||||||
for (String next : keys) {
|
|
||||||
if (next.startsWith("resource.")) {
|
TreeSet<String> keys = new TreeSet<String>();
|
||||||
includeResources.add(next.substring("resource.".length()).toLowerCase());
|
for(Object next : p.keySet()) {
|
||||||
}
|
keys.add((String) next);
|
||||||
}
|
}
|
||||||
|
for (String next : keys) {
|
||||||
if (fhirContext.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
|
if (next.startsWith("resource.")) {
|
||||||
includeResources.remove("conformance");
|
includeResources.add(next.substring("resource.".length()).toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < includeResources.size(); i++) {
|
if (fhirContext.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
|
||||||
includeResources.set(i, includeResources.get(i).toLowerCase());
|
includeResources.remove("conformance");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (excludeResources != null) {
|
|
||||||
for (int i = 0; i < excludeResources.size(); i++) {
|
for (int i = 0; i < includeResources.size(); i++) {
|
||||||
excludeResources.set(i, excludeResources.get(i).toLowerCase());
|
includeResources.set(i, includeResources.get(i).toLowerCase());
|
||||||
}
|
}
|
||||||
includeResources.removeAll(excludeResources);
|
|
||||||
}
|
if (excludeResources != null) {
|
||||||
context.setIncludeResources(includeResources);
|
for (int i = 0; i < excludeResources.size(); i++) {
|
||||||
|
excludeResources.set(i, excludeResources.get(i).toLowerCase());
|
||||||
logInfo("Including the following elements: "+includeResources);
|
}
|
||||||
|
includeResources.removeAll(excludeResources);
|
||||||
|
}
|
||||||
/*
|
context.setIncludeResources(includeResources);
|
||||||
* Fill in ValueSet and DataTypes used by the resources
|
|
||||||
*/
|
logInfo("Including the following elements: "+includeResources);
|
||||||
ValueSetGenerator vsp = null;
|
|
||||||
DatatypeGeneratorUsingSpreadsheet dtp = null;
|
|
||||||
Map<String, String> datatypeLocalImports = new HashMap<String, String>();
|
/*
|
||||||
|
* Fill in ValueSet and DataTypes used by the resources
|
||||||
vsp = new ValueSetGenerator(context.getVersion());
|
*/
|
||||||
vsp.setResourceValueSetFiles(context.getValueSetFiles());
|
ValueSetGenerator vsp = null;
|
||||||
context.setValueSetGenerator(vsp);
|
DatatypeGeneratorUsingSpreadsheet dtp = null;
|
||||||
try {
|
Map<String, String> datatypeLocalImports = new HashMap<String, String>();
|
||||||
vsp.parse();
|
|
||||||
} catch (Exception e) {
|
vsp = new ValueSetGenerator(context.getVersion());
|
||||||
throw new FailureException("Failed to load valuesets", e);
|
vsp.setResourceValueSetFiles(context.getValueSetFiles());
|
||||||
}
|
context.setValueSetGenerator(vsp);
|
||||||
|
try {
|
||||||
/*
|
vsp.parse();
|
||||||
* A few enums are not found by default because none of the generated classes
|
} catch (Exception e) {
|
||||||
* refer to them, but we still want them.
|
throw new FailureException("Failed to load valuesets", e);
|
||||||
*/
|
}
|
||||||
vsp.getClassForValueSetIdAndMarkAsNeeded("NarrativeStatus");
|
|
||||||
|
/*
|
||||||
logInfo("Loading Datatypes...");
|
* A few enums are not found by default because none of the generated classes
|
||||||
|
* refer to them, but we still want them.
|
||||||
dtp = new DatatypeGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
*/
|
||||||
context.setDatatypeGenerator(dtp);
|
vsp.getClassForValueSetIdAndMarkAsNeeded("NarrativeStatus");
|
||||||
try {
|
|
||||||
dtp.parse();
|
logInfo("Loading Datatypes...");
|
||||||
dtp.markResourcesForImports();
|
|
||||||
} catch (Exception e) {
|
dtp = new DatatypeGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
||||||
throw new FailureException("Failed to load datatypes", e);
|
context.setDatatypeGenerator(dtp);
|
||||||
}
|
try {
|
||||||
dtp.bindValueSets(vsp);
|
dtp.parse();
|
||||||
|
dtp.markResourcesForImports();
|
||||||
datatypeLocalImports = dtp.getLocalImports();
|
} catch (Exception e) {
|
||||||
|
throw new FailureException("Failed to load datatypes", e);
|
||||||
/*
|
}
|
||||||
* Load the requested resources
|
dtp.bindValueSets(vsp);
|
||||||
*/
|
|
||||||
ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
datatypeLocalImports = dtp.getLocalImports();
|
||||||
context.setResourceGenerator(rp);
|
|
||||||
logInfo("Loading Resources...");
|
/*
|
||||||
try {
|
* Load the requested resources
|
||||||
rp.setBaseResourceNames(includeResources);
|
*/
|
||||||
rp.parse();
|
|
||||||
rp.markResourcesForImports();
|
logInfo("Loading Resources...");
|
||||||
} catch (Exception e) {
|
try {
|
||||||
throw new FailureException("Failed to load resources", e);
|
switch (context.getResourceSource()) {
|
||||||
}
|
case SPREADSHEET: {
|
||||||
|
logInfo("... resource definitions from spreadsheets");
|
||||||
rp.bindValueSets(vsp);
|
ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
||||||
rp.getLocalImports().putAll(datatypeLocalImports);
|
context.setResourceGenerator(rp);
|
||||||
datatypeLocalImports.putAll(rp.getLocalImports());
|
|
||||||
rp.combineContentMaps(dtp);
|
rp.setBaseResourceNames(includeResources);
|
||||||
dtp.combineContentMaps(rp);
|
rp.parse();
|
||||||
|
|
||||||
}
|
rp.markResourcesForImports();
|
||||||
|
rp.bindValueSets(vsp);
|
||||||
public class FailureException extends Exception {
|
|
||||||
|
rp.getLocalImports().putAll(datatypeLocalImports);
|
||||||
public FailureException(String message, Throwable cause) {
|
datatypeLocalImports.putAll(rp.getLocalImports());
|
||||||
super(message, cause);
|
|
||||||
}
|
rp.combineContentMaps(dtp);
|
||||||
public FailureException(Throwable cause) {
|
dtp.combineContentMaps(rp);
|
||||||
super(cause);
|
break;
|
||||||
}
|
}
|
||||||
|
case MODEL: {
|
||||||
public FailureException(String message) {
|
logInfo("... resource definitions from model structures");
|
||||||
super(message);
|
ResourceGeneratorUsingModel rp = new ResourceGeneratorUsingModel(context.getVersion(), context.getBaseDir());
|
||||||
}
|
context.setResourceGenerator(rp);
|
||||||
|
|
||||||
}
|
rp.setBaseResourceNames(includeResources);
|
||||||
|
rp.parse();
|
||||||
public class ExecutionException extends Exception {
|
break;
|
||||||
|
}
|
||||||
public ExecutionException(String message, Throwable cause) {
|
}
|
||||||
super(message, cause);
|
} catch (Exception e) {
|
||||||
}
|
throw new FailureException("Failed to load resources", e);
|
||||||
|
}
|
||||||
public ExecutionException(String message) {
|
|
||||||
super(message);
|
}
|
||||||
}
|
|
||||||
|
public static class FailureException extends Exception {
|
||||||
}
|
|
||||||
}
|
public FailureException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
public FailureException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FailureException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ExecutionException extends Exception {
|
||||||
|
|
||||||
|
public ExecutionException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExecutionException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,137 +1,169 @@
|
||||||
package ca.uhn.fhir.tinder;
|
package ca.uhn.fhir.tinder;
|
||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR Tinder Plug-In
|
* HAPI FHIR Tinder Plug-In
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2016 University Health Network
|
* Copyright (C) 2014 - 2016 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
import java.util.List;
|
||||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
|
||||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
import javax.security.auth.login.FailedLoginException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import java.util.List;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
|
||||||
/**
|
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||||
* @author Bill.Denton
|
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||||
*
|
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||||
*/
|
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||||
public class GeneratorContext {
|
|
||||||
private String version;
|
/**
|
||||||
private String packageSuffix;
|
* @author Bill.Denton
|
||||||
private String baseDir;
|
*
|
||||||
private List<String> includeResources;
|
*/
|
||||||
private List<String> excludeResources;
|
public class GeneratorContext {
|
||||||
private List<ValueSetFileDefinition> valueSetFiles;
|
public enum ResourceSource {SPREADSHEET, MODEL};
|
||||||
private ResourceGeneratorUsingSpreadsheet resourceGenerator = null;
|
public static final ResourceSource DEFAULT_RESOURCE_SOURCE = ResourceSource.SPREADSHEET;
|
||||||
private ValueSetGenerator valueSetGenerator = null;
|
|
||||||
private DatatypeGeneratorUsingSpreadsheet datatypeGenerator = null;
|
private String version;
|
||||||
|
private String packageSuffix;
|
||||||
public String getBaseDir() {
|
private String baseDir;
|
||||||
return baseDir;
|
private List<String> includeResources;
|
||||||
}
|
private List<String> excludeResources;
|
||||||
|
private ResourceSource resourceSource = DEFAULT_RESOURCE_SOURCE;
|
||||||
public void setBaseDir(String baseDir) {
|
private List<ValueSetFileDefinition> valueSetFiles;
|
||||||
this.baseDir = baseDir;
|
private BaseStructureParser resourceGenerator = null;
|
||||||
}
|
private ValueSetGenerator valueSetGenerator = null;
|
||||||
|
private DatatypeGeneratorUsingSpreadsheet datatypeGenerator = null;
|
||||||
public DatatypeGeneratorUsingSpreadsheet getDatatypeGenerator() {
|
|
||||||
return datatypeGenerator;
|
public String getBaseDir() {
|
||||||
}
|
return baseDir;
|
||||||
|
}
|
||||||
public void setDatatypeGenerator(DatatypeGeneratorUsingSpreadsheet datatypeGenerator) {
|
|
||||||
this.datatypeGenerator = datatypeGenerator;
|
public void setBaseDir(String baseDir) {
|
||||||
}
|
this.baseDir = baseDir;
|
||||||
|
}
|
||||||
public List<String> getExcludeResources() {
|
|
||||||
return excludeResources;
|
public DatatypeGeneratorUsingSpreadsheet getDatatypeGenerator() {
|
||||||
}
|
return datatypeGenerator;
|
||||||
|
}
|
||||||
public void setExcludeResources(List<String> excludeResources) {
|
|
||||||
this.excludeResources = excludeResources;
|
public void setDatatypeGenerator(DatatypeGeneratorUsingSpreadsheet datatypeGenerator) {
|
||||||
}
|
this.datatypeGenerator = datatypeGenerator;
|
||||||
|
}
|
||||||
public List<String> getIncludeResources() {
|
|
||||||
return includeResources;
|
public List<String> getExcludeResources() {
|
||||||
}
|
return excludeResources;
|
||||||
public void setIncludeResources(List<String> includeResources) {
|
}
|
||||||
this.includeResources = includeResources;
|
|
||||||
}
|
public void setExcludeResources(List<String> excludeResources) {
|
||||||
|
this.excludeResources = excludeResources;
|
||||||
public String getPackageSuffix() {
|
}
|
||||||
return packageSuffix;
|
|
||||||
}
|
public List<String> getIncludeResources() {
|
||||||
|
return includeResources;
|
||||||
public void setPackageSuffix(String packageSuffix) {
|
}
|
||||||
this.packageSuffix = packageSuffix;
|
public void setIncludeResources(List<String> includeResources) {
|
||||||
}
|
this.includeResources = includeResources;
|
||||||
|
}
|
||||||
public ResourceGeneratorUsingSpreadsheet getResourceGenerator() {
|
|
||||||
return resourceGenerator;
|
public ResourceSource getResourceSource() {
|
||||||
}
|
return resourceSource;
|
||||||
|
}
|
||||||
public void setResourceGenerator(ResourceGeneratorUsingSpreadsheet resourceGenerator) {
|
|
||||||
this.resourceGenerator = resourceGenerator;
|
public void setResourceSource(ResourceSource resourceSource) {
|
||||||
}
|
this.resourceSource = resourceSource;
|
||||||
|
}
|
||||||
public List<ValueSetFileDefinition> getValueSetFiles() {
|
|
||||||
return valueSetFiles;
|
public void setResourceSource(String resourceSource) throws FailureException {
|
||||||
}
|
resourceSource = StringUtils.stripToNull(resourceSource);
|
||||||
|
if (null == resourceSource) {
|
||||||
public void setValueSetFiles(List<ValueSetFileDefinition> valueSetFiles) {
|
this.resourceSource = DEFAULT_RESOURCE_SOURCE;
|
||||||
this.valueSetFiles = valueSetFiles;
|
} else
|
||||||
}
|
if (ResourceSource.SPREADSHEET.name().equalsIgnoreCase(resourceSource)) {
|
||||||
|
this.resourceSource = ResourceSource.SPREADSHEET;
|
||||||
public ValueSetGenerator getValueSetGenerator() {
|
} else
|
||||||
return valueSetGenerator;
|
if (ResourceSource.MODEL.name().equalsIgnoreCase(resourceSource)) {
|
||||||
}
|
this.resourceSource = ResourceSource.MODEL;
|
||||||
public void setValueSetGenerator(ValueSetGenerator valueSetGenerator) {
|
} else {
|
||||||
this.valueSetGenerator = valueSetGenerator;
|
throw new FailureException("Unknown resource-source option: " + resourceSource);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
public String getPackageSuffix() {
|
||||||
}
|
return packageSuffix;
|
||||||
|
}
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
public void setPackageSuffix(String packageSuffix) {
|
||||||
}
|
this.packageSuffix = packageSuffix;
|
||||||
|
}
|
||||||
public static class ProfileFileDefinition {
|
|
||||||
@Parameter(required = true)
|
public BaseStructureParser getResourceGenerator() {
|
||||||
String profileFile;
|
return resourceGenerator;
|
||||||
|
}
|
||||||
@Parameter(required = true)
|
|
||||||
String profileSourceUrl;
|
public void setResourceGenerator(BaseStructureParser resourceGenerator) {
|
||||||
|
this.resourceGenerator = resourceGenerator;
|
||||||
public String getProfileFile() {
|
}
|
||||||
return profileFile;
|
|
||||||
}
|
public List<ValueSetFileDefinition> getValueSetFiles() {
|
||||||
|
return valueSetFiles;
|
||||||
public void setProfileFile(String profileFile) {
|
}
|
||||||
this.profileFile = profileFile;
|
|
||||||
}
|
public void setValueSetFiles(List<ValueSetFileDefinition> valueSetFiles) {
|
||||||
|
this.valueSetFiles = valueSetFiles;
|
||||||
public String getProfileSourceUrl() {
|
}
|
||||||
return profileSourceUrl;
|
|
||||||
}
|
public ValueSetGenerator getValueSetGenerator() {
|
||||||
|
return valueSetGenerator;
|
||||||
public void setProfileSourceUrl(String profileSourceUrl) {
|
}
|
||||||
this.profileSourceUrl = profileSourceUrl;
|
public void setValueSetGenerator(ValueSetGenerator valueSetGenerator) {
|
||||||
}
|
this.valueSetGenerator = valueSetGenerator;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProfileFileDefinition {
|
||||||
|
@Parameter(required = true)
|
||||||
|
String profileFile;
|
||||||
|
|
||||||
|
@Parameter(required = true)
|
||||||
|
String profileSourceUrl;
|
||||||
|
|
||||||
|
public String getProfileFile() {
|
||||||
|
return profileFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileFile(String profileFile) {
|
||||||
|
this.profileFile = profileFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProfileSourceUrl() {
|
||||||
|
return profileSourceUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileSourceUrl(String profileSourceUrl) {
|
||||||
|
this.profileSourceUrl = profileSourceUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,411 +1,424 @@
|
||||||
package ca.uhn.fhir.tinder;
|
package ca.uhn.fhir.tinder;
|
||||||
|
|
||||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
import java.io.File;
|
||||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
import java.io.IOException;
|
||||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
import java.util.List;
|
||||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
|
||||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
import org.apache.maven.model.Resource;
|
||||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.model.Resource;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugins.annotations.Component;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Component;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
|
||||||
import org.apache.maven.project.MavenProject;
|
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||||
|
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||||
import java.io.File;
|
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||||
import java.io.IOException;
|
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||||
import java.util.List;
|
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||||
|
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||||
/**
|
|
||||||
* Generate files from FHIR resource/composite metadata using Velocity templates.
|
/**
|
||||||
* <p>
|
* Generate files from FHIR resource/composite metadata using Velocity templates.
|
||||||
* Generates either source or resource files for each selected resource or
|
* <p>
|
||||||
* composite data type. One file is generated for each selected entity. The
|
* Generates either source or resource files for each selected resource or
|
||||||
* files are generated using a Velocity template that can be taken from
|
* composite data type. One file is generated for each selected entity. The
|
||||||
* inside the hapi-timder-plugin project or can be located in other projects
|
* files are generated using a Velocity template that can be taken from
|
||||||
* <p>
|
* inside the hapi-timder-plugin project or can be located in other projects
|
||||||
* The following Maven plug-in configuration properties are used with this plug-in
|
* <p>
|
||||||
* <p>
|
* The following Maven plug-in configuration properties are used with this plug-in
|
||||||
* <table border="1" cellpadding="2" cellspacing="0">
|
* <p>
|
||||||
* <tr>
|
* <table border="1" cellpadding="2" cellspacing="0">
|
||||||
* <td valign="top"><b>Attribute</b></td>
|
* <tr>
|
||||||
* <td valign="top"><b>Description</b></td>
|
* <td valign="top"><b>Attribute</b></td>
|
||||||
* <td align="center" valign="top"><b>Required</b></td>
|
* <td valign="top"><b>Description</b></td>
|
||||||
* </tr>
|
* <td align="center" valign="top"><b>Required</b></td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">version</td>
|
* <tr>
|
||||||
* <td valign="top">The FHIR version whose resource metadata
|
* <td valign="top">version</td>
|
||||||
* is to be used to generate the files<br>
|
* <td valign="top">The FHIR version whose resource metadata
|
||||||
* Valid values: <code><b>dstu</b></code> | <code><b>dstu2</b></code> | <code><b>dstu3</b></code></td>
|
* is to be used to generate the files<br>
|
||||||
* <td valign="top" align="center">Yes</td>
|
* Valid values: <code><b>dstu2</b></code> | <code><b>dstu3</b></code> | <code><b>r4</b></code></td>
|
||||||
* </tr>
|
* <td valign="top" align="center">Yes</td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">baseDir</td>
|
* <tr>
|
||||||
* <td valign="top">The Maven project's base directory. This is used to
|
* <td valign="top">baseDir</td>
|
||||||
* possibly locate other assets within the project used in file generation.</td>
|
* <td valign="top">The Maven project's base directory. This is used to
|
||||||
* <td valign="top" align="center">No. Defaults to: <code>${project.build.directory}/..</code></td>
|
* possibly locate other assets within the project used in file generation.</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No. Defaults to: <code>${project.build.directory}/..</code></td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">generateResources</td>
|
* <tr>
|
||||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
* <td valign="top">generateResources</td>
|
||||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
||||||
* <td valign="top" align="center" rowspan="4">One of these four options must be specified</td>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* </tr>
|
* <td valign="top" align="center" rowspan="4">One of these four options must be specified as <code><b>true</b></code></td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">generateDataTypes</td>
|
* <tr>
|
||||||
* <td valign="top">Should files be generated from FHIR composite data type metadata?<br>
|
* <td valign="top">generateDataTypes</td>
|
||||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
* <td valign="top">Should files be generated from FHIR composite data type metadata?<br>
|
||||||
* </tr>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">generateValueSets</td>
|
* <tr>
|
||||||
* <td valign="top">Should files be generated from FHIR value set metadata?<br>
|
* <td valign="top">generateValueSets</td>
|
||||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
* <td valign="top">Should files be generated from FHIR value set metadata?<br>
|
||||||
* </tr>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">generateProfiles</td>
|
* <tr>
|
||||||
* <td valign="top">Should files be generated from FHIR profile metadata?<br>
|
* <td valign="top">generateProfiles</td>
|
||||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
* <td valign="top">Should files be generated from FHIR profile metadata?<br>
|
||||||
* </tr>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td colspan="3" />
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top">resourceSource</td>
|
||||||
* <tr>
|
* <td valign="top">Which source of resource definitions should be processed? Valid values are:<br>
|
||||||
* <td valign="top" colspan="3">Java source files can be generated
|
* <ul>
|
||||||
* for FHIR resources or composite data types. There is one file
|
* <li><code><b>spreadsheet</b></code> to cause resources to be generated based on the FHIR spreadsheets</li>
|
||||||
* generated for each selected entity. The following configuration
|
* <li><code><b>model</b></code> to cause resources to be generated based on the model structure classes</li></ul></td>
|
||||||
* properties control the naming of the generated source files:<br>
|
* <td valign="top" align="center">No. Defaults to: <code><b>spreadsheet</b></code></td>
|
||||||
* <targetSourceDirectory>/<targetPackage>/<filenamePrefix><i>element-name</i><filenameSuffix><br>
|
* </tr>
|
||||||
* where: <i>element-name</i> is the "title-case" name of the selected resource or composite data type.<br>
|
* <tr>
|
||||||
* Note that all dots in the targetPackage will be replaced by the path separator character when building the
|
* <td colspan="3" />
|
||||||
* actual source file location. Also note that <code>.java</code> will be added to the filenameSuffix if it is not already included.
|
* </tr>
|
||||||
* </td>
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top" colspan="3">Java source files can be generated
|
||||||
* <tr>
|
* for FHIR resources or composite data types. There is one file
|
||||||
* <td valign="top">targetSourceDirectory</td>
|
* generated for each selected entity. The following configuration
|
||||||
* <td valign="top">The Maven source directory to contain the generated files.</td>
|
* properties control the naming of the generated source files:<br>
|
||||||
* <td valign="top" align="center">Yes when Java source files are to be generated</td>
|
* <targetSourceDirectory>/<targetPackage>/<filenamePrefix><i>element-name</i><filenameSuffix><br>
|
||||||
* </tr>
|
* where: <i>element-name</i> is the "title-case" name of the selected resource or composite data type.<br>
|
||||||
* <tr>
|
* Note that all dots in the targetPackage will be replaced by the path separator character when building the
|
||||||
* <td valign="top">targetPackage</td>
|
* actual source file location. Also note that <code>.java</code> will be added to the filenameSuffix if it is not already included.
|
||||||
* <td valign="top">The Java package that will contain the generated classes.
|
* </td>
|
||||||
* This package is generated in the <targetSourceDirectory> if needed.</td>
|
* </tr>
|
||||||
* <td valign="top" align="center">Yes when <i>targetSourceDirectory</i> is specified</td>
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top">targetSourceDirectory</td>
|
||||||
* <tr>
|
* <td valign="top">The Maven source directory to contain the generated files.</td>
|
||||||
* <td valign="top">filenamePrefix</td>
|
* <td valign="top" align="center">Yes when Java source files are to be generated</td>
|
||||||
* <td valign="top">The prefix string that is to be added onto the
|
* </tr>
|
||||||
* beginning of the resource or composite data type name to become
|
* <tr>
|
||||||
* the Java class name or resource file name.</td>
|
* <td valign="top">targetPackage</td>
|
||||||
* <td valign="top" align="center">No</td>
|
* <td valign="top">The Java package that will contain the generated classes.
|
||||||
* </tr>
|
* This package is generated in the <targetSourceDirectory> if needed.</td>
|
||||||
* <tr>
|
* <td valign="top" align="center">Yes when <i>targetSourceDirectory</i> is specified</td>
|
||||||
* <td valign="top">filenameSuffix</td>
|
* </tr>
|
||||||
* <td valign="top">Suffix that will be added onto the end of the resource
|
* <tr>
|
||||||
* or composite data type name to become the Java class name or resource file name.</td>
|
* <td valign="top">filenamePrefix</td>
|
||||||
* <td valign="top" align="center">No.</code></td>
|
* <td valign="top">The prefix string that is to be added onto the
|
||||||
* </tr>
|
* beginning of the resource or composite data type name to become
|
||||||
* <tr>
|
* the Java class name or resource file name.</td>
|
||||||
* <td colspan="3" />
|
* <td valign="top" align="center">No</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top" colspan="3">Maven resource files can also be generated
|
* <td valign="top">filenameSuffix</td>
|
||||||
* for FHIR resources or composite data types. The following configuration
|
* <td valign="top">Suffix that will be added onto the end of the resource
|
||||||
* properties control the naming of the generated resource files:<br>
|
* or composite data type name to become the Java class name or resource file name.</td>
|
||||||
* <targetResourceDirectory>/<targetFolder>/<filenamePrefix><i>element-name</i><filenameSuffix><br>
|
* <td valign="top" align="center">No.</code></td>
|
||||||
* where: <i>element-name</i> is the "title-case" name of the selected resource or composite data type.
|
* </tr>
|
||||||
* </td>
|
* <tr>
|
||||||
* </tr>
|
* <td colspan="3" />
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">targetResourceDirectory</td>
|
* <tr>
|
||||||
* <td valign="top">The Maven resource directory to contain the generated files.</td>
|
* <td valign="top" colspan="3">Maven resource files can also be generated
|
||||||
* <td valign="top" align="center">Yes when resource files are to be generated</td>
|
* for FHIR resources or composite data types. The following configuration
|
||||||
* </tr>
|
* properties control the naming of the generated resource files:<br>
|
||||||
* <tr>
|
* <targetResourceDirectory>/<targetFolder>/<filenamePrefix><i>element-name</i><filenameSuffix><br>
|
||||||
* <td valign="top">targetFolder</td>
|
* where: <i>element-name</i> is the "title-case" name of the selected resource or composite data type.
|
||||||
* <td valign="top">The folder within the targetResourceDirectory where the generated files will be placed.
|
* </td>
|
||||||
* This folder is generated in the <targetResourceDirectory> if needed.</td>
|
* </tr>
|
||||||
* <td valign="top" align="center">No</td>
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top">targetResourceDirectory</td>
|
||||||
* <tr>
|
* <td valign="top">The Maven resource directory to contain the generated files.</td>
|
||||||
* <td colspan="3" />
|
* <td valign="top" align="center">Yes when resource files are to be generated</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">template</td>
|
* <td valign="top">targetFolder</td>
|
||||||
* <td valign="top">The path of one of the <i>Velocity</i> templates
|
* <td valign="top">The folder within the targetResourceDirectory where the generated files will be placed.
|
||||||
* contained within the <code>hapi-tinder-plugin</code> Maven plug-in
|
* This folder is generated in the <targetResourceDirectory> if needed.</td>
|
||||||
* classpath that will be used to generate the files.</td>
|
* <td valign="top" align="center">No</td>
|
||||||
* <td valign="top" align="center" rowspan="2">One of these two options must be configured</td>
|
* </tr>
|
||||||
* </tr>
|
* <tr>
|
||||||
* <tr>
|
* <td colspan="3" />
|
||||||
* <td valign="top">templateFile</td>
|
* </tr>
|
||||||
* <td valign="top">The full path to the <i>Velocity</i> template that is
|
* <tr>
|
||||||
* to be used to generate the files.</td>
|
* <td valign="top">template</td>
|
||||||
* </tr>
|
* <td valign="top">The path of one of the <i>Velocity</i> templates
|
||||||
* <tr>
|
* contained within the <code>hapi-tinder-plugin</code> Maven plug-in
|
||||||
* <td valign="top">velocityPath</td>
|
* classpath that will be used to generate the files.</td>
|
||||||
* <td valign="top">When using the <code>templateFile</code> option, this property
|
* <td valign="top" align="center" rowspan="2">One of these two options must be configured</td>
|
||||||
* can be used to specify where Velocity macros and other resources are located.</td>
|
* </tr>
|
||||||
* <td valign="top" align="center">No. Defaults to same directory as the template file.</td>
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top">templateFile</td>
|
||||||
* <tr>
|
* <td valign="top">The full path to the <i>Velocity</i> template that is
|
||||||
* <td valign="top">velocityProperties</td>
|
* to be used to generate the files.</td>
|
||||||
* <td valign="top">Specifies the full path to a java properties file
|
* </tr>
|
||||||
* containing Velocity configuration properties</td>
|
* <tr>
|
||||||
* <td valign="top" align="center">No.</td>
|
* <td valign="top">velocityPath</td>
|
||||||
* </tr>
|
* <td valign="top">When using the <code>templateFile</code> option, this property
|
||||||
* <tr>
|
* can be used to specify where Velocity macros and other resources are located.</td>
|
||||||
* <td valign="top">includeResources</td>
|
* <td valign="top" align="center">No. Defaults to same directory as the template file.</td>
|
||||||
* <td valign="top">A list of the names of the resources or composite data types that should
|
* </tr>
|
||||||
* be used in the file generation</td>
|
* <tr>
|
||||||
* <td valign="top" align="center">No. Defaults to all defined resources except for DSTU2,
|
* <td valign="top">velocityProperties</td>
|
||||||
* the <code>Binary</code> resource is excluded and
|
* <td valign="top">Specifies the full path to a java properties file
|
||||||
* for DSTU3, the <code>Conformance</code> resource is excluded.</td>
|
* containing Velocity configuration properties</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No.</td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">excludeResources</td>
|
* <tr>
|
||||||
* <td valign="top">A list of the names of the resources or composite data types that should
|
* <td valign="top">includeResources</td>
|
||||||
* excluded from the file generation</td>
|
* <td valign="top">A list of the names of the resources or composite data types that should
|
||||||
* <td valign="top" align="center">No.</td>
|
* be used in the file generation</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No. Defaults to all defined resources except for DSTU2,
|
||||||
* <tr>
|
* the <code>Binary</code> resource is excluded and
|
||||||
* <td valign="top">valueSetFiles</td>
|
* for DSTU3, the <code>Conformance</code> resource is excluded.</td>
|
||||||
* <td valign="top">A list of files containing value-set resource definitions
|
* </tr>
|
||||||
* to be used.</td>
|
* <tr>
|
||||||
* <td valign="top" align="center">No. Defaults to all defined value-sets that
|
* <td valign="top">excludeResources</td>
|
||||||
* are referenced from the selected resources.</td>
|
* <td valign="top">A list of the names of the resources or composite data types that should
|
||||||
* </tr>
|
* excluded from the file generation</td>
|
||||||
* <tr>
|
* <td valign="top" align="center">No.</td>
|
||||||
* <td valign="top">profileFiles</td>
|
* </tr>
|
||||||
* <td valign="top">A list of files containing profile definitions
|
* <tr>
|
||||||
* to be used.</td>
|
* <td valign="top">valueSetFiles</td>
|
||||||
* <td valign="top" align="center">No. Defaults to the default profile
|
* <td valign="top">A list of files containing value-set resource definitions
|
||||||
* for each selected resource</td>
|
* to be used.</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No. Defaults to all defined value-sets that
|
||||||
* </table>
|
* are referenced from the selected resources.</td>
|
||||||
*
|
* </tr>
|
||||||
*
|
* <tr>
|
||||||
*
|
* <td valign="top">profileFiles</td>
|
||||||
* @author Bill.Denton
|
* <td valign="top">A list of files containing profile definitions
|
||||||
*
|
* to be used.</td>
|
||||||
*/
|
* <td valign="top" align="center">No. Defaults to the default profile
|
||||||
@Mojo(name = "generate-multi-files", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
* for each selected resource</td>
|
||||||
public class TinderGenericMultiFileMojo extends AbstractMojo {
|
* </tr>
|
||||||
|
* </table>
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderGenericMultiFileMojo.class);
|
*
|
||||||
|
*
|
||||||
@Parameter(required = true)
|
*
|
||||||
private String version;
|
* @author Bill.Denton
|
||||||
|
*
|
||||||
@Parameter(required = true, defaultValue = "${project.build.directory}/..")
|
*/
|
||||||
private String baseDir;
|
@Mojo(name = "generate-multi-files", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||||
|
public class TinderGenericMultiFileMojo extends AbstractMojo {
|
||||||
@Parameter(required = false, defaultValue="false")
|
|
||||||
private boolean generateResources;
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderGenericMultiFileMojo.class);
|
||||||
|
|
||||||
@Parameter(required = false, defaultValue = "false")
|
@Parameter(required = true)
|
||||||
private boolean generateDatatypes;
|
private String version;
|
||||||
|
|
||||||
@Parameter(required = false, defaultValue = "false")
|
@Parameter(required = true, defaultValue = "${project.build.directory}/..")
|
||||||
private boolean generateValueSets;
|
private String baseDir;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false, defaultValue="false")
|
||||||
private File targetSourceDirectory;
|
private boolean generateResources;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false, defaultValue = "false")
|
||||||
private String targetPackage;
|
private boolean generateDatatypes;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false, defaultValue = "false")
|
||||||
private String filenamePrefix;
|
private boolean generateValueSets;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private String filenameSuffix;
|
private File targetSourceDirectory;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private File targetResourceDirectory;
|
private String targetPackage;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private String targetFolder;
|
private String filenamePrefix;
|
||||||
|
|
||||||
// one of these two is required
|
@Parameter(required = false)
|
||||||
@Parameter(required = false)
|
private String filenameSuffix;
|
||||||
private String template;
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private File templateFile;
|
private File targetResourceDirectory;
|
||||||
@Parameter(required = false)
|
|
||||||
private String velocityPath;
|
@Parameter(required = false)
|
||||||
@Parameter(required = false)
|
private String targetFolder;
|
||||||
private String velocityProperties;
|
|
||||||
|
// one of these two is required
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private List<String> includeResources;
|
private String template;
|
||||||
|
@Parameter(required = false)
|
||||||
@Parameter(required = false)
|
private File templateFile;
|
||||||
private List<String> excludeResources;
|
@Parameter(required = false)
|
||||||
|
private String velocityPath;
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private List<ValueSetFileDefinition> valueSetFiles;
|
private String velocityProperties;
|
||||||
|
|
||||||
@Component
|
@Parameter(required = false)
|
||||||
private MavenProject myProject;
|
private List<String> includeResources;
|
||||||
|
|
||||||
@Override
|
@Parameter(required = false)
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
private List<String> excludeResources;
|
||||||
|
|
||||||
GeneratorContext context = new GeneratorContext();
|
@Parameter(required = false)
|
||||||
context.setVersion(version);
|
private String resourceSource;
|
||||||
context.setBaseDir(baseDir);
|
|
||||||
context.setIncludeResources(includeResources);
|
@Parameter(required = false)
|
||||||
context.setExcludeResources(excludeResources);
|
private List<ValueSetFileDefinition> valueSetFiles;
|
||||||
context.setValueSetFiles(valueSetFiles);
|
|
||||||
|
@Component
|
||||||
Generator generator = new Generator();
|
private MavenProject myProject;
|
||||||
try {
|
|
||||||
generator.prepare(context);
|
@Override
|
||||||
} catch (ExecutionException e) {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
|
||||||
} catch (FailureException e) {
|
GeneratorContext context = new GeneratorContext();
|
||||||
throw new MojoFailureException(e.getMessage(), e.getCause());
|
Generator generator = new Generator();
|
||||||
}
|
try {
|
||||||
|
context.setVersion(version);
|
||||||
/*
|
context.setBaseDir(baseDir);
|
||||||
* Deal with the generation target
|
context.setIncludeResources(includeResources);
|
||||||
*/
|
context.setExcludeResources(excludeResources);
|
||||||
TargetType targetType = null;
|
context.setResourceSource(resourceSource);
|
||||||
File targetDirectory = null;
|
context.setValueSetFiles(valueSetFiles);
|
||||||
if (targetSourceDirectory != null) {
|
|
||||||
if (targetResourceDirectory != null) {
|
generator.prepare(context);
|
||||||
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
} catch (ExecutionException e) {
|
||||||
}
|
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
||||||
targetType = TargetType.SOURCE;
|
} catch (FailureException e) {
|
||||||
if (null == targetPackage) {
|
throw new MojoFailureException(e.getMessage(), e.getCause());
|
||||||
throw new MojoFailureException("The [targetPackage] property must be specified when generating Java source code.");
|
}
|
||||||
}
|
|
||||||
targetDirectory = new File(targetSourceDirectory, targetPackage.replace('.', File.separatorChar));
|
/*
|
||||||
} else
|
* Deal with the generation target
|
||||||
if (targetResourceDirectory != null) {
|
*/
|
||||||
if (targetSourceDirectory != null) {
|
TargetType targetType = null;
|
||||||
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
File targetDirectory = null;
|
||||||
}
|
if (targetSourceDirectory != null) {
|
||||||
targetType = TargetType.RESOURCE;
|
if (targetResourceDirectory != null) {
|
||||||
if (targetFolder != null) {
|
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
||||||
targetDirectory = new File(targetResourceDirectory, targetFolder);
|
}
|
||||||
} else {
|
targetType = TargetType.SOURCE;
|
||||||
targetDirectory = targetResourceDirectory;
|
if (null == targetPackage) {
|
||||||
}
|
throw new MojoFailureException("The [targetPackage] property must be specified when generating Java source code.");
|
||||||
if (null == targetPackage) {
|
}
|
||||||
targetPackage = "";
|
targetDirectory = new File(targetSourceDirectory, targetPackage.replace('.', File.separatorChar));
|
||||||
}
|
} else
|
||||||
} else {
|
if (targetResourceDirectory != null) {
|
||||||
throw new MojoFailureException("Either [targetSourceDirectory] or [targetResourceDirectory] must be specified.");
|
if (targetSourceDirectory != null) {
|
||||||
}
|
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
||||||
targetDirectory.mkdirs();
|
}
|
||||||
ourLog.info(" * Output ["+targetType.toString()+"] Directory: " + targetDirectory.getAbsolutePath());
|
targetType = TargetType.RESOURCE;
|
||||||
|
if (targetFolder != null) {
|
||||||
/*
|
targetDirectory = new File(targetResourceDirectory, targetFolder);
|
||||||
* Write resources if selected
|
} else {
|
||||||
*/
|
targetDirectory = targetResourceDirectory;
|
||||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
}
|
||||||
if (generateResources && rp != null) {
|
if (null == targetPackage) {
|
||||||
ourLog.info("Writing Resources...");
|
targetPackage = "";
|
||||||
rp.setFilenamePrefix(filenamePrefix);
|
}
|
||||||
rp.setFilenameSuffix(filenameSuffix);
|
} else {
|
||||||
rp.setTemplate(template);
|
throw new MojoFailureException("Either [targetSourceDirectory] or [targetResourceDirectory] must be specified.");
|
||||||
rp.setTemplateFile(templateFile);
|
}
|
||||||
rp.setVelocityPath(velocityPath);
|
targetDirectory.mkdirs();
|
||||||
rp.setVelocityProperties(velocityProperties);
|
ourLog.info(" * Output ["+targetType.toString()+"] Directory: " + targetDirectory.getAbsolutePath());
|
||||||
rp.writeAll(targetType, targetDirectory, null, targetPackage);
|
|
||||||
}
|
/*
|
||||||
|
* Write resources if selected
|
||||||
/*
|
*/
|
||||||
* Write composite datatypes
|
BaseStructureParser rp = context.getResourceGenerator();
|
||||||
*/
|
if (generateResources && rp != null) {
|
||||||
DatatypeGeneratorUsingSpreadsheet dtp = context.getDatatypeGenerator();
|
ourLog.info("Writing Resources...");
|
||||||
if (generateDatatypes && dtp != null) {
|
rp.setFilenamePrefix(filenamePrefix);
|
||||||
ourLog.info("Writing Composite Datatypes...");
|
rp.setFilenameSuffix(filenameSuffix);
|
||||||
dtp.setFilenamePrefix(filenamePrefix);
|
rp.setTemplate(template);
|
||||||
dtp.setFilenameSuffix(filenameSuffix);
|
rp.setTemplateFile(templateFile);
|
||||||
dtp.setTemplate(template);
|
rp.setVelocityPath(velocityPath);
|
||||||
dtp.setTemplateFile(templateFile);
|
rp.setVelocityProperties(velocityProperties);
|
||||||
dtp.setVelocityPath(velocityPath);
|
rp.writeAll(targetType, targetDirectory, null, targetPackage);
|
||||||
dtp.setVelocityProperties(velocityProperties);
|
}
|
||||||
dtp.writeAll(targetType, targetDirectory, null, targetPackage);
|
|
||||||
}
|
/*
|
||||||
|
* Write composite datatypes
|
||||||
/*
|
*/
|
||||||
* Write valuesets
|
DatatypeGeneratorUsingSpreadsheet dtp = context.getDatatypeGenerator();
|
||||||
*/
|
if (generateDatatypes && dtp != null) {
|
||||||
ValueSetGenerator vsp = context.getValueSetGenerator();
|
ourLog.info("Writing Composite Datatypes...");
|
||||||
if (generateValueSets && vsp != null) {
|
dtp.setFilenamePrefix(filenamePrefix);
|
||||||
ourLog.info("Writing ValueSet Enums...");
|
dtp.setFilenameSuffix(filenameSuffix);
|
||||||
vsp.setFilenamePrefix(filenamePrefix);
|
dtp.setTemplate(template);
|
||||||
vsp.setFilenameSuffix(filenameSuffix);
|
dtp.setTemplateFile(templateFile);
|
||||||
vsp.setTemplate(template);
|
dtp.setVelocityPath(velocityPath);
|
||||||
vsp.setTemplateFile(templateFile);
|
dtp.setVelocityProperties(velocityProperties);
|
||||||
vsp.setVelocityPath(velocityPath);
|
dtp.writeAll(targetType, targetDirectory, null, targetPackage);
|
||||||
vsp.setVelocityProperties(velocityProperties);
|
}
|
||||||
vsp.writeMarkedValueSets(targetType, targetDirectory, targetPackage);
|
|
||||||
}
|
/*
|
||||||
|
* Write valuesets
|
||||||
switch (targetType) {
|
*/
|
||||||
case SOURCE: {
|
ValueSetGenerator vsp = context.getValueSetGenerator();
|
||||||
myProject.addCompileSourceRoot(targetSourceDirectory.getAbsolutePath());
|
if (generateValueSets && vsp != null) {
|
||||||
break;
|
ourLog.info("Writing ValueSet Enums...");
|
||||||
}
|
vsp.setFilenamePrefix(filenamePrefix);
|
||||||
case RESOURCE: {
|
vsp.setFilenameSuffix(filenameSuffix);
|
||||||
Resource resource = new Resource();
|
vsp.setTemplate(template);
|
||||||
resource.setDirectory(targetResourceDirectory.getAbsolutePath());
|
vsp.setTemplateFile(templateFile);
|
||||||
if (targetFolder != null) {
|
vsp.setVelocityPath(velocityPath);
|
||||||
resource.addInclude(targetFolder+"/*");
|
vsp.setVelocityProperties(velocityProperties);
|
||||||
} else {
|
vsp.writeMarkedValueSets(targetType, targetDirectory, targetPackage);
|
||||||
resource.addInclude("*");
|
}
|
||||||
}
|
|
||||||
myProject.addResource(resource);
|
switch (targetType) {
|
||||||
break;
|
case SOURCE: {
|
||||||
}
|
myProject.addCompileSourceRoot(targetSourceDirectory.getAbsolutePath());
|
||||||
default:
|
break;
|
||||||
}
|
}
|
||||||
|
case RESOURCE: {
|
||||||
}
|
Resource resource = new Resource();
|
||||||
|
resource.setDirectory(targetResourceDirectory.getAbsolutePath());
|
||||||
public static void main(String[] args) throws IOException, MojoFailureException, MojoExecutionException {
|
if (targetFolder != null) {
|
||||||
|
resource.addInclude(targetFolder+"/*");
|
||||||
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
} else {
|
||||||
// HttpClientBuilder builder = HttpClientBuilder.create();
|
resource.addInclude("*");
|
||||||
// builder.setConnectionManager(connectionManager);
|
}
|
||||||
// CloseableHttpClient client = builder.build();
|
myProject.addResource(resource);
|
||||||
//
|
break;
|
||||||
// HttpGet get = new HttpGet("http://fhir.healthintersections.com.au/open/metadata");
|
}
|
||||||
// CloseableHttpResponse response = client.execute(get);
|
default:
|
||||||
//
|
}
|
||||||
// String metadataString = EntityUtils.toString(response.getEntity());
|
|
||||||
//
|
}
|
||||||
// ourLog.info("Metadata String: {}", metadataString);
|
|
||||||
|
public static void main(String[] args) throws IOException, MojoFailureException, MojoExecutionException {
|
||||||
// String metadataString = IOUtils.toString(new FileInputStream("src/test/resources/healthintersections-metadata.xml"));
|
|
||||||
// Conformance conformance = new FhirContext(Conformance.class).newXmlParser().parseResource(Conformance.class, metadataString);
|
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||||
|
// HttpClientBuilder builder = HttpClientBuilder.create();
|
||||||
TinderGenericMultiFileMojo mojo = new TinderGenericMultiFileMojo();
|
// builder.setConnectionManager(connectionManager);
|
||||||
mojo.myProject = new MavenProject();
|
// CloseableHttpClient client = builder.build();
|
||||||
mojo.version = "dstu2";
|
//
|
||||||
mojo.targetPackage = "ca.uhn.test";
|
// HttpGet get = new HttpGet("http://fhir.healthintersections.com.au/open/metadata");
|
||||||
mojo.template = "/vm/jpa_resource_provider.vm";
|
// CloseableHttpResponse response = client.execute(get);
|
||||||
mojo.targetSourceDirectory = new File("target/generated/valuesets");
|
//
|
||||||
mojo.execute();
|
// String metadataString = EntityUtils.toString(response.getEntity());
|
||||||
}
|
//
|
||||||
|
// ourLog.info("Metadata String: {}", metadataString);
|
||||||
class Generator extends AbstractGenerator {
|
|
||||||
@Override
|
// String metadataString = IOUtils.toString(new FileInputStream("src/test/resources/healthintersections-metadata.xml"));
|
||||||
protected void logDebug(String message) {
|
// Conformance conformance = new FhirContext(Conformance.class).newXmlParser().parseResource(Conformance.class, metadataString);
|
||||||
ourLog.debug(message);
|
|
||||||
}
|
TinderGenericMultiFileMojo mojo = new TinderGenericMultiFileMojo();
|
||||||
|
mojo.myProject = new MavenProject();
|
||||||
@Override
|
mojo.version = "dstu2";
|
||||||
protected void logInfo(String message) {
|
mojo.targetPackage = "ca.uhn.test";
|
||||||
ourLog.info(message);
|
mojo.template = "/vm/jpa_resource_provider.vm";
|
||||||
}
|
mojo.targetSourceDirectory = new File("target/generated/valuesets");
|
||||||
}
|
mojo.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Generator extends AbstractGenerator {
|
||||||
|
@Override
|
||||||
|
protected void logDebug(String message) {
|
||||||
|
ourLog.debug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void logInfo(String message) {
|
||||||
|
ourLog.info(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,432 +1,451 @@
|
||||||
package ca.uhn.fhir.tinder;
|
package ca.uhn.fhir.tinder;
|
||||||
|
|
||||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
import java.io.File;
|
||||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
import java.io.FileInputStream;
|
||||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
import java.io.FileOutputStream;
|
||||||
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
|
import java.io.IOException;
|
||||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
import java.io.InputStream;
|
||||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
import java.io.InputStreamReader;
|
||||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
import java.io.OutputStreamWriter;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import java.util.List;
|
||||||
import org.apache.maven.model.Resource;
|
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.model.Resource;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugins.annotations.Component;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Component;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.apache.velocity.app.VelocityEngine;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.velocity.tools.generic.EscapeTool;
|
import org.apache.velocity.VelocityContext;
|
||||||
|
import org.apache.velocity.app.VelocityEngine;
|
||||||
import java.io.*;
|
import org.apache.velocity.tools.generic.EscapeTool;
|
||||||
import java.util.List;
|
|
||||||
|
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||||
/**
|
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||||
* Generate a single file based on resource or composite type metadata.
|
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||||
* <p>
|
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||||
* Generates either a source or resource file containing all selected resources or
|
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
|
||||||
* composite data types. The file is
|
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||||
* generated using a Velocity template that can be taken from
|
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||||
* inside the hapi-timder-plugin project or can be located in other projects
|
|
||||||
* <p>
|
/**
|
||||||
* The following Maven plug-in configuration properties are used with this plug-in
|
* Generate a single file based on resource or composite type metadata.
|
||||||
* <p>
|
* <p>
|
||||||
* <table border="1" cellpadding="2" cellspacing="0">
|
* Generates either a source or resource file containing all selected resources or
|
||||||
* <tr>
|
* composite data types. The file is
|
||||||
* <td valign="top"><b>Attribute</b></td>
|
* generated using a Velocity template that can be taken from
|
||||||
* <td valign="top"><b>Description</b></td>
|
* inside the hapi-timder-plugin project or can be located in other projects
|
||||||
* <td align="center" valign="top"><b>Required</b></td>
|
* <p>
|
||||||
* </tr>
|
* The following Maven plug-in configuration properties are used with this plug-in
|
||||||
* <tr>
|
* <p>
|
||||||
* <td valign="top">version</td>
|
* <table border="1" cellpadding="2" cellspacing="0">
|
||||||
* <td valign="top">The FHIR version whose resource metadata
|
* <tr>
|
||||||
* is to be used to generate the files<br>
|
* <td valign="top"><b>Attribute</b></td>
|
||||||
* Valid values: <code><b>dstu</b></code> | <code><b>dstu2</b></code> | <code><b>dstu3</b></code></td>
|
* <td valign="top"><b>Description</b></td>
|
||||||
* <td valign="top" align="center">Yes</td>
|
* <td align="center" valign="top"><b>Required</b></td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">baseDir</td>
|
* <td valign="top">version</td>
|
||||||
* <td valign="top">The Maven project's base directory. This is used to
|
* <td valign="top">The FHIR version whose resource metadata
|
||||||
* possibly locate other assets within the project used in file generation.</td>
|
* is to be used to generate the files<br>
|
||||||
* <td valign="top" align="center">No. Defaults to: <code>${project.build.directory}/..</code></td>
|
* Valid values: <code><b>dstu2</b></code> | <code><b>dstu3</b></code> | <code><b>r4</b></code></td>
|
||||||
* </tr>
|
* <td valign="top" align="center">Yes</td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">generateResources</td>
|
* <tr>
|
||||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
* <td valign="top">baseDir</td>
|
||||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
* <td valign="top">The Maven project's base directory. This is used to
|
||||||
* <td valign="top" align="center" rowspan="2">One of these two options must be specified</td>
|
* possibly locate other assets within the project used in file generation.</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No. Defaults to: <code>${project.build.directory}/..</code></td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">generateDataTypes</td>
|
* <tr>
|
||||||
* <td valign="top">Should files be generated from FHIR composite data type metadata?<br>
|
* <td valign="top">generateResources</td>
|
||||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
||||||
* </tr>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* <tr>
|
* <td valign="top" align="center" rowspan="2">One of these two options must be specified as <code><b>true</b></code></td>
|
||||||
* <td colspan="3" />
|
* </tr>
|
||||||
* </tr>
|
* <tr>
|
||||||
* <tr>
|
* <td valign="top">generateDataTypes</td>
|
||||||
* <td valign="top" colspan="3">Java source files can be generated
|
* <td valign="top">Should files be generated from FHIR composite data type metadata?<br>
|
||||||
* for FHIR resources or composite data types. There is one file
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* generated for each selected entity. The following configuration
|
* </tr>
|
||||||
* properties control the naming of the generated source files:<br>
|
* <tr>
|
||||||
* <targetSourceDirectory>/<targetPackage>/<targetFile><br>
|
* <td valign="top">resourceSource</td>
|
||||||
* Note that all dots in the targetPackage will be replaced by the path separator character when building the
|
* <td valign="top">Which source of resource definitions should be processed? Valid values are:<br>
|
||||||
* actual source file location. Also note that <code>.java</code> will be added to the targetFile if it is not already included.
|
* <ul>
|
||||||
* </td>
|
* <li><code><b>spreadsheet</b></code> to cause resources to be generated based on the FHIR spreadsheets</li>
|
||||||
* </tr>
|
* <li><code><b>model</b></code> to cause resources to be generated based on the model structure classes</li></ul></td>
|
||||||
* <tr>
|
* <td valign="top" align="center">No. Defaults to: <code><b>spreadsheet</b></code></td>
|
||||||
* <td valign="top">targetSourceDirectory</td>
|
* </tr>
|
||||||
* <td valign="top">The Maven source directory to contain the generated file.</td>
|
* <tr>
|
||||||
* <td valign="top" align="center">Yes when a Java source file is to be generated</td>
|
* <td colspan="3" />
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">targetPackage</td>
|
* <td valign="top" colspan="3">Java source files can be generated
|
||||||
* <td valign="top">The Java package that will contain the generated classes.
|
* for FHIR resources or composite data types. There is one file
|
||||||
* This package is generated in the <targetSourceDirectory> if needed.</td>
|
* generated for each selected entity. The following configuration
|
||||||
* <td valign="top" align="center">Yes when <i>targetSourceDirectory</i> is specified</td>
|
* properties control the naming of the generated source files:<br>
|
||||||
* </tr>
|
* <targetSourceDirectory>/<targetPackage>/<targetFile><br>
|
||||||
* <tr>
|
* Note that all dots in the targetPackage will be replaced by the path separator character when building the
|
||||||
* <td valign="top">packageBase</td>
|
* actual source file location. Also note that <code>.java</code> will be added to the targetFile if it is not already included.
|
||||||
* <td valign="top">The base Java package for related classes. This property
|
* </td>
|
||||||
* can be used to reference class in other places in a folder structure.</td>
|
* </tr>
|
||||||
* <td valign="top" align="center">No</td>
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top">targetSourceDirectory</td>
|
||||||
* <tr>
|
* <td valign="top">The Maven source directory to contain the generated file.</td>
|
||||||
* <td valign="top">targetFile</td>
|
* <td valign="top" align="center">Yes when a Java source file is to be generated</td>
|
||||||
* <td valign="top">The name of the file to be generated</td>
|
* </tr>
|
||||||
* <td valign="top" align="center">Yes</td>
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top">targetPackage</td>
|
||||||
* <tr>
|
* <td valign="top">The Java package that will contain the generated classes.
|
||||||
* <td colspan="3" />
|
* This package is generated in the <targetSourceDirectory> if needed.</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">Yes when <i>targetSourceDirectory</i> is specified</td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top" colspan="3">Maven resource files can also be generated
|
* <tr>
|
||||||
* for FHIR resources or composite data types. The following configuration
|
* <td valign="top">packageBase</td>
|
||||||
* properties control the naming of the generated resource files:<br>
|
* <td valign="top">The base Java package for related classes. This property
|
||||||
* <targetResourceDirectory>/<targetFolder>/<targetFile><br>
|
* can be used to reference class in other places in a folder structure.</td>
|
||||||
* </td>
|
* <td valign="top" align="center">No</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">targetResourceDirectory</td>
|
* <td valign="top">targetFile</td>
|
||||||
* <td valign="top">The Maven resource directory to contain the generated file.</td>
|
* <td valign="top">The name of the file to be generated</td>
|
||||||
* <td valign="top" align="center">Yes when a resource file is to be generated</td>
|
* <td valign="top" align="center">Yes</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">targetFolder</td>
|
* <td colspan="3" />
|
||||||
* <td valign="top">The folder within the targetResourceDirectory where the generated file will be placed.
|
* </tr>
|
||||||
* This folder is generated in the <targetResourceDirectory> if needed.</td>
|
* <tr>
|
||||||
* <td valign="top" align="center">No</td>
|
* <td valign="top" colspan="3">Maven resource files can also be generated
|
||||||
* </tr>
|
* for FHIR resources or composite data types. The following configuration
|
||||||
* <tr>
|
* properties control the naming of the generated resource files:<br>
|
||||||
* <td colspan="3" />
|
* <targetResourceDirectory>/<targetFolder>/<targetFile><br>
|
||||||
* </tr>
|
* </td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">template</td>
|
* <tr>
|
||||||
* <td valign="top">The path of one of the <i>Velocity</i> templates
|
* <td valign="top">targetResourceDirectory</td>
|
||||||
* contained within the <code>hapi-tinder-plugin</code> Maven plug-in
|
* <td valign="top">The Maven resource directory to contain the generated file.</td>
|
||||||
* classpath that will be used to generate the files.</td>
|
* <td valign="top" align="center">Yes when a resource file is to be generated</td>
|
||||||
* <td valign="top" align="center" rowspan="2">One of these two options must be configured</td>
|
* </tr>
|
||||||
* </tr>
|
* <tr>
|
||||||
* <tr>
|
* <td valign="top">targetFolder</td>
|
||||||
* <td valign="top">templateFile</td>
|
* <td valign="top">The folder within the targetResourceDirectory where the generated file will be placed.
|
||||||
* <td valign="top">The full path to the <i>Velocity</i> template that is
|
* This folder is generated in the <targetResourceDirectory> if needed.</td>
|
||||||
* to be used to generate the files.</td>
|
* <td valign="top" align="center">No</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">velocityPath</td>
|
* <td colspan="3" />
|
||||||
* <td valign="top">When using the <code>templateFile</code> option, this property
|
* </tr>
|
||||||
* can be used to specify where Velocity macros and other resources are located.</td>
|
* <tr>
|
||||||
* <td valign="top" align="center">No. Defaults to same directory as the template file.</td>
|
* <td valign="top">template</td>
|
||||||
* </tr>
|
* <td valign="top">The path of one of the <i>Velocity</i> templates
|
||||||
* <tr>
|
* contained within the <code>hapi-tinder-plugin</code> Maven plug-in
|
||||||
* <td valign="top">velocityProperties</td>
|
* classpath that will be used to generate the files.</td>
|
||||||
* <td valign="top">Specifies the full path to a java properties file
|
* <td valign="top" align="center" rowspan="2">One of these two options must be configured</td>
|
||||||
* containing Velocity configuration properties</td>
|
* </tr>
|
||||||
* <td valign="top" align="center">No.</td>
|
* <tr>
|
||||||
* </tr>
|
* <td valign="top">templateFile</td>
|
||||||
* <tr>
|
* <td valign="top">The full path to the <i>Velocity</i> template that is
|
||||||
* <td valign="top">includeResources</td>
|
* to be used to generate the files.</td>
|
||||||
* <td valign="top">A list of the names of the resources or composite data types that should
|
* </tr>
|
||||||
* be used in the file generation</td>
|
* <tr>
|
||||||
* <td valign="top" align="center">No. Defaults to all defined resources except for DSTU2,
|
* <td valign="top">velocityPath</td>
|
||||||
* the <code>Binary</code> resource is excluded and
|
* <td valign="top">When using the <code>templateFile</code> option, this property
|
||||||
* for DSTU3, the <code>Conformance</code> resource is excluded.</td>
|
* can be used to specify where Velocity macros and other resources are located.</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No. Defaults to same directory as the template file.</td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">excludeResources</td>
|
* <tr>
|
||||||
* <td valign="top">A list of the names of the resources or composite data types that should
|
* <td valign="top">velocityProperties</td>
|
||||||
* excluded from the file generation</td>
|
* <td valign="top">Specifies the full path to a java properties file
|
||||||
* <td valign="top" align="center">No.</td>
|
* containing Velocity configuration properties</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No.</td>
|
||||||
* <tr>
|
* </tr>
|
||||||
* <td valign="top">valueSetFiles</td>
|
* <tr>
|
||||||
* <td valign="top">A list of files containing value-set resource definitions
|
* <td valign="top">includeResources</td>
|
||||||
* to be used.</td>
|
* <td valign="top">A list of the names of the resources or composite data types that should
|
||||||
* <td valign="top" align="center">No. Defaults to all defined value-sets that
|
* be used in the file generation</td>
|
||||||
* are referenced from the selected resources.</td>
|
* <td valign="top" align="center">No. Defaults to all defined resources except for DSTU2,
|
||||||
* </tr>
|
* the <code>Binary</code> resource is excluded and
|
||||||
* <tr>
|
* for DSTU3, the <code>Conformance</code> resource is excluded.</td>
|
||||||
* <td valign="top">profileFiles</td>
|
* </tr>
|
||||||
* <td valign="top">A list of files containing profile definitions
|
* <tr>
|
||||||
* to be used.</td>
|
* <td valign="top">excludeResources</td>
|
||||||
* <td valign="top" align="center">No. Defaults to the default profile
|
* <td valign="top">A list of the names of the resources or composite data types that should
|
||||||
* for each selected resource</td>
|
* excluded from the file generation</td>
|
||||||
* </tr>
|
* <td valign="top" align="center">No.</td>
|
||||||
* </table>
|
* </tr>
|
||||||
*
|
* <tr>
|
||||||
*
|
* <td valign="top">valueSetFiles</td>
|
||||||
*
|
* <td valign="top">A list of files containing value-set resource definitions
|
||||||
* @author Bill.Denton
|
* to be used.</td>
|
||||||
*
|
* <td valign="top" align="center">No. Defaults to all defined value-sets that
|
||||||
*/
|
* are referenced from the selected resources.</td>
|
||||||
@Mojo(name = "generate-single-file", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
* </tr>
|
||||||
public class TinderGenericSingleFileMojo extends AbstractMojo {
|
* <tr>
|
||||||
|
* <td valign="top">profileFiles</td>
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderGenericSingleFileMojo.class);
|
* <td valign="top">A list of files containing profile definitions
|
||||||
|
* to be used.</td>
|
||||||
@Parameter(required = true)
|
* <td valign="top" align="center">No. Defaults to the default profile
|
||||||
private String version;
|
* for each selected resource</td>
|
||||||
|
* </tr>
|
||||||
@Parameter(required = true, defaultValue = "${project.build.directory}/..")
|
* </table>
|
||||||
private String baseDir;
|
*
|
||||||
|
*
|
||||||
@Parameter(required = false, defaultValue="false")
|
*
|
||||||
private boolean generateResources;
|
* @author Bill.Denton
|
||||||
|
*
|
||||||
@Parameter(required = false, defaultValue = "false")
|
*/
|
||||||
private boolean generateDatatypes;
|
@Mojo(name = "generate-single-file", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||||
|
public class TinderGenericSingleFileMojo extends AbstractMojo {
|
||||||
@Parameter(required = false)
|
|
||||||
private File targetSourceDirectory;
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderGenericSingleFileMojo.class);
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = true)
|
||||||
private String targetPackage;
|
private String version;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = true, defaultValue = "${project.build.directory}/..")
|
||||||
private String packageBase;
|
private String baseDir;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false, defaultValue="false")
|
||||||
private File targetResourceDirectory;
|
private boolean generateResources;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false, defaultValue = "false")
|
||||||
private String targetFolder;
|
private boolean generateDatatypes;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private String targetFile;
|
private File targetSourceDirectory;
|
||||||
|
|
||||||
// one of these two is required
|
@Parameter(required = false)
|
||||||
@Parameter(required = false)
|
private String targetPackage;
|
||||||
private String template;
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private File templateFile;
|
private String packageBase;
|
||||||
@Parameter(required = false)
|
|
||||||
private String velocityPath;
|
@Parameter(required = false)
|
||||||
@Parameter(required = false)
|
private File targetResourceDirectory;
|
||||||
private String velocityProperties;
|
|
||||||
|
@Parameter(required = false)
|
||||||
@Parameter(required = false)
|
private String targetFolder;
|
||||||
private List<String> includeResources;
|
|
||||||
|
@Parameter(required = false)
|
||||||
@Parameter(required = false)
|
private String targetFile;
|
||||||
private List<String> excludeResources;
|
|
||||||
|
// one of these two is required
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private List<ValueSetFileDefinition> valueSetFiles;
|
private String template;
|
||||||
|
@Parameter(required = false)
|
||||||
@Component
|
private File templateFile;
|
||||||
private MavenProject myProject;
|
@Parameter(required = false)
|
||||||
|
private String velocityPath;
|
||||||
@Override
|
@Parameter(required = false)
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
private String velocityProperties;
|
||||||
|
|
||||||
GeneratorContext context = new GeneratorContext();
|
@Parameter(required = false)
|
||||||
context.setVersion(version);
|
private List<String> includeResources;
|
||||||
context.setBaseDir(baseDir);
|
|
||||||
context.setIncludeResources(includeResources);
|
@Parameter(required = false)
|
||||||
context.setExcludeResources(excludeResources);
|
private List<String> excludeResources;
|
||||||
context.setValueSetFiles(valueSetFiles);
|
|
||||||
|
@Parameter(required = false)
|
||||||
Generator generator = new Generator();
|
private String resourceSource;
|
||||||
try {
|
|
||||||
generator.prepare(context);
|
@Parameter(required = false)
|
||||||
} catch (ExecutionException e) {
|
private List<ValueSetFileDefinition> valueSetFiles;
|
||||||
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
|
||||||
} catch (FailureException e) {
|
@Component
|
||||||
throw new MojoFailureException(e.getMessage(), e.getCause());
|
private MavenProject myProject;
|
||||||
}
|
|
||||||
|
@Override
|
||||||
try {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
/*
|
|
||||||
* Deal with the generation target
|
GeneratorContext context = new GeneratorContext();
|
||||||
*/
|
Generator generator = new Generator();
|
||||||
TargetType targetType = null;
|
try {
|
||||||
File targetDirectory = null;
|
context.setVersion(version);
|
||||||
if (null == targetFile) {
|
context.setBaseDir(baseDir);
|
||||||
throw new MojoFailureException("The [targetFile] parameter is required.");
|
context.setIncludeResources(includeResources);
|
||||||
}
|
context.setExcludeResources(excludeResources);
|
||||||
if (targetSourceDirectory != null) {
|
context.setResourceSource(resourceSource);
|
||||||
if (targetResourceDirectory != null) {
|
context.setValueSetFiles(valueSetFiles);
|
||||||
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
|
||||||
}
|
generator.prepare(context);
|
||||||
targetType = TargetType.SOURCE;
|
} catch (ExecutionException e) {
|
||||||
if (null == targetPackage) {
|
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
||||||
throw new MojoFailureException("The [targetPackage] property must be specified when generating Java source code.");
|
} catch (FailureException e) {
|
||||||
}
|
throw new MojoFailureException(e.getMessage(), e.getCause());
|
||||||
targetDirectory = new File(targetSourceDirectory, targetPackage.replace('.', File.separatorChar));
|
}
|
||||||
if (!targetFile.endsWith(".java")) {
|
|
||||||
targetFile += ".java";
|
try {
|
||||||
}
|
/*
|
||||||
} else
|
* Deal with the generation target
|
||||||
if (targetResourceDirectory != null) {
|
*/
|
||||||
if (targetSourceDirectory != null) {
|
TargetType targetType = null;
|
||||||
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
File targetDirectory = null;
|
||||||
}
|
if (null == targetFile) {
|
||||||
targetType = TargetType.RESOURCE;
|
throw new MojoFailureException("The [targetFile] parameter is required.");
|
||||||
if (targetFolder != null) {
|
}
|
||||||
targetFolder = targetFolder.replace('\\', '/');
|
if (targetSourceDirectory != null) {
|
||||||
targetFolder = targetFolder.replace('/', File.separatorChar);
|
if (targetResourceDirectory != null) {
|
||||||
targetDirectory = new File(targetResourceDirectory, targetFolder);
|
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
||||||
} else {
|
}
|
||||||
targetDirectory = targetResourceDirectory;
|
targetType = TargetType.SOURCE;
|
||||||
}
|
if (null == targetPackage) {
|
||||||
if (null == targetPackage) {
|
throw new MojoFailureException("The [targetPackage] property must be specified when generating Java source code.");
|
||||||
targetPackage = "";
|
}
|
||||||
}
|
targetDirectory = new File(targetSourceDirectory, targetPackage.replace('.', File.separatorChar));
|
||||||
} else {
|
if (!targetFile.endsWith(".java")) {
|
||||||
throw new MojoFailureException("Either [targetSourceDirectory] or [targetResourceDirectory] must be specified.");
|
targetFile += ".java";
|
||||||
}
|
}
|
||||||
ourLog.info(" * Output ["+targetType.toString()+"] file ["+targetFile+"] in directory: " + targetDirectory.getAbsolutePath());
|
} else
|
||||||
targetDirectory.mkdirs();
|
if (targetResourceDirectory != null) {
|
||||||
File target = new File(targetDirectory, targetFile);
|
if (targetSourceDirectory != null) {
|
||||||
OutputStreamWriter targetWriter = new OutputStreamWriter(new FileOutputStream(target, false), "UTF-8");
|
throw new MojoFailureException("Both [targetSourceDirectory] and [targetResourceDirectory] are specified. Please choose just one.");
|
||||||
|
}
|
||||||
/*
|
targetType = TargetType.RESOURCE;
|
||||||
* Next, deal with the template and initialize velocity
|
if (targetFolder != null) {
|
||||||
*/
|
targetFolder = targetFolder.replace('\\', '/');
|
||||||
VelocityEngine v = VelocityHelper.configureVelocityEngine(templateFile, velocityPath, velocityProperties);
|
targetFolder = targetFolder.replace('/', File.separatorChar);
|
||||||
InputStream templateIs = null;
|
targetDirectory = new File(targetResourceDirectory, targetFolder);
|
||||||
if (templateFile != null) {
|
} else {
|
||||||
templateIs = new FileInputStream(templateFile);
|
targetDirectory = targetResourceDirectory;
|
||||||
} else {
|
}
|
||||||
templateIs = this.getClass().getResourceAsStream(template);
|
if (null == targetPackage) {
|
||||||
}
|
targetPackage = "";
|
||||||
InputStreamReader templateReader = new InputStreamReader(templateIs);
|
}
|
||||||
|
} else {
|
||||||
/*
|
throw new MojoFailureException("Either [targetSourceDirectory] or [targetResourceDirectory] must be specified.");
|
||||||
* build new Velocity Context
|
}
|
||||||
*/
|
ourLog.info(" * Output ["+targetType.toString()+"] file ["+targetFile+"] in directory: " + targetDirectory.getAbsolutePath());
|
||||||
VelocityContext ctx = new VelocityContext();
|
targetDirectory.mkdirs();
|
||||||
if (packageBase != null) {
|
File target = new File(targetDirectory, targetFile);
|
||||||
ctx.put("packageBase", packageBase);
|
OutputStreamWriter targetWriter = new OutputStreamWriter(new FileOutputStream(target, false), "UTF-8");
|
||||||
} else
|
|
||||||
if (targetPackage != null) {
|
/*
|
||||||
int ix = targetPackage.lastIndexOf('.');
|
* Next, deal with the template and initialize velocity
|
||||||
if (ix > 0) {
|
*/
|
||||||
ctx.put("packageBase", targetPackage.subSequence(0, ix));
|
VelocityEngine v = VelocityHelper.configureVelocityEngine(templateFile, velocityPath, velocityProperties);
|
||||||
} else {
|
InputStream templateIs = null;
|
||||||
ctx.put("packageBase", targetPackage);
|
if (templateFile != null) {
|
||||||
}
|
templateIs = new FileInputStream(templateFile);
|
||||||
}
|
} else {
|
||||||
ctx.put("targetPackage", targetPackage);
|
templateIs = this.getClass().getResourceAsStream(template);
|
||||||
ctx.put("targetFolder", targetFolder);
|
}
|
||||||
ctx.put("version", version);
|
InputStreamReader templateReader = new InputStreamReader(templateIs);
|
||||||
ctx.put("isRi", BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi());
|
|
||||||
ctx.put("hash", "#");
|
/*
|
||||||
ctx.put("esc", new EscapeTool());
|
* build new Velocity Context
|
||||||
if (BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()) {
|
*/
|
||||||
ctx.put("resourcePackage", "org.hl7.fhir." + version + ".model");
|
VelocityContext ctx = new VelocityContext();
|
||||||
} else {
|
if (packageBase != null) {
|
||||||
ctx.put("resourcePackage", "ca.uhn.fhir.model." + version + ".resource");
|
ctx.put("packageBase", packageBase);
|
||||||
}
|
} else
|
||||||
|
if (targetPackage != null) {
|
||||||
String capitalize = WordUtils.capitalize(version);
|
int ix = targetPackage.lastIndexOf('.');
|
||||||
if ("Dstu".equals(capitalize)) {
|
if (ix > 0) {
|
||||||
capitalize="Dstu1";
|
ctx.put("packageBase", targetPackage.subSequence(0, ix));
|
||||||
}
|
} else {
|
||||||
ctx.put("versionCapitalized", capitalize);
|
ctx.put("packageBase", targetPackage);
|
||||||
|
}
|
||||||
/*
|
}
|
||||||
* Write resources if selected
|
ctx.put("targetPackage", targetPackage);
|
||||||
*/
|
ctx.put("targetFolder", targetFolder);
|
||||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
ctx.put("version", version);
|
||||||
if (generateResources && rp != null) {
|
ctx.put("isRi", BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi());
|
||||||
ourLog.info("Writing Resources...");
|
ctx.put("hash", "#");
|
||||||
ctx.put("resources", rp.getResources());
|
ctx.put("esc", new EscapeTool());
|
||||||
v.evaluate(ctx, targetWriter, "", templateReader);
|
if (BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()) {
|
||||||
targetWriter.close();
|
ctx.put("resourcePackage", "org.hl7.fhir." + version + ".model");
|
||||||
} else {
|
} else {
|
||||||
DatatypeGeneratorUsingSpreadsheet dtp = context.getDatatypeGenerator();
|
ctx.put("resourcePackage", "ca.uhn.fhir.model." + version + ".resource");
|
||||||
if (generateDatatypes && dtp != null) {
|
}
|
||||||
ourLog.info("Writing DataTypes...");
|
|
||||||
ctx.put("datatypes", dtp.getResources());
|
String capitalize = WordUtils.capitalize(version);
|
||||||
v.evaluate(ctx, targetWriter, "", templateReader);
|
if ("Dstu".equals(capitalize)) {
|
||||||
targetWriter.close();
|
capitalize="Dstu1";
|
||||||
}
|
}
|
||||||
}
|
ctx.put("versionCapitalized", capitalize);
|
||||||
|
|
||||||
switch (targetType) {
|
/*
|
||||||
case SOURCE: {
|
* Write resources if selected
|
||||||
myProject.addCompileSourceRoot(targetSourceDirectory.getAbsolutePath());
|
*/
|
||||||
break;
|
BaseStructureParser rp = context.getResourceGenerator();
|
||||||
}
|
if (generateResources && rp != null) {
|
||||||
case RESOURCE: {
|
ourLog.info("Writing Resources...");
|
||||||
Resource resource = new Resource();
|
ctx.put("resources", rp.getResources());
|
||||||
resource.setDirectory(targetResourceDirectory.getAbsolutePath());
|
v.evaluate(ctx, targetWriter, "", templateReader);
|
||||||
String resName = targetFile;
|
targetWriter.close();
|
||||||
if (targetFolder != null) {
|
} else {
|
||||||
resName = targetFolder+File.separator+targetFile;
|
DatatypeGeneratorUsingSpreadsheet dtp = context.getDatatypeGenerator();
|
||||||
}
|
if (generateDatatypes && dtp != null) {
|
||||||
resource.addInclude(resName);
|
ourLog.info("Writing DataTypes...");
|
||||||
myProject.addResource(resource);
|
ctx.put("datatypes", dtp.getResources());
|
||||||
break;
|
v.evaluate(ctx, targetWriter, "", templateReader);
|
||||||
}
|
targetWriter.close();
|
||||||
default:
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
switch (targetType) {
|
||||||
throw new MojoFailureException("Failed to generate file", e);
|
case SOURCE: {
|
||||||
}
|
myProject.addCompileSourceRoot(targetSourceDirectory.getAbsolutePath());
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
public static void main(String[] args) throws IOException, MojoFailureException, MojoExecutionException {
|
case RESOURCE: {
|
||||||
|
Resource resource = new Resource();
|
||||||
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
resource.setDirectory(targetResourceDirectory.getAbsolutePath());
|
||||||
// HttpClientBuilder builder = HttpClientBuilder.create();
|
String resName = targetFile;
|
||||||
// builder.setConnectionManager(connectionManager);
|
if (targetFolder != null) {
|
||||||
// CloseableHttpClient client = builder.build();
|
resName = targetFolder+File.separator+targetFile;
|
||||||
//
|
}
|
||||||
// HttpGet get = new HttpGet("http://fhir.healthintersections.com.au/open/metadata");
|
resource.addInclude(resName);
|
||||||
// CloseableHttpResponse response = client.execute(get);
|
myProject.addResource(resource);
|
||||||
//
|
break;
|
||||||
// String metadataString = EntityUtils.toString(response.getEntity());
|
}
|
||||||
//
|
default:
|
||||||
// ourLog.info("Metadata String: {}", metadataString);
|
}
|
||||||
|
|
||||||
// String metadataString = IOUtils.toString(new FileInputStream("src/test/resources/healthintersections-metadata.xml"));
|
} catch (Exception e) {
|
||||||
// Conformance conformance = new FhirContext(Conformance.class).newXmlParser().parseResource(Conformance.class, metadataString);
|
throw new MojoFailureException("Failed to generate file", e);
|
||||||
|
}
|
||||||
TinderGenericSingleFileMojo mojo = new TinderGenericSingleFileMojo();
|
}
|
||||||
mojo.myProject = new MavenProject();
|
|
||||||
mojo.template = "/vm/jpa_spring_beans.vm";
|
public static void main(String[] args) throws IOException, MojoFailureException, MojoExecutionException {
|
||||||
mojo.version = "dstu2";
|
|
||||||
mojo.targetPackage = "ca.uhn.test";
|
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||||
mojo.targetSourceDirectory = new File("target/generated/valuesets");
|
// HttpClientBuilder builder = HttpClientBuilder.create();
|
||||||
mojo.targetFile = "tmp_beans.xml";
|
// builder.setConnectionManager(connectionManager);
|
||||||
mojo.execute();
|
// CloseableHttpClient client = builder.build();
|
||||||
}
|
//
|
||||||
|
// HttpGet get = new HttpGet("http://fhir.healthintersections.com.au/open/metadata");
|
||||||
class Generator extends AbstractGenerator {
|
// CloseableHttpResponse response = client.execute(get);
|
||||||
@Override
|
//
|
||||||
protected void logDebug(String message) {
|
// String metadataString = EntityUtils.toString(response.getEntity());
|
||||||
ourLog.debug(message);
|
//
|
||||||
}
|
// ourLog.info("Metadata String: {}", metadataString);
|
||||||
|
|
||||||
@Override
|
// String metadataString = IOUtils.toString(new FileInputStream("src/test/resources/healthintersections-metadata.xml"));
|
||||||
protected void logInfo(String message) {
|
// Conformance conformance = new FhirContext(Conformance.class).newXmlParser().parseResource(Conformance.class, metadataString);
|
||||||
ourLog.info(message);
|
|
||||||
}
|
TinderGenericSingleFileMojo mojo = new TinderGenericSingleFileMojo();
|
||||||
}
|
mojo.myProject = new MavenProject();
|
||||||
}
|
mojo.template = "/vm/jpa_spring_beans.vm";
|
||||||
|
mojo.version = "dstu2";
|
||||||
|
mojo.targetPackage = "ca.uhn.test";
|
||||||
|
mojo.targetSourceDirectory = new File("target/generated/valuesets");
|
||||||
|
mojo.targetFile = "tmp_beans.xml";
|
||||||
|
mojo.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
class Generator extends AbstractGenerator {
|
||||||
|
@Override
|
||||||
|
protected void logDebug(String message) {
|
||||||
|
ourLog.debug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void logInfo(String message) {
|
||||||
|
ourLog.info(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue