Skip to content

Commit b15bb29

Browse files
AustinShalitJLLeitschuh
authored andcommitted
Adds the PMD Plugin (#620)
* Add pmd rulesets
1 parent b3ff91c commit b15bb29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+192
-168
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ install:
3030
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ./gradlew :ui:assemble --stacktrace || ./gradlew --stacktrace '
3131

3232
script:
33-
- ./gradlew checkstyleMain checkstyleTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
33+
- ./gradlew checkstyleMain checkstyleTest pmdMain jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
3434

3535
after_success:
3636
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then codecov ; fi

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build_script:
66

77
# to run your custom scripts instead of automatic tests
88
test_script:
9-
- gradlew.bat checkstyleMain checkstyleTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
9+
- gradlew.bat checkstyleMain checkstyleTest pmdMain jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
1010

1111
platform:
1212
- x64

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ allprojects {
9090
apply plugin: 'jacoco'
9191
apply plugin: 'net.ltgt.errorprone'
9292
apply plugin: 'checkstyle'
93+
apply plugin: 'pmd'
9394

9495
configurations.errorprone {
9596
resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9'
@@ -109,6 +110,14 @@ allprojects {
109110
it.dependsOn = []
110111
}
111112

113+
pmd {
114+
consoleOutput = true
115+
sourceSets = [sourceSets.main]
116+
reportsDir = file("$project.buildDir/reports/pmd")
117+
ruleSetFiles = files(new File(rootDir, "pmd-ruleset.xml"))
118+
ruleSets = []
119+
}
120+
112121
repositories {
113122
mavenCentral()
114123
jcenter()

core/src/main/java/edu/wpi/grip/core/ConnectionValidator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ public interface ConnectionValidator {
1919
* @return The return value of {@link #canConnect(OutputSocket, InputSocket)}
2020
*/
2121
default boolean canConnect(Socket socket1, Socket socket2) {
22-
final OutputSocket<?> outputSocket;
23-
final InputSocket<?> inputSocket;
24-
2522
// One socket must be an input and one must be an output
2623
if (socket1.getDirection() == socket2.getDirection()) {
2724
return false;
2825
}
2926

27+
final OutputSocket<?> outputSocket;
28+
final InputSocket<?> inputSocket;
3029
if (socket1.getDirection().equals(Socket.Direction.OUTPUT)) {
3130
outputSocket = (OutputSocket) socket1;
3231
inputSocket = (InputSocket) socket2;

core/src/main/java/edu/wpi/grip/core/GripCoreModule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
*/
4343
@SuppressWarnings("PMD.MoreThanOneLogger")
4444
public class GripCoreModule extends AbstractModule {
45+
46+
private final EventBus eventBus;
47+
4548
private static final Logger logger = Logger.getLogger(GripCoreModule.class.getName());
4649

4750
// This is in a static initialization block so that we don't create a ton of
@@ -93,8 +96,6 @@ public synchronized void publish(final LogRecord record) {
9396
}
9497
}
9598

96-
private final EventBus eventBus;
97-
9899
/*
99100
* This class should not be used in tests. Use GRIPCoreTestModule for tests.
100101
*/

core/src/main/java/edu/wpi/grip/core/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
public class Main {
3030

31+
private static final Logger logger = Logger.getLogger(Main.class.getName());
32+
3133
@Inject
3234
private Project project;
3335
@Inject
@@ -39,20 +41,18 @@ public class Main {
3941
@Inject
4042
private CVOperations cvOperations;
4143
@Inject
42-
private Logger logger;
43-
@Inject
4444
private GripServer gripServer;
4545
@Inject
4646
private HttpPipelineSwitcher pipelineSwitcher;
4747

48-
@SuppressWarnings({"PMD.SystemPrintln", "JavadocMethod"})
48+
@SuppressWarnings("JavadocMethod")
4949
public static void main(String[] args) throws IOException, InterruptedException {
5050
final Injector injector = Guice.createInjector(Modules.override(
5151
new GripCoreModule(), new GripSourcesHardwareModule()).with(new GripNetworkModule()));
5252
injector.getInstance(Main.class).start(args);
5353
}
5454

55-
@SuppressWarnings({"PMD.SystemPrintln", "JavadocMethod"})
55+
@SuppressWarnings("JavadocMethod")
5656
public void start(String[] args) throws IOException, InterruptedException {
5757
String projectPath = null;
5858
if (args.length == 1) {

core/src/main/java/edu/wpi/grip/core/OperationDescription.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import com.google.common.collect.ImmutableSet;
77

88
import java.io.InputStream;
9+
import java.util.Objects;
910
import java.util.Optional;
1011
import java.util.Set;
11-
1212
import javax.annotation.Nullable;
1313
import javax.annotation.concurrent.Immutable;
1414

@@ -105,39 +105,25 @@ public boolean equals(@Nullable Object o) {
105105

106106
OperationDescription that = (OperationDescription) o;
107107

108-
if (name() != null ? !name().equals(that.name()) : that.name() != null) {
109-
return false;
110-
}
111-
if (summary() != null ? !summary().equals(that.summary()) : that.summary() != null) {
112-
return false;
113-
}
114-
if (category() != that.category()) {
115-
return false;
116-
}
117-
if (icon() != null ? !icon().equals(that.icon()) : that.icon() != null) {
118-
return false;
119-
}
120-
return aliases() != null ? aliases().equals(that.aliases()) : that.aliases() == null;
121-
108+
return Objects.equals(name, that.name)
109+
&& Objects.equals(summary, that.summary)
110+
&& Objects.equals(category, that.category)
111+
&& Objects.equals(icon, that.icon)
112+
&& Objects.equals(aliases, that.aliases);
122113
}
123114

124115
@Override
125116
public int hashCode() {
126-
int result = name() != null ? name().hashCode() : 0;
127-
result = 31 * result + (summary() != null ? summary().hashCode() : 0);
128-
result = 31 * result + (category() != null ? category().hashCode() : 0);
129-
result = 31 * result + (icon() != null ? icon().hashCode() : 0);
130-
result = 31 * result + (aliases() != null ? aliases().hashCode() : 0);
131-
return result;
117+
return Objects.hash(name, summary, category, icon, aliases);
132118
}
133119

134120
@Override
135121
public String toString() {
136122
return MoreObjects.toStringHelper(this)
137-
.add("name", name())
138-
.add("summary", summary())
139-
.add("aliases", aliases())
140-
.add("category", category())
123+
.add("name", name)
124+
.add("summary", summary)
125+
.add("aliases", aliases)
126+
.add("category", category)
141127
.toString();
142128
}
143129

core/src/main/java/edu/wpi/grip/core/Pipeline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Pipeline implements ConnectionValidator, SettingsProvider {
6161
@Inject
6262
@XStreamOmitField
6363
private EventBus eventBus;
64-
private transient ReadWriteLock stepLock = new ReentrantReadWriteLock();
64+
private final transient ReadWriteLock stepLock = new ReentrantReadWriteLock();
6565
private ProjectSettings settings = new ProjectSettings();
6666

6767
/**

core/src/main/java/edu/wpi/grip/core/PipelineRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
@Singleton
4040
public class PipelineRunner implements RestartableService {
41-
private final Logger logger = Logger.getLogger(getClass().getName());
41+
private static final Logger logger = Logger.getLogger(PipelineRunner.class.getName());
4242
/**
4343
* This is used to flag that the pipeline needs to run because of an update.
4444
*/

core/src/main/java/edu/wpi/grip/core/Source.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Base class for an input into the pipeline.
2222
*/
2323
public abstract class Source {
24-
private final Logger logger = Logger.getLogger(getClass().getName());
24+
private static final Logger logger = Logger.getLogger(Source.class.getName());
2525
private final ExceptionWitness exceptionWitness;
2626

2727
/**

0 commit comments

Comments
 (0)