Skip to content

Format issues after updating pomModel and write back to pom files #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Yougoss opened this issue Dec 9, 2021 · 1 comment
Open

Comments

@Yougoss
Copy link

Yougoss commented Dec 9, 2021

Hi,
We have encountered some format issues when using this library to update our dependencies in pom. We leverage the library to upgrade dependencies automatically.
Here is the usecase. First get pomModel and SAXBuilder doc from pom file, then calculate the pomModel we need based on some rules(will adding or removing some dependency in pomModel), update SAXBuilder doc with the pomModel, then write doc back to pom file.
new MavenJDOMWriter().setExpandEmptyElements(true).write(module.pomModel, doc, outWriter, format)

The format issue may cause thousands of different lines in an enterprise level project, and most of them are just caused by format difference. It costs a lot of extra efforts to let us locate which really changes.

So I have made some changes to enhance the result. Do you have any plan to make enhancement for below cases?

  1. hard code indent: I notice that the indent is hard code in WriterUtils as two whitespace which make new added dependencies with incorrect format as below.(The indent in below sample is '\t')
<project>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.jdom</groupId>
				<artifactId>jdom2</artifactId>
				<version>2.0.6</version>
			</dependency>
			<!-- new added dependency -->
			<dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-model</artifactId>
        <version>${mavenVersion}</version>
      </dependency>

    		</dependencies>
	</dependencyManagement>
</project>

  1. In some cases, the target element to update in iterateDependency will lead format issues. As below picture, we removed dep B in pomModel and when it updates dep C back to SAX document, it will update the content to the second element(dep B), and there is no exclusions there. So, all the extension elements will be created and element in it will follow default order. The default means artifactId is the first element in extension, and groupId is the second one. If the element order in pom file is different, there will be different lines. Meanwhile, since the constant indent in first case, the new added extension elements is most likely with the different indent and caused different lines.
    image

Sample pom (The indent in below sample is '\t')

<project>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.jdom</groupId>
				<artifactId>jdom2</artifactId>
				<version>2.0.6</version>
			</dependency>
			<dependency>
				<groupId>org.apache.maven</groupId>
				<artifactId>maven-model</artifactId>
				<version>${mavenVersion}</version>
			</dependency>
			<dependency>
				<groupId>org.apache.maven</groupId>
				<artifactId>maven-core</artifactId>
				<version>${mavenVersion}</version>
				<exclusions>
					<exclusion>
						<groupId>org.apache.maven</groupId>
						<artifactId>maven-artifact</artifactId>
					</exclusion>
				</exclusions>
			</dependency>
		</dependencies>
	</dependencyManagement>
</project>

After remove dependency maven-model

<project>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.jdom</groupId>
				<artifactId>jdom2</artifactId>
				<version>2.0.6</version>
			</dependency>
			<dependency>
				<groupId>org.apache.maven</groupId>
				<artifactId>maven-core</artifactId>
				<version>${mavenVersion}</version>
				<exclusions>
          <exclusion>
            <artifactId>maven-artifact</artifactId>
            <groupId>org.apache.maven</groupId>
          </exclusion>
        </exclusions>
			</dependency>
		</dependencies>
	</dependencyManagement>
</project>

  1. Also, we noticed that with current iterateDependency implement, the comment will also cause different lines if there is any dependency removed.
@Yougoss
Copy link
Author

Yougoss commented Dec 9, 2021

I have made some change to enhance the result for our cases, #15
Any comments are helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant