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