From ccc14fab999ee1d16c91b331ec1eacfea58d288e Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Sun, 29 Sep 2024 07:37:54 -0700 Subject: [PATCH] feat: [3807] Tidy pom.xml files created by generate-app-project goal --- .../maven/GenerateAppProjectMojo.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/GenerateAppProjectMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/GenerateAppProjectMojo.java index ddad72f807..dd4d8c94eb 100644 --- a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/GenerateAppProjectMojo.java +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/GenerateAppProjectMojo.java @@ -38,6 +38,9 @@ @Mojo(name="generate-app-project", requiresProject = false) public class GenerateAppProjectMojo extends AbstractMojo { + @Parameter(property = "cn1.tidy", defaultValue = "true") + private boolean tidy; + @Parameter(property = "sourceProject") private File sourceProject; @@ -65,6 +68,30 @@ private Properties loadSourceProjectProperties() throws IOException { return props; } + private void tidyPomXmlFiles(File projectDirectory) { + InvocationRequest request = new DefaultInvocationRequest(); + request.setBaseDirectory(projectDirectory); + if (getLog().isDebugEnabled()) { + request.setDebug(true); + } + request.setGoals(Collections.singletonList("com.diffplug.spotless:spotless-maven-plugin:2.43.0:apply")); + Properties props = new Properties(); + props.setProperty("spotless.pom.includes", "pom.xml"); + props.setProperty("spotless.pom.sortPom.keepBlankLines", "false"); + + request.setProperties(props); + + Invoker invoker = new DefaultInvoker(); + try { + InvocationResult result = invoker.execute(request); + if (result.getExitCode() != 0) { + getLog().warn("Failed to tidy pom.xml files. Exit code "+result.getExitCode()); + } + } catch (MavenInvocationException ex) { + getLog().warn("Failed to tidy pom.xml files", ex); + } + } + private void generateProject() throws MojoExecutionException{ @@ -926,7 +953,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { } catch (IOException ex) { throw new MojoExecutionException("Failed to copy files", ex); } - + if (tidy) { + tidyPomXmlFiles(targetProjectDir()); + } } private Project antProject;