Unexpected behavior with whitespace in comma separated elements
pkwarren opened this issue · comments
Philip K. Warren commented
I've noticed that pedantic-pom-enforcers preserves whitespace in comma-separated values. This can lead to unexpected behavior - for example:
<compound implementation="com.github.ferstl.maven.pomenforcers.CompoundPedanticEnforcer">
<enforcers>POM_SECTION_ORDER,MODULE_ORDER,DEPENDENCY_MANAGEMENT_ORDER,DEPENDENCY_ORDER,DEPENDENCY_CONFIGURATION,DEPENDENCY_ELEMENT,DEPENDENCY_SCOPE,PLUGIN_MANAGEMENT_ORDER,PLUGIN_CONFIGURATION</enforcers>
<!-- DEPENDENCY_SCOPE configuration -->
<testDependencies>
org.assertj:assertj-core,
org.junit.jupiter:junit-jupiter,
org.junit.jupiter:junit-jupiter-api,
org.junit.jupiter:junit-jupiter-engine,
org.junit.jupiter:junit-jupiter-params
</testDependencies>
</compound>
This gets parsed internally into ArtifactModel keys:
\n org.junit.jupiter:junit-jupiter-engine:
org.assertj:assertj-core:
\n org.junit.jupiter:junit-jupiter-params:
\n org.junit.jupiter:junit-jupiter:
\n org.junit.jupiter:junit-jupiter-api:
As a result, the test dependencies aren't validated unless they are the first one listed.
You can also reproduce this with the list of enforcers:
<enforcers>
POM_SECTION_ORDER,
MODULE_ORDER,
DEPENDENCY_MANAGEMENT_ORDER,
DEPENDENCY_ORDER,
DEPENDENCY_CONFIGURATION,
DEPENDENCY_ELEMENT,
DEPENDENCY_SCOPE,
PLUGIN_MANAGEMENT_ORDER,
PLUGIN_CONFIGURATION
</enforcers>
which results in the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce (enforce) on project ...: Unable to parse configuration of mojo org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce for parameter enforcers: Cannot set 'enforcers' in class com.github.ferstl.maven.pomenforcers.CompoundPedanticEnforcer: InvocationTargetException: No enum constant com.github.ferstl.maven.pomenforcers.PedanticEnforcerRule.
[ERROR] MODULE_ORDER
To fix, I think adding a .map(String::trim)
before this line will allow whitespace in comma separated values: