diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy index d663db8c..5542d842 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy @@ -10,6 +10,7 @@ import groovy.xml.slurpersupport.Node /** * This class represents a Mule Configuration XML file. */ +@SuppressWarnings('SpaceAroundMapEntryColon') class ConfigurationFile extends ProjectFile { static final String MULE_CORE_NAMESPACE = 'http://www.mulesoft.org/schema/mule/core' @@ -17,8 +18,9 @@ class ConfigurationFile extends ProjectFile { MuleXmlParser parser private final GPathResult configXml private final Boolean exists - private Map nonGlobalConfig = ['sub-flow':MULE_CORE_NAMESPACE, - 'flow':MULE_CORE_NAMESPACE] + private Map nonGlobalConfig = ['sub-flow' : MULE_CORE_NAMESPACE, + 'flow' : MULE_CORE_NAMESPACE, + 'error-handler': MULE_CORE_NAMESPACE] ConfigurationFile(File file) { super(file) diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/rule/RuleExecutor.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/rule/RuleExecutor.groovy index 247eb8a8..b58e10d6 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/rule/RuleExecutor.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/rule/RuleExecutor.groovy @@ -28,7 +28,7 @@ class RuleExecutor { outputStream.write('Rule Results\n'.bytes) results.each { violation -> - outputStream.write(" $violation.rule.severity: $violation.fileName ".bytes) + outputStream.write(" [$violation.rule.severity] $violation.rule.ruleId - $violation.fileName ".bytes) outputStream.write((violation.lineNumber > 0 ? "( $violation.lineNumber ) " : '').bytes) outputStream.write("$violation.message \n".bytes) } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRule.groovy index 88726daf..366e2398 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRule.groovy @@ -12,7 +12,7 @@ class OnErrorLogExceptionRule extends Rule { 'on-error-continue and on-error-propagate' private static final List ON_ERROR_COMPONENTS = ['on-error-continue', 'on-error-propagate'] private static final String ATTRIBUTE_NAME = 'logException' - private static final String ATTRIBUTE_VALUE_CHECK = 'false' + private static final String ATTRIBUTE_VALUE_CHECK = 'true' OnErrorLogExceptionRule() { this.ruleId = RULE_ID @@ -25,7 +25,7 @@ class OnErrorLogExceptionRule extends Rule { application.configurationFiles.each { file -> ON_ERROR_COMPONENTS.each { file.findComponents(it, file.MULE_CORE_NAMESPACE).each { comp -> - if (comp.getAttributeValue(ATTRIBUTE_NAME).equalsIgnoreCase(ATTRIBUTE_VALUE_CHECK)) { + if (comp.getAttributeValue(ATTRIBUTE_NAME) != ATTRIBUTE_VALUE_CHECK) { violations.add(new RuleViolation(this, file.name, comp.lineNumber, RULE_VIOLATION_MESSAGE)) } } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/UnusedFlowRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/UnusedFlowRule.groovy index 02b3a826..656e3432 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/UnusedFlowRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/UnusedFlowRule.groovy @@ -8,7 +8,8 @@ class UnusedFlowRule extends Rule { static final String RULE_ID = 'UNUSED_FLOW' static final String RULE_NAME = 'All Flow and sub-flow are used in application.' - static final String RULE_VIOLATION_MESSAGE = 'Flow or sub-flow is not referenced by flow ref: ' + static final String RULE_VIOLATION_MESSAGE = 'Flow component is unused. ' + + 'The following flow is not referenced by any flow ref components: ' UnusedFlowRule() { this.ruleId = RULE_ID diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRule.groovy index 4d958d31..40e0a164 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRule.groovy @@ -28,8 +28,8 @@ class MuleArtifactHasSecurePropertiesRule extends Rule { List violations = [] JsonArray sprops = app.muleArtifact.secureProperties secureProperties.each { prop -> - if (!sprops.contains(prop)) { - violations.add(new RuleViolation(this, app.muleArtifact.name, sprops.lineNumber, + if (!sprops?.contains(prop)) { + violations.add(new RuleViolation(this, app.muleArtifact.name, sprops == null ? 0 : sprops.lineNumber, 'The secureProperties array does not contain the property ' + prop)) } } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy index 39ad1e65..a7ceafa1 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy @@ -95,4 +95,5 @@ class GlobalConfigNoFlowsRuleTest extends Specification { \t ''' + } \ No newline at end of file diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy index 945e7bcb..1fa664d7 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy @@ -66,6 +66,7 @@ class GlobalConfigRuleTest extends Specification { when: testApp.addFile('src/main/mule/bad-global-with-listener.xml', BAD_CONFIG_1) testApp.addFile('src/main/mule/bad-global-with-router.xml', BAD_CONFIG_2) + testApp.addFile('src/main/mule/global-error-handler.xml', GLOBAL_ERROR_HANDLER_CONFIG) app = new Application(testApp.appDir) List violations = rule.execute(app) @@ -74,6 +75,7 @@ class GlobalConfigRuleTest extends Specification { violations[0].lineNumber == 9 violations[0].message.contains('config') violations[0].fileName.contains('bad-global-with-router.xml') + violations.findAll { it.fileName.endsWith('global-error-handler.xml') }.size() == 0 } @SuppressWarnings(['MethodName', 'MethodReturnTypeRequired']) @@ -126,4 +128,17 @@ class GlobalConfigRuleTest extends Specification { \t ''' + + private static final String GLOBAL_ERROR_HANDLER_CONFIG = ''' + +\t +\t\t +\t\t\t +\t\t +\t + +''' + } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy index 794a8b0d..3b1fa597 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy @@ -121,7 +121,7 @@ output application/java \t\t\t \t\t\t -\t\t\t\t \t\t\t\t\t violations = rule.execute(app) + + then: + app.muleArtifact != null + violations.size() == 2 + violations[0].lineNumber == 0 + violations[0].message.contains('client_id') + violations[1].message.contains('client_secret') + } + private static final String MISSING_PROPS_MULE_ARTIFACT = '''{ "minMuleVersion": "4.2.2", "secureProperties": [ "new.property" ] +}''' + private static final String MISSING_SECURE_PROPS = '''{ + "minMuleVersion": "4.2.2" }''' }