1 /** 2 The contents of this file are subject to the Mozilla Public License Version 1.1 3 (the "License"); you may not use this file except in compliance with the License. 4 You may obtain a copy of the License at http://www.mozilla.org/MPL/ 5 Software distributed under the License is distributed on an "AS IS" basis, 6 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 7 specific language governing rights and limitations under the License. 8 9 The Original Code is "DataTypeGenerator.java". Description: 10 "Generates skeletal source code for Datatype classes based on the 11 HL7 database" 12 13 The Initial Developer of the Original Code is University Health Network. Copyright (C) 14 2001. All Rights Reserved. 15 16 Contributor(s): James Agnew 17 18 Alternatively, the contents of this file may be used under the terms of the 19 GNU General Public License (the �GPL�), in which case the provisions of the GPL are 20 applicable instead of those above. If you wish to allow use of your version of this 21 file only under the terms of the GPL and not to allow others to use your version 22 of this file under the MPL, indicate your decision by deleting the provisions above 23 and replace them with the notice and other provisions required by the GPL License. 24 If you do not delete the provisions above, a recipient may use your version of 25 this file under either the MPL or the GPL. 26 27 */ 28 29 package ca.uhn.hl7v2.mvnplugin; 30 31 import java.util.HashSet; 32 import java.util.Set; 33 34 import org.apache.maven.plugin.AbstractMojo; 35 import org.apache.maven.plugin.MojoExecutionException; 36 import org.apache.maven.project.MavenProject; 37 38 import ca.uhn.hl7v2.HL7Exception; 39 import ca.uhn.hl7v2.database.NormativeDatabase; 40 import ca.uhn.hl7v2.sourcegen.DataTypeGenerator; 41 import ca.uhn.hl7v2.sourcegen.EventMapGenerator; 42 import ca.uhn.hl7v2.sourcegen.SourceGenerator; 43 44 /** 45 * Maven Plugin Mojo for generating HAPI HL7 message/segment/etc source files 46 * 47 * @author <a href="mailto:jamesagnew@sourceforge.net">James Agnew</a> 48 * @goal xrefgen 49 * @phase generate-sources 50 * @requiresDependencyResolution runtime 51 * @requiresProject 52 * @inheritedByDefault false 53 */ 54 public class XrefGenMojo extends AbstractMojo 55 { 56 private static final Set<String> alreadyMade = new HashSet<>(); 57 58 /** 59 * The maven project. 60 * 61 * @parameter property="project" 62 * @required 63 * @readonly 64 */ 65 @SuppressWarnings("unused") 66 private MavenProject project; 67 68 69 /** 70 * The target directory for the generated source 71 * 72 * @parameter 73 * @required 74 */ 75 private String targetDirectory; 76 77 /** 78 * The version for the generated source 79 * 80 * @parameter 81 */ 82 private String version; 83 84 85 /** 86 * The JDBC URL for the HL7 database 87 * 88 * @parameter 89 */ 90 private String jdbcUrl; 91 92 /** 93 * The JDBC User for the HL7 database 94 * 95 * @parameter 96 */ 97 private String jdbcUser; 98 99 /** 100 * The JDBC Password for the HL7 database 101 * 102 * @parameter 103 */ 104 private String jdbcPassword; 105 106 107 /** 108 * Should build be skipped 109 * 110 * @parameter 111 */ 112 private boolean skip; 113 114 /** 115 * The package from which to load the templates 116 * 117 * @parameter default="ca.uhn.hl7v2.sourcegen.templates" 118 */ 119 private final String templatePackage = "ca.uhn.hl7v2.sourcegen.templates.json"; 120 121 /** 122 * {@inheritDoc} 123 */ 124 public void execute() throws MojoExecutionException { 125 126 if (skip) { 127 getLog().warn("Configured to skip"); 128 } 129 130 if (!alreadyMade.contains(version)) { 131 132 // I haven't entirely figured out why, but Maven runs this plugin 133 // several times for each version, which takes forever, so we assume 134 // that if the directory exists, we don't need to generate again 135 alreadyMade.add(version); 136 137 if (jdbcUser == null) { 138 jdbcUser = ""; 139 } 140 if (jdbcPassword == null) { 141 jdbcPassword = ""; 142 } 143 144 System.setProperty(NormativeDatabase.PROP_DATABASE_USER, jdbcUser); 145 System.setProperty(NormativeDatabase.PROP_DATABASE_PASSWORD, jdbcPassword); 146 System.setProperty(NormativeDatabase.PROP_DATABASE_URL, jdbcUrl); 147 148 DataTypeGenerator.setMakeAll(true); 149 150 try { 151 SourceGenerator.makeAll(targetDirectory, version, false, templatePackage, "json"); 152 EventMapGenerator.generateEventDesc(targetDirectory, version, templatePackage); 153 } catch (Exception e) { 154 e.printStackTrace(); 155 throw new MojoExecutionException("Failed to build source ", e); 156 } 157 158 } else { 159 getLog().warn("Already made version " + version + ", skipping!"); 160 } 161 162 } 163 164 }