@@ -130,7 +130,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
130130 // Ask for archetype group id (defaults to distribution group id)
131131 archetypeGroupId = prompter .promptInput ("Enter the archetype group id" , archetypeGroupId );
132132 // Ask for archetype artifact id
133- archetypeArtifactId = prompter .promptInput ("Enter the archetype artifact id" , null );
133+ archetypeArtifactId = prompter .promptInput ("Enter the archetype artifact id" , "web-archetype" );
134134 // Ask for archetype version (defaults to latest)
135135 try {
136136 archetypeVersion = artifactResolver .getHighestVersion (mavenProject , archetypeGroupId , archetypeArtifactId , allowSnapshots );
@@ -206,8 +206,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
206206
207207 executionEnvironment (mavenProject , mavenSession , buildPluginManager ));
208208
209- File projectDir = new File ("." + File .separator + artifactId );
209+ final File projectDir = new File ("." + File .separator + artifactId );
210210 if (projectDir .exists () && projectDir .canWrite ()) {
211+ final File questionFile = new File (projectDir , "questions.json" );
212+
211213 // Create template engines
212214 stringTemplateEngine = new PebbleEngine .Builder ()
213215 .loader (new StringLoader ())
@@ -218,7 +220,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
218220 .build ();
219221
220222 // Create vars
221- HashMap <String , Object > vars = new HashMap <>();
223+ final HashMap <String , Object > vars = new HashMap <>();
222224
223225 // Put project values in vars
224226 HashMap <String , Object > projectVars = new HashMap <>();
@@ -240,11 +242,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
240242 archetypeVars .put ("version" , archetypeVersion );
241243 vars .put ("archetype" , archetypeVars );
242244
245+ Thread shutdownRender = new Thread (new Runnable () {
246+ @ Override
247+ public void run () {
248+ renderTemplates (projectDir , vars );
249+ if (questionFile .exists () && questionFile .canRead () && !questionFile .delete ()) {
250+ getLog ().warn ("Unable to delete question file, useless files may be still be present in project" );
251+ }
252+ }
253+ }, "render-hook" );
254+
255+ // If the user cancels during question, complete the process with minimal vars
256+ Runtime .getRuntime ().addShutdownHook (shutdownRender );
257+
243258 // Inquire from user if a question file is present
259+ HashMap <String , Object > varsWithAnswers = new HashMap <>(vars );
244260 try {
245- File questionFile = new File (projectDir , "questions.json" );
246261 if (questionFile .exists () && questionFile .canRead ()) {
247- vars .putAll (inquire .inquire (questionFile .toURI ().toURL ()));
262+ varsWithAnswers .putAll (inquire .inquire (questionFile .toURI ().toURL ()));
248263 if (!questionFile .delete ()) {
249264 getLog ().warn ("Unable to delete question file, useless files may be still be present in project" );
250265 }
@@ -253,7 +268,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
253268 getLog ().error ("Unable to process question file, resulting project might be unusable" , e );
254269 }
255270
256- renderTemplates (projectDir , vars );
271+ // We can now do the rendering properly, cancel the shutdown hook
272+ Runtime .getRuntime ().removeShutdownHook (shutdownRender );
273+
274+ renderTemplates (projectDir , varsWithAnswers );
257275 }
258276 }
259277
0 commit comments