@@ -61,13 +61,20 @@ public class ModelloVelocityMojo
61
61
/**
62
62
* The output directory of the generated files.
63
63
*/
64
- @ Parameter ( defaultValue = "${project.build.directory}/generated-sources/modello" , required = true )
64
+ @ Parameter ( defaultValue = "${project.build.directory}/generated-sources/modello" )
65
65
private File outputDirectory ;
66
66
67
+ /**
68
+ * The directory where Velocity templates are looked for.
69
+ */
70
+ @ Parameter ( defaultValue = "${project.basedir}" )
71
+ private File velocityBasedir ;
72
+
67
73
/**
68
74
* A list of template paths to be run against the loaded modello model.
69
75
* Those are {@code .vm} files as described in the
70
- * <a href="https://velocity.apache.org/engine/devel/user-guide.html">Velocity Users Guide</a>.
76
+ * <a href="https://velocity.apache.org/engine/devel/user-guide.html">Velocity Users Guide</a>
77
+ * relative to {@code velocityBasedir}.
71
78
*/
72
79
@ Parameter
73
80
private List <String > templates ;
@@ -87,13 +94,15 @@ protected String getGeneratorType()
87
94
protected void customizeParameters ( Properties parameters )
88
95
{
89
96
super .customizeParameters ( parameters );
90
- Map <String , String > params = this .params != null ? this .params .stream ().collect ( Collectors .toMap (
91
- s -> s .substring ( 0 , s .indexOf ( '=' ) ), s -> s .substring ( s .indexOf ( '=' ) + 1 )
92
- ) ) : Collections .emptyMap ();
93
- parameters .put ( "basedir" , Objects .requireNonNull ( getBasedir (), "basedir is null" ) );
94
- Path basedir = Paths .get ( getBasedir () );
95
- parameters .put ( VelocityGenerator .VELOCITY_TEMPLATES , templates .stream ()
96
- .collect ( Collectors .joining ( "," ) ) );
97
+
98
+ Map <String , String > params = this .params == null ? Collections .emptyMap ()
99
+ : this .params .stream ().collect ( Collectors .toMap ( s -> s .substring ( 0 , s .indexOf ( '=' ) ),
100
+ s -> s .substring ( s .indexOf ( '=' ) + 1 ) ) );
101
+
102
+ parameters .put ( VelocityGenerator .VELOCITY_BASEDIR , velocityBasedir .getAbsolutePath () );
103
+
104
+ parameters .put ( VelocityGenerator .VELOCITY_TEMPLATES ,
105
+ templates .stream ().collect ( Collectors .joining ( "," ) ) );
97
106
parameters .put ( VelocityGenerator .VELOCITY_PARAMETERS , params );
98
107
}
99
108
@@ -102,13 +111,9 @@ protected boolean producesCompilableResult()
102
111
return true ;
103
112
}
104
113
114
+ @ Override
105
115
public File getOutputDirectory ()
106
116
{
107
117
return outputDirectory ;
108
118
}
109
-
110
- public void setOutputDirectory ( File outputDirectory )
111
- {
112
- this .outputDirectory = outputDirectory ;
113
- }
114
119
}
0 commit comments