Comments (12)
from sortpom.
Have you tried the indentSchemaLocation parameter?
from sortpom.
That results in
-<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">
+<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">
I need each attribute on its own line because, although not applicable for poms, other xml files sometimes have many attributes on a tag.
from sortpom.
Let me have a look
from sortpom.
Branch issue-267-Xml_formatting created!
from sortpom.
I did some experiments with this. I have some form of functionality, but it breaks existing tests.
The test case is that somebody adds an xml namespace at a lower level of the POM file. Not very realistic, but it is possible.
The indentation of the namespace will also be (normal indent * 2) + 1 space character which is not ideal.
Feel free to check out the branch and try out the code for yourself.
from sortpom.
@Ekryd how do I configure it though?
from sortpom.
Check out the branch, compile it and use the parameter indentSchemaLocation to get the extra line breaks (this is just a concept code)
from sortpom.
You asked me to try out indentSchemaLocation parameter earlier. What have you done on the branch to get each attribute on its own line, or leave the line breaks alone?
from sortpom.
The branch makes sure that each attribute gets its own line:
<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">
I cannot preserve line breaks, as the whole xml file is parsed as a DOM tree and recreated completely during sorting.
from sortpom.
Hi Björn. I don't know how you got that output. Using the released 3.2.1, I get either all attributes on one line or, with indentSchemaLocation
to true, 2 lines. I don't get 3 lines - each attribute on its own line.
I tried changing
diff --git a/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java b/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java
index 67dc29d..e0b3cd7 100644
--- a/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java
+++ b/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java
@@ -99 +99 @@ class PatchedXMLWriter extends XMLWriter {
- if (indentSchemaLocation && "xsi:schemaLocation".equals(qualifiedName)) {
+ if (indentSchemaLocation) {
the test failed with
[ERROR] Failures:
[ERROR] IndentationTest.otherAttributeShouldNotBeIndented:103 expected: <<?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">
<Gurka xmlns="" key="value"></Gurka>
</project>
> but was: <<?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">
<Gurka xmlns=""
key="value"></Gurka>
</project>
>
Since it breaks before key
but not xmlns:xsi
Im led to believes its only processing attributes in the default namespace?
from sortpom.
You have to use git to checkout the branch issue-267-Xml_formatting in order to see the changes. The branch should compile, although some tests will fail on it.
from sortpom.
Related Issues (20)
- sorting doesn't work in >=v3.0.0 HOT 11
- no sort xmls with doctype HOT 4
- Add entry for the 3.2.1 release on the wiki page `Versions` HOT 2
- Tone down sortpom output HOT 6
- Properties configuration Suggestion HOT 7
- Setting to disable pom sorting? HOT 4
- LATEST using in pom is deprecated and will be removed from maven 4 HOT 8
- Handle plugin warnings HOT 1
- Dependency Dashboard
- Setup Maven 4 build pipe HOT 1
- Preserve formatting inside project element HOT 9
- Add configuration to suppress XML declaration HOT 7
- Add configuration for newline at the end of file HOT 6
- XML tag with `xml:space="preserve"` containing only spaces should not be collapsed HOT 4
- Attributes resulting in long lines should be wrapped or chopped down HOT 10
- Revisit schema location indent choice HOT 11
- Java Class File Version 52+ ( 55=Java 11 and/or 61=Java 17)
- Newlines aren't kept at beginning or end of String content. HOT 4
- Not sorting with mvn comand HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sortpom.