Skip to content

Commit

Permalink
fix: Update POM rules to use pom.xml as filename when reporting valid…
Browse files Browse the repository at this point in the history
…ation errors

With the feature to support parent POM by evaluating the effective pom, the base POM rules where reporting validation errors on the effective pom file instead of the pom.xml. This would cause SonarQube to ignore these errors, as they are reported on a file that does not exist in the code base.

Also replaces Unicode characters in EncryptedPasswordRule Unicode character U+2018 in both RULE_NAME & RULE_VIOLATION_MESSAGE cause the Sonar JSON importer to break.

---------

Co-authored-by: Elias Rangel <Elias.Rangel@lla.com>
Co-authored-by: Elias Rangel <1860346@lla.com>
  • Loading branch information
3 people authored Jul 17, 2024
1 parent f845c03 commit 337b111
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.avioconsulting.mule.linter.model.CaseNaming
import com.avioconsulting.mule.linter.model.Version
import com.avioconsulting.mule.linter.model.pom.PomDependency
import com.avioconsulting.mule.linter.model.pom.PomElement
import com.avioconsulting.mule.linter.model.pom.PomFile
import com.avioconsulting.mule.linter.model.rule.Param
import com.avioconsulting.mule.linter.model.rule.Rule
import com.avioconsulting.mule.linter.model.rule.RuleViolation
Expand Down Expand Up @@ -76,7 +77,7 @@ class PomDependencyVersionRule extends Rule {
PomDependency dependency = app.pomFile.getDependency(groupId, artifactId)

if ( dependency == null ) {
violations.add(new RuleViolation(this, app.pomFile.path, 0, MISSING_DEPENDENCY + "$groupId , $artifactId"))
violations.add(new RuleViolation(this, PomFile.POM_XML, 0, MISSING_DEPENDENCY + "$groupId , $artifactId"))
} else {
Boolean isViolated = false;
PomElement attribute = dependency.getAttribute('version')
Expand All @@ -89,7 +90,7 @@ class PomDependencyVersionRule extends Rule {
isViolated = (!version.isGreater(dependencyVersion)) ? true : false
}
if (isViolated) {
violations.add(new RuleViolation(this, app.pomFile.path, 0,
violations.add(new RuleViolation(this, PomFile.POM_XML, 0,
RULE_VIOLATION_MESSAGE + "$groupId , $artifactId, $attribute.value"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.avioconsulting.mule.linter.rule.pom

import com.avioconsulting.mule.linter.model.Application
import com.avioconsulting.mule.linter.model.pom.PomElement
import com.avioconsulting.mule.linter.model.pom.PomFile
import com.avioconsulting.mule.linter.model.pom.PomPlugin
import com.avioconsulting.mule.linter.model.rule.Param
import com.avioconsulting.mule.linter.model.rule.Rule
Expand Down Expand Up @@ -53,12 +54,12 @@ class PomPluginAttributeRule extends Rule {
PomPlugin plugin = app.pomFile.getPlugin(groupId, artifactId)

if ( plugin == null ) {
violations.add(new RuleViolation(this, app.pomFile.path, 0, MISSING_PLUGIN + "$groupId , $artifactId"))
violations.add(new RuleViolation(this, PomFile.POM_XML, 0, MISSING_PLUGIN + "$groupId , $artifactId"))
} else {
attributes.each {
PomElement attribute = plugin.getAttribute(it.key)
if ( attribute.value != it.value) {
violations.add(new RuleViolation(this, app.pomFile.path, 0,
violations.add(new RuleViolation(this, PomFile.POM_XML, 0,
RULE_VIOLATION_MESSAGE + "$it.key : $it.value"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.avioconsulting.mule.linter.rule.pom

import com.avioconsulting.mule.linter.model.Application
import com.avioconsulting.mule.linter.model.pom.PomElement
import com.avioconsulting.mule.linter.model.pom.PomFile
import com.avioconsulting.mule.linter.model.rule.Param
import com.avioconsulting.mule.linter.model.rule.Rule
import com.avioconsulting.mule.linter.model.rule.RuleViolation
Expand Down Expand Up @@ -43,12 +44,12 @@ class PomPropertyValueRule extends Rule {
try {
PomElement pomProperty = app.pomFile.getPomProperty(propertyName)
if (!pomProperty.value.equalsIgnoreCase(propertyValue)) {
violations.add(new RuleViolation(this, app.pomFile.path,
violations.add(new RuleViolation(this, PomFile.POM_XML,
0, pomProperty.name + RULE_VIOLATION_MESSAGE + 'Expected: ' + propertyValue
+ ' found: ' + pomProperty.value))
}
} catch (IllegalArgumentException e) {
violations.add(new RuleViolation(this, app.pomFile.path,
violations.add(new RuleViolation(this, PomFile.POM_XML,
0, propertyName + ATTRIBUTE_MISSING_MESSAGE))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PomArtifactAttributeRuleTest extends Specification {
then:
violations.size() == 1
violations[0].message.startsWith(PomPluginAttributeRule.MISSING_PLUGIN)
violations[0].fileName == PomFile.POM_XML
}

def 'Correct Maven Plugin version'() {
Expand Down Expand Up @@ -71,6 +72,7 @@ class PomArtifactAttributeRuleTest extends Specification {
then:
violations.size() == 1
violations[0].message.startsWith(PomPluginAttributeRule.RULE_VIOLATION_MESSAGE)
violations[0].fileName == PomFile.POM_XML
}

def 'Correct Maven Plugin version check as property'() {
Expand Down Expand Up @@ -106,6 +108,7 @@ class PomArtifactAttributeRuleTest extends Specification {
then:
violations.size() == 1
violations[0].message.startsWith(PomPluginAttributeRule.RULE_VIOLATION_MESSAGE)
violations[0].fileName == PomFile.POM_XML
}

private static final String MISSING_PLUGINS_POM = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PomDependencyVersionRuleTest extends Specification {
then:
violations.size() == 1
violations[0].message.startsWith(PomDependencyVersionRule.MISSING_DEPENDENCY)
violations[0].fileName == PomFile.POM_XML
}

def 'Correct Equal Maven Dependency version'() {
Expand Down Expand Up @@ -74,6 +75,7 @@ class PomDependencyVersionRuleTest extends Specification {
then:
violations.size() == 1
violations[0].message.startsWith(PomDependencyVersionRule.RULE_VIOLATION_MESSAGE)
violations[0].fileName == PomFile.POM_XML
}

def 'Multiple Greater Than Maven Dependency version'() {
Expand All @@ -93,6 +95,10 @@ class PomDependencyVersionRuleTest extends Specification {

then:
violations.size() == size
if (violations.size() == 1) {
violations[0].fileName == PomFile.POM_XML
}


where:
version | size
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.avioconsulting.mule.linter.rule.pom

import com.avioconsulting.mule.linter.model.MuleApplication
import com.avioconsulting.mule.linter.model.pom.PomFile
import com.avioconsulting.mule.linter.model.rule.Rule
import com.avioconsulting.mule.linter.model.rule.RuleViolation
import com.avioconsulting.mule.linter.TestApplication
Expand Down Expand Up @@ -44,6 +45,7 @@ class PomPropertyValueRuleTest extends Specification {
then:
violations.size() == 1
violations[0].message == 'munit.version maven property value does not match expected value. Expected: 3.2.1 found: 2.2.1'
violations[0].fileName == PomFile.POM_XML
}

def 'Missing Property'() {
Expand All @@ -56,6 +58,7 @@ class PomPropertyValueRuleTest extends Specification {
then:
violations.size() == 1
violations[0].message == 'invalid.munit.version does not exist in <properties></properties>'
violations[0].fileName == PomFile.POM_XML
}

}

0 comments on commit 337b111

Please sign in to comment.