1 | |
package com.aurea.maven.plugins.sonic.sdm; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.apache.maven.plugin.MojoExecutionException; |
7 | |
import org.apache.maven.plugin.MojoFailureException; |
8 | |
|
9 | |
import com.aurea.maven.plugins.sonic.sdm.util.ESBDeploymentModel; |
10 | |
import com.aurea.maven.plugins.sonic.sdm.util.ESBDeploymentModelBuilder; |
11 | |
import com.aurea.maven.plugins.util.VelocityRunner; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | 0 | public class VelocityGeneratorMojo extends AbstractSdmMojo { |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
private List<String> templateFiles; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
private String propFileName; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | private String aiOutputDirName = "ai"; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
protected void doExecute() throws MojoExecutionException, MojoFailureException { |
51 | |
|
52 | 0 | ESBDeploymentModelBuilder builder = new ESBDeploymentModelBuilder(project, getLog()); |
53 | 0 | ESBDeploymentModel model = null; |
54 | |
|
55 | |
try { |
56 | 0 | model = builder.getModel(); |
57 | 0 | } catch (Exception e) { |
58 | 0 | throw new MojoExecutionException("Error building Deployment Model", e); |
59 | 0 | } |
60 | |
|
61 | 0 | getLog().info("Executing Velocity ...."); |
62 | |
|
63 | 0 | VelocityRunner runner = VelocityRunner.getInstance(project); |
64 | 0 | runner.setOutputDirectory(aiOutputDirName); |
65 | 0 | runner.addProperty("env", System.getenv()); |
66 | 0 | runner.addProperty("system", System.getProperties()); |
67 | 0 | runner.addProperties("user", propFileName); |
68 | 0 | runner.addProperty("model", model); |
69 | |
|
70 | 0 | for(String tplFile: templateFiles) { |
71 | 0 | getLog().debug("Generating Template: " + tplFile); |
72 | |
try { |
73 | 0 | runner.run(tplFile, new File(tplFile).getName()); |
74 | 0 | } catch (Exception e) { |
75 | 0 | throw new MojoExecutionException("Template generation failed.", e); |
76 | 0 | } |
77 | 0 | } |
78 | |
|
79 | 0 | } |
80 | |
|
81 | |
} |