Skip to content

Commit

Permalink
feat: [3807] Tidy pom.xml files created by generate-app-project goal
Browse files Browse the repository at this point in the history
  • Loading branch information
shannah committed Sep 29, 2024
1 parent 342dc11 commit ccc14fa
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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{


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ccc14fa

Please sign in to comment.