1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package ca.uhn.hl7v2.mvnplugin;
30
31 import java.io.File;
32 import java.io.IOException;
33 import java.sql.SQLException;
34 import java.util.HashSet;
35 import java.util.Set;
36
37 import org.apache.maven.plugin.AbstractMojo;
38 import org.apache.maven.plugin.MojoExecutionException;
39 import org.apache.maven.project.MavenProject;
40
41 import ca.uhn.hl7v2.HL7Exception;
42 import ca.uhn.hl7v2.database.NormativeDatabase;
43 import ca.uhn.hl7v2.sourcegen.EventMapGenerator;
44 import ca.uhn.hl7v2.sourcegen.SourceGenerator;
45
46
47
48
49
50
51
52
53
54
55
56 public class SourceGenMojo extends AbstractMojo
57 {
58 private static final Set<String> alreadyMade = new HashSet<>();
59
60
61
62
63
64
65
66
67 private MavenProject project;
68
69
70
71
72
73
74
75
76 private String targetDirectory;
77
78
79
80
81
82
83
84 private String targetResourceDirectory;
85
86
87
88
89
90
91 private String version;
92
93
94
95
96
97
98 private boolean forceGroupNames;
99
100
101
102
103
104
105 private String jdbcUrl;
106
107
108
109
110
111
112 private String jdbcUser;
113
114
115
116
117
118
119 private String jdbcPassword;
120
121
122
123
124
125
126
127 private boolean skip;
128
129
130
131
132
133
134 private final String templatePackage = "ca.uhn.hl7v2.sourcegen.templates";
135
136
137
138
139
140
141 private boolean structuresAsResources;
142
143
144
145
146 public void execute() throws MojoExecutionException {
147
148 if (skip) {
149 getLog().warn("Configured to skip");
150 }
151
152 if (forceGroupNames) {
153 System.setProperty("force.group", "true");
154 } else {
155 System.setProperty("force.group", "false");
156 }
157
158 if (new File(targetDirectory).exists()) {
159 getLog().warn("Already exists version " + version + ", skipping!");
160 } else if (!alreadyMade.contains(version)) {
161
162
163
164
165 alreadyMade.add(version);
166
167 if (jdbcUser == null) {
168 jdbcUser = "";
169 }
170 if (jdbcPassword == null) {
171 jdbcPassword = "";
172 }
173
174 System.setProperty(NormativeDatabase.PROP_DATABASE_USER, jdbcUser);
175 System.setProperty(NormativeDatabase.PROP_DATABASE_PASSWORD, jdbcPassword);
176 System.setProperty(NormativeDatabase.PROP_DATABASE_URL, jdbcUrl);
177
178 try {
179 EventMapGenerator.generateEventMap(targetResourceDirectory, version);
180 String targetDir = structuresAsResources ? targetResourceDirectory : targetDirectory;
181 SourceGenerator.makeAll(targetDir, version, false, templatePackage, "java");
182 } catch (HL7Exception | IOException | SQLException e) {
183 throw new MojoExecutionException("Failed to build source ", e);
184 }
185
186 } else {
187 getLog().warn("Already made version " + version + ", skipping!");
188 }
189
190 if (!structuresAsResources) {
191 getLog().info("Adding " + targetDirectory + " to compile source root");
192 project.addCompileSourceRoot(targetDirectory);
193 }
194 }
195
196 }