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.FhirContext;
|
||||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
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.DatatypeGeneratorUsingSpreadsheet;
|
||||||
|
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingModel;
|
||||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -45,6 +48,9 @@ public abstract class AbstractGenerator {
|
||||||
} else if ("dstu3".equals(context.getVersion())) {
|
} else if ("dstu3".equals(context.getVersion())) {
|
||||||
fhirContext = FhirContext.forDstu3();
|
fhirContext = FhirContext.forDstu3();
|
||||||
packageSuffix = ".dstu3";
|
packageSuffix = ".dstu3";
|
||||||
|
} else if ("r4".equals(context.getVersion())) {
|
||||||
|
fhirContext = FhirContext.forR4();
|
||||||
|
packageSuffix = ".r4";
|
||||||
} else {
|
} else {
|
||||||
throw new FailureException("Unknown version configured: " + context.getVersion());
|
throw new FailureException("Unknown version configured: " + context.getVersion());
|
||||||
}
|
}
|
||||||
|
@ -107,6 +113,7 @@ public abstract class AbstractGenerator {
|
||||||
DatatypeGeneratorUsingSpreadsheet dtp = null;
|
DatatypeGeneratorUsingSpreadsheet dtp = null;
|
||||||
Map<String, String> datatypeLocalImports = new HashMap<String, String>();
|
Map<String, String> datatypeLocalImports = new HashMap<String, String>();
|
||||||
|
|
||||||
|
if (ResourceSource.SPREADSHEET.equals(context.getResourceSource())) {
|
||||||
vsp = new ValueSetGenerator(context.getVersion());
|
vsp = new ValueSetGenerator(context.getVersion());
|
||||||
vsp.setResourceValueSetFiles(context.getValueSetFiles());
|
vsp.setResourceValueSetFiles(context.getValueSetFiles());
|
||||||
context.setValueSetGenerator(vsp);
|
context.setValueSetGenerator(vsp);
|
||||||
|
@ -135,30 +142,51 @@ public abstract class AbstractGenerator {
|
||||||
dtp.bindValueSets(vsp);
|
dtp.bindValueSets(vsp);
|
||||||
|
|
||||||
datatypeLocalImports = dtp.getLocalImports();
|
datatypeLocalImports = dtp.getLocalImports();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load the requested resources
|
* Load the requested resources
|
||||||
*/
|
*/
|
||||||
ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet(context.getVersion(), context.getBaseDir());
|
|
||||||
context.setResourceGenerator(rp);
|
|
||||||
logInfo("Loading Resources...");
|
logInfo("Loading Resources...");
|
||||||
try {
|
try {
|
||||||
|
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.setBaseResourceNames(includeResources);
|
||||||
rp.parse();
|
rp.parse();
|
||||||
rp.markResourcesForImports();
|
rp.markResourcesForImports();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new FailureException("Failed to load resources", 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) {
|
public FailureException(String message, Throwable cause) {
|
||||||
super(message, 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) {
|
public ExecutionException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
|
|
|
@ -19,25 +19,34 @@ package ca.uhn.fhir.tinder;
|
||||||
* #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.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
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
|
* @author Bill.Denton
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GeneratorContext {
|
public class GeneratorContext {
|
||||||
|
public enum ResourceSource {SPREADSHEET, MODEL};
|
||||||
|
public static final ResourceSource DEFAULT_RESOURCE_SOURCE = ResourceSource.SPREADSHEET;
|
||||||
|
|
||||||
private String version;
|
private String version;
|
||||||
private String packageSuffix;
|
private String packageSuffix;
|
||||||
private String baseDir;
|
private String baseDir;
|
||||||
private List<String> includeResources;
|
private List<String> includeResources;
|
||||||
private List<String> excludeResources;
|
private List<String> excludeResources;
|
||||||
|
private ResourceSource resourceSource = DEFAULT_RESOURCE_SOURCE;
|
||||||
private List<ValueSetFileDefinition> valueSetFiles;
|
private List<ValueSetFileDefinition> valueSetFiles;
|
||||||
private ResourceGeneratorUsingSpreadsheet resourceGenerator = null;
|
private BaseStructureParser resourceGenerator = null;
|
||||||
private ValueSetGenerator valueSetGenerator = null;
|
private ValueSetGenerator valueSetGenerator = null;
|
||||||
private DatatypeGeneratorUsingSpreadsheet datatypeGenerator = null;
|
private DatatypeGeneratorUsingSpreadsheet datatypeGenerator = null;
|
||||||
|
|
||||||
|
@ -72,6 +81,29 @@ public class GeneratorContext {
|
||||||
this.includeResources = includeResources;
|
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() {
|
public String getPackageSuffix() {
|
||||||
return packageSuffix;
|
return packageSuffix;
|
||||||
}
|
}
|
||||||
|
@ -80,11 +112,11 @@ public class GeneratorContext {
|
||||||
this.packageSuffix = packageSuffix;
|
this.packageSuffix = packageSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceGeneratorUsingSpreadsheet getResourceGenerator() {
|
public BaseStructureParser getResourceGenerator() {
|
||||||
return resourceGenerator;
|
return resourceGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResourceGenerator(ResourceGeneratorUsingSpreadsheet resourceGenerator) {
|
public void setResourceGenerator(BaseStructureParser resourceGenerator) {
|
||||||
this.resourceGenerator = resourceGenerator;
|
this.resourceGenerator = resourceGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
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 ca.uhn.fhir.tinder.parser.TargetType;
|
|
||||||
import org.apache.maven.model.Resource;
|
import org.apache.maven.model.Resource;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
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.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
import java.io.File;
|
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||||
import java.io.IOException;
|
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
||||||
import java.util.List;
|
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.
|
* 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">version</td>
|
||||||
* <td valign="top">The FHIR version whose resource metadata
|
* <td valign="top">The FHIR version whose resource metadata
|
||||||
* is to be used to generate the files<br>
|
* 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>
|
* <td valign="top" align="center">Yes</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
|
@ -53,7 +55,7 @@ import java.util.List;
|
||||||
* <td valign="top">generateResources</td>
|
* <td valign="top">generateResources</td>
|
||||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
* <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>
|
* 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>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">generateDataTypes</td>
|
* <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>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <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" />
|
* <td colspan="3" />
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
|
@ -246,6 +257,9 @@ public class TinderGenericMultiFileMojo extends AbstractMojo {
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private List<String> excludeResources;
|
private List<String> excludeResources;
|
||||||
|
|
||||||
|
@Parameter(required = false)
|
||||||
|
private String resourceSource;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private List<ValueSetFileDefinition> valueSetFiles;
|
private List<ValueSetFileDefinition> valueSetFiles;
|
||||||
|
|
||||||
|
@ -256,14 +270,23 @@ public class TinderGenericMultiFileMojo extends AbstractMojo {
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
|
|
||||||
GeneratorContext context = new GeneratorContext();
|
GeneratorContext context = new GeneratorContext();
|
||||||
|
Generator generator = new Generator();
|
||||||
|
try {
|
||||||
context.setVersion(version);
|
context.setVersion(version);
|
||||||
context.setBaseDir(baseDir);
|
context.setBaseDir(baseDir);
|
||||||
context.setIncludeResources(includeResources);
|
context.setIncludeResources(includeResources);
|
||||||
context.setExcludeResources(excludeResources);
|
context.setExcludeResources(excludeResources);
|
||||||
|
context.setResourceSource(resourceSource);
|
||||||
context.setValueSetFiles(valueSetFiles);
|
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 generator = new Generator();
|
|
||||||
try {
|
|
||||||
generator.prepare(context);
|
generator.prepare(context);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
||||||
|
@ -308,7 +331,7 @@ public class TinderGenericMultiFileMojo extends AbstractMojo {
|
||||||
/*
|
/*
|
||||||
* Write resources if selected
|
* Write resources if selected
|
||||||
*/
|
*/
|
||||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
BaseStructureParser rp = context.getResourceGenerator();
|
||||||
if (generateResources && rp != null) {
|
if (generateResources && rp != null) {
|
||||||
ourLog.info("Writing Resources...");
|
ourLog.info("Writing Resources...");
|
||||||
rp.setFilenamePrefix(filenamePrefix);
|
rp.setFilenamePrefix(filenamePrefix);
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
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 java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.apache.maven.model.Resource;
|
import org.apache.maven.model.Resource;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
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.app.VelocityEngine;
|
||||||
import org.apache.velocity.tools.generic.EscapeTool;
|
import org.apache.velocity.tools.generic.EscapeTool;
|
||||||
|
|
||||||
import java.io.*;
|
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||||
import java.util.List;
|
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.
|
* 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">version</td>
|
||||||
* <td valign="top">The FHIR version whose resource metadata
|
* <td valign="top">The FHIR version whose resource metadata
|
||||||
* is to be used to generate the files<br>
|
* 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>
|
* <td valign="top" align="center">Yes</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
|
@ -57,7 +65,7 @@ import java.util.List;
|
||||||
* <td valign="top">generateResources</td>
|
* <td valign="top">generateResources</td>
|
||||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
* <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>
|
* 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>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">generateDataTypes</td>
|
* <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>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <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" />
|
* <td colspan="3" />
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
|
@ -233,6 +250,9 @@ public class TinderGenericSingleFileMojo extends AbstractMojo {
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private List<String> excludeResources;
|
private List<String> excludeResources;
|
||||||
|
|
||||||
|
@Parameter(required = false)
|
||||||
|
private String resourceSource;
|
||||||
|
|
||||||
@Parameter(required = false)
|
@Parameter(required = false)
|
||||||
private List<ValueSetFileDefinition> valueSetFiles;
|
private List<ValueSetFileDefinition> valueSetFiles;
|
||||||
|
|
||||||
|
@ -243,14 +263,20 @@ public class TinderGenericSingleFileMojo extends AbstractMojo {
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
|
|
||||||
GeneratorContext context = new GeneratorContext();
|
GeneratorContext context = new GeneratorContext();
|
||||||
|
Generator generator = new Generator();
|
||||||
|
try {
|
||||||
context.setVersion(version);
|
context.setVersion(version);
|
||||||
context.setBaseDir(baseDir);
|
context.setBaseDir(baseDir);
|
||||||
context.setIncludeResources(includeResources);
|
context.setIncludeResources(includeResources);
|
||||||
context.setExcludeResources(excludeResources);
|
context.setExcludeResources(excludeResources);
|
||||||
|
context.setResourceSource(resourceSource);
|
||||||
context.setValueSetFiles(valueSetFiles);
|
context.setValueSetFiles(valueSetFiles);
|
||||||
|
if (ResourceSource.MODEL.equals(context.getResourceSource())) {
|
||||||
|
if (generateDatatypes) {
|
||||||
|
throw new MojoFailureException("Cannot use \"generateDatatypes\" when resourceSource=model");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Generator generator = new Generator();
|
|
||||||
try {
|
|
||||||
generator.prepare(context);
|
generator.prepare(context);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
throw new MojoExecutionException(e.getMessage(), e.getCause());
|
||||||
|
@ -351,7 +377,7 @@ public class TinderGenericSingleFileMojo extends AbstractMojo {
|
||||||
/*
|
/*
|
||||||
* Write resources if selected
|
* Write resources if selected
|
||||||
*/
|
*/
|
||||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
BaseStructureParser rp = context.getResourceGenerator();
|
||||||
if (generateResources && rp != null) {
|
if (generateResources && rp != null) {
|
||||||
ourLog.info("Writing Resources...");
|
ourLog.info("Writing Resources...");
|
||||||
ctx.put("resources", rp.getResources());
|
ctx.put("resources", rp.getResources());
|
||||||
|
|
|
@ -19,18 +19,16 @@ package ca.uhn.fhir.tinder.ant;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import java.io.File;
|
||||||
import ca.uhn.fhir.tinder.AbstractGenerator;
|
import java.io.FileInputStream;
|
||||||
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
import java.io.FileOutputStream;
|
||||||
import ca.uhn.fhir.tinder.AbstractGenerator.FailureException;
|
import java.io.InputStream;
|
||||||
import ca.uhn.fhir.tinder.GeneratorContext;
|
import java.io.InputStreamReader;
|
||||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
import java.io.OutputStreamWriter;
|
||||||
import ca.uhn.fhir.tinder.ValueSetGenerator;
|
import java.util.ArrayList;
|
||||||
import ca.uhn.fhir.tinder.VelocityHelper;
|
import java.util.List;
|
||||||
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
|
import java.util.StringTokenizer;
|
||||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
|
||||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
|
||||||
import ca.uhn.fhir.tinder.parser.TargetType;
|
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
import org.apache.tools.ant.Task;
|
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.app.VelocityEngine;
|
||||||
import org.apache.velocity.tools.generic.EscapeTool;
|
import org.apache.velocity.tools.generic.EscapeTool;
|
||||||
|
|
||||||
import java.io.*;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import java.util.ArrayList;
|
import ca.uhn.fhir.tinder.AbstractGenerator;
|
||||||
import java.util.List;
|
import ca.uhn.fhir.tinder.AbstractGenerator.ExecutionException;
|
||||||
import java.util.StringTokenizer;
|
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">version</td>
|
||||||
* <td valign="top">The FHIR version whose resource metadata
|
* <td valign="top">The FHIR version whose resource metadata
|
||||||
* is to be used to generate the files<br>
|
* 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>
|
* <td valign="top" align="center">Yes</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
|
@ -77,7 +84,7 @@ import java.util.StringTokenizer;
|
||||||
* <td valign="top">generateResources</td>
|
* <td valign="top">generateResources</td>
|
||||||
* <td valign="top">Should files be generated from FHIR resource metadata?<br>
|
* <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>
|
* 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>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td valign="top">generateDataTypes</td>
|
* <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>
|
* Valid values: <code><b>true</b></code> | <code><b>false</b></code></td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <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" />
|
* <td colspan="3" />
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
|
@ -281,6 +297,8 @@ public class TinderGeneratorTask extends Task {
|
||||||
|
|
||||||
private List<String> excludeResources;
|
private List<String> excludeResources;
|
||||||
|
|
||||||
|
private String resourceSource;
|
||||||
|
|
||||||
private List<ValueSetFileDefinition> valueSetFiles;
|
private List<ValueSetFileDefinition> valueSetFiles;
|
||||||
|
|
||||||
private boolean verbose;
|
private boolean verbose;
|
||||||
|
@ -303,14 +321,23 @@ public class TinderGeneratorTask extends Task {
|
||||||
|
|
||||||
|
|
||||||
GeneratorContext context = new GeneratorContext();
|
GeneratorContext context = new GeneratorContext();
|
||||||
|
Generator generator = new Generator();
|
||||||
|
try {
|
||||||
context.setVersion(version);
|
context.setVersion(version);
|
||||||
context.setBaseDir(projectHome);
|
context.setBaseDir(projectHome);
|
||||||
context.setIncludeResources(includeResources);
|
context.setIncludeResources(includeResources);
|
||||||
context.setExcludeResources(excludeResources);
|
context.setExcludeResources(excludeResources);
|
||||||
|
context.setResourceSource(resourceSource);
|
||||||
context.setValueSetFiles(valueSetFiles);
|
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 generator = new Generator();
|
|
||||||
try {
|
|
||||||
generator.prepare(context);
|
generator.prepare(context);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new BuildException(e.getMessage(), e.getCause());
|
throw new BuildException(e.getMessage(), e.getCause());
|
||||||
|
@ -413,7 +440,7 @@ public class TinderGeneratorTask extends Task {
|
||||||
/*
|
/*
|
||||||
* Write resources if selected
|
* Write resources if selected
|
||||||
*/
|
*/
|
||||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
BaseStructureParser rp = context.getResourceGenerator();
|
||||||
if (generateResources && rp != null) {
|
if (generateResources && rp != null) {
|
||||||
log("Writing Resources...");
|
log("Writing Resources...");
|
||||||
ctx.put("resources", rp.getResources());
|
ctx.put("resources", rp.getResources());
|
||||||
|
@ -436,7 +463,7 @@ public class TinderGeneratorTask extends Task {
|
||||||
/*
|
/*
|
||||||
* Write resources if selected
|
* Write resources if selected
|
||||||
*/
|
*/
|
||||||
ResourceGeneratorUsingSpreadsheet rp = context.getResourceGenerator();
|
BaseStructureParser rp = context.getResourceGenerator();
|
||||||
if (generateResources && rp != null) {
|
if (generateResources && rp != null) {
|
||||||
log("Writing Resources...");
|
log("Writing Resources...");
|
||||||
rp.setFilenamePrefix(filenamePrefix);
|
rp.setFilenamePrefix(filenamePrefix);
|
||||||
|
@ -550,6 +577,14 @@ public class TinderGeneratorTask extends Task {
|
||||||
this.projectHome = projectHome;
|
this.projectHome = projectHome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getResourceSource() {
|
||||||
|
return resourceSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceSource(String resourceSource) {
|
||||||
|
this.resourceSource = resourceSource;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTargetFile(String targetFile) {
|
public void setTargetFile(String targetFile) {
|
||||||
this.targetFile = targetFile;
|
this.targetFile = targetFile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,11 @@
|
||||||
<artifactId>hapi-fhir-structures-dstu3</artifactId>
|
<artifactId>hapi-fhir-structures-dstu3</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
|
<artifactId>hapi-fhir-structures-r4</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
|
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
|
||||||
|
@ -119,6 +124,11 @@
|
||||||
<artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
|
<artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
|
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<executions>
|
<executions>
|
||||||
<!--
|
<!--
|
||||||
|
@ -174,7 +184,7 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
<execution>
|
<execution>
|
||||||
<id>generic_multi</id>
|
<id>generic_multi_dstu2</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>generate-multi-files</goal>
|
<goal>generate-multi-files</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
@ -191,6 +201,44 @@
|
||||||
</includeResources>
|
</includeResources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</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>
|
<execution>
|
||||||
<id>generic_multi_json</id>
|
<id>generic_multi_json</id>
|
||||||
<goals>
|
<goals>
|
||||||
|
@ -199,6 +247,7 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<version>dstu2</version>
|
<version>dstu2</version>
|
||||||
<generateResources>true</generateResources>
|
<generateResources>true</generateResources>
|
||||||
|
<resourceSource>spreadsheet</resourceSource>
|
||||||
<templateFile>${project.basedir}/src/test/resources/templates/resource_map.vm</templateFile>
|
<templateFile>${project.basedir}/src/test/resources/templates/resource_map.vm</templateFile>
|
||||||
<velocityPath>${project.basedir}/src/test/resources/macros</velocityPath>
|
<velocityPath>${project.basedir}/src/test/resources/macros</velocityPath>
|
||||||
<targetResourceDirectory>${project.build.directory}/generated-resources/tinder</targetResourceDirectory>
|
<targetResourceDirectory>${project.build.directory}/generated-resources/tinder</targetResourceDirectory>
|
||||||
|
@ -213,7 +262,7 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
<execution>
|
<execution>
|
||||||
<id>generic_single</id>
|
<id>generic_single_dstu2</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>generate-single-file</goal>
|
<goal>generate-single-file</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
@ -231,6 +280,26 @@
|
||||||
</includeResources>
|
</includeResources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</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>
|
<execution>
|
||||||
<id>generic_single_json</id>
|
<id>generic_single_json</id>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
Loading…
Reference in New Issue