Skip to content

Commit

Permalink
Resharper support #3
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Mar 6, 2016
1 parent e1a7ad7 commit 5bfc5d3
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 2 deletions.
45 changes: 44 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,55 @@
Changelog of Git Changelog.

## Unreleased
### GitHub [#1](https://github.com/tomasbjerre/violations-lib/issues/#1)

**Resharper support**


[4b00706b1d9cbc4](https://github.com/tomasbjerre/git-changelog-lib/commit/4b00706b1d9cbc4) Tomas Bjerre *2016-03-05 21:14:33*

**CPPCheck support**


[d92013ebb6f4111](https://github.com/tomasbjerre/git-changelog-lib/commit/d92013ebb6f4111) Tomas Bjerre *2016-03-05 20:28:19*


## 1.4
### No issue

**Adding possibility to set findbugs messages**


[3a8c7089d924848](https://github.com/tomasbjerre/git-changelog-lib/commit/3a8c7089d924848) Tomas Bjerre *2016-03-05 09:34:51*


## 1.3
### No issue

**Only most specific FindBugs line**

* Also SLF4J and some debug logging.

[b50c549861119cf](https://github.com/tomasbjerre/git-changelog-lib/commit/b50c549861119cf) Tomas Bjerre *2016-03-04 17:16:52*


## 1.2
### No issue

**Adding reporter to Violation**


[ddddaefba1f1aee](https://github.com/tomasbjerre/git-changelog-lib/commit/ddddaefba1f1aee) Tomas Bjerre *2016-03-04 05:34:23*

**Adding links to projects using this lib**


[b6b4b74339b5008](https://github.com/tomasbjerre/git-changelog-lib/commit/b6b4b74339b5008) Tomas Bjerre *2016-03-03 21:05:58*

**Moving example reports to its own repo**


[7a2e967de70bc6f](https://github.com/tomasbjerre/git-changelog-lib/commit/7a2e967de70bc6f) Tomas Bjerre *2016-03-03 18:36:49*
[344567418ac1167](https://github.com/tomasbjerre/git-changelog-lib/commit/344567418ac1167) Tomas Bjerre *2016-03-03 18:53:24*


## 1.1
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ It supports:
* [_CPPCheck_](http://cppcheck.sourceforge.net/)
* [_CSSLint_](https://github.com/CSSLint/csslint)
* [_JSHint_](http://jshint.com/)
* [_Resharper_](https://www.jetbrains.com/resharper/)

Very easy to use with a nice builder pattern
```
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ apply plugin: "se.bjurr.gitchangelog.git-changelog-gradle-plugin"
task gitChangelogTask(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
filePath = "CHANGELOG.md";
templateContent = new File('changelog.mustache').getText('UTF-8');
removeIssueFromMessage = true
customIssues = [
[ "GitHub", "#([0-9]+)", "https://github.com/tomasbjerre/violations-lib/issues/\${PATTERN_GROUP}" ]
]
}

group = 'se.bjurr.violations'
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/se/bjurr/violations/lib/parsers/ResharperParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package se.bjurr.violations.lib.parsers;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.model.SEVERITY.WARN;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.reports.Reporter.RESHARPER;

import java.io.File;
import java.util.List;
import java.util.Map;

import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

public class ResharperParser extends ViolationsParser {

@Override
public List<Violation> parseFile(File file) throws Exception {
String string = Files.toString(file, Charsets.UTF_8);
List<Violation> violations = newArrayList();
List<String> issueTypeChunks = getChunks(string, "<IssueType ", "/>");
Map<String, Map<String, String>> issueTypesPerTypeId = newHashMap();
for (String issueTypesChunk : issueTypeChunks) {
Map<String, String> issueType = newHashMap();
String id = getAttribute(issueTypesChunk, "Id");
issueType.put("category", getAttribute(issueTypesChunk, "Category"));
issueType.put("description", getAttribute(issueTypesChunk, "Description"));
issueType.put("severity", getAttribute(issueTypesChunk, "Severity"));
issueTypesPerTypeId.put(id, issueType);
}

List<String> issueChunks = getChunks(string, "<Issue ", "/>");
for (String issueChunk : issueChunks) {
String typeId = getAttribute(issueChunk, "TypeId");
String filename = getAttribute(issueChunk, "File");
String message = getAttribute(issueChunk, "Message") + ". " + issueTypesPerTypeId.get(typeId).get("category") + ". "
+ issueTypesPerTypeId.get(typeId).get("description");
Integer line = findIntegerAttribute(issueChunk, "Line").or(0);
String severity = issueTypesPerTypeId.get(typeId).get("severity");
violations.add(//
violationBuilder()//
.setReporter(RESHARPER)//
.setStartLine(line)//
.setFile(filename)//
.setSeverity(toSeverity(severity))//
.setMessage(message)//
.setRule(typeId)//
.build()//
);
}
return violations;
}

public SEVERITY toSeverity(String severity) {
if (severity.equalsIgnoreCase("ERROR")) {
return ERROR;
}
if (severity.equalsIgnoreCase("WARNING")) {
return WARN;
}
return INFO;
}

}
4 changes: 3 additions & 1 deletion src/main/java/se/bjurr/violations/lib/reports/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import se.bjurr.violations.lib.parsers.FindbugsParser;
import se.bjurr.violations.lib.parsers.JSHintParser;
import se.bjurr.violations.lib.parsers.PMDParser;
import se.bjurr.violations.lib.parsers.ResharperParser;
import se.bjurr.violations.lib.parsers.ViolationsParser;

public enum Reporter {
Expand All @@ -22,7 +23,8 @@ public enum Reporter {
FINDBUGS(new FindbugsParser()), //
JSHINT(new JSHintParser()), //
PMD(new PMDParser()), //
CPPCHECK(new CPPCheckParser());
CPPCHECK(new CPPCheckParser()), //
RESHARPER(new ResharperParser());

private static Logger LOG = Logger.getLogger(Reporter.class.getSimpleName());
private ViolationsParser violationsParser;
Expand Down
64 changes: 64 additions & 0 deletions src/test/java/se/bjurr/violations/lib/ResharperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package se.bjurr.violations.lib;

import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.violations.lib.TestUtils.getRootFolder;
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.model.SEVERITY.WARN;
import static se.bjurr.violations.lib.reports.Reporter.RESHARPER;

import java.util.List;

import org.junit.Test;

import se.bjurr.violations.lib.model.Violation;

public class ResharperTest {

@Test
public void testThatViolationsCanBeParsed() {
String rootFolder = getRootFolder();

List<Violation> actual = violationsReporterApi() //
.withPattern(".*/resharper/.*\\.xml$") //
.inFolder(rootFolder) //
.findAll(RESHARPER) //
.violations();

assertThat(actual)//
.hasSize(3);

assertThat(actual.get(0).getReporter())//
.isEqualTo(RESHARPER);

assertThat(actual.get(0).getMessage())//
.isEqualTo(
"Using directive is not required by the code and can be safely removed. Redundancies in Code. Redundant using directive");
assertThat(actual.get(0).getRule().get())//
.isEqualTo("RedundantUsingDirective");
assertThat(actual.get(0).getFile())//
.isEqualTo("MyLibrary/Class1.cs");
assertThat(actual.get(0).getSeverity())//
.isEqualTo(WARN);

assertThat(actual.get(1).getMessage())//
.isEqualTo(
"Join declaration and assignment. Common Practices and Code Improvements. Join local variable declaration and assignment");
assertThat(actual.get(1).getRule().get())//
.isEqualTo("JoinDeclarationAndInitializer");
assertThat(actual.get(1).getFile())//
.isEqualTo("MyLibrary/Class1.cs");
assertThat(actual.get(1).getSeverity())//
.isEqualTo(INFO);

assertThat(actual.get(2).getMessage())//
.isEqualTo(
"Using directive is not required by the code and can be safely removed. Redundancies in Code. Redundant using directive");
assertThat(actual.get(2).getRule().get())//
.isEqualTo("RedundantUsingDirective");
assertThat(actual.get(2).getFile())//
.isEqualTo("MyLibrary/Properties/AssemblyInfo.cs");
assertThat(actual.get(2).getSeverity())//
.isEqualTo(WARN);
}
}
21 changes: 21 additions & 0 deletions src/test/resources/resharper/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by InspectCode 8.1.23.523 -->
<Report ToolsVersion="8.1">
<Information>
<Solution>CSharpPlayground.sln</Solution>
<InspectionScope>
<Element>9B2650A2-C7C6-435F-80D6-D6C7B522FFF9</Element>
</InspectionScope>
</Information>
<IssueTypes>
<IssueType Id="JoinDeclarationAndInitializer" Category="Common Practices and Code Improvements" Description="Join local variable declaration and assignment" Severity="SUGGESTION" />
<IssueType Id="RedundantUsingDirective" Category="Redundancies in Code" Description="Redundant using directive" Severity="WARNING" WikiUrl="http://confluence.jetbrains.net/display/ReSharper/Redundant+using+directive" />
</IssueTypes>
<Issues>
<Project Name="MyLibrary">
<Issue TypeId="RedundantUsingDirective" File="MyLibrary\Class1.cs" Offset="0-13" Message="Using directive is not required by the code and can be safely removed" />
<Issue TypeId="JoinDeclarationAndInitializer" File="MyLibrary\Class1.cs" Offset="138-144" Line="9" Message="Join declaration and assignment" />
<Issue TypeId="RedundantUsingDirective" File="MyLibrary\Properties\AssemblyInfo.cs" Offset="26-64" Line="2" Message="Using directive is not required by the code and can be safely removed" />
</Project>
</Issues>
</Report>

0 comments on commit 5bfc5d3

Please sign in to comment.