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.io.FileNotFoundException; 32 import java.io.FileReader; 33 import java.io.IOException; 34 35 import org.apache.maven.plugin.AbstractMojo; 36 import org.apache.maven.plugin.MojoExecutionException; 37 import org.apache.maven.project.MavenProject; 38 import org.codehaus.plexus.util.IOUtil; 39 40 import ca.uhn.hl7v2.conf.classes.exceptions.ConformanceException; 41 import ca.uhn.hl7v2.conf.classes.generator.builders.DeploymentManager; 42 43 /** 44 * Maven Plugin Mojo for generating HAPI conformance classes 45 * 46 * @author <a href="mailto:jamesagnew@sourceforge.net">James Agnew</a> 47 * @goal confgen-classic 48 * @phase generate-sources 49 * @requiresDependencyResolution runtime 50 * @requiresProject 51 * @inheritedByDefault false 52 */ 53 public class ClassicConfGenMojo extends AbstractMojo 54 { 55 56 /** 57 * The maven project. 58 * 59 * @parameter property="project" 60 * @required 61 * @readonly 62 */ 63 private MavenProject project; 64 65 66 /** 67 * The target directory for the generated source 68 * 69 * @parameter 70 * @required 71 */ 72 private String targetDirectory; 73 74 75 /** 76 * The conformance profile (XML file path) to use 77 * 78 * @parameter 79 * @required 80 */ 81 private String profile; 82 83 84 /** 85 * The package for the generated source 86 * 87 * @parameter 88 * @required 89 */ 90 private String packageName; 91 92 93 /** 94 * {@inheritDoc} 95 */ 96 public void execute() throws MojoExecutionException { 97 98 try { 99 String profileString; 100 FileReader reader = new FileReader(profile); 101 profileString = IOUtil.toString(reader); 102 103 DeploymentManager dm = new DeploymentManager(targetDirectory, packageName); 104 dm.generate(profileString); 105 106 } catch (ConformanceException | IOException e) { 107 throw new MojoExecutionException(e.getMessage(), e); 108 } 109 110 project.addCompileSourceRoot(targetDirectory); 111 112 } 113 114 }