1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.codehaus.modello.plugin.velocity;
20
21 import java.io.File;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Objects;
26 import java.util.Properties;
27 import java.util.stream.Collectors;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.codehaus.modello.maven.AbstractModelloGeneratorMojo;
32
33
34
35
36
37
38 @Mojo(name = "velocity", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
39 public class ModelloVelocityMojo extends AbstractModelloGeneratorMojo {
40
41
42
43 @Parameter(defaultValue = "${project.build.directory}/generated-sources/modello", required = true)
44 private File outputDirectory;
45
46 @Parameter
47 private List<String> templates;
48
49 @Parameter
50 private List<String> params;
51
52 protected String getGeneratorType() {
53 return "velocity";
54 }
55
56 protected void customizeParameters(Properties parameters) {
57 super.customizeParameters(parameters);
58 Map<String, String> params = this.params != null
59 ? this.params.stream()
60 .collect(Collectors.toMap(
61 s -> s.substring(0, s.indexOf('=')), s -> s.substring(s.indexOf('=') + 1)))
62 : Collections.emptyMap();
63 parameters.put("basedir", Objects.requireNonNull(getBasedir(), "basedir is null"));
64 parameters.put(VelocityGenerator.VELOCITY_TEMPLATES, String.join(",", templates));
65 parameters.put(VelocityGenerator.VELOCITY_PARAMETERS, params);
66 }
67
68 protected boolean producesCompilableResult() {
69 return true;
70 }
71
72 public File getOutputDirectory() {
73 return outputDirectory;
74 }
75
76 public void setOutputDirectory(File outputDirectory) {
77 this.outputDirectory = outputDirectory;
78 }
79 }