Merge pull request #1112 from bdenton/master
Enhancements to tinder generic Mojo and Ant tasks
This commit is contained in:
commit
ba225c6945
|
@ -21,7 +21,10 @@ package ca.uhn.fhir.tinder;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.tinder.GeneratorContext.ResourceSource;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingModel;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -45,6 +48,9 @@ public abstract class AbstractGenerator {
|
|||
} else if ("dstu3".equals(context.getVersion())) {
|
||||
fhirContext = FhirContext.forDstu3();
|
||||
packageSuffix = ".dstu3";
|
||||
} else if ("r4".equals(context.getVersion())) {
|
||||
fhirContext = FhirContext.forR4();
|
||||
packageSuffix = ".r4";
|
||||
} else {
|
||||
throw new FailureException("Unknown version configured: " + context.getVersion());
|
||||
}
|
||||
|
@ -107,58 +113,80 @@ public abstract class AbstractGenerator {
|
|||
DatatypeGeneratorUsingSpreadsheet dtp = null;
|
||||
Map<String, String> datatypeLocalImports = new HashMap<String, String>();
|
||||
|
||||
vsp = new ValueSetGenerator(context.getVersion());
|
||||
vsp.setResourceValueSetFiles(context.getValueSetFiles());
|
||||
context.setValueSetGenerator(vsp);
|
||||
try {
|
||||
vsp.parse();
|
||||
} catch (Exception e) {
|
||||
throw new FailureException("Failed to load valuesets", e);
|
||||
if (ResourceSource.SPREADSHEET.equals(context.getResourceSource())) {
|
||||
vsp = new ValueSetGenerator(context.getVersion());
|
||||
vsp.setResourceValueSetFiles(context.getValueSetFiles());
|
||||
context.setValueSetGenerator(vsp);
|
||||
try {
|
||||
vsp.parse();
|
||||
} catch (Exception e) {
|
||||
throw new FailureException("Failed to load valuesets", e);
|
||||
}
|
||||
|
||||
/*
|
||||
* A few enums are not found by default because none of the generated classes
|
||||
* refer to them, but we still want them.
|
||||
*/
|
||||
vsp.getClassForValueSetIdAndMarkAsNeeded("NarrativeStatus");
|
||||
|
||||
logInfo("Loading Datatypes...");
|
||||
|
||||
dtp = new DatatypeGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
||||
context.setDatatypeGenerator(dtp);
|
||||
try {
|
||||
dtp.parse();
|
||||
dtp.markResourcesForImports();
|
||||
} catch (Exception e) {
|
||||
throw new FailureException("Failed to load datatypes", e);
|
||||
}
|
||||
dtp.bindValueSets(vsp);
|
||||
|
||||
datatypeLocalImports = dtp.getLocalImports();
|
||||
}
|
||||
|
||||
/*
|
||||
* A few enums are not found by default because none of the generated classes
|
||||
* refer to them, but we still want them.
|
||||
*/
|
||||
vsp.getClassForValueSetIdAndMarkAsNeeded("NarrativeStatus");
|
||||
|
||||
logInfo("Loading Datatypes...");
|
||||
|
||||
dtp = new DatatypeGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
||||
context.setDatatypeGenerator(dtp);
|
||||
try {
|
||||
dtp.parse();
|
||||
dtp.markResourcesForImports();
|
||||
} catch (Exception e) {
|
||||
throw new FailureException("Failed to load datatypes", e);
|
||||
}
|
||||
dtp.bindValueSets(vsp);
|
||||
|
||||
datatypeLocalImports = dtp.getLocalImports();
|
||||
|
||||
/*
|
||||
* Load the requested resources
|
||||
*/
|
||||
ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
||||
context.setResourceGenerator(rp);
|
||||
|
||||
logInfo("Loading Resources...");
|
||||
try {
|
||||
rp.setBaseResourceNames(includeResources);
|
||||
rp.parse();
|
||||
rp.markResourcesForImports();
|
||||
switch (context.getResourceSource()) {
|
||||
case SPREADSHEET: {
|
||||
logInfo("... resource definitions from spreadsheets");
|
||||
ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
||||
context.setResourceGenerator(rp);
|
||||
|
||||
rp.setBaseResourceNames(includeResources);
|
||||
rp.parse();
|
||||
|
||||
rp.markResourcesForImports();
|
||||
rp.bindValueSets(vsp);
|
||||
|
||||
rp.getLocalImports().putAll(datatypeLocalImports);
|
||||
datatypeLocalImports.putAll(rp.getLocalImports());
|
||||
|
||||
rp.combineContentMaps(dtp);
|
||||
dtp.combineContentMaps(rp);
|
||||
break;
|
||||
}
|
||||
case MODEL: {
|
||||
logInfo("... resource definitions from model structures");
|
||||
ResourceGeneratorUsingModel rp = new ResourceGeneratorUsingModel(context.getVersion(), context.getBaseDir());
|
||||
context.setResourceGenerator(rp);
|
||||
|
||||
rp.setBaseResourceNames(includeResources);
|
||||
rp.parse();
|
||||
rp.markResourcesForImports();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FailureException("Failed to load resources", e);
|
||||
}
|
||||
|
||||
rp.bindValueSets(vsp);
|
||||
rp.getLocalImports().putAll(datatypeLocalImports);
|
||||
datatypeLocalImports.putAll(rp.getLocalImports());
|
||||
rp.combineContentMaps(dtp);
|
||||
dtp.combineContentMaps(rp);
|
||||
|
||||
}
|
||||
|
||||
public class FailureException extends Exception {
|
||||
public static class FailureException extends Exception {
|
||||
|
||||
public FailureException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
|
@ -173,7 +201,7 @@ public abstract class AbstractGenerator {
|
|||
|
||||
}
|
||||
|
||||
public class ExecutionException extends Exception {
|
||||
public static class ExecutionException extends Exception {
|
||||
|
||||
public ExecutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
|
|
|
@ -19,25 +19,34 @@ package ca.uhn.fhir.tinder;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.FailedLoginException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
import java.util.List;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
|
||||
/**
|
||||
* @author Bill.Denton
|
||||
*
|
||||
*/
|
||||
public class GeneratorContext {
|
||||
public enum ResourceSource {SPREADSHEET, MODEL};
|
||||
public static final ResourceSource DEFAULT_RESOURCE_SOURCE = ResourceSource.SPREADSHEET;
|
||||
|
||||
private String version;
|
||||
private String packageSuffix;
|
||||
private String baseDir;
|
||||
private List<String> includeResources;
|
||||
private List<String> excludeResources;
|
||||
private ResourceSource resourceSource = DEFAULT_RESOURCE_SOURCE;
|
||||
private List<ValueSetFileDefinition> valueSetFiles;
|
||||
private ResourceGeneratorUsingSpreadsheet resourceGenerator = null;
|
||||
private BaseStructureParser resourceGenerator = null;
|
||||
private ValueSetGenerator valueSetGenerator = null;
|
||||
private DatatypeGeneratorUsingSpreadsheet datatypeGenerator = null;
|
||||
|
||||
|
@ -72,6 +81,29 @@ public class GeneratorContext {
|
|||
this.includeResources = includeResources;
|
||||
}
|
||||
|
||||
public ResourceSource getResourceSource() {
|
||||
return resourceSource;
|
||||
}
|
||||
|
||||
public void setResourceSource(ResourceSource resourceSource) {
|
||||
this.resourceSource = resourceSource;
|
||||
}
|
||||
|
||||
public void setResourceSource(String resourceSource) throws FailureException {
|
||||
resourceSource = StringUtils.stripToNull(resourceSource);
|
||||
if (null == resourceSource) {
|
||||
this.resourceSource = DEFAULT_RESOURCE_SOURCE;
|
||||
} else
|
||||
if (ResourceSource.SPREADSHEET.name().equalsIgnoreCase(resourceSource)) {
|
||||
this.resourceSource = ResourceSource.SPREADSHEET;
|
||||
} else
|
||||
if (ResourceSource.MODEL.name().equalsIgnoreCase(resourceSource)) {
|
||||
this.resourceSource = ResourceSource.MODEL;
|
||||
} else {
|
||||
throw new FailureException("Unknown resource-source option: " + resourceSource);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPackageSuffix() {
|
||||
return packageSuffix;
|
||||
}
|
||||
|
@ -80,11 +112,11 @@ public class GeneratorContext {
|
|||
this.packageSuffix = packageSuffix;
|
||||
}
|
||||
|
||||
public ResourceGeneratorUsingSpreadsheet getResourceGenerator() {
|
||||
public BaseStructureParser getResourceGenerator() {
|
||||
return resourceGenerator;
|
||||
}
|
||||
|
||||
public void setResourceGenerator(ResourceGeneratorUsingSpreadsheet resourceGenerator) {
|
||||
public void setResourceGenerator(BaseStructureParser resourceGenerator) {
|
||||
this.resourceGenerator = resourceGenerator;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
@ -16,9 +14,13 @@ import org.apache.maven.plugins.annotations.Mojo;
|
|||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||
import ca.uhn.fhir.tinder.GeneratorContext.ResourceSource;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||
|
||||
/**
|
||||
* Generate files from FHIR resource/composite metadata using Velocity templates.
|
||||
|
@ -40,7 +42,7 @@ import java.util.List;
|
|||
* <td valign="top">version</td>
|
||||
* <td valign="top">The FHIR version whose resource metadata
|
||||
* is to be used to generate the files<br>
|
||||
* Valid values: <code><b>dstu</b></code> | <code><b>dstu2</b></code> | <code><b>dstu3</b></code></td>
|
||||
* Valid values: <code><b>dstu2</b></code> | <code><b>dstu3</b></code> | <code><b>r4</b></code></td>
|
||||
* <td valign="top" align="center">Yes</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -53,7 +55,7 @@ import java.util.List;
|
|||
* <td valign="top">generateResources</td>
|
||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||
* <td valign="top" align="center" rowspan="4">One of these four options must be specified</td>
|
||||
* <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>
|
||||
|
@ -71,6 +73,15 @@ import java.util.List;
|
|||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign="top">resourceSource</td>
|
||||
* <td valign="top">Which source of resource definitions should be processed? Valid values are:<br>
|
||||
* <ul>
|
||||
* <li><code><b>spreadsheet</b></code> to cause resources to be generated based on the FHIR spreadsheets</li>
|
||||
* <li><code><b>model</b></code> to cause resources to be generated based on the model structure classes. Note that
|
||||
* <code>generateResources</code> is the only one of the above options that can be used when <code>model</code> is specified.</li></ul></td>
|
||||
* <td valign="top" align="center">No. Defaults to: <code><b>spreadsheet</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td colspan="3" />
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -246,6 +257,9 @@ public class TinderGenericMultiFileMojo extends AbstractMojo {
|
|||
@Parameter(required = false)
|
||||
private List<String> excludeResources;
|
||||
|
||||
@Parameter(required = false)
|
||||
private String resourceSource;
|
||||
|
||||
@Parameter(required = false)
|
||||
private List<ValueSetFileDefinition> valueSetFiles;
|
||||
|
||||
|
@ -256,14 +270,23 @@ public class TinderGenericMultiFileMojo extends AbstractMojo {
|
|||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
GeneratorContext context = new GeneratorContext();
|
||||
context.setVersion(version);
|
||||
context.setBaseDir(baseDir);
|
||||
context.setIncludeResources(includeResources);
|
||||
context.setExcludeResources(excludeResources);
|
||||
context.setValueSetFiles(valueSetFiles);
|
||||
|
||||
Generator generator = new Generator();
|
||||
try {
|
||||
context.setVersion(version);
|
||||
context.setBaseDir(baseDir);
|
||||
context.setIncludeResources(includeResources);
|
||||
context.setExcludeResources(excludeResources);
|
||||
context.setResourceSource(resourceSource);
|
||||
context.setValueSetFiles(valueSetFiles);
|
||||
if (ResourceSource.MODEL.equals(context.getResourceSource())) {
|
||||
if (generateDatatypes) {
|
||||
throw new MojoFailureException("Cannot use \"generateDatatypes\" when resourceSource=model");
|
||||
}
|
||||
if (generateValueSets) {
|
||||
throw new MojoFailureException("Cannot use \"generateValueSets\" when resourceSource=model");
|
||||
}
|
||||
}
|
||||
|
||||
generator.prepare(context);
|
||||
} catch (ExecutionException e) {
|
||||
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
||||
|
@ -308,7 +331,7 @@ public class TinderGenericMultiFileMojo extends AbstractMojo {
|
|||
/*
|
||||
* Write resources if selected
|
||||
*/
|
||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
||||
BaseStructureParser rp = context.getResourceGenerator();
|
||||
if (generateResources && rp != null) {
|
||||
ourLog.info("Writing Resources...");
|
||||
rp.setFilenamePrefix(filenamePrefix);
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
|
@ -21,8 +23,14 @@ import org.apache.velocity.VelocityContext;
|
|||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.tools.generic.EscapeTool;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||
import ca.uhn.fhir.tinder.GeneratorContext.ResourceSource;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||
|
||||
/**
|
||||
* Generate a single file based on resource or composite type metadata.
|
||||
|
@ -44,7 +52,7 @@ import java.util.List;
|
|||
* <td valign="top">version</td>
|
||||
* <td valign="top">The FHIR version whose resource metadata
|
||||
* is to be used to generate the files<br>
|
||||
* Valid values: <code><b>dstu</b></code> | <code><b>dstu2</b></code> | <code><b>dstu3</b></code></td>
|
||||
* Valid values: <code><b>dstu2</b></code> | <code><b>dstu3</b></code> | <code><b>r4</b></code></td>
|
||||
* <td valign="top" align="center">Yes</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -57,7 +65,7 @@ import java.util.List;
|
|||
* <td valign="top">generateResources</td>
|
||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||
* <td valign="top" align="center" rowspan="2">One of these two options must be specified</td>
|
||||
* <td valign="top" align="center" rowspan="2">One of these two options must be specified as <code><b>true</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign="top">generateDataTypes</td>
|
||||
|
@ -65,6 +73,15 @@ import java.util.List;
|
|||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign="top">resourceSource</td>
|
||||
* <td valign="top">Which source of resource definitions should be processed? Valid values are:<br>
|
||||
* <ul>
|
||||
* <li><code><b>spreadsheet</b></code> to cause resources to be generated based on the FHIR spreadsheets</li>
|
||||
* <li><code><b>model</b></code> to cause resources to be generated based on the model structure classes. Note that
|
||||
* <code>generateResources</code> is the only one of the above options that can be used when <code>model</code> is specified.</li></ul></td>
|
||||
* <td valign="top" align="center">No. Defaults to: <code><b>spreadsheet</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td colspan="3" />
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -233,6 +250,9 @@ public class TinderGenericSingleFileMojo extends AbstractMojo {
|
|||
@Parameter(required = false)
|
||||
private List<String> excludeResources;
|
||||
|
||||
@Parameter(required = false)
|
||||
private String resourceSource;
|
||||
|
||||
@Parameter(required = false)
|
||||
private List<ValueSetFileDefinition> valueSetFiles;
|
||||
|
||||
|
@ -243,14 +263,20 @@ public class TinderGenericSingleFileMojo extends AbstractMojo {
|
|||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
GeneratorContext context = new GeneratorContext();
|
||||
context.setVersion(version);
|
||||
context.setBaseDir(baseDir);
|
||||
context.setIncludeResources(includeResources);
|
||||
context.setExcludeResources(excludeResources);
|
||||
context.setValueSetFiles(valueSetFiles);
|
||||
|
||||
Generator generator = new Generator();
|
||||
try {
|
||||
context.setVersion(version);
|
||||
context.setBaseDir(baseDir);
|
||||
context.setIncludeResources(includeResources);
|
||||
context.setExcludeResources(excludeResources);
|
||||
context.setResourceSource(resourceSource);
|
||||
context.setValueSetFiles(valueSetFiles);
|
||||
if (ResourceSource.MODEL.equals(context.getResourceSource())) {
|
||||
if (generateDatatypes) {
|
||||
throw new MojoFailureException("Cannot use \"generateDatatypes\" when resourceSource=model");
|
||||
}
|
||||
}
|
||||
|
||||
generator.prepare(context);
|
||||
} catch (ExecutionException e) {
|
||||
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
||||
|
@ -351,7 +377,7 @@ public class TinderGenericSingleFileMojo extends AbstractMojo {
|
|||
/*
|
||||
* Write resources if selected
|
||||
*/
|
||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
||||
BaseStructureParser rp = context.getResourceGenerator();
|
||||
if (generateResources && rp != null) {
|
||||
ourLog.info("Writing Resources...");
|
||||
ctx.put("resources", rp.getResources());
|
||||
|
|
|
@ -19,18 +19,16 @@ package ca.uhn.fhir.tinder.ant;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||
import ca.uhn.fhir.tinder.GeneratorContext;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.ValueSetGenerator;
|
||||
import ca.uhn.fhir.tinder.VelocityHelper;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
@ -38,10 +36,19 @@ import org.apache.velocity.VelocityContext;
|
|||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.tools.generic.EscapeTool;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||
import ca.uhn.fhir.tinder.GeneratorContext;
|
||||
import ca.uhn.fhir.tinder.GeneratorContext.ResourceSource;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.ValueSetGenerator;
|
||||
import ca.uhn.fhir.tinder.VelocityHelper;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureParser;
|
||||
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
||||
|
||||
/**
|
||||
/**
|
||||
|
@ -64,7 +71,7 @@ import java.util.StringTokenizer;
|
|||
* <td valign="top">version</td>
|
||||
* <td valign="top">The FHIR version whose resource metadata
|
||||
* is to be used to generate the files<br>
|
||||
* Valid values: <code><b>dstu</b></code> | <code><b>dstu2</b></code> | <code><b>dstu3</b></code></td>
|
||||
* Valid values: <code><b>dstu2</b></code> | <code><b>dstu3</b></code> | <code><b>r4</b></code></td>
|
||||
* <td valign="top" align="center">Yes</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -77,7 +84,7 @@ import java.util.StringTokenizer;
|
|||
* <td valign="top">generateResources</td>
|
||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
||||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||
* <td valign="top" align="center" rowspan="4">At least one of these four options must be specified</td>
|
||||
* <td valign="top" align="center" rowspan="4">At least one of these four options must be specified as <code><b>true</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign="top">generateDataTypes</td>
|
||||
|
@ -97,6 +104,15 @@ import java.util.StringTokenizer;
|
|||
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign="top">resourceSource</td>
|
||||
* <td valign="top">Which source of resource definitions should be processed? Valid values are:<br>
|
||||
* <ul>
|
||||
* <li><code><b>spreadsheet</b></code> to cause resources to be generated based on the FHIR spreadsheets</li>
|
||||
* <li><code><b>model</b></code> to cause resources to be generated based on the model structure classes. Note that
|
||||
* <code>generateResources</code> is the only one of the above options that can be used when <code>model</code> is specified.</li></ul></td>
|
||||
* <td valign="top" align="center">No. Defaults to: <code><b>spreadsheet</b></code></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td colspan="3" />
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -281,6 +297,8 @@ public class TinderGeneratorTask extends Task {
|
|||
|
||||
private List<String> excludeResources;
|
||||
|
||||
private String resourceSource;
|
||||
|
||||
private List<ValueSetFileDefinition> valueSetFiles;
|
||||
|
||||
private boolean verbose;
|
||||
|
@ -303,14 +321,23 @@ public class TinderGeneratorTask extends Task {
|
|||
|
||||
|
||||
GeneratorContext context = new GeneratorContext();
|
||||
context.setVersion(version);
|
||||
context.setBaseDir(projectHome);
|
||||
context.setIncludeResources(includeResources);
|
||||
context.setExcludeResources(excludeResources);
|
||||
context.setValueSetFiles(valueSetFiles);
|
||||
|
||||
Generator generator = new Generator();
|
||||
try {
|
||||
context.setVersion(version);
|
||||
context.setBaseDir(projectHome);
|
||||
context.setIncludeResources(includeResources);
|
||||
context.setExcludeResources(excludeResources);
|
||||
context.setResourceSource(resourceSource);
|
||||
context.setValueSetFiles(valueSetFiles);
|
||||
if (ResourceSource.MODEL.equals(context.getResourceSource())) {
|
||||
if (generateDatatypes) {
|
||||
throw new BuildException("Cannot use \"generateDatatypes\" when resourceSource=model");
|
||||
}
|
||||
if (generateValueSets) {
|
||||
throw new BuildException("Cannot use \"generateValueSets\" when resourceSource=model");
|
||||
}
|
||||
}
|
||||
|
||||
generator.prepare(context);
|
||||
} catch (ExecutionException e) {
|
||||
throw new BuildException(e.getMessage(), e.getCause());
|
||||
|
@ -413,7 +440,7 @@ public class TinderGeneratorTask extends Task {
|
|||
/*
|
||||
* Write resources if selected
|
||||
*/
|
||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
||||
BaseStructureParser rp = context.getResourceGenerator();
|
||||
if (generateResources && rp != null) {
|
||||
log("Writing Resources...");
|
||||
ctx.put("resources", rp.getResources());
|
||||
|
@ -436,7 +463,7 @@ public class TinderGeneratorTask extends Task {
|
|||
/*
|
||||
* Write resources if selected
|
||||
*/
|
||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
||||
BaseStructureParser rp = context.getResourceGenerator();
|
||||
if (generateResources && rp != null) {
|
||||
log("Writing Resources...");
|
||||
rp.setFilenamePrefix(filenamePrefix);
|
||||
|
@ -550,6 +577,14 @@ public class TinderGeneratorTask extends Task {
|
|||
this.projectHome = projectHome;
|
||||
}
|
||||
|
||||
public String getResourceSource() {
|
||||
return resourceSource;
|
||||
}
|
||||
|
||||
public void setResourceSource(String resourceSource) {
|
||||
this.resourceSource = resourceSource;
|
||||
}
|
||||
|
||||
public void setTargetFile(String targetFile) {
|
||||
this.targetFile = targetFile;
|
||||
}
|
||||
|
|
|
@ -104,6 +104,11 @@
|
|||
<artifactId>hapi-fhir-structures-dstu3</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||
<artifactId>hapi-fhir-structures-r4</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
|
||||
|
@ -119,6 +124,11 @@
|
|||
<artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<!--
|
||||
|
@ -174,7 +184,7 @@
|
|||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generic_multi</id>
|
||||
<id>generic_multi_dstu2</id>
|
||||
<goals>
|
||||
<goal>generate-multi-files</goal>
|
||||
</goals>
|
||||
|
@ -191,6 +201,44 @@
|
|||
</includeResources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generic_multi_dstu3</id>
|
||||
<goals>
|
||||
<goal>generate-multi-files</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<version>dstu3</version>
|
||||
<generateResources>true</generateResources>
|
||||
<resourceSource>model</resourceSource>
|
||||
<templateFile>${project.basedir}/src/test/resources/templates/resource_test.vm</templateFile>
|
||||
<targetSourceDirectory>${project.build.directory}/generated-sources/tinder</targetSourceDirectory>
|
||||
<targetPackage>ca.uhn.test.generic.multi.dstu3</targetPackage>
|
||||
<filenameSuffix>ResourceTest.java</filenameSuffix>
|
||||
<includeResources>
|
||||
<includeResource>patient</includeResource>
|
||||
<includeResource>organization</includeResource>
|
||||
</includeResources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generic_multi_r4</id>
|
||||
<goals>
|
||||
<goal>generate-multi-files</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<version>r4</version>
|
||||
<generateResources>true</generateResources>
|
||||
<resourceSource>model</resourceSource>
|
||||
<templateFile>${project.basedir}/src/test/resources/templates/resource_test.vm</templateFile>
|
||||
<targetSourceDirectory>${project.build.directory}/generated-sources/tinder</targetSourceDirectory>
|
||||
<targetPackage>ca.uhn.test.generic.multi.r4</targetPackage>
|
||||
<filenameSuffix>ResourceTest.java</filenameSuffix>
|
||||
<includeResources>
|
||||
<includeResource>patient</includeResource>
|
||||
<includeResource>organization</includeResource>
|
||||
</includeResources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generic_multi_json</id>
|
||||
<goals>
|
||||
|
@ -199,6 +247,7 @@
|
|||
<configuration>
|
||||
<version>dstu2</version>
|
||||
<generateResources>true</generateResources>
|
||||
<resourceSource>spreadsheet</resourceSource>
|
||||
<templateFile>${project.basedir}/src/test/resources/templates/resource_map.vm</templateFile>
|
||||
<velocityPath>${project.basedir}/src/test/resources/macros</velocityPath>
|
||||
<targetResourceDirectory>${project.build.directory}/generated-resources/tinder</targetResourceDirectory>
|
||||
|
@ -213,7 +262,7 @@
|
|||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generic_single</id>
|
||||
<id>generic_single_dstu2</id>
|
||||
<goals>
|
||||
<goal>generate-single-file</goal>
|
||||
</goals>
|
||||
|
@ -231,6 +280,26 @@
|
|||
</includeResources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generic_single_r4</id>
|
||||
<goals>
|
||||
<goal>generate-single-file</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<version>r4</version>
|
||||
<generateResources>true</generateResources>
|
||||
<resourceSource>model</resourceSource>
|
||||
<templateFile>${project.basedir}/src/test/resources/templates/resource_test_beans_java.vm</templateFile>
|
||||
<targetSourceDirectory>${project.build.directory}/generated-sources/tinder</targetSourceDirectory>
|
||||
<targetPackage>ca.uhn.test.generic.single.r4</targetPackage>
|
||||
<packageBase>ca.uhn.test.generic.multi.r4</packageBase>
|
||||
<targetFile>TestConfigR4.java</targetFile>
|
||||
<includeResources>
|
||||
<includeResource>patient</includeResource>
|
||||
<includeResource>organization</includeResource>
|
||||
</includeResources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generic_single_json</id>
|
||||
<goals>
|
||||
|
|
Loading…
Reference in New Issue