Add PMD and solve issues (#389)

This commit is contained in:
Austin Shalit
2016-12-08 00:24:44 -05:00
committed by Peter Johnson
parent 77f664a6b1
commit a705eb1c61
13 changed files with 87 additions and 50 deletions

View File

@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<ruleset name="WPILibRuleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<rule ref="rulesets/java/basic.xml" />
<rule ref="rulesets/java/braces.xml" />
<rule ref="rulesets/java/empty.xml" />
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
<properties>
<property name="allowCommentedBlocks" value="true"/>
</properties>
</rule>
<rule ref="rulesets/java/imports.xml" />
<rule ref="rulesets/java/junit.xml">
<exclude name="JUnitTestContainsTooManyAsserts" />
</rule>
<rule ref="rulesets/java/strings.xml">
<exclude name="AvoidDuplicateLiterals" />
</rule>
<rule ref="rulesets/java/unnecessary.xml" />
</ruleset>

View File

@@ -99,6 +99,10 @@ jar {
from sourceSets.shared.output
}
pmd {
sourceSets = [sourceSets.shared, sourceSets.athena]
}
task wpilibjSources(type: Jar, dependsOn: classes) {
description = 'Creates the sources jar for the maven publishing routine'
group = 'WPILib'

View File

@@ -1,6 +1,7 @@
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'pmd'
configurations.errorprone {
resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9'
@@ -52,6 +53,13 @@ clean {
delete wpilibVersionFile
}
pmd {
consoleOutput = true
reportsDir = file("$project.buildDir/reports/pmd")
ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml"))
ruleSets = []
}
sourceSets {
shared
}

View File

@@ -85,7 +85,7 @@ public class CameraServer {
return m_tables.get(source);
}
@SuppressWarnings("JavadocMethod")
@SuppressWarnings({"JavadocMethod", "PMD.AvoidUsingHardCodedIP"})
private synchronized void updateStreamValues() {
// Over all the sinks...
for (VideoSink i : m_sinks.values()) {

View File

@@ -153,7 +153,7 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
*/
public boolean isFwdSolenoidBlackListed() {
int blackList = getPCMSolenoidBlackList();
return ((blackList & m_forwardMask) != 0);
return (blackList & m_forwardMask) != 0;
}
/**
@@ -165,7 +165,7 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
*/
public boolean isRevSolenoidBlackListed() {
int blackList = getPCMSolenoidBlackList();
return ((blackList & m_reverseMask) != 0);
return (blackList & m_reverseMask) != 0;
}
/*

View File

@@ -190,7 +190,7 @@ public class DriverStation implements RobotState.Interface {
if (traces.length > 3) {
locString = traces[3].toString();
} else {
locString = new String();
locString = "";
}
boolean haveLoc = false;
String traceString = " at ";
@@ -854,7 +854,7 @@ public class DriverStation implements RobotState.Interface {
private void updateControlWord(boolean force) {
long now = System.currentTimeMillis();
synchronized (m_controlWordMutex) {
if ((now - m_lastControlWordUpdate > 50) || force) {
if (now - m_lastControlWordUpdate > 50 || force) {
HAL.getControlWord(m_controlWordCache);
m_lastControlWordUpdate = now;
}

View File

@@ -75,7 +75,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
allocateInterrupts(false);
assert (m_interrupt != 0);
assert m_interrupt != 0;
InterruptJNI.requestInterrupts(m_interrupt, getPortHandleForRouting(),
getAnalogTriggerTypeForRouting());
@@ -96,7 +96,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
allocateInterrupts(true);
assert (m_interrupt != 0);
assert m_interrupt != 0;
InterruptJNI.requestInterrupts(m_interrupt, getPortHandleForRouting(),
getAnalogTriggerTypeForRouting());

View File

@@ -185,6 +185,7 @@ public class IterativeRobot extends RobotBase {
* <p>Users should override this method for initialization code which will be called each time the
* robot enters test mode.
*/
@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
public void testInit() {
System.out.println("Default IterativeRobot.testInit() method... Overload me!");
}
@@ -283,6 +284,7 @@ public class IterativeRobot extends RobotBase {
* disconnected. For most use cases the variable timing will not be an issue. If your code does
* require guaranteed fixed periodic timing, consider using Notifier or PIDController instead.
*/
@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
public void testPeriodic() {
if (m_tmpFirstRun) {
System.out.println("Default IterativeRobot.testPeriodic() method... Overload me!");

View File

@@ -282,12 +282,12 @@ public class RobotDrive implements MotorSafety {
rightValue = limit(rightValue);
if (squaredInputs) {
if (leftValue >= 0.0) {
leftValue = (leftValue * leftValue);
leftValue = leftValue * leftValue;
} else {
leftValue = -(leftValue * leftValue);
}
if (rightValue >= 0.0) {
rightValue = (rightValue * rightValue);
rightValue = rightValue * rightValue;
} else {
rightValue = -(rightValue * rightValue);
}
@@ -395,12 +395,12 @@ public class RobotDrive implements MotorSafety {
// square the inputs (while preserving the sign) to increase fine control
// while permitting full power
if (moveValue >= 0.0) {
moveValue = (moveValue * moveValue);
moveValue = moveValue * moveValue;
} else {
moveValue = -(moveValue * moveValue);
}
if (rotateValue >= 0.0) {
rotateValue = (rotateValue * rotateValue);
rotateValue = rotateValue * rotateValue;
} else {
rotateValue = -(rotateValue * rotateValue);
}

View File

@@ -83,6 +83,7 @@ public class SampleRobot extends RobotBase {
* Test code should go here. Users should add test code to this method that should run while the
* robot is in test mode.
*/
@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
public void test() {
System.out.println("Default test() method running, consider providing your own");
}

View File

@@ -89,10 +89,10 @@ public abstract class SensorBase {
protected static void checkSolenoidModule(final int moduleNumber) {
if (!SolenoidJNI.checkSolenoidModule(moduleNumber)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested solenoid module is out of range. Minimumm: 0, Maximum: ");
buf.append(kPCMModules);
buf.append(", Requested: ");
buf.append(moduleNumber);
buf.append("Requested solenoid module is out of range. Minimumm: 0, Maximum: ")
.append(kPCMModules)
.append(", Requested: ")
.append(moduleNumber);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -106,10 +106,10 @@ public abstract class SensorBase {
protected static void checkDigitalChannel(final int channel) {
if (!DIOJNI.checkDIOChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested DIO channel is out of range. Minimumm: 0, Maximum: ");
buf.append(kDigitalChannels);
buf.append(", Requested: ");
buf.append(channel);
buf.append("Requested DIO channel is out of range. Minimumm: 0, Maximum: ")
.append(kDigitalChannels)
.append(", Requested: ")
.append(channel);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -123,10 +123,10 @@ public abstract class SensorBase {
protected static void checkRelayChannel(final int channel) {
if (!RelayJNI.checkRelayChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested relay channel is out of range. Minimumm: 0, Maximum: ");
buf.append(kRelayChannels);
buf.append(", Requested: ");
buf.append(channel);
buf.append("Requested relay channel is out of range. Minimumm: 0, Maximum: ")
.append(kRelayChannels)
.append(", Requested: ")
.append(channel);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -140,10 +140,10 @@ public abstract class SensorBase {
protected static void checkPWMChannel(final int channel) {
if (!PWMJNI.checkPWMChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested PWM channel is out of range. Minimumm: 0, Maximum: ");
buf.append(kPwmChannels);
buf.append(", Requested: ");
buf.append(channel);
buf.append("Requested PWM channel is out of range. Minimumm: 0, Maximum: ")
.append(kPwmChannels)
.append(", Requested: ")
.append(channel);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -157,10 +157,10 @@ public abstract class SensorBase {
protected static void checkAnalogInputChannel(final int channel) {
if (!AnalogJNI.checkAnalogInputChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested analog input channel is out of range. Minimumm: 0, Maximum: ");
buf.append(kAnalogInputChannels);
buf.append(", Requested: ");
buf.append(channel);
buf.append("Requested analog input channel is out of range. Minimumm: 0, Maximum: ")
.append(kAnalogInputChannels)
.append(", Requested: ")
.append(channel);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -174,10 +174,10 @@ public abstract class SensorBase {
protected static void checkAnalogOutputChannel(final int channel) {
if (!AnalogJNI.checkAnalogOutputChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested analog output channel is out of range. Minimumm: 0, Maximum: ");
buf.append(kAnalogOutputChannels);
buf.append(", Requested: ");
buf.append(channel);
buf.append("Requested analog output channel is out of range. Minimumm: 0, Maximum: ")
.append(kAnalogOutputChannels)
.append(", Requested: ")
.append(channel);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -190,10 +190,10 @@ public abstract class SensorBase {
protected static void checkSolenoidChannel(final int channel) {
if (!SolenoidJNI.checkSolenoidChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested solenoid channel is out of range. Minimumm: 0, Maximum: ");
buf.append(kSolenoidChannels);
buf.append(", Requested: ");
buf.append(channel);
buf.append("Requested solenoid channel is out of range. Minimumm: 0, Maximum: ")
.append(kSolenoidChannels)
.append(", Requested: ")
.append(channel);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -207,10 +207,10 @@ public abstract class SensorBase {
protected static void checkPDPChannel(final int channel) {
if (!PDPJNI.checkPDPChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested PDP channel is out of range. Minimumm: 0, Maximum: ");
buf.append(kPDPChannels);
buf.append(", Requested: ");
buf.append(channel);
buf.append("Requested PDP channel is out of range. Minimumm: 0, Maximum: ")
.append(kPDPChannels)
.append(", Requested: ")
.append(channel);
throw new IndexOutOfBoundsException(buf.toString());
}
}
@@ -223,10 +223,10 @@ public abstract class SensorBase {
protected static void checkPDPModule(final int module) {
if (!PDPJNI.checkPDPModule(module)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested PDP module is out of range. Minimumm: 0, Maximum: ");
buf.append(kPDPModules);
buf.append(", Requested: ");
buf.append(module);
buf.append("Requested PDP module is out of range. Minimumm: 0, Maximum: ")
.append(kPDPModules)
.append(", Requested: ")
.append(module);
throw new IndexOutOfBoundsException(buf.toString());
}
}

View File

@@ -39,10 +39,9 @@ public abstract class Trigger implements Sendable {
*
* @return whether get() return true or the internal table for SmartDashboard use is pressed.
*/
@SuppressWarnings("PMD.UselessParentheses")
private boolean grab() {
// FIXME make is connected work?
return get()
|| (m_table != null /* && m_table.isConnected() */ && m_table.getBoolean("pressed", false));
return get() || (m_table != null && m_table.getBoolean("pressed", false));
}

View File

@@ -46,6 +46,7 @@ class LinkedListElement {
}
}
@SuppressWarnings("PMD.EmptyIfStmt")
public LinkedListElement remove() {
if (m_previous == null && m_next == null) {
// no-op