Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable PMD static analysis during the build #325

Merged
merged 14 commits into from Feb 10, 2019
1 change: 0 additions & 1 deletion base/src/main/java/io/spine/base/Identifier.java
Expand Up @@ -27,7 +27,6 @@
import com.google.protobuf.StringValue;
import io.spine.annotation.Internal;
import io.spine.protobuf.AnyPacker;
import io.spine.protobuf.Messages;
import io.spine.protobuf.TypeConverter;
import io.spine.string.StringifierRegistry;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down
1 change: 0 additions & 1 deletion base/src/main/java/io/spine/base/UuidFactory.java
Expand Up @@ -22,7 +22,6 @@

import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Internal;
import com.google.protobuf.Message;
import io.spine.protobuf.Messages;

Expand Down
2 changes: 1 addition & 1 deletion base/src/main/java/io/spine/logging/Logging.java
Expand Up @@ -63,7 +63,7 @@
"ClassWithTooManyMethods"
/* We provide shortcut methods for calling Slf4J Logger API. */,

"NewMethodNamingConvention"
"NewMethodNamingConvention", "PMD.MethodNamingConventions"
/* These methods are prefixed with underscore to highlight the fact that these methods
are for logging, and to make them more visible in the real code. */
})
Expand Down
8 changes: 2 additions & 6 deletions base/src/main/java/io/spine/reflect/PackageGraph.java
Expand Up @@ -283,12 +283,8 @@ public boolean test(Package aPackage) {
return true;
}

if (exclusions.stream()
.anyMatch(packageName::startsWith)) {
return false;
}

return true;
return exclusions.stream()
.noneMatch(packageName::startsWith);
}
}
}
1 change: 1 addition & 0 deletions base/src/main/java/io/spine/validate/ComparableNumber.java
Expand Up @@ -36,6 +36,7 @@ final class ComparableNumber extends Number implements Comparable<Number> {

/** Creates a new instance from the specified number. */
ComparableNumber(Number value) {
super();
this.value = value;
}

Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Expand Up @@ -109,6 +109,7 @@ subprojects {
}

apply plugin: 'java-library'
apply plugin: 'pmd'
apply plugin: 'com.google.protobuf'
apply plugin: 'net.ltgt.errorprone'

Expand Down Expand Up @@ -215,6 +216,8 @@ subprojects {
}

clean.dependsOn cleanGenerated

apply from: deps.scripts.pmd
}

// IDEA project configuration.
Expand Down
Expand Up @@ -57,7 +57,7 @@ void hasUtilityConstructor() {

@Test
@DisplayName("not accept nulls in public static methods if the arg is non-Nullable")
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssertRule")
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
/* This test does assert via `NullPointerTester. */
void nullCheckPublicStaticMethods() {
NullPointerTester tester = new NullPointerTester();
Expand Down
Expand Up @@ -213,7 +213,7 @@ private enum KnownOption {
EXPERIMENTAL(new ApiOption(experimentalAll, experimentalType, null, experimental)),
INTERNAL(new ApiOption(internalAll, internalType, null, internal));

@SuppressWarnings("NonSerializableFieldInSerializableClass")
@SuppressWarnings({"NonSerializableFieldInSerializableClass", "PMD.SingularField"})
// This private enum should not be serialized.
private final ApiOption option;

Expand Down
Expand Up @@ -243,7 +243,7 @@ public Builder add(Job job) {
* @see #setInternalAnnotation
*/
public Builder setInternalPatterns(ImmutableSet<@Regex String> patterns) {
this.internalPatterns = checkNotNull(patterns);;
this.internalPatterns = checkNotNull(patterns);
return this;
}

Expand All @@ -255,7 +255,7 @@ public Builder setInternalPatterns(ImmutableSet<@Regex String> patterns) {
* @see #setInternalAnnotation
*/
public Builder setInternalMethodNames(ImmutableSet<String> methodNames) {
this.internalMethodNames = checkNotNull(methodNames);;
this.internalMethodNames = checkNotNull(methodNames);
return this;
}

Expand Down
Expand Up @@ -48,7 +48,7 @@
@SuppressWarnings({
"PublicField", "WeakerAccess" /* Expose fields as a Gradle extension */,
"ClassWithTooManyMethods" /* The methods are needed for handing default values. */,
"ClassWithTooManyFields" /* OK for a Gradle extension to have a flat structure. */})
"ClassWithTooManyFields", "PMD.TooManyFields" /* Gradle extensions are flat like this. */})
public class Extension extends GradleExtension {

/**
Expand Down
Expand Up @@ -263,6 +263,7 @@ public static final class PostfixPattern extends FilePattern {
private final String postfix;

private PostfixPattern(String postfix) {
super();
this.postfix = postfix;
}

Expand Down
Expand Up @@ -35,6 +35,7 @@ final class PostfixInterfaceConfig extends PatternInterfaceConfig {
private final String postfix;

PostfixInterfaceConfig(@Regex String postfix) {
super();
this.postfix = postfix;
}

Expand Down
Expand Up @@ -257,6 +257,7 @@ private enum ProtocPlugin {
GRPC("grpc"),
SPINE("spineProtoc");

@SuppressWarnings("PMD.SingularField") /* Accessed from the outer class. */
private final String name;

ProtocPlugin(String name) {
Expand Down
Expand Up @@ -43,6 +43,7 @@
* <p>Instantiated via {@link Builder}, forces the new task to be added to
* the Gradle build lifecycle.
*/
@SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass") /* Instantiated via Builder. */
public final class GradleTask {

private final Task task;
Expand Down
Expand Up @@ -37,7 +37,7 @@ public final class MergedDescriptorSet {
private final FileSet fileSet;

MergedDescriptorSet(FileDescriptorSet descriptorSet) {
this.descriptors = ImmutableSet.copyOf(descriptorSet.getFileList());;
this.descriptors = ImmutableSet.copyOf(descriptorSet.getFileList());
this.fileSet = FileSet.ofFiles(descriptors);
}

Expand Down
Expand Up @@ -20,7 +20,6 @@

package io.spine.js.generate.field.parser;

import com.google.protobuf.Descriptors;
import com.google.protobuf.Descriptors.FieldDescriptor;
import io.spine.code.proto.FieldDeclaration;
import io.spine.js.generate.output.CodeLines;
Expand Down Expand Up @@ -64,7 +63,6 @@ static FieldParser parserFor(FieldDescriptor field, CodeLines jsOutput) {
checkNotNull(jsOutput);
FieldDeclaration fdecl = new FieldDeclaration(field);
if (fdecl.isMessage()) {
Descriptors.Descriptor message = field.getMessageType();
return MessageFieldParser.createFor(field, jsOutput);
}
if (fdecl.isEnum()) {
Expand Down