Skip to content

Commit

Permalink
Merge pull request #87 from avioconsulting/feature/extension-refactor
Browse files Browse the repository at this point in the history
Extensions Support, Maven Plugin, DSL, and other refactors
  • Loading branch information
manikmagar authored Dec 15, 2021
2 parents 608c7eb + d0a2f34 commit 6ba0336
Show file tree
Hide file tree
Showing 228 changed files with 4,284 additions and 1,965 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- 'master'

jobs:
build:
Build:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -40,10 +40,10 @@ jobs:
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: ./build/test-results/test/*.xml
files: ./**/build/test-results/test/*.xml

- name: Publish Artifact
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
env:
MVN_USER: ${{ secrets.GIT_USER }}
MVN_PASSWORD: ${{ secrets.GIT_TOKEN }}
Expand All @@ -53,11 +53,11 @@ jobs:
./gradlew publish
- name: Perform Release
if: ${{ !contains(steps.set-version.outputs.version, 'SNAPSHOT') && github.event_name != 'pull_request' }}
if: ${{ !contains(steps.set-version.outputs.version, 'SNAPSHOT') && github.event_name != 'pull_request' && github.ref == 'refs/heads/master'}}
run: echo "Releasing version ${{ steps.set-version.outputs.version }}"

- name: Perform Release
if: ${{ !contains(steps.set-version.outputs.version, 'SNAPSHOT') && github.event_name != 'pull_request' }}
if: ${{ !contains(steps.set-version.outputs.version, 'SNAPSHOT') && github.event_name != 'pull_request' && github.ref == 'refs/heads/master'}}
env:
GIT_USER: ${{ secrets.GIT_USER }}
GIT_PASSWORD: ${{ secrets.GIT_TOKEN }}
Expand All @@ -72,7 +72,7 @@ jobs:
git push --follow-tags
- name: Add Release Note and Create Github Release
if: ${{ !contains(steps.set-version.outputs.version, 'SNAPSHOT') && github.event_name != 'pull_request' }}
if: ${{ !contains(steps.set-version.outputs.version, 'SNAPSHOT') && github.event_name != 'pull_request' && github.ref == 'refs/heads/master'}}
uses: release-drafter/release-drafter@v5
with:
version: ${{ steps.set-version.outputs.version }}
Expand Down
28 changes: 28 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mule-linter</name>
<comment>Project mule-linter created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1634743890935</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
13 changes: 13 additions & 0 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
1 change: 1 addition & 0 deletions AVIOCustomRuleConfiguration.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.avioconsulting.mule.linter.model.CaseNaming
import com.avioconsulting.mule.linter.model.rule.RuleSet
import com.avioconsulting.mule.linter.model.CaseNaming
import com.avioconsulting.mule.linter.rule.cicd.*
Expand Down
102 changes: 31 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@ A linter is a tool that analyzes source code looking for patterns that don’t f

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.

## Execution
## Usage

The mule-linter can be run as a jar with the following command:
### Maven Plugin
See [Readme](mule-linter-maven-plugin/README.md) in `mule-linter-maven-plugin` module.

### CLI

Project uses Gradle build system. Run following command to build all components in local -

```shell
./gradlew build
```
~/code/avio/mule-linter$ java -jar mule-linter-1.0-SNAPSHOT.jar --dir=SampleMuleApp --rules='AVIOCustomRuleConfiguration.groovy'

The CLI distributions are generated in `./mule-linter-cli/build/distributions/`.
Unzip/Untar the distribution. You can run the CLI from expanded files -

```shell
./bin/mule-linter-cli
```

`--dir` is the root directory of the Mule project. `--rules` is the path to the rule configuration file.
You may move expanded distribution folder to other persistent location and add it on OS PATH,
and then run cli from anywhere on the system.

## Build
To build the project run -

`./gradlew build`

Generated Distribution and install in local -

`./gradlew installDist`


## Rule Configuration

Expand All @@ -24,76 +47,13 @@ static RuleSet getRules() { }
Initialize the Rules you would like to use, and add them to the RuleSet with the `.addRule(Rule)` method.
Make sure to import the rules and helper classes you intend to use.

Sample configuration:
```groovy
import com.avioconsulting.mule.linter.model.rule.RuleSet
import com.avioconsulting.mule.linter.model.CaseNaming
import com.avioconsulting.mule.linter.rule.cicd.*
import com.avioconsulting.mule.linter.rule.configuration.*
import com.avioconsulting.mule.linter.rule.git.*
import com.avioconsulting.mule.linter.rule.muleartifact.*
import com.avioconsulting.mule.linter.rule.pom.*
import com.avioconsulting.mule.linter.rule.property.*
class AVIOCustomRuleConfiguration {
static final List<String> ENVIRONMENTS = ['dev','test','prod']
static final String GLOBALS_FILENAME = 'globals.xml'
static RuleSet getRules() {
RuleSet rules = new RuleSet()
//cicd
rules.addRule(new JenkinsFileExistsRule())
//configuration
rules.addRule(new ConfigFileNamingRule(CaseNaming.CaseFormat.KEBAB_CASE))
rules.addRule(new FlowSubflowNamingRule(CaseNaming.CaseFormat.KEBAB_CASE))
rules.addRule(new GlobalConfigNoFlowsRule(GLOBALS_FILENAME))
rules.addRule(new GlobalConfigRule(GLOBALS_FILENAME))
rules.addRule(new LoggerCategoryExistsRule())
rules.addRule(new LoggerMessageExistsRule())
rules.addRule(new OnErrorLogExceptionRule())
rules.addRule(new UnusedFlowRule())
//git
rules.addRule(new GitIgnoreRule())
//muleArtifact
rules.addRule(new MuleArtifactHasSecurePropertiesRule())
rules.addRule(new MuleArtifactMinMuleVersionRule())
//pom
rules.addRule(new MuleMavenPluginVersionRule('3.3.5'))
rules.addRule(new MuleRuntimeVersionRule('4.2.1'))
rules.addRule(new MunitMavenPluginAttributesRule())
rules.addRule(new MunitVersionRule('2.2.1'))
rules.addRule(new PomExistsRule())
//property
rules.addRule(new EncryptedPasswordRule())
rules.addRule(new PropertyExistsRule('db.user', ENVIRONMENTS))
rules.addRule(new PropertyFileNamingRule(ENVIRONMENTS))
rules.addRule(new PropertyFilePropertyCountRule(ENVIRONMENTS))
return rules
}
}
```
For a full breakdown on the available rules, [check here](docs/available_rules.md).

## Maven Plugin
The mule linter can be run as mvn plugin

The Maven Plugin is located in the *mavenPlugin* folder. Install it with the following command:
See [AVIOGDSLRuleConfiguration.groovy](mule-linter-core/AVIOGDSLRuleConfiguration.groovy) for sample configuration.

```mvn install```

This is an example of how to use the maven plugin by command line
```mvn com.avioconsulting.mule.maven:mule-linter-maven-plugin:0.0.1-SNAPSHOT:mule-linter -DappDir=<<Path to the Mule project>> -DruleConfiguration=<<Path to groovy rules file>> -Dformats=console,html,json```

Reports from JSON and HTML format will be saved in the *target/site* directory
For a full breakdown on the available rules, [check here](docs/available_rules.md).

### Using IntelliJ Auto Completion
Mule Linter's core library contains the GDSL file to support autocompletion in IntelliJ. To use that feature, `com.avioconsulting.mule:mule-linter-core` dependency must be added with `provided` scope in the project. `provided` scope will avoid maven packaging core into project artifact but still allow IntelliJ to detect the GDSL script from classpath.

## Code Checkout
When cloning add the 'recurse-submodules' flag
Expand Down
65 changes: 22 additions & 43 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,56 +1,35 @@

plugins {
id 'groovy'
id 'java'
id 'application'
id 'codenarc'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '6.0.0'
id 'base'
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
}

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

repositories {
mavenCentral()
}
subprojects {
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'net.thauvin.erik.gradle.semver'

dependencies {
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
implementation 'org.codehaus.groovy:groovy-all:3.0.0'
implementation 'info.picocli:picocli-groovy:4.3.2'
testImplementation platform('org.spockframework:spock-bom:2.0-M3-groovy-3.0')
testImplementation 'org.spockframework:spock-core'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.json:json:20171018'
implementation 'org.yaml:snakeyaml:1.29'
}
group 'com.avioconsulting.mule'

test {
useJUnitPlatform()
}
repositories {
mavenCentral()
}

// https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.CodeNarcExtension.html
codenarc {
configFile = file("${project.projectDir}/config/code-quality-config/codenarc/codenarc.xml")
ignoreFailures = true
}
test {
useJUnitPlatform()
}

publishing {
publications {
maven(MavenPublication) {
from components.java
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
repositories {
maven {
credentials {
username = System.getenv("MVN_USER") != null ? System.getenv("MVN_USER") : ''
password = System.getenv("MVN_PASSWORD") != null ? System.getenv("MVN_PASSWORD") : ''
}
url = 'https://maven.pkg.github.com/avioconsulting/public-packages'

dependencies {
implementation (group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.8', ext: 'pom'){
transitive= true
}
}

}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Mon Jun 29 21:21:08 CDT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
Loading

0 comments on commit 6ba0336

Please sign in to comment.