Skip to content

Commit ef1bc9f

Browse files
authored
Merge pull request #1 from mulesoft-consulting/develop
Full Version
2 parents 6627293 + 46f3cb2 commit ef1bc9f

30 files changed

+1732
-2
lines changed

.gitignore

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
##############################
2+
## Java
3+
##############################
4+
.mtj.tmp/
5+
*.class
6+
*.jar
7+
*.war
8+
*.ear
9+
*.nar
10+
hs_err_pid*
11+
12+
##############################
13+
## Maven
14+
##############################
15+
target/
16+
pom.xml.tag
17+
pom.xml.releaseBackup
18+
pom.xml.versionsBackup
19+
pom.xml.next
20+
pom.xml.bak
21+
release.properties
22+
dependency-reduced-pom.xml
23+
buildNumber.properties
24+
.mvn/timing.properties
25+
.mvn/wrapper/maven-wrapper.jar
26+
27+
##############################
28+
## Gradle
29+
##############################
30+
bin/
31+
build/
32+
.gradle
33+
.gradletasknamecache
34+
gradle-app.setting
35+
!gradle-wrapper.jar
36+
37+
##############################
38+
## IntelliJ
39+
##############################
40+
out/
41+
.idea/
42+
.idea_modules/
43+
*.iml
44+
*.ipr
45+
*.iws
46+
47+
##############################
48+
## Eclipse
49+
##############################
50+
.settings/
51+
bin/
52+
tmp/
53+
.metadata
54+
.classpath
55+
.project
56+
*.tmp
57+
*.bak
58+
*.swp
59+
*~.nib
60+
local.properties
61+
.loadpath
62+
.factorypath
63+
64+
##############################
65+
## NetBeans
66+
##############################
67+
nbproject/private/
68+
build/
69+
nbbuild/
70+
dist/
71+
nbdist/
72+
nbactions.xml
73+
nb-configuration.xml
74+
75+
##############################
76+
## Visual Studio Code
77+
##############################
78+
.vscode/
79+
80+
##############################
81+
## OS X
82+
##############################
83+
.DS_Store

README.md

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,112 @@
1-
# mule-sonarqube-plugin
2-
Mule Sonarqube Plugin
1+
# Mule Sonarqube Validation Plugin
2+
3+
Sonarqube plugin:
4+
5+
* Ensure the consistency of Mule Applications by a set of predefined rules focused on specific quality attributes like: _Conceptual Integrity_, _Maintainability_, _Reusability_, _Security_, _Traceability_ and _Availability_.
6+
7+
**This module requires Java 8**.
8+
9+
## Prerequisites
10+
11+
## Install mule-validation-xpath-core dependency
12+
13+
1. Download the module source code.
14+
2. Open a terminal window and browse to module mule-validation-xpath-core folder.
15+
3. Install this module by running `mvn install`.
16+
17+
## Plugin Generation
18+
19+
1. Download the module source code.
20+
2. Open a terminal window and browse to module root folder.
21+
3. Build the mule plugin for Mule rules running `mvn clean package sonar-packaging:sonar-plugin -Dlanguage=mule`.
22+
23+
## Maven Configuration
24+
1. In your settings file add sonar profile.
25+
```
26+
<profile>
27+
<id>sonar</id>
28+
<activation>
29+
<activeByDefault>true</activeByDefault>
30+
</activation>
31+
<properties>
32+
<!-- Optional URL to server. Default value is http://localhost:9000 -->
33+
<sonar.host.url>
34+
http://localhost:9000
35+
</sonar.host.url>
36+
</properties>
37+
</profile>
38+
```
39+
40+
41+
## Sonar Configuration
42+
1. Copy the generated file, mule-validation-sonarqube-plugin-{version}-mule.jar to *sonar-home*/extensions/plugins
43+
2. Copy rules [Mule 3 Rules](https://github.com/mulesoft-consulting/mule-validation-toolkit/blob/master/mule-validation-xpath-core/src/main/resources/rules-3.xml) or [Mule 4 Rules](https://github.com/mulesoft-consulting/mule-validation-toolkit/blob/master/mule-validation-xpath-core/src/main/resources/rules-4.xml) to *sonar-home*/extensions/plugins
44+
3. Start the server
45+
46+
## Project Configuration
47+
### Alternative 1
48+
1. Modify project's pom.xml file to add language and location of the source files to analysis.
49+
```
50+
<properties>
51+
...
52+
<sonar.sources>src</sonar.sources>
53+
...
54+
</properties>
55+
```
56+
2. Analyze the project executing mvn sonar:sonar
57+
58+
### Alternative 2
59+
1. Analyze the project executing mvn sonar:sonar -Dsonar.sources=src
60+
61+
## Release Notes
62+
63+
#### 1.0.0
64+
##### Changes
65+
- Added Line Number processing in Coverage Sensor
66+
67+
#### 0.0.11
68+
##### Changes
69+
- Added Rule Template.
70+
You could create new custom rules from SonarQube Console.
71+
72+
#### 0.0.10
73+
##### Changes
74+
- Added Rule description.
75+
Now you could add an extended description to the rules. The description supports HTML.
76+
77+
#### 0.0.9
78+
##### Changes
79+
- Added property sonar.mule.ruleset.categories. It allows to filter ruleset categories to apply in the project.
80+
Value should be a string separated by commas.
81+
For example run, `mvn sonar:sonar -Dsonar.mule.ruleset.categories=flows` to only apply the flows category ruleset
82+
83+
#### 0.0.8
84+
##### Changes
85+
- Bug Fixes
86+
- Added Metric LOC
87+
- Added Support for SonarQube 7.2.1
88+
#### 0.0.7
89+
##### Changes
90+
- Added new rules + http namespace
91+
#### 0.0.6
92+
##### Changes
93+
- Added Munit Coverage and Minor Improvements
94+
#### 0.0.5
95+
##### Changes
96+
- Externalized Rules to $SONARQUBE_HOME/extensions/plugins/[rules-3.xml|rules-4.xml].
97+
Basic set of rules for [mule3](https://github.com/mulesoft-consulting/mule-validation-toolkit/blob/master/mule-validation-xpath-core/src/main/resources/rules-3.xml), [mule4](https://github.com/mulesoft-consulting/mule-validation-toolkit/blob/master/mule-validation-xpath-core/src/main/resources/rules-4.xml)
98+
99+
**Adding new rules: if it is needed to add a new namespace you will have to added to [mule3-namespaces](https://github.com/mulesoft-consulting/mule-validation-toolkit/blob/master/mule-validation-xpath-core/src/main/resources/namespace-3.properties) or to [mule4-namespaces](https://github.com/mulesoft-consulting/mule-validation-toolkit/blob/master/mule-validation-xpath-core/src/main/resources/namespace-4.properties) and regenerate all plugins**
100+
101+
**Updating existing rule: if you need to update an existing rule, you will also have to update its id number**
102+
103+
#### 0.0.4
104+
##### Changes
105+
- Added Measures
106+
- Number of Flows
107+
- Number of SubFlows
108+
- Number of DW Transformations
109+
- Application Complexity
110+
111+
## Final Note
112+
Enjoy and provide feedback / contribute :)

pom.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.mulesoft.services</groupId>
7+
<artifactId>mule-validation-sonarqube-plugin</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<url>http://maven.apache.org</url>
12+
<description>Sonar Plugin for Mule Projects</description>
13+
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<sonar.apiVersion>7.7</sonar.apiVersion>
18+
<sonar.language>java</sonar.language> <!-- Language to Scan -->
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>3.8.1</version>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.sonarsource.sonarqube</groupId>
30+
<artifactId>sonar-plugin-api</artifactId>
31+
<!-- minimal version of SonarQube to support. Note that the groupId was
32+
"org.codehaus.sonar" before version 5.2 -->
33+
<version>${sonar.apiVersion}</version>
34+
<!-- mandatory scope -->
35+
<scope>provided</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.jdom</groupId>
39+
<artifactId>jdom2</artifactId>
40+
<version>2.0.6</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.mulesoft.services</groupId>
44+
<artifactId>mule-validation-xpath-core</artifactId>
45+
<version>0.1.0</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.fasterxml.jackson.core</groupId>
49+
<artifactId>jackson-databind</artifactId>
50+
<version>2.8.9</version>
51+
</dependency>
52+
</dependencies>
53+
<build>
54+
<finalName>${project.artifactId}-${project.version}-mule</finalName>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
58+
<artifactId>sonar-packaging-maven-plugin</artifactId>
59+
<version>1.17</version>
60+
<extensions>true</extensions>
61+
<configuration>
62+
<!-- the entry-point class that extends org.sonar.api.SonarPlugin -->
63+
<pluginClass>com.mulesoft.services.tools.sonarqube.MulePlugin</pluginClass>
64+
<pluginName>MulePlugin</pluginName>
65+
<pluginKey>mulevalidationsonarqubeplugin-mule</pluginKey>
66+
<!-- advanced properties can be set here. See paragraph "Advanced Build
67+
Properties". -->
68+
</configuration>
69+
</plugin>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-compiler-plugin</artifactId>
73+
<version>3.7.0</version>
74+
<configuration>
75+
<source>1.8</source>
76+
<target>1.8</target>
77+
<encoding>UTF-8</encoding>
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.mulesoft.services.tools.sonarqube;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.sonar.api.Plugin;
6+
import org.sonar.api.config.PropertyDefinition;
7+
import org.sonar.api.resources.Qualifiers;
8+
9+
import com.mulesoft.services.tools.sonarqube.language.MuleLanguage;
10+
import com.mulesoft.services.tools.sonarqube.measures.MuleFlowCount;
11+
import com.mulesoft.services.tools.sonarqube.measures.MuleSizeRating;
12+
import com.mulesoft.services.tools.sonarqube.measures.MuleSubFlowCount;
13+
import com.mulesoft.services.tools.sonarqube.measures.MuleTransformationCount;
14+
import com.mulesoft.services.tools.sonarqube.metrics.ConfigurationFilesSensor;
15+
import com.mulesoft.services.tools.sonarqube.metrics.CoverageSensor;
16+
import com.mulesoft.services.tools.sonarqube.metrics.MUnitSensor;
17+
import com.mulesoft.services.tools.sonarqube.metrics.MuleMetrics;
18+
import com.mulesoft.services.tools.sonarqube.profile.MuleQualityProfile;
19+
import com.mulesoft.services.tools.sonarqube.rule.MuleRulesDefinition;
20+
import com.mulesoft.services.tools.sonarqube.sensor.MuleSensor;
21+
22+
public class MulePlugin implements Plugin {
23+
24+
// public static final String LANGUAGE_NAME = "Mule";
25+
private static final String GENERAL = "General";
26+
27+
Logger logger = LoggerFactory.getLogger(getClass());
28+
29+
@Override
30+
public void define(Context context) {
31+
if (logger.isDebugEnabled())
32+
logger.debug("Configuring Mule Plugin");
33+
34+
// Added Language
35+
context.addExtensions(MuleLanguage.class, MuleSensor.class);
36+
// context.addExtension(getProperties());
37+
38+
// Added Rules
39+
context.addExtension(MuleRulesDefinition.class);
40+
41+
// Added Profile
42+
context.addExtension(MuleQualityProfile.class);
43+
44+
context.addExtension(PropertyDefinition.builder(MuleLanguage.FILE_SUFFIXES_KEY)
45+
.defaultValue(MuleLanguage.FILE_SUFFIXES_DEFAULT_VALUE).name("File Suffixes")
46+
.description("List of suffixes for files to analyze.").subCategory(GENERAL)
47+
.category(MuleLanguage.LANGUAGE_NAME).multiValues(true).onQualifiers(Qualifiers.PROJECT).build());
48+
49+
context.addExtensions(MuleMetrics.class, ConfigurationFilesSensor.class, MuleSizeRating.class,
50+
MuleFlowCount.class, MuleSubFlowCount.class, MuleTransformationCount.class, CoverageSensor.class,
51+
MUnitSensor.class);
52+
}
53+
54+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.mulesoft.services.tools.sonarqube.filter;
2+
3+
import java.io.IOException;
4+
5+
import org.jdom2.Document;
6+
import org.jdom2.JDOMException;
7+
import org.jdom2.input.SAXBuilder;
8+
import org.sonar.api.batch.fs.FilePredicate;
9+
import org.sonar.api.batch.fs.InputFile;
10+
import org.sonar.api.utils.log.Logger;
11+
import org.sonar.api.utils.log.Loggers;
12+
13+
public class MuleFilePredicate implements FilePredicate {
14+
private final Logger logger = Loggers.get(MuleFilePredicate.class);
15+
SAXBuilder saxBuilder = new SAXBuilder();
16+
String muleNamespace = "http://www.mulesoft.org/schema/mule/core";
17+
String fileExtension = ".xml";
18+
19+
@Override
20+
public boolean apply(InputFile inputFile) {
21+
if (logger.isDebugEnabled()) {
22+
logger.debug("Executing Mule Sensor on file:" + inputFile.filename());
23+
}
24+
25+
if (inputFile.filename().endsWith(fileExtension)) {
26+
try {
27+
Document document = saxBuilder.build(inputFile.inputStream());
28+
29+
String namespace = document.getRootElement().getNamespaceURI();
30+
if (muleNamespace.equals(namespace))
31+
return true;
32+
} catch (JDOMException | IOException e) {
33+
logger.error("Parsing document:" + inputFile.filename(), e);
34+
}
35+
}
36+
return false;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)