Skip to content

Commit

Permalink
Merge pull request #208 from Ekryd/issue-206-Whitespace_removed_from_…
Browse files Browse the repository at this point in the history
…within_XML_tags_in_3_1_0_release

Issue 206 whitespace removed from within xml tags in 3 1 0 release
  • Loading branch information
Ekryd committed May 24, 2022
2 parents 65db673 + 64311fe commit f19edf0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions sorter/src/main/java/sortpom/XmlProcessor.java
Expand Up @@ -34,6 +34,7 @@ public XmlProcessor(WrapperFactory factory) {
public void setOriginalXml(final InputStream originalXml) throws DocumentException, SAXException {
SAXReader parser = new SAXReader();
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
parser.setMergeAdjacentText(true);
originalDocument = parser.read(originalXml);
}

Expand Down
Expand Up @@ -29,7 +29,7 @@ Wrapper<Node> createWrapper(Text text) {
}

private boolean isSingleNewLine(Text content) {
return content.getText().matches("[\\t ]*[\\r]?[\\n]?[\\t ]*");
return content.getText().matches("[\\t ]*\\r?\\n?[\\t ]*");
}

boolean isBlankLineOrLines(Text content) {
Expand Down
9 changes: 9 additions & 0 deletions sorter/src/test/java/sortpom/sort/LineSeparatorTest.java
Expand Up @@ -3,10 +3,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static sortpom.sort.XmlFragment.createXmlFragment;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import sortpom.output.XmlOutputGenerator;
import sortpom.parameter.PluginParameters;
import sortpom.util.SortPomImplUtil;

class LineSeparatorTest {
@ParameterizedTest
Expand All @@ -25,4 +27,11 @@ void formattingXmlWithLineEndingsShouldResultInOneLineBreakAtEnd(String lineSepa
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + lineSeparator + "<Gurka />" + lineSeparator,
actual);
}

@Test
void linesInContentShouldBePreserved() throws Exception {
SortPomImplUtil.create()
.lineSeparator("\r\n")
.testFiles("/MultilineContent_input.xml", "/MultilineContent_expected.xml");
}
}
21 changes: 21 additions & 0 deletions sorter/src/test/resources/MultilineContent_expected.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<groupId>sortpom</groupId>
<artifactId>sortpom</artifactId>
<build>
<plugins>
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<message>junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.mode.classes.default=concurrent
junit.jupiter.execution.parallel.config.strategy=dynamic
junit.jupiter.execution.parallel.config.dynamic.factor=1</message>
</configuration>
</plugin>
</plugins>
</build>
</project>
21 changes: 21 additions & 0 deletions sorter/src/test/resources/MultilineContent_input.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>sortpom</artifactId>
<groupId>sortpom</groupId>
<build>
<plugins>
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<message>junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.mode.classes.default=concurrent
junit.jupiter.execution.parallel.config.strategy=dynamic
junit.jupiter.execution.parallel.config.dynamic.factor=1</message>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit f19edf0

Please sign in to comment.