-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* With sorting by file or severity. * With filtering of severity.
- Loading branch information
1 parent
57f3be8
commit 9b87b1d
Showing
14 changed files
with
271 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/bin/bash | ||
./gradlew clean build -i | ||
./gradlew clean gitChangelogTask build -i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import java.util.Comparator; | ||
|
||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public enum ORDERED_BY { | ||
FILE(new Comparator<Violation>() { | ||
@Override | ||
public int compare(Violation o1, Violation o2) { | ||
return o1.getFile().compareTo(o2.getFile()); | ||
} | ||
}), SEVERITY(new Comparator<Violation>() { | ||
@Override | ||
public int compare(Violation o1, Violation o2) { | ||
return new Integer(o1.getSeverity().ordinal())// | ||
.compareTo(new Integer(o2.getSeverity().ordinal())); | ||
} | ||
}); | ||
private Comparator<Violation> comparator; | ||
|
||
private ORDERED_BY(Comparator<Violation> comparable) { | ||
this.comparator = comparable; | ||
} | ||
|
||
public Comparator<Violation> getComparator() { | ||
return comparator; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/se/bjurr/violations/lib/ViolationsAccumulatedReporterApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static com.google.common.collect.Iterables.filter; | ||
import static com.google.common.collect.Lists.newArrayList; | ||
import static com.google.common.collect.Ordering.from; | ||
import static se.bjurr.violations.lib.model.SEVERITY.INFO; | ||
|
||
import java.util.List; | ||
|
||
import se.bjurr.violations.lib.model.SEVERITY; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
public class ViolationsAccumulatedReporterApi { | ||
|
||
private final List<Violation> violations = newArrayList(); | ||
private SEVERITY atLeastSeverity = INFO; | ||
private ORDERED_BY orderedBy; | ||
|
||
private ViolationsAccumulatedReporterApi() { | ||
} | ||
|
||
public ViolationsAccumulatedReporterApi withViolationsReporterApiList(List<Violation> violations) { | ||
this.violations.addAll(violations); | ||
return this; | ||
} | ||
|
||
public static ViolationsAccumulatedReporterApi violationsAccumulatedReporterApi() { | ||
return new ViolationsAccumulatedReporterApi(); | ||
} | ||
|
||
public ViolationsAccumulatedReporterApi withAtLeastSeverity(SEVERITY atLeastSeverity) { | ||
this.atLeastSeverity = atLeastSeverity; | ||
return this; | ||
} | ||
|
||
public ViolationsAccumulatedReporterApi orderedBy(ORDERED_BY orderedBy) { | ||
this.orderedBy = orderedBy; | ||
return this; | ||
} | ||
|
||
public List<Violation> violations() { | ||
return from(orderedBy.getComparator())// | ||
.sortedCopy(// | ||
filter(violations, new Predicate<Violation>() { | ||
@Override | ||
public boolean apply(Violation input) { | ||
return input.getSeverity().ordinal() >= atLeastSeverity.ordinal(); | ||
} | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/test/java/se/bjurr/violations/lib/AccumulatedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static com.google.common.collect.Lists.reverse; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static se.bjurr.violations.lib.ORDERED_BY.FILE; | ||
import static se.bjurr.violations.lib.ORDERED_BY.SEVERITY; | ||
import static se.bjurr.violations.lib.TestUtils.getRootFolder; | ||
import static se.bjurr.violations.lib.ViolationsAccumulatedReporterApi.violationsAccumulatedReporterApi; | ||
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi; | ||
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.reports.Reporter.CHECKSTYLE; | ||
import static se.bjurr.violations.lib.reports.Reporter.JSHINT; | ||
|
||
import org.junit.Test; | ||
|
||
public class AccumulatedTest { | ||
|
||
@Test | ||
public void testThatViolationsCanBeFiltered() { | ||
ViolationsAccumulatedReporterApi violationsAccumulatedReporterApi = getAccumulatedReporterApi(); | ||
|
||
assertThat(violationsAccumulatedReporterApi// | ||
.withAtLeastSeverity(ERROR)// | ||
.orderedBy(FILE)// | ||
.violations())// | ||
.hasSize(1); | ||
|
||
assertThat(violationsAccumulatedReporterApi// | ||
.withAtLeastSeverity(WARN)// | ||
.orderedBy(FILE)// | ||
.violations())// | ||
.hasSize(8); | ||
|
||
assertThat(violationsAccumulatedReporterApi// | ||
.withAtLeastSeverity(INFO)// | ||
.orderedBy(FILE)// | ||
.violations())// | ||
.hasSize(10); | ||
} | ||
|
||
@Test | ||
public void testThatViolationsCanBeOrdered() { | ||
ViolationsAccumulatedReporterApi violationsAccumulatedReporterApi = getAccumulatedReporterApi(); | ||
|
||
assertThat(violationsAccumulatedReporterApi// | ||
.withAtLeastSeverity(INFO)// | ||
.orderedBy(FILE)// | ||
.violations()// | ||
.get(0).getFile())// | ||
.isEqualTo("../../../../example-reports/web/js-file.js"); | ||
|
||
assertThat(reverse(violationsAccumulatedReporterApi// | ||
.withAtLeastSeverity(INFO)// | ||
.orderedBy(FILE)// | ||
.violations())// | ||
.get(0).getFile())// | ||
.isEqualTo("/src/main/java/se/bjurr/violations/lib/example/OtherClass.java"); | ||
|
||
assertThat(violationsAccumulatedReporterApi// | ||
.withAtLeastSeverity(INFO)// | ||
.orderedBy(SEVERITY)// | ||
.violations()// | ||
.get(0).getSeverity())// | ||
.isEqualTo(INFO); | ||
|
||
assertThat(reverse(violationsAccumulatedReporterApi// | ||
.withAtLeastSeverity(INFO)// | ||
.orderedBy(SEVERITY)// | ||
.violations())// | ||
.get(0).getSeverity())// | ||
.isEqualTo(ERROR); | ||
|
||
} | ||
|
||
private ViolationsAccumulatedReporterApi getAccumulatedReporterApi() { | ||
String rootFolder = getRootFolder(); | ||
|
||
return violationsAccumulatedReporterApi()// | ||
.withViolationsReporterApiList(// | ||
violationsReporterApi() // | ||
.withPattern(".*/checkstyle/.*\\.xml$") // | ||
.inFolder(rootFolder) // | ||
.findAll(CHECKSTYLE) // | ||
.violations()// | ||
) // | ||
.withViolationsReporterApiList(// | ||
violationsReporterApi() // | ||
.withPattern(".*/jshint/.*\\.xml$") // | ||
.inFolder(rootFolder) // | ||
.findAll(JSHINT) // | ||
.violations()// | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.