Skip to content

Commit

Permalink
Feature/mip 309 (#4)
Browse files Browse the repository at this point in the history
* Updating dependencies and gradle build configuration
* Implemented initial RuleExecuter
* Implemented 4 initial POM rules with spock tests

Co-authored-by: Kevin King <kking@avioconsulting.com>
Co-authored-by: Nisarg Pansuria <npansuria@avioconsulting.com>
Co-authored-by: Adam DesJardin <adesjardin@avioconsulting.com>
  • Loading branch information
4 people authored Jun 30, 2020
1 parent 8e59f14 commit 9595a18
Show file tree
Hide file tree
Showing 33 changed files with 1,607 additions and 143 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ hs_err_pid*
.gradle/

build/
out/
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# mule-linter
Mule Linter Tool
#Mule Linter Tool
A linter is a tool that analyzes source code looking for patterns that don’t follow convention. Linting helps prevent errors and improve the overall quality of the code by following best practices. Lint tools are a form of static code analyzers. Some common code analyzers for Java are Checkstyle, FindBugs, and PMD.

The Mule Linter will enforce that all Mule projects are developed with a baseline set of rules. Some basic examples of rules that will be enforced, are the proper usage of property and pom files, useful logging messages, and standard project structure.

## Mule Application Design
![Mermaid Design](config/mermaid/mule-application-diagram.png)


## Code Coverage
[CodeNarc](https://codenarc.github.io/CodeNarc/) is used to ensure quality in groovy code. The configuration file is located [here.](config/codenarc/codenarc.xml) To execute run ```gradle check```, and an output [report](build/reports/codenarc/main.html) will be generated.
30 changes: 15 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ plugins {
id 'groovy'
id 'java'
id 'application'
id 'codenarc'
id 'com.github.johnrengelman.shadow' version '6.0.0'
}

group 'com.avioconsulting.mule'
version '1.0-SNAPSHOT'
mainClassName = 'com.avioconsulting.mule.MuleLinter'

sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'com.avioconsulting.mule.MuleLinterCli'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
}

dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'info.picocli:picocli-groovy:4.1.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
implementation 'org.codehaus.groovy:groovy-all:3.0.0'
implementation 'info.picocli:picocli-groovy:4.3.2'
implementation 'org.apache.maven:maven-core:3.6.3'
implementation 'org.apache.maven:maven-model:3.6.3'

task uberjar(type: Jar) {
from files(sourceSets.main.output.classesDirs)
from configurations.runtime.asFileTree.files.collect { zipTree(it) }
testImplementation platform('org.spockframework:spock-bom:2.0-M3-groovy-3.0')
testImplementation 'org.spockframework:spock-core'
}

manifest {
attributes 'Main-Class': mainClassName
}
}
test {
useJUnitPlatform()
}
371 changes: 371 additions & 0 deletions codenarc-intellij.xml

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions config/codenarc/codenarc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<ruleset xmlns="http://codenarc.org/ruleset/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://codenarc.org/ruleset/1.0 http://codenarc.org/ruleset-schema.xsd"
xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset-schema.xsd">

<description>
Basic rule set.
These rules are intended to be broadly (if not universally) applicable.
</description>

<rule class='org.codenarc.rule.basic.AssertWithinFinallyBlockRule'/>
<rule class='org.codenarc.rule.basic.AssignmentInConditionalRule'/>
<rule class='org.codenarc.rule.basic.BigDecimalInstantiationRule'/>
<rule class='org.codenarc.rule.basic.BitwiseOperatorInConditionalRule'/>
<rule class='org.codenarc.rule.basic.BooleanGetBooleanRule'/>
<rule class='org.codenarc.rule.basic.BrokenNullCheckRule'/>
<rule class='org.codenarc.rule.basic.BrokenOddnessCheckRule'/>
<rule class='org.codenarc.rule.basic.ClassForNameRule'/>
<rule class='org.codenarc.rule.basic.ComparisonOfTwoConstantsRule'/>
<rule class='org.codenarc.rule.basic.ComparisonWithSelfRule'/>
<rule class='org.codenarc.rule.basic.ConstantAssertExpressionRule'/>
<rule class='org.codenarc.rule.basic.ConstantTernaryExpressionRule'/>
<rule class='org.codenarc.rule.basic.ConstantIfExpressionRule'/>
<rule class='org.codenarc.rule.basic.DeadCodeRule'/>
<rule class='org.codenarc.rule.basic.DoubleNegativeRule'/>
<rule class='org.codenarc.rule.basic.DuplicateCaseStatementRule'/>
<rule class='org.codenarc.rule.basic.DuplicateMapKeyRule'/>
<rule class='org.codenarc.rule.basic.DuplicateSetValueRule'/>
<rule class='org.codenarc.rule.basic.EmptyCatchBlockRule'/>
<rule class='org.codenarc.rule.basic.EmptyClassRule'/>
<rule class='org.codenarc.rule.basic.EmptyElseBlockRule'/>
<rule class='org.codenarc.rule.basic.EmptyFinallyBlockRule'/>
<rule class='org.codenarc.rule.basic.EmptyForStatementRule'/>
<rule class='org.codenarc.rule.basic.EmptyIfStatementRule'/>
<rule class='org.codenarc.rule.basic.EmptySwitchStatementRule'/>
<rule class='org.codenarc.rule.basic.EmptySynchronizedStatementRule'/>
<rule class='org.codenarc.rule.basic.EmptyStaticInitializerRule'/>
<rule class='org.codenarc.rule.basic.EmptyTryBlockRule'/>
<rule class='org.codenarc.rule.basic.EmptyWhileStatementRule'/>
<rule class='org.codenarc.rule.basic.EmptyInstanceInitializerRule'/>
<rule class='org.codenarc.rule.basic.EmptyMethodRule'/>
<rule class='org.codenarc.rule.basic.EqualsAndHashCodeRule'/>
<rule class='org.codenarc.rule.basic.EqualsOverloadedRule'/>
<rule class='org.codenarc.rule.basic.ExplicitGarbageCollectionRule'/>
<rule class='org.codenarc.rule.basic.ForLoopShouldBeWhileLoopRule'/>
<rule class='org.codenarc.rule.basic.HardCodedWindowsFileSeparatorRule'/>
<rule class='org.codenarc.rule.basic.HardCodedWindowsRootDirectoryRule'/>
<rule class='org.codenarc.rule.basic.IntegerGetIntegerRule'/>
<rule class='org.codenarc.rule.basic.MultipleUnaryOperatorsRule'/>
<rule class='org.codenarc.rule.basic.RandomDoubleCoercedToZeroRule'/>
<rule class='org.codenarc.rule.basic.RemoveAllOnSelfRule'/>
<rule class='org.codenarc.rule.basic.ReturnFromFinallyBlockRule'/>
<rule class='org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule'/>
</ruleset>
93 changes: 93 additions & 0 deletions config/mermaid/mule-application-design.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
classDiagram
class Application{
+File applicationPath
+String name
+Map<String, ProjectFile> files
+hasFile(name)
+getFilesByType(type)
+getPomFile()
+getPropertyFiles()
+getMuleConfigs()
+getMuleArtifactJson()
}
Application "1" --> "*" ProjectFile
class ProjectFile{
+String name
+String type
+String File
}
ProjectFile <|-- Pom
class Pom {
+hasProperty(name)
+getMuleMavenVersion()
+getMunitVersion()
+getMuleVersion()
}
ProjectFile <|-- PropertyFile
class PropertyFile {
+hasProperty(propName)
+isSecure(propName)
}
ProjectFile <|-- MuleArtifactJson
class MuleArtifactJson {
+hasSecureProperty(name)
}
ProjectFile <|-- GitIgnore
class GitIgnore {
+hasEntry(name)
}

ProjectFile <|-- MuleConfig
class MuleConfig{
+MuleComponent[] components
+hasGlobals()
}

MuleConfig "1" --> "*" MuleComponent
class MuleComponent{
+String type
+String name
+Integer lineNumber
+Map[] attributes
+MuleComponent[] contains
+hasComponent()
+getComponent(name)
+hasAttribute()
+getAttribute(name)
}
MuleComponent <|-- MuleFlow
class MuleFlow{

}
MuleComponent <|-- MuleLogger
class MuleLogger{
+hasMessage()
+hasCategory()
}
MuleFlow "0" --> "*" MuleLogger
class RuleExecuter {
+Rule[] rules
+executeRules()
}
RuleExecuter "1" --> "*" Rule
class Rule{
+String ruleId
+String ruleName
+String severity
+ProjectFile file
+RuleResult result
+execute()
+raiseIssue()
}
Rule --> RuleResult
class RuleResult{
+Boolean success
+Integer lineNumber
+String file
+String severity
+String message
}
Rule <|-- ASpecificRule
class ASpecificRule {

}
Binary file added config/mermaid/mule-application-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Mon Jun 29 21:21:08 CDT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
53 changes: 33 additions & 20 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -66,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit 9595a18

Please sign in to comment.