Skip to content

Commit

Permalink
Finish getting superstructures building cleanly and document the mave…
Browse files Browse the repository at this point in the history
…n plugins
  • Loading branch information
jamesagnew committed Jan 30, 2013
1 parent 3153e87 commit 30090e2
Show file tree
Hide file tree
Showing 21 changed files with 508 additions and 150 deletions.
3 changes: 2 additions & 1 deletion hapi-sourcegen/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar"/>
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.6/slf4j-api-1.6.6.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring/2.5.6/spring-2.5.6.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/velocity/velocity/1.6.3/velocity-1.6.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/velocity/velocity/1.7/velocity-1.7.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/maven/wagon/wagon-file/1.0-beta-6/wagon-file-1.0-beta-6.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/maven/wagon/wagon-http/1.0-beta-6/wagon-http-1.0-beta-6.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/maven/wagon/wagon-http-shared/1.0-beta-6/wagon-http-shared-1.0-beta-6.jar"/>
Expand All @@ -64,5 +64,6 @@
<attribute name="javadoc_location" value="jar:file:/Users/james/.m2/repository/ca/uhn/hapi/hapi-structures-v25/2.0/hapi-structures-v25-2.0-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/apache/velocity/velocity-tools/2.0/velocity-tools-2.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
7 changes: 6 additions & 1 deletion hapi-sourcegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.6.3</version>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<!-- Needed by velocity -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ GNU General Public License (the �GPL�), in which case the provisions of the
* @requiresDependencyResolution runtime
* @requiresProject
* @inheritedByDefault false
* @since 2.1
*/
public class ConfGenMojo extends AbstractMojo {

Expand All @@ -61,6 +62,7 @@ public class ConfGenMojo extends AbstractMojo {
* @parameter property="project"
* @required
* @readonly
* @since 2.1
*/
MavenProject project;

Expand All @@ -69,6 +71,7 @@ public class ConfGenMojo extends AbstractMojo {
*
* @parameter
* @required
* @since 2.1
*/
String targetDirectory;

Expand All @@ -77,6 +80,7 @@ public class ConfGenMojo extends AbstractMojo {
*
* @parameter
* @required
* @since 2.1
*/
String profile;

Expand All @@ -85,6 +89,7 @@ public class ConfGenMojo extends AbstractMojo {
*
* @parameter
* @required
* @since 2.1
*/
String packageName;

Expand All @@ -109,13 +114,15 @@ public class ConfGenMojo extends AbstractMojo {
* </ul>
*
* @parameter default-value="NONE"
* @since 2.1
*/
String generateDataTypes = "NONE";

/**
* The package from which to load the templates
*
* @parameter default="ca.uhn.hl7v2.sourcegen.templates"
* @since 2.1
*/
String templatePackage = "ca.uhn.hl7v2.sourcegen.templates";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ GNU General Public License (the �GPL�), in which case the provisions of the

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.Version;
import ca.uhn.hl7v2.model.AbstractType;
import ca.uhn.hl7v2.model.GenericComposite;
import ca.uhn.hl7v2.model.Group;
import ca.uhn.hl7v2.model.Message;
Expand All @@ -58,7 +57,6 @@ GNU General Public License (the �GPL�), in which case the provisions of the
import ca.uhn.hl7v2.sourcegen.MessageGenerator;
import ca.uhn.hl7v2.sourcegen.SegmentDef;
import ca.uhn.hl7v2.sourcegen.StructureDef;
import ca.uhn.hl7v2.sourcegen.util.ResourceLoader;
import ca.uhn.hl7v2.util.ReflectionUtil;

/**
Expand All @@ -73,8 +71,6 @@ GNU General Public License (the �GPL�), in which case the provisions of the
*/
public class SuperStructureMojo extends AbstractMojo {

private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SuperStructureMojo.class);

/**
* The maven project.
*
Expand Down Expand Up @@ -114,11 +110,6 @@ public class SuperStructureMojo extends AbstractMojo {
*/
private String targetStructureName;

/**
* The package from which to load the templates
*
* @parameter default="ca.uhn.hl7v2.sourcegen.templates"
*/
private String templatePackage = "ca.uhn.hl7v2.sourcegen.templates";

/**
Expand Down Expand Up @@ -185,7 +176,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
throw new MojoExecutionException("No structures found matching structures to merge");
}

ourLog.info("Creating directory: {}", targetDirectory);
getLog().info("Creating directory: " + targetDirectory);
new File(targetDirectory).mkdirs();

boolean haveGroups = false;
Expand All @@ -197,7 +188,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

String fileName = MessageGenerator.determineTargetDir(targetDirectory + "/", version) + "/" + targetStructureName + ".java";
ourLog.info("Filename will be: {}", fileName);
getLog().info("Filename will be: " + fileName);

StructureDef[] contents = structures.toArray(new StructureDef[structures.size()]);
String basePackageName = DefaultModelClassFactory.getVersionPackageName(version);
Expand Down Expand Up @@ -351,13 +342,13 @@ private ListOfStructureDefsAndMapOfStructreNames mergeGroups(List<? extends Grou
return retVal;
}

static ArrayList<String> mergeStringLists(List<List<String>> allNameLists) {
ArrayList<String> mergeStringLists(List<List<String>> allNameLists) {
ArrayList<String> baseList = new ArrayList<String>(allNameLists.remove(0));
ourLog.info("Base list is: {}", baseList);
getLog().debug("Base list is: "+ baseList);

for (List<String> nextCompareList : allNameLists) {

ourLog.info("Next compare list: {}", nextCompareList);
getLog().debug("Next compare list: "+ nextCompareList);

int baseIndex = 0;
int compareIndex = 0;
Expand Down Expand Up @@ -421,11 +412,11 @@ static ArrayList<String> mergeStringLists(List<List<String>> allNameLists) {
// break;
// }
}
ourLog.info("Base list is now: {}", baseList);
getLog().debug("Base list is now: "+ baseList);

}

ourLog.info("Merged name list: {}", baseList);
getLog().debug("Merged name list: "+ baseList);
return baseList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,49 @@
import ca.uhn.hl7v2.util.XMLUtils;

/**
* @author <a href="mailto:[email protected]">James Agnew</a>
* The XsdConfGen tool takes an HL7 conformance profile and creates an XSD
* schema which matches the XML encoding for messages meeting that conformance
* profile. In addition, it is able to combine multiple profiles into a single
* schema.
*
* See the <a href="./xsdconfgen-usage.html">usage page</a> for information on
* how to use this plugin.
*
* This plugin was contributed as a part of the <a
* href="http://conftest.connectinggta.ca/">ConnectingGTA</a> project.
*
* @author This plugin was contributed as a part of the <a
* href="http://conftest.connectinggta.ca/">ConnectingGTA</a> project
* @goal xsdconfgen
* @phase generate-sources
* @requiresDependencyResolution runtime
* @requiresProject
* @inheritedByDefault false
* @since 2.1
*/
public class XsdConfGenMojo extends AbstractMojo {

private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XsdConfGenMojo.class);

/**
* The conformance profiles (XML file paths) to use
* One or more XML conformance profiles. If more than one is used, the
* contents will be combined. Note that this has the effect of merging the
* profiles in a specific way: When an element is found in a profile for the
* first time (e.g. a definition for the PID segment), that element is
* generated into the XSD. If the same element is found in a subsequent
* profile, it is ignored and the definition from the first profile is used.
* <p>
* This is desirable if you want to process multiple message types in
* certain toolsets and reuse modules for processing some structures.
* </p><p>
* If completely separate definitions are desired, this can be accomplished
* by configuring the xsdconfgen plugin to have multiple executions and to
* use only a single conformance profile for each execution.
* </p>
*
* @parameter
* @required
* @since 2.1
*/
private List<String> profiles;

Expand All @@ -63,6 +90,7 @@ public class XsdConfGenMojo extends AbstractMojo {
*
* @parameter expression="${project}"
* @required
* @since 2.1
* @readonly
*/
private MavenProject project;
Expand All @@ -72,17 +100,18 @@ public class XsdConfGenMojo extends AbstractMojo {
*
* @parameter
* @required
* @since 2.1
*/
private String targetDirectory;

/**
* The Message Workbench tool generally creates segment groups as two
* level structures, with an outer group which has only a single
* child which is the actual group. If this is set to true (which is
* the default), these "bogus" groups are filtered.
* The Message Workbench tool generally creates segment groups as two level
* structures, with an outer group which has only a single child which is
* the actual group. If this is set to true (which is the default), these
* "bogus" groups are filtered.
*
* @parameter
* @required
* @parameter default="true"
* @since 2.1
*/
private boolean filterBogusGroups = true;

Expand All @@ -92,28 +121,37 @@ public class XsdConfGenMojo extends AbstractMojo {
*
* @parameter
* @required
* @since 2.1
*/
private String targetFile;

/**
* The file name for the generated file (file will be placed in the
* targetDirectory)
* If set to <code>true</code> (default is <code>false</code>), any elements
* which are defined to have a usage of "X" (not supported) will not be
* generated as elements in the schema.
*
* @parameter
* @required
* @parameter default="false"
* @since 2.1
*/
private boolean constrain;

private Map<String, String> linkTriggerToStructure;
private boolean constrain = false;

/**
* The package from which to load the templates
* If provided, created additional message types in the schema and links
* them to a structure provided by any of the conformance profiles defined
* by the &lt;profiles&gt; configuration element. For example, if you have a
* conformance profile which defines a structure called ADT_A01, you may use
* this parameter to create an additional message of ADT_A02 which also uses
* the ADT_A01 structure. This is useful when you want to have a single
* structure to use for a number of message types.
*
* @parameter default="ca.uhn.hl7v2.sourcegen.templates.xsd"
* @parameter
* @since 2.1
*/
private Map<String, String> linkTriggerToStructure;

private String templatePackage = "ca.uhn.hl7v2.sourcegen.templates.xsd";

private static final Set<String> ourConstrainedUsageTypes = new HashSet<String>(new ArrayList<String>(Arrays.asList(new String[] {"R", "RE", "O", "C" })));
private static final Set<String> ourConstrainedUsageTypes = new HashSet<String>(new ArrayList<String>(Arrays.asList(new String[] { "R", "RE", "O", "C" })));

/**
* {@inheritDoc}
Expand All @@ -122,6 +160,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {

try {

if (!new File(targetDirectory).exists()) {
ourLog.info("Creating directory: {}", targetDirectory);
new File(targetDirectory).mkdirs();
}

List<RuntimeProfile> parsedProfiles = new ArrayList<RuntimeProfile>();
for (String nextProfile : profiles) {

Expand Down Expand Up @@ -152,7 +195,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
StaticDef staticDef = runtimeProfile.getMessage();
filterBogusGroups(staticDef);
}

parsedProfiles.add(runtimeProfile);
}

Expand Down Expand Up @@ -180,11 +223,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
template.merge(ctx, sw);
sw.close();

FileWriter w3 = new FileWriter(targetFileDef, false);
w3.write(sw.toString());
w3.close();
// FileWriter w3 = new FileWriter(targetFileDef, false);
// w3.write(sw.toString());
// w3.close();

if (ourLog.isDebugEnabled()) {
ourLog.debug("DOcument: " + sw.toString());
}

ourLog.info("DOcument: " + sw.toString());
String xml = XMLUtils.serialize(XMLUtils.parse(sw.toString()));

FileWriter w = new FileWriter(targetFileDef, false);
Expand All @@ -203,7 +249,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

private void filterBogusGroups(AbstractSegmentContainer theParent) {
List<ProfileStructure> children = theParent.getChildrenAsList();

for (int childIndex = 0; childIndex < children.size(); childIndex++) {
ProfileStructure nextChild = children.get(childIndex);
if (nextChild instanceof SegGroup) {
Expand All @@ -214,13 +260,12 @@ private void filterBogusGroups(AbstractSegmentContainer theParent) {
nextChildSg = newNextChildSg;
children.set(childIndex, nextChildSg);
}

filterBogusGroups(nextChildSg);
}
}

}


private void constrainSegGroup(SegGroup theNext) throws ProfileException {
for (int i = 0; i < theNext.getChildrenAsList().size(); i++) {
Expand Down Expand Up @@ -327,7 +372,7 @@ public static void main(String[] args) throws MojoExecutionException, MojoFailur
tst.profiles.add("/eclipse/workspace//CGTA_Input_Tester_gc/ConverterLibrary/src/main/resources/ca/cgta/input/conf/cgta-ras_o17.xml");

tst.templatePackage = "ca.uhn.hl7v2.sourcegen.templates.xsd";

tst.constrain = true;
tst.execute();

Expand Down
Loading

0 comments on commit 30090e2

Please sign in to comment.