Skip to content

Commit 0f8cd6c

Browse files
committed
update dependencies, use proper java 1.8 code
1 parent 535ac21 commit 0f8cd6c

35 files changed

+279
-356
lines changed

code-assert-gui/src/test/java/guru/nidi/codeassert/gui/CodeTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
import guru.nidi.codeassert.checkstyle.*;
1919
import guru.nidi.codeassert.config.AnalyzerConfig;
20-
import guru.nidi.codeassert.config.In;
2120
import guru.nidi.codeassert.dependency.*;
22-
import guru.nidi.codeassert.findbugs.*;
21+
import guru.nidi.codeassert.findbugs.FindBugsResult;
2322
import guru.nidi.codeassert.junit.CodeAssertJunit5Test;
2423
import guru.nidi.codeassert.junit.PredefConfig;
2524
import guru.nidi.codeassert.pmd.*;

code-assert-maven-plugin/src/main/java/guru/nidi/codeassert/AssertMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class AssertMojo extends AbstractMojo {
5050
@Component
5151
private BuildPluginManager pluginManager;
5252

53-
public void execute() throws MojoExecutionException, MojoFailureException {
53+
public void execute() throws MojoExecutionException {
5454
report();
5555
if (canRunTest()) {
5656
runTest();

code-assert-maven-plugin/src/main/java/guru/nidi/codeassert/PrepareMojo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.maven.project.MavenProject;
2323

2424
import java.io.*;
25+
import java.nio.charset.StandardCharsets;
2526

2627
import static guru.nidi.codeassert.AssertMojo.JACOCO_VERSION;
2728
import static org.twdata.maven.mojoexecutor.MojoExecutor.*;
@@ -41,7 +42,7 @@ public class PrepareMojo extends AbstractMojo {
4142
@Component
4243
private BuildPluginManager pluginManager;
4344

44-
public void execute() throws MojoExecutionException, MojoFailureException {
45+
public void execute() throws MojoExecutionException {
4546
executeJacocoPlugin();
4647
writeArgLineFile();
4748
}
@@ -64,7 +65,7 @@ private void writeArgLineFile() {
6465
if (argLine != null) {
6566
final File file = new File("target", "coverageOptions.txt");
6667
file.getParentFile().mkdirs();
67-
try (final Writer out = new OutputStreamWriter(new FileOutputStream(file), "utf-8")) {
68+
try (final Writer out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
6869
out.write(argLine);
6970
getLog().info("Wrote argLine to " + file);
7071
} catch (IOException e) {

code-assert/pom.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
@@ -14,12 +15,12 @@
1415
<properties>
1516
<slf4j.version>1.7.25</slf4j.version>
1617
<checkstyle.version>6.19</checkstyle.version>
17-
<findbugs.version>3.0.1</findbugs.version>
18-
<findsecbugs.version>1.7.1</findsecbugs.version>
19-
<pmd.version>5.4.1</pmd.version>
18+
<findbugs.version>3.1.6</findbugs.version>
19+
<findsecbugs.version>1.8.0</findsecbugs.version>
20+
<pmd.version>5.8.1</pmd.version>
2021
<kotlin.version>1.2.30</kotlin.version>
21-
<detekt.version>1.0.0.RC6-4</detekt.version>
22-
<ktlint.version>0.20.0</ktlint.version>
22+
<detekt.version>1.0.0.RC8</detekt.version>
23+
<ktlint.version>0.27.0</ktlint.version>
2324
</properties>
2425

2526
<build>
@@ -91,8 +92,8 @@
9192
<version>1.3</version>
9293
</dependency>
9394
<dependency>
94-
<groupId>com.google.code.findbugs</groupId>
95-
<artifactId>findbugs</artifactId>
95+
<groupId>com.github.spotbugs</groupId>
96+
<artifactId>spotbugs</artifactId>
9697
<version>${findbugs.version}</version>
9798
<exclusions>
9899
<exclusion>

code-assert/src/main/java/guru/nidi/codeassert/checkstyle/CheckstyleAnalyzer.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,18 @@
2727
import java.lang.reflect.Field;
2828
import java.util.*;
2929

30+
import static java.util.stream.Collectors.toList;
31+
3032
public class CheckstyleAnalyzer implements Analyzer<List<AuditEvent>> {
3133
private static final Logger LOG = LoggerFactory.getLogger(CheckstyleAnalyzer.class);
3234

3335
private final AnalyzerConfig config;
3436
private final StyleChecks checks;
3537
private final StyleEventCollector collector;
3638

37-
private static final Comparator<AuditEvent> EVENT_SORTER = new Comparator<AuditEvent>() {
38-
@Override
39-
public int compare(AuditEvent b1, AuditEvent b2) {
40-
final int severity = b1.getSeverityLevel().compareTo(b2.getSeverityLevel());
41-
if (severity != 0) {
42-
return severity;
43-
}
44-
return b1.getLocalizedMessage().getKey().compareTo(b2.getLocalizedMessage().getKey());
45-
}
46-
};
39+
private static final Comparator<AuditEvent> EVENT_COMPARATOR = Comparator
40+
.comparing(AuditEvent::getSeverityLevel)
41+
.thenComparing(e -> e.getLocalizedMessage().getKey());
4742

4843
private static class LoggingAuditListener implements AuditListener {
4944
final List<AuditEvent> events = new ArrayList<>();
@@ -107,7 +102,7 @@ private PropertyResolver createPropertyResolver() {
107102

108103
private String propertyValue(String name, Object value) {
109104
if (name.endsWith("-tokens")) {
110-
final StringBuilder tokens = new StringBuilder("");
105+
final StringBuilder tokens = new StringBuilder();
111106
for (final Integer val : (List<Integer>) value) {
112107
for (final Field f : TokenTypes.class.getFields()) {
113108
try {
@@ -125,17 +120,13 @@ private String propertyValue(String name, Object value) {
125120
}
126121

127122
private CheckstyleResult createResult(List<AuditEvent> events) {
128-
final List<AuditEvent> sorted = new ArrayList<>(events);
129-
Collections.sort(sorted, EVENT_SORTER);
130-
final List<AuditEvent> filtered = new ArrayList<>();
131123
final UsageCounter counter = new UsageCounter();
132-
for (final AuditEvent event : sorted) {
133-
if (counter.accept(collector.accept(event))) {
134-
filtered.add(event);
135-
}
136-
}
124+
final List<AuditEvent> res = events.stream()
125+
.filter(e -> counter.accept(collector.accept(e)))
126+
.sorted(EVENT_COMPARATOR)
127+
.collect(toList());
137128
collector.printUnusedWarning(counter);
138-
return new CheckstyleResult(this, filtered, collector.unusedActions(counter));
129+
return new CheckstyleResult(this, res, collector.unusedActions(counter));
139130
}
140131

141132
}

code-assert/src/main/java/guru/nidi/codeassert/config/AnalyzerConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static guru.nidi.codeassert.config.Language.JAVA;
2525
import static guru.nidi.codeassert.util.ListUtils.concat;
2626
import static java.util.Arrays.asList;
27+
import static java.util.Collections.emptyList;
2728
import static java.util.Collections.singletonList;
2829

2930
public class AnalyzerConfig {
@@ -32,7 +33,7 @@ public class AnalyzerConfig {
3233
private final List<Path> classes;
3334

3435
public AnalyzerConfig() {
35-
this(EnumSet.of(JAVA), Collections.<Path>emptyList(), Collections.<Path>emptyList());
36+
this(EnumSet.of(JAVA), emptyList(), emptyList());
3637
}
3738

3839
public AnalyzerConfig(AnalyzerConfig config) {

code-assert/src/main/java/guru/nidi/codeassert/config/BaseCollector.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
import org.slf4j.Logger;
2020
import org.slf4j.LoggerFactory;
2121

22-
import java.util.*;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
import static java.util.Collections.emptyList;
26+
import static java.util.Collections.singletonList;
2327

2428
public abstract class BaseCollector<S, A extends Action, T extends BaseCollector<S, A, T>> {
2529
private static final Logger LOG = LoggerFactory.getLogger(BaseCollector.class);
@@ -107,9 +111,7 @@ public void printUnusedWarning(UsageCounter counter) {
107111
}
108112

109113
protected List<A> unusedNullAction(UsageCounter counter, boolean hasDefaultConfig) {
110-
return counter.getCount(null) == 0 && hasDefaultConfig
111-
? Collections.<A>singletonList(null)
112-
: Collections.<A>emptyList();
114+
return counter.getCount(null) == 0 && hasDefaultConfig ? singletonList(null) : emptyList();
113115
}
114116

115117
protected String guessClassFromFile(String filename, Language language) {

code-assert/src/main/java/guru/nidi/codeassert/dependency/Dependencies.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public class Dependencies {
2929

3030
public Dependencies() {
3131
this(new DependencyMap(), new DependencyMap(), new DependencyMap(),
32-
new TreeSet<LocationMatcher>(), new TreeSet<String>(),
33-
new HashSet<DependencyMap>());
32+
new TreeSet<>(), new TreeSet<>(), new HashSet<>());
3433
}
3534

3635
public Dependencies(DependencyMap allowed, DependencyMap missing, DependencyMap denied,

code-assert/src/main/java/guru/nidi/codeassert/dependency/DependencyCycleMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected void describeMismatchSafely(DependencyResult item, Description descrip
5252

5353
private static List<DependencyMap> sortedDepMaps(Collection<DependencyMap> maps) {
5454
final List<DependencyMap> sorted = new ArrayList<>(maps);
55-
Collections.sort(sorted, DEP_MAP_COMPARATOR);
55+
sorted.sort(DEP_MAP_COMPARATOR);
5656
return sorted;
5757
}
5858

code-assert/src/main/java/guru/nidi/codeassert/dependency/DependencyMap.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ public <T> void with(int specificity, UsingElement<T> from, UsingElement<T> to)
2929
}
3030

3131
DependencyMap with(int specificity, String from, Collection<String> vias, String to) {
32-
Map<String, Info> deps = map.get(from);
33-
if (deps == null) {
34-
deps = new HashMap<>();
35-
map.put(from, deps);
36-
}
32+
final Map<String, Info> deps = map.computeIfAbsent(from, k -> new HashMap<>());
3733
final Info info = deps.get(to);
3834
if (info == null) {
3935
deps.put(to, new Info(vias, specificity));

0 commit comments

Comments
 (0)