From 6d5b7c4ac691e5a92abe2f9711ab94401c72f6f3 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 8 Jul 2020 13:07:15 -0400 Subject: [PATCH 1/7] MIP-395 Fixed unit tests --- .../mule/linter/model/LoggerComponent.groovy | 2 +- .../rule/configuration/GlobalConfigRuleTest.groovy | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/LoggerComponent.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/LoggerComponent.groovy index f6786a35..f8bbef36 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/LoggerComponent.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/LoggerComponent.groovy @@ -10,7 +10,7 @@ class LoggerComponent extends MuleComponent { private final String category LoggerComponent(Map attributes) { - super(attributes) + super(COMPONENT_NAME, COMPONENT_NAMESPACE, attributes) this.docName = attributes.get('{http://www.mulesoft.org/schema/mule/documentation}name') this.message = attributes.get('message') this.level = attributes.get('level') 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 b46d318d..7ea08069 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 @@ -38,12 +38,12 @@ class GlobalConfigRuleTest extends Specification { then: violations.size() == 2 - violations[0].lineNumber == 10 - violations[0].message.contains('listener-config') - violations[0].fileName.contains('simple-logging-flow.xml') - violations[1].lineNumber == 9 - violations[1].message.contains('config') - violations[1].fileName.contains('simple-logging-flow-with-errors.xml') + violations[1].lineNumber == 10 + violations[1].message.contains('listener-config') + violations[1].fileName.contains('simple-logging-flow.xml') + violations[0].lineNumber == 9 + violations[0].message.contains('config') + violations[0].fileName.contains('simple-logging-flow-with-errors.xml') } @SuppressWarnings(['MethodName', 'MethodReturnTypeRequired']) From 7b98b806fec35422d7687803de495dfadf2dbf4b Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 8 Jul 2020 14:23:45 -0400 Subject: [PATCH 2/7] MIP-395 Fixed CodeNarc rules --- .../com/avioconsulting/mule/MuleLinter.groovy | 3 ++- .../mule/linter/model/Application.groovy | 1 + .../linter/model/ConfigurationFile.groovy | 19 +++++++++---------- .../mule/linter/model/GitIgnoreFile.groovy | 1 + .../mule/linter/model/MuleArtifact.groovy | 14 +++++++------- .../mule/linter/model/MuleComponent.groovy | 2 +- .../mule/linter/parser/JsonSlurper.groovy | 1 + .../configuration/GlobalConfigRule.groovy | 2 +- .../mule/linter/rule/git/GitIgnoreRule.groovy | 1 + ...MuleArtifactHasSecurePropertiesRule.groovy | 7 ++++--- .../groovy/json/internal/JsonArray.java | 2 +- .../mule/linter/model/MuleArtifactTest.groovy | 9 +++++---- .../mule/linter/parser/JsonSlurperTest.groovy | 8 ++++---- .../configuration/GlobalConfigRuleTest.groovy | 4 ++-- .../linter/rule/git/GitIgnoreRuleTest.groovy | 3 ++- ...ArtifactHasSecurePropertiesRuleTest.groovy | 1 + 16 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/main/groovy/com/avioconsulting/mule/MuleLinter.groovy b/src/main/groovy/com/avioconsulting/mule/MuleLinter.groovy index b49afd2e..bef47ec3 100644 --- a/src/main/groovy/com/avioconsulting/mule/MuleLinter.groovy +++ b/src/main/groovy/com/avioconsulting/mule/MuleLinter.groovy @@ -21,6 +21,7 @@ class MuleLinter { this.app = new Application(new File(applicationDirectory)) } + @SuppressWarnings('UnnecessaryObjectReferences') void runLinter() { // Build a list of rules RuleSet rules = new RuleSet() @@ -29,7 +30,7 @@ class MuleLinter { rules.addRule(new MunitVersionRule('2.2.1')) rules.addRule(new MuleRuntimeVersionRule('4.2.1')) rules.addRule(new PropertyFileNamingRule(['dev', 'test'])) - rules.addRule(new PropertyFilePropertyCountRule(['test', 'uat'], '${env}.properties')) + rules.addRule(new PropertyFilePropertyCountRule(['uat'], '${env}.properties')) rules.addRule(new LoggerCategoryExistsRule()) rules.addRule(new LoggerMessageExistsRule()) diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy index 178336a1..cff33dac 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy @@ -88,4 +88,5 @@ class Application { MuleArtifact getMuleArtifact() { return muleArtifact } + } 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 f372f25a..f804b28f 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy @@ -1,6 +1,5 @@ package com.avioconsulting.mule.linter.model - import groovy.xml.slurpersupport.GPathResult import groovy.xml.slurpersupport.Node @@ -9,11 +8,12 @@ import groovy.xml.slurpersupport.Node */ class ConfigurationFile extends ProjectFile { + private static final String MULE_CORE_NAMESPACE = 'http://www.mulesoft.org/schema/mule/core' MuleXmlParser parser private final GPathResult configXml private final Boolean exists - private Map GlobalConfig = ['sub-flow': 'http://www.mulesoft.org/schema/mule/core', - 'flow' : 'http://www.mulesoft.org/schema/mule/core'] + private Map globalConfig = ['sub-flow':MULE_CORE_NAMESPACE, + 'flow':MULE_CORE_NAMESPACE] ConfigurationFile(File file) { super(file) @@ -31,17 +31,16 @@ class ConfigurationFile extends ProjectFile { } void addAdditionalGlobalConfig(Map noneGlobalElements) { - GlobalConfig += noneGlobalElements + globalConfig += noneGlobalElements } List findGlobalConfigs() { List componentList = [] - def childNodes = configXml.childNodes() - def comps = [] - childNodes.each { - node -> - if (!checkElementExists( node, GlobalConfig )) { - comps.add(node) + Iterator childNodes = configXml.childNodes() + List comps = [] + childNodes.each { node -> + if (!checkElementExists(node, globalConfig)) { + comps.add(node) } } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/GitIgnoreFile.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/GitIgnoreFile.groovy index 5da696de..ea7739b5 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/GitIgnoreFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/GitIgnoreFile.groovy @@ -33,4 +33,5 @@ class GitIgnoreFile extends ProjectFile { Boolean contains(String expression) { return expressions.contains(expression) } + } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy index 0a6bf050..5abad29b 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy @@ -23,11 +23,6 @@ class MuleArtifact extends ProjectFile { } } - private void parseMuleArtifact() { - JsonSlurper slurper = new JsonSlurper() - muleArtifact = slurper.parse(file) - } - JsonArray getSecureProperties() { return muleArtifact.secureProperties } @@ -53,12 +48,17 @@ class MuleArtifact extends ProjectFile { } Object getProperty(String propertyName) { - def meta = this.metaClass.getMetaProperty(propertyName) - if(meta) { + MetaProperty meta = this.metaClass.getMetaProperty(propertyName) + if (meta) { meta.getProperty(this) } else { return muleArtifact[propertyName] } } + private void parseMuleArtifact() { + JsonSlurper slurper = new JsonSlurper() + muleArtifact = slurper.parse(file) as JsonMap + } + } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy index 4d27fb58..a53d0405 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy @@ -15,7 +15,7 @@ class MuleComponent { MuleComponent(String componentName, String componentNamespace, Map attributes, List children) { - this(componentName,componentNamespace,attributes) + this(componentName, componentNamespace, attributes) this.children = children } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/parser/JsonSlurper.groovy b/src/main/groovy/com/avioconsulting/mule/linter/parser/JsonSlurper.groovy index ebd4f427..f264f473 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/parser/JsonSlurper.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/parser/JsonSlurper.groovy @@ -79,6 +79,7 @@ import groovy.json.JsonParser; * @see groovy.json.JsonParserType * @since 1.8.0 */ +@SuppressWarnings('All') public class JsonSlurper { private int maxSizeForInMemory = 2000000; diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy index be7cd583..26dad5af 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy @@ -1,7 +1,6 @@ package com.avioconsulting.mule.linter.rule.configuration import com.avioconsulting.mule.linter.model.Application -import com.avioconsulting.mule.linter.model.ConfigurationFile import com.avioconsulting.mule.linter.model.MuleComponent import com.avioconsulting.mule.linter.model.Rule import com.avioconsulting.mule.linter.model.RuleViolation @@ -60,4 +59,5 @@ class GlobalConfigRule extends Rule { return violations } + } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRule.groovy index 9bbaa968..c57d014c 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRule.groovy @@ -44,4 +44,5 @@ class GitIgnoreRule extends Rule { return violations } + } 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 9346a65e..11a323c4 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 @@ -11,7 +11,7 @@ class MuleArtifactHasSecurePropertiesRule extends Rule { static final String RULE_NAME = 'mule-artifact.json should contain certain secured properties' static final List DEFAULT_PROPERTIES = ['anypoint.platform.client_id', 'anypoint.platform.client_secret'] - private List secureProperties + private final List secureProperties MuleArtifactHasSecurePropertiesRule() { this([], true) @@ -29,10 +29,11 @@ class MuleArtifactHasSecurePropertiesRule extends Rule { JsonArray sprops = app.muleArtifact.secureProperties secureProperties.each { prop -> if (!sprops.contains(prop)) { - violations.add(new RuleViolation(this, app.muleArtifact.name, sprops.lineNumber, 'The secureProperties array does not contain the property ' + prop)) + violations.add(new RuleViolation(this, app.muleArtifact.name, sprops.lineNumber, + 'The secureProperties array does not contain the property ' + prop)) } } return violations } -} +} diff --git a/src/main/groovy/org/apache/groovy/json/internal/JsonArray.java b/src/main/groovy/org/apache/groovy/json/internal/JsonArray.java index f605077f..c28a0b7c 100644 --- a/src/main/groovy/org/apache/groovy/json/internal/JsonArray.java +++ b/src/main/groovy/org/apache/groovy/json/internal/JsonArray.java @@ -10,7 +10,7 @@ public class JsonArray extends ArrayList { this.lineNumber = lineNumber; } - Integer getLineNumber() { + public Integer getLineNumber() { return lineNumber; } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy index b49b7858..02102f04 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy @@ -19,7 +19,7 @@ class MuleArtifactTest extends Specification { def "MuleArtifact attributes"() { given: - def artifactString = '''{ + String artifactString = '''{ "configs": [ "ch-usage-sync.xml" ], @@ -43,7 +43,7 @@ class MuleArtifactTest extends Specification { ] }''' muleArtifactFile.withPrintWriter { pw -> - pw.print(artifactString) + pw.print(artifactString) } when: @@ -63,7 +63,7 @@ class MuleArtifactTest extends Specification { def "MuleArtifact dynamic attributes"() { given: - def artifactString = '''{ + String artifactString = '''{ "configs": [ "ch-usage-sync.xml" ], @@ -93,7 +93,8 @@ class MuleArtifactTest extends Specification { muleArtifact.classLoaderModelLoaderDescriptor.id.lineNumber == 9 muleArtifact.classLoaderModelLoaderDescriptor.attributes.getLineNumber() == 10 muleArtifact.classLoaderModelLoaderDescriptor.attributes.exportedResources.size() == 0 - muleArtifact.classLoaderModelLoaderDescriptor.attributes.exportedResources.class.name == 'org.apache.groovy.json.internal.JsonArray' + muleArtifact.classLoaderModelLoaderDescriptor.attributes.exportedResources.class.name == + 'org.apache.groovy.json.internal.JsonArray' } } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy index f790ba84..c2cac5db 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy @@ -7,7 +7,7 @@ import spock.lang.Specification class JsonSlurperTest extends Specification { - private static final String APP_NAME = "SampleMuleApp" + private static final String APP_NAME = 'SampleMuleApp' def "String values with line numbers"() { given: @@ -21,8 +21,8 @@ class JsonSlurperTest extends Specification { then: minMuleVersion == '4.2.2' minMuleVersion.lineNumber == 2 - muleArtifact.getClass().getName() == 'org.apache.groovy.json.internal.JsonMap' - minMuleVersion.getClass().getName() == 'org.apache.groovy.json.internal.JsonString' + muleArtifact.getClass().name == 'org.apache.groovy.json.internal.JsonMap' + minMuleVersion.getClass().name == 'org.apache.groovy.json.internal.JsonString' } def "Boolean values with line numbers"() { @@ -77,7 +77,6 @@ class JsonSlurperTest extends Specification { when: JsonMap muleArtifact = slurper.parse(json) - ArrayList t = new ArrayList(); then: muleArtifact.secureProperties.size() == 7 @@ -92,4 +91,5 @@ class JsonSlurperTest extends Specification { muleArtifact.secureProperties.contains(true) muleArtifact.secureProperties.contains(false) } + } 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 7ea08069..896fcb85 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 @@ -5,7 +5,6 @@ import com.avioconsulting.mule.linter.model.Rule import com.avioconsulting.mule.linter.model.RuleViolation import spock.lang.Specification - class GlobalConfigRuleTest extends Specification { private static final String GLOBALCONFIG_APP = 'GlobalConfigMuleApp' @@ -79,4 +78,5 @@ class GlobalConfigRuleTest extends Specification { violations[0].lineNumber == 0 violations[0].message == GlobalConfigRule.FILE_MISSING_VIOLATION_MESSAGE } -} \ No newline at end of file + +} diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRuleTest.groovy index e62267fe..49e98cad 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/git/GitIgnoreRuleTest.groovy @@ -106,4 +106,5 @@ class GitIgnoreRuleTest extends Specification { !app.gitignoreFile.contains('') !app.gitignoreFile.contains('# Ending Comment') } -} \ No newline at end of file + +} diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRuleTest.groovy index 8222a80f..f7c07b8c 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRuleTest.groovy @@ -69,4 +69,5 @@ class MuleArtifactHasSecurePropertiesRuleTest extends Specification { violations[0].message.contains('client_id') violations[1].message.contains('client_secret') } + } From 513ec025e23c718d7d3b349e657f01d768254ebd Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 8 Jul 2020 14:26:13 -0400 Subject: [PATCH 3/7] MIP-395 Fixed CodeNarc rules --- .../linter/rule/property/PropertyFilePropertyCountRule.groovy | 2 ++ .../avioconsulting/mule/linter/model/MuleArtifactTest.groovy | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy index b9c54769..d52d2369 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy @@ -28,6 +28,7 @@ class PropertyFilePropertyCountRule extends Rule { this.pattern = pattern } + @SuppressWarnings('UnnecessaryGetter') @Override List execute(Application app) { List violations = [] @@ -54,6 +55,7 @@ class PropertyFilePropertyCountRule extends Rule { return validPropertyFilenames } + @SuppressWarnings('UnnecessaryGetter') List getValidPropertyFiles(List validPropertyFilenames, List propertyFiles) { List validPropertyFiles = [] propertyFiles.each { diff --git a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy index 02102f04..fb577cc0 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleArtifactTest.groovy @@ -61,6 +61,7 @@ class MuleArtifactTest extends Specification { muleArtifact.redeploymentEnabled == true } + @SuppressWarnings('UnnecessaryGetter') def "MuleArtifact dynamic attributes"() { given: String artifactString = '''{ From 6da63518aaf466cc7aae32fe9ada4808a8eddd64 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 8 Jul 2020 14:34:11 -0400 Subject: [PATCH 4/7] MIP-395 Updated ruleset --- codenarc-intellij.xml | 767 ++++++++++++++++++++++-------------------- 1 file changed, 396 insertions(+), 371 deletions(-) diff --git a/codenarc-intellij.xml b/codenarc-intellij.xml index 206a5758..6cb260ce 100644 --- a/codenarc-intellij.xml +++ b/codenarc-intellij.xml @@ -1,371 +1,396 @@ - - - - + + \ No newline at end of file From b958749bdaa25b9d30f8056a3548e191199b1419 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 8 Jul 2020 14:54:44 -0400 Subject: [PATCH 5/7] MIP-395 Groovy style code inspection cleanup --- .../mule/linter/model/ConfigurationFile.groovy | 2 +- .../mule/linter/model/MuleComponent.groovy | 2 +- .../mule/linter/model/PomFile.groovy | 4 ++-- .../property/PropertyFilePropertyCountRule.groovy | 2 +- .../apache/groovy/json/internal/JsonValue.java | 2 +- .../mule/linter/model/MuleXmlParserTest.groovy | 4 ++-- .../mule/linter/parser/JsonSlurperTest.groovy | 15 ++++++++------- 7 files changed, 16 insertions(+), 15 deletions(-) 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 f804b28f..e9c5e696 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy @@ -36,7 +36,7 @@ class ConfigurationFile extends ProjectFile { List findGlobalConfigs() { List componentList = [] - Iterator childNodes = configXml.childNodes() + List childNodes = configXml.childNodes() as List List comps = [] childNodes.each { node -> if (!checkElementExists(node, globalConfig)) { diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy index a53d0405..c909fc6a 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy @@ -4,7 +4,7 @@ class MuleComponent { private final String componentName private final String componentNamespace - private final Map attributes = [:] + private final Map attributes private final List children MuleComponent(String componentName, String componentNamespace, Map attributes) { diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy index 66ecb0a7..81745ce2 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy @@ -41,7 +41,7 @@ class PomFile extends ProjectFile { } PomProperty getPomProperty(String propertyName) throws IllegalArgumentException { - GPathResult p = pomProperties[propertyName] + GPathResult p = pomProperties[propertyName] as GPathResult if (p == null) { throw new IllegalArgumentException('Property doesn\'t exist') } @@ -58,7 +58,7 @@ class PomFile extends ProjectFile { } private GPathResult getPomProperties() { - return pomXml[PROPERTIES] + return pomXml[PROPERTIES] as GPathResult } } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy index d52d2369..2fad2757 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRule.groovy @@ -60,7 +60,7 @@ class PropertyFilePropertyCountRule extends Rule { List validPropertyFiles = [] propertyFiles.each { if (it.getName() in validPropertyFilenames) { - validPropertyFiles.add(it) + validPropertyFiles.add(it as PropertyFile) } } return validPropertyFiles diff --git a/src/main/groovy/org/apache/groovy/json/internal/JsonValue.java b/src/main/groovy/org/apache/groovy/json/internal/JsonValue.java index 5a751648..01d9d103 100644 --- a/src/main/groovy/org/apache/groovy/json/internal/JsonValue.java +++ b/src/main/groovy/org/apache/groovy/json/internal/JsonValue.java @@ -19,7 +19,7 @@ Object getValue() { return value; } - Integer getLineNumber() { + public Integer getLineNumber() { return lineNumber; } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy index d2c905ce..cd1da0c5 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy @@ -43,8 +43,8 @@ class MuleXmlParserTest extends Specification { when: MuleXmlParser parser = new MuleXmlParser() GPathResult project = parser.parseText(pomXml) - GPathResult appRuntime = project.'properties'.'app.runtime' - GPathResult munitVersion = project.'properties'.'munit.version' + GPathResult appRuntime = project.'properties'.'app.runtime' as GPathResult + GPathResult munitVersion = project.'properties'.'munit.version' as GPathResult String artifactId = project.getProperty('artifactId') then: diff --git a/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy index c2cac5db..0cb4f7d3 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/parser/JsonSlurperTest.groovy @@ -15,23 +15,24 @@ class JsonSlurperTest extends Specification { File json = new File(new File(this.class.classLoader.getResource(APP_NAME).file), 'mule-artifact.json') when: - JsonMap muleArtifact = slurper.parse(json) - JsonString minMuleVersion = muleArtifact['minMuleVersion'] + JsonMap muleArtifact = slurper.parse(json) as JsonMap + JsonString minMuleVersion = muleArtifact['minMuleVersion'] as JsonString then: - minMuleVersion == '4.2.2' + minMuleVersion.toString() == '4.2.2' minMuleVersion.lineNumber == 2 muleArtifact.getClass().name == 'org.apache.groovy.json.internal.JsonMap' minMuleVersion.getClass().name == 'org.apache.groovy.json.internal.JsonString' } + @SuppressWarnings('GrEqualsBetweenInconvertibleTypes') def "Boolean values with line numbers"() { given: JsonSlurper slurper = new JsonSlurper() File json = new File(new File(this.class.classLoader.getResource(APP_NAME).file), 'mule-artifact.json') when: - JsonMap muleArtifact = slurper.parse(json) + JsonMap muleArtifact = slurper.parse(json) as JsonMap JsonBoolean itsTrue = muleArtifact.itsTrue JsonBoolean itsFalse = muleArtifact.itsFalse @@ -48,7 +49,7 @@ class JsonSlurperTest extends Specification { File json = new File(new File(this.class.classLoader.getResource(APP_NAME).file), 'mule-artifact.json') when: - JsonMap muleArtifact = slurper.parse(json) + JsonMap muleArtifact = slurper.parse(json) as JsonMap then: muleArtifact.itsNull.value == null @@ -61,7 +62,7 @@ class JsonSlurperTest extends Specification { File json = new File(new File(this.class.classLoader.getResource(APP_NAME).file), 'mule-artifact.json') when: - JsonMap muleArtifact = slurper.parse(json) + JsonMap muleArtifact = slurper.parse(json) as JsonMap then: muleArtifact.itsNumber == 100 @@ -76,7 +77,7 @@ class JsonSlurperTest extends Specification { File json = new File(new File(this.class.classLoader.getResource(APP_NAME).file), 'mule-artifact.json') when: - JsonMap muleArtifact = slurper.parse(json) + JsonMap muleArtifact = slurper.parse(json) as JsonMap then: muleArtifact.secureProperties.size() == 7 From f5bc93da6183b7b10e7301a7f2bf8cdbc734cd71 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 8 Jul 2020 15:15:27 -0400 Subject: [PATCH 6/7] MIP-395 Codenarc cleanup --- build.gradle | 2 + config/codenarc/codenarc.xml | 79 ++++++++----------- .../mule/linter/model/MuleArtifact.groovy | 2 +- .../mule/linter/model/RuleSet.groovy | 3 - .../configuration/GlobalConfigRule.groovy | 3 +- ...MuleArtifactHasSecurePropertiesRule.groovy | 2 +- ...ArtifactHasSecurePropertiesRuleTest.groovy | 2 +- 7 files changed, 39 insertions(+), 54 deletions(-) rename src/main/groovy/com/avioconsulting/mule/linter/rule/{muleArtifact => muleartifact}/MuleArtifactHasSecurePropertiesRule.groovy (96%) rename src/test/groovy/com/avioconsulting/mule/linter/rule/{muleArtifact => muleartifact}/MuleArtifactHasSecurePropertiesRuleTest.groovy (97%) diff --git a/build.gradle b/build.gradle index 5e5322b2..306f7120 100644 --- a/build.gradle +++ b/build.gradle @@ -27,3 +27,5 @@ dependencies { test { useJUnitPlatform() } + +[codenarcMain, codenarcTest]*.ignoreFailures = true diff --git a/config/codenarc/codenarc.xml b/config/codenarc/codenarc.xml index 4f936a6f..bd60b2ec 100644 --- a/config/codenarc/codenarc.xml +++ b/config/codenarc/codenarc.xml @@ -4,51 +4,38 @@ xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset-schema.xsd"> - Basic rule set. - These rules are intended to be broadly (if not universally) applicable. + Complete rule set, AVIO Inspection. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy index 5abad29b..0aa95f72 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleArtifact.groovy @@ -10,7 +10,7 @@ class MuleArtifact extends ProjectFile { public static final String MULE_ARTIFACT_JSON = 'mule-artifact.json' - private JsonMap muleArtifact; + private JsonMap muleArtifact private final Boolean exists MuleArtifact(File f) { diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/RuleSet.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/RuleSet.groovy index 875ec3f4..a15f2738 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/RuleSet.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/RuleSet.groovy @@ -4,9 +4,6 @@ class RuleSet { List rules = [] - RuleSet() { - } - void addRule(Rule rule) { rules.add(rule) } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy index 26dad5af..215c9d89 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRule.groovy @@ -11,9 +11,8 @@ class GlobalConfigRule extends Rule { static final String RULE_NAME = 'Global mule configuration xml exists and contain required configuration.' static final String RULE_VIOLATION_MESSAGE = 'Mule configuration xml contain global configuration: ' static final String FILE_MISSING_VIOLATION_MESSAGE = 'Mule global configuration xml does not exist' - + static final String DEFAULT_FILE_NAME = 'globals.xml' static Map noneGlobalElements = [:] - static String DEFAULT_FILE_NAME = 'globals.xml' String globalFileName GlobalConfigRule(String globalFileName, Map noneGlobalElements) { 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 similarity index 96% rename from src/main/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRule.groovy rename to src/main/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRule.groovy index 11a323c4..3034d691 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 @@ -1,4 +1,4 @@ -package com.avioconsulting.mule.linter.rule.muleArtifact +package com.avioconsulting.mule.linter.rule.muleartifact import com.avioconsulting.mule.linter.model.Application import com.avioconsulting.mule.linter.model.Rule diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRuleTest.groovy similarity index 97% rename from src/test/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRuleTest.groovy rename to src/test/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRuleTest.groovy index f7c07b8c..cab96a47 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/muleArtifact/MuleArtifactHasSecurePropertiesRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRuleTest.groovy @@ -1,4 +1,4 @@ -package com.avioconsulting.mule.linter.rule.muleArtifact +package com.avioconsulting.mule.linter.rule.muleartifact import com.avioconsulting.mule.linter.model.Application import com.avioconsulting.mule.linter.model.Rule From a9ccd8ed504a5145f7fa9bc27b391213117de1cf Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 8 Jul 2020 17:00:52 -0400 Subject: [PATCH 7/7] MIP-395 Groovy code inspection cleanup --- .../mule/linter/model/ConfigurationFile.groovy | 7 ++++--- .../avioconsulting/mule/linter/model/MuleComponent.groovy | 8 ++++---- .../com/avioconsulting/mule/linter/model/PomFile.groovy | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) 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 e9c5e696..813989a1 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy @@ -23,6 +23,7 @@ class ConfigurationFile extends ProjectFile { configXml = parser.parse(file) } else { exists = false + configXml = null } } @@ -37,7 +38,7 @@ class ConfigurationFile extends ProjectFile { List findGlobalConfigs() { List componentList = [] List childNodes = configXml.childNodes() as List - List comps = [] + List comps = [] childNodes.each { node -> if (!checkElementExists(node, globalConfig)) { comps.add(node) @@ -45,7 +46,7 @@ class ConfigurationFile extends ProjectFile { } comps.each { comp -> - componentList.add(new MuleComponent(comp.name(), comp.namespaceURI(), comp.attributes)) + componentList.add(new MuleComponent(comp.name(), comp.namespaceURI(), comp.attributes())) } return componentList } @@ -58,7 +59,7 @@ class ConfigurationFile extends ProjectFile { */ Boolean checkElementExists(Node node, Map elements) { Map found = elements.findAll { - it.key == node.name && it.value == node.namespaceURI() + it.key == node.name() && it.value == node.namespaceURI() } return (found.size() > 0) } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy index c909fc6a..1d4ae96f 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy @@ -8,14 +8,14 @@ class MuleComponent { private final List children MuleComponent(String componentName, String componentNamespace, Map attributes) { - this.componentName = componentName - this.componentNamespace = componentNamespace - this.attributes = attributes + this(componentName, componentNamespace, attributes, null) } MuleComponent(String componentName, String componentNamespace, Map attributes, List children) { - this(componentName, componentNamespace, attributes) + this.componentName = componentName + this.componentNamespace = componentNamespace + this.attributes = attributes this.children = children } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy index 81745ce2..addcda91 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy @@ -17,6 +17,7 @@ class PomFile extends ProjectFile { pomXml = parser.parse(file) } else { exists = false + pomXml = null } }