Skip to content

Commit

Permalink
sort each pom profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 1, 2024
1 parent 6909fc4 commit 9b8687f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion generators/maven/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default class MavenGenerator extends BaseApplicationGenerator<SpringBootG
if (this.sortMavenPom) {
this.queueTransformStream(
{
name: 'translating angular application',
name: 'sorting pom.xml file',
filter: file =>
isFileStateModified(file) && file.path.startsWith(this.destinationPath()) && basename(file.path) === 'pom.xml',
refresh: false,
Expand Down
37 changes: 22 additions & 15 deletions generators/maven/internal/pom-project-sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,36 @@ const sortArtifacts = (artifacts: MavenArtifact[]) =>

const sortProfiles = (profiles: MavenProfile[]) => profiles.sort((a, b) => a.id?.localeCompare(b.id) ?? 1);

export const sortPomProject = project => {
project = sortKeys(project, { compare: comparator(rootOrder) });
if (project.properties) {
project.properties = sortProperties(project.properties);
const sortProjectLike = (projectLike: any): any => {
projectLike = sortKeys(projectLike, { compare: comparator(rootOrder) });
if (projectLike.properties) {
projectLike.properties = sortProperties(projectLike.properties);
}
if (Array.isArray(project.dependencies?.dependency)) {
project.dependencies.dependency = sortArtifacts(project.dependencies.dependency);
if (Array.isArray(projectLike.dependencies?.dependency)) {
projectLike.dependencies.dependency = sortArtifacts(projectLike.dependencies.dependency);
}
if (Array.isArray(project.dependencyManagement?.dependencies?.dependency)) {
project.dependencyManagement.dependencies.dependency = sortArtifacts(project.dependencyManagement.dependencies.dependency);
if (Array.isArray(projectLike.dependencyManagement?.dependencies?.dependency)) {
projectLike.dependencyManagement.dependencies.dependency = sortArtifacts(projectLike.dependencyManagement.dependencies.dependency);
}
if (project.build) {
project.build = sortSection(project.build);
if (projectLike.build) {
projectLike.build = sortSection(projectLike.build);

if (Array.isArray(project.build.plugins?.plugin)) {
project.build.plugins.plugin = sortArtifacts(project.build.plugins.plugin);
if (Array.isArray(projectLike.build.plugins?.plugin)) {
projectLike.build.plugins.plugin = sortArtifacts(projectLike.build.plugins.plugin);
}
if (Array.isArray(project.build.pluginManagement?.plugins?.plugin)) {
project.build.pluginManagement.plugins.plugin = sortArtifacts(project.build.pluginManagement.plugins.plugin);
if (Array.isArray(projectLike.build.pluginManagement?.plugins?.plugin)) {
projectLike.build.pluginManagement.plugins.plugin = sortArtifacts(projectLike.build.pluginManagement.plugins.plugin);
}
}
return projectLike;
};

export const sortPomProject = (project: any): any => {
project = sortProjectLike(project);
if (Array.isArray(project.profiles?.profile)) {
project.profiles.profile = sortProfiles(project.profiles.profile);
project.profiles.profile = sortProfiles(project.profiles.profile.map(profile => sortProjectLike(profile)));
} else if (project.profiles?.profile) {
project.profiles.profile = sortProjectLike(project.profiles.profile);
}
return project;
};

0 comments on commit 9b8687f

Please sign in to comment.