mojohaus / tidy-maven-plugin Goto Github PK
View Code? Open in Web Editor NEWThe Tidy plugin provides goals for tidying up your source code.
Home Page: https://www.mojohaus.org/tidy-maven-plugin/
License: Apache License 2.0
The Tidy plugin provides goals for tidying up your source code.
Home Page: https://www.mojohaus.org/tidy-maven-plugin/
License: Apache License 2.0
We have a number of custom archetypes that we use for development, and we were rolling tidy pom into them, but have run into this issue.
In an archetype there is no modules section in the parent pom, it is added during the process, but it is added between and in my case, but tidy pom wants it at the end of the file.
This issue causes our integration test of the archetype to fail.
When a dependency have multiple exclusions, is seems like the order of groupId
and artifactId
are consistently, ordered inconsistently:
<exclusions>
<exclusion>
<groupId>com.smxemail</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<artifactId>*</artifactId>
<groupId>smx3</groupId>
</exclusion>
</exclusions>
The first exclusion, puts groupId
first as expected, but the second gets artifactId
first.
On the Usage page, the version in the pom snippet is declared as ${project.version}. Obviously that will not work but should be repalced by the current version of the plugin.
this was fixed in #27 however no new version was released since then.
we would like to avoid these warnings in all of our modules:
2022-03-10T07:47:46.4483999Z [INFO] --------------------------------[ jar ]---------------------------------
2022-03-10T07:47:46.4484394Z [WARNING] *****************************************************************
2022-03-10T07:47:46.4484675Z [WARNING] * Your build is requesting parallel execution, but project *
2022-03-10T07:47:46.4484980Z [WARNING] * contains the following plugin(s) that have goals not marked *
2022-03-10T07:47:46.4485294Z [WARNING] * as @threadSafe to support parallel building. *
2022-03-10T07:47:46.4485660Z [WARNING] * While this /may/ work fine, please look for plugin updates *
2022-03-10T07:47:46.4486065Z [WARNING] * and/or request plugins be made thread-safe. *
2022-03-10T07:47:46.4486369Z [WARNING] * If reporting an issue, report it against the plugin in *
2022-03-10T07:47:46.4486730Z [WARNING] * question, not against maven-core *
2022-03-10T07:47:46.4486979Z [WARNING] *****************************************************************
2022-03-10T07:47:46.4487376Z [WARNING] The following plugins are not marked @threadSafe in (project):
2022-03-10T07:47:46.4487791Z [WARNING] org.codehaus.mojo:tidy-maven-plugin:1.1.0
2022-03-10T07:47:46.4488107Z [WARNING] Enable debug to see more precisely which goals are not marked @threadSafe.
2022-03-10T07:47:46.4488392Z [WARNING] *****************************************************************
Thank you
Plugin states that
The pom.xml file will be rewritten according to the POM Code Convention of the Maven team.
POM Code Convention states that
Indentation: Always use 2 space indents, unless you're wrapping a new XML tags line in which case you should indent 4 spaces.
Tidy-maven-plugin seems to ignore indent altogether.
Please mark the tidy-maven-plugin
as @threadSafe
(likely safe, unless some underlying XML parser factory or similar isn’t).
Using tidy-maven-plugin:1.2.0, I'm seeing a build failure while running clean package deploy
on a multi-module project. It appears tidy:check
is checking the generated file: dependency-reduced-pom.xml
, and failing the build because that file is not formatted correctly.
Is there some way to make tidy
ignore the generated dependency-reduced-pom.xml
file?
FWIW, using <createDependencyReducedPom>false</createDependencyReducedPom>
on the maven-shade-plugin
does not solve the issue as there are other side effects from not generating this pom. I also tried moving the location of that generated file, and renaming it.
In case it matters, tidy:check
is configured in an external parent pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tidy-maven-plugin</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Also wondering if there is some way to force a tidy:pom
invocation on just the generated file to get that file reformatted before the tidy:check
occurs?
Update: Well in true "describe the problem, solve the problem" fashion, I just ran clean deploy
(without the explicit package
phase), and the problem does not occur. It this behavior "expected"?
PS: Thanks for this nifty plugin!
tidy-m-p staged v1.0.0
Maven 3.3.3 on Oracle JDK 1.7.0_79 on Windows 7.
For some scenarios the pom mojomoves comments in the pom.
Case 1
<dependency>
<!-- bla bla -->
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
is changed to
<dependency><!-- bla bla -->
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
Case 2:
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-java-dsl</artifactId>
<version>1.1.2.RELEASE</version> <!-- TODO bla bla -->
</dependency>
is changed to
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-java-dsl</artifactId>
<version>1.1.2.RELEASE</version>
<!-- TODO bla bla -->
</dependency>
http://maven.apache.org/developers/conventions/code.html#XML_Code_Style
Tidy currently applies the "POM Code Convention". However since pom.xml files are also XML, the "XML Code Style" should also be applied. In particular, tabs should not be used, and indentation is mostly 2-spaces, with 4-space "hanging" indents for long opening tags (many attributes). Line breaks are also required in many places -- all complex XML types -- and forbidden in a few -- simple XML types.
While it is possible that some projects would prefer to follow the "POM Code Convention" without the "XML Code Style"; they are likely to be rare. In any case, it would be a nice option for tidy-maven-plugin to also apply the XML Code Style, either by default or at least when explicitly requested, either via a new goal or configuration of the existing check/pom goals.
May be a duplicate of #18
Taking a failure during tidy:pom and tidy:check. The line specified, 2766 is actually the end of file.
[ERROR] Failed to execute goal org.codehaus.mojo:tidy-maven-plugin:1.0.0:check (default-cli) on project base: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
[ERROR] at [row,col {unknown-source}]: [2766,7]
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:tidy-maven-plugin:1.0.0:check (default-cli) on project base: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
at [row,col {unknown-source}]: [2766,7]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:185)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:181)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.maven.plugin.MojoExecutionException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
at [row,col {unknown-source}]: [2766,7]
at org.codehaus.mojo.tidy.TidyMojo.tidy(TidyMojo.java:106)
at org.codehaus.mojo.tidy.CheckMojo.executeForPom(CheckMojo.java:39)
at org.codehaus.mojo.tidy.TidyMojo.execute(TidyMojo.java:67)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 11 more
Caused by: com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
at [row,col {unknown-source}]: [2766,7]
at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:580)
at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:453)
at com.ctc.wstx.sr.BasicStreamReader.readPIPrimary(BasicStreamReader.java:3877)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2017)
at com.ctc.wstx.sr.BasicStreamReader.closeContentTree(BasicStreamReader.java:2858)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2609)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1054)
at org.codehaus.stax2.ri.Stax2EventReaderImpl.nextEvent(Stax2EventReaderImpl.java:255)
at org.codehaus.mojo.tidy.task.EnsureOrderAndIndent$SectionSorter.sortSections(EnsureOrderAndIndent.java:117)
at org.codehaus.mojo.tidy.task.EnsureOrderAndIndent.tidyPom(EnsureOrderAndIndent.java:78)
at org.codehaus.mojo.tidy.task.PomTidy.tidy(PomTidy.java:44)
at org.codehaus.mojo.tidy.TidyMojo.tidy(TidyMojo.java:102)
... 15 more
I was able to figure out what in my pom.xml is causing this, it's build > pluginManagement > plugins >
<plugin>
<groupId>org.apache.openejb.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<configuration>
<synchronization>
<extensions>
<extension>.class</extension>
<extension>.css</extension>
<extension>.html</extension>
<extension>.js</extension>
<extension>.ui.xml</extension>
</extensions>
</synchronization>
</configuration>
</plugin>
Falling back to 1.0-beta-1 lets tidy:pom work again.
Some paths for sections in the SectionSorter is currently too loosely specified, which causes problems e.g. with some plugins which have configuration elements with the same name as some elements/sections of the pom.
I created one from 1.0-beta-1 (but I had to modify the parent POM to version 34 to get it to build the site). You can see my gh-pages here:
https://github.com/ctubbsii/tidy-maven-plugin
And the site is here:
This is possibly duplicate of #3
but how to disable comments formatting?
on http://www.mojohaus.org/tidy-maven-plugin/ it must clarify what tidy pom is
The SectionSorter defined at https://github.com/mojohaus/tidy-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/tidy/task/EnsureOrderAndIndent.java#L70 incorrectly matches "relocation" sections of the pom such as:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.foo.bar</pattern>
<shadedPattern>somewhereelse.com.foo.bar</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
This interacts badly to cause the whole pom to be duplicated a number of times. This can be fixed by setting the scope to "/project/distributionManagement/relocation", however I don't know if this will have any unintended side effects.
It seems that there are a number of quite loose matchers there that could interact badly with any pom that contains third party plugin that uses "exclusion", "extension", "parent", "plugin" or "relocation" in their configuration.
The following self-contained pom.xml
is completely broken by tidy:pom
(version 1.0.0):
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId>
<version>5.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.apache.lucene</pattern>
<shadedPattern>org.apache.maven.indexer.lucene</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The resulting POM consists of two POMs concatenated together:
…
</build>
</project>
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
…
Also, the resulting POM contains this sequence of broken formatting:
<relocations>
<relocation><pattern>org.apache.lucene</pattern>
<shadedPattern>org.apache.maven.indexer.lucene</shadedPattern>
</relocation>
</relocations>
According to http://www.mojohaus.org/plugins.html, the latest release of the tidy-maven-plugin
is 1.0-beta-1. This is wrong. The tidy-maven-plugin
1.0.0 should instead be listed as a “production plugin.”
tidy-m-p staged v1.0.0
Maven 3.3.3 on Oracle JDK 1.7.0_79 on Windows 7.
For this snippet:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
I'd like the trailing blank rows to be removed (before the close dependencies tag), which they aren't.
Eclipse Tycho (a Maven plugin used to build OSGi bundles with Maven) has a .mvn/extensions.xml
build extension that allows POM-less builds for projects with a certain <packaging>
to not have a physical pom.xml
; all information in the POM is inferred from other files in the project (META-INF/MANIFEST.MF
).
Apparently, tidy:check
tries to check the (virtual) POM of the POM-less Tycho project – and fails.
The attached project illustrates this problem. Performing a mvn clean verify
ultimately results in
[ERROR] Failed to execute goal org.codehaus.mojo:tidy-maven-plugin:1.0.0:check (check-pom) on project org.example.plugin: The POM violates the code style. Please format it by running `mvn tidy:pom`. -> [Help 1]
FWIW, if you think that this is rather a problem with Tycho, feel free to open a bug with the Tycho project instead.
This parameter would IMHO make sense for both the tidy:check
and tidy:pom
goals.
Hi guys!
I just found this line...
This actually should be return path.endsWith( "/" + scope );
as we are looking for the element named like the scope, not an element ending just with the scope...
The current version causes an exception when a property is ending with something like "-dependency" or "-plugin.
com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
at [row,col {unknown-source}]: [15,7]
at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:621)
at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:491)
at com.ctc.wstx.sr.BasicStreamReader.readPIPrimary(BasicStreamReader.java:4019)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2141)
at com.ctc.wstx.sr.BasicStreamReader.closeContentTree(BasicStreamReader.java:2991)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2734)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1123)
at org.codehaus.stax2.ri.Stax2EventReaderImpl.nextEvent(Stax2EventReaderImpl.java:255)
at org.codehaus.mojo.tidy.task.EnsureOrderAndIndent$SectionSorter.sortSections(EnsureOrderAndIndent.java:110)
at org.codehaus.mojo.tidy.task.EnsureOrderAndIndent.tidyPom(EnsureOrderAndIndent.java:71)
at org.codehaus.mojo.tidy.task.PomTidy.tidy(PomTidy.java:44)
After 52917c0 the tidy-maven-plugin
now uses HTTPS for xsi:schemaLocation
s (good). But ironically tidy:check
itself still insists that only HTTP xsi:schemaLocation
s are valid (bad):
<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/xsd/maven-4.0.0.xsd">
is valid, but
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
is not.
Also, tidy:format
reverts https://maven.apache.org/xsd/maven-4.0.0.xsd
back to http://maven.apache.org/xsd/maven-4.0.0.xsd
, which it shouldn’t.
In the recommended POM Code Convention[1] dependencyManagement
and dependencies
come before repositories
and pluginRepositories
.
But currently in EnsureOrderAndIndent.java
, new NodeGroup( "repositories", "pluginRepositories" )
comes before new NodeGroup( "dependencyManagement", "dependencies" )
which is backwards from the recommendation.
[1] https://maven.apache.org/developers/conventions/code.html#POM_Code_Convention
This is a valid property for the element, but it seems that tidy will complain if it is there, and then remove it if you do mvn tidy:pom on 1.2.0
I'd like to use this plugin but to use this we'd like to be able to also check our assembly descriptors. I'd be happy to do the work if you're open to this behavior.
I was thinking of something akin the following for the configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tidy-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<includes>
<include>pom.xml</include>
<include>src/assembly/*.xml</include>
</includes>
</configuration
</plugin>
It would be good to have the plugin available in a full release version and have all the info on the website like SCM and so on correct..
Also to fix https://issues.apache.org/jira/browse/MNGSITE-251 with a non-beta plugin....
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.