Skip to content

Commit

Permalink
NIFI-14073 Added PMD Plugin to contrib-check Profile
Browse files Browse the repository at this point in the history
- Added standard PMD rules scoped to current project conventions
- Updated multiple classes to meet UseDiamondOperator rule requirements
- Applied selected SuppressWarnings to selected classes
- Streamlined ci-workflow build to avoid unnecessary exclusions
  • Loading branch information
exceptionfactory committed Dec 13, 2024
1 parent a5086a9 commit bf131c9
Show file tree
Hide file tree
Showing 148 changed files with 478 additions and 463 deletions.
32 changes: 2 additions & 30 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ env:
DEFAULT_MAVEN_OPTS: >-
-Xmx4g
-XX:ReservedCodeCacheSize=1g
-XX:+UseG1GC
-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN
-Daether.connector.http.retryHandler.count=5
-Daether.connector.http.connectionMaxTtl=30
Expand All @@ -37,25 +36,6 @@ env:
--no-snapshot-updates
--no-transfer-progress
--fail-fast
-pl -:minifi-integration-tests
-pl -:minifi-assembly
-pl -:nifi-assembly
-pl -:nifi-toolkit-assembly
-pl -:nifi-registry-assembly
-pl -:nifi-registry-toolkit-assembly
-pl -:nifi-runtime-manifest
-pl -:nifi-runtime-manifest-test
-pl -:nifi-stateless-assembly
-pl -:nifi-stateless-system-test-suite
-pl -:nifi-system-test-suite
-pl -:nifi-nar-provider-assembly
-pl -:nifi-py4j-integration-tests
-pl -:nifi-server-nar
-pl -:nifi-ui
-pl -:nifi-jolt-nar
-pl -:nifi-jolt-transform-json-ui
-pl -:nifi-standard-content-viewer-nar
-pl -:nifi-standard-content-viewer
MAVEN_VERIFY_COMMAND: >-
verify
--show-version
Expand All @@ -65,13 +45,6 @@ env:
-D dir-only
MAVEN_BUILD_PROFILES: >-
-P skip-nifi-bin-assembly
MAVEN_PROJECTS: >-
-pl -minifi/minifi-assembly
-pl -minifi/minifi-toolkit/minifi-toolkit-assembly
-pl -nifi-registry/nifi-registry-assembly
-pl -nifi-registry/nifi-registry-toolkit/nifi-registry-toolkit-assembly
-pl -nifi-stateless/nifi-stateless-assembly
-pl -nifi-toolkit/nifi-toolkit-assembly
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -124,8 +97,10 @@ jobs:
env:
MAVEN_OPTS: >-
${{ env.COMPILE_MAVEN_OPTS }}
# Run PMD Check with compile phase to resolve modules
run: >
${{ env.MAVEN_COMMAND }}
pmd:check
${{ env.MAVEN_COMPILE_COMMAND }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down Expand Up @@ -191,7 +166,6 @@ jobs:
${{ env.MAVEN_VERIFY_COMMAND }}
${{ env.MAVEN_BUILD_PROFILES }}
-P python-unit-tests
${{ env.MAVEN_PROJECTS }}
- name: Upload Test Reports
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -268,7 +242,6 @@ jobs:
${{ env.MAVEN_VERIFY_COMMAND }}
${{ env.MAVEN_BUILD_PROFILES }}
-P python-unit-tests
${{ env.MAVEN_PROJECTS }}
- name: Upload Test Reports
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -342,7 +315,6 @@ jobs:
${{ env.MAVEN_COMMAND_WINDOWS }}
${{ env.MAVEN_VERIFY_COMMAND }}
${{ env.MAVEN_BUILD_PROFILES }}
${{ env.MAVEN_PROJECTS }}
- name: Upload Test Reports
uses: actions/upload-artifact@v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PropertyDescriptor implements Serializable {
private boolean required;
private boolean sensitive;
private ExpressionLanguageScope expressionLanguageScope = ExpressionLanguageScope.NONE;
@SuppressWarnings("PMD.UnusedPrivateField")
private String expressionLanguageScopeDescription = ExpressionLanguageScope.NONE.getDescription();
private DefinedType typeProvidedByValue;
private String validRegex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum SensitiveProperty {
NIFI_MINIFI_SECURITY_TRUSTSTORE_PASSWORD("nifi.minifi.security.truststorePasswd"),
NIFI_MINIFI_SENSITIVE_PROPS_KEY("nifi.minifi.sensitive.props.key");

public static final Set<String> SENSITIVE_PROPERTIES = Arrays.stream(SensitiveProperty.values()).map(SensitiveProperty::getKey)
public static final Set<String> SENSITIVE_PROPERTIES = Arrays.stream(values()).map(SensitiveProperty::getKey)
.collect(collectingAndThen(toSet(), Collections::unmodifiableSet));

private final String key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public enum MiNiFiProperties {
}

public static LinkedHashMap<String, MiNiFiProperties> sortedPropertiesByKey() {
return Arrays.stream(MiNiFiProperties.values())
return Arrays.stream(values())
.sorted()
.collect(Collectors.toMap(MiNiFiProperties::getKey, Function.identity(), (x, y) -> y, LinkedHashMap::new));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.nio.file.StandardOpenOption.WRITE;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -115,7 +114,7 @@ public synchronized Optional<ResourceItem> addResourceItem(ResourceItem resource
newItems.add(resourceItem);
ResourceRepositoryDescriptor newRepositoryDescriptor = new ResourceRepositoryDescriptor(resourceRepositoryDescriptor.resourcesGlobalHash(), newItems);
persist(newRepositoryDescriptor);
return of(resourceItem);
return Optional.of(resourceItem);
} catch (IOException e) {
LOG.error("Unable to persist repository metadata", e);
return empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public Map<String, Object> toMap() {
public List<String> getValidationIssues() {
List<String> validationIssues = super.getValidationIssues();
if (StringUtil.isNullOrEmpty(id)) {
validationIssues.add(getIssueText(CommonPropertyKeys.ID_KEY, getWrapperName(), IT_WAS_NOT_FOUND_AND_IT_IS_REQUIRED));
validationIssues.add(getIssueText(ID_KEY, getWrapperName(), IT_WAS_NOT_FOUND_AND_IT_IS_REQUIRED));
} else if (!isValidId(id)) {
validationIssues.add(getIssueText(CommonPropertyKeys.ID_KEY, getWrapperName(), "Id value of " + id + " is not a valid UUID"));
validationIssues.add(getIssueText(ID_KEY, getWrapperName(), "Id value of " + id + " is not a valid UUID"));
}
return validationIssues;
}
Expand Down
2 changes: 1 addition & 1 deletion nifi-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ language governing permissions and limitations under the License. -->
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-resources</phase>
<phase>prepare-package</phase>
<configuration>
<includeTypes>nar</includeTypes>
<includes>**/docs/**</includes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static boolean isValidExpression(final String value) {
}

public static ResultType getResultType(final String value) throws AttributeExpressionLanguageParsingException {
return Query.compile(value).getResultType();
return compile(value).getResultType();
}

public static List<ResultType> extractResultTypes(final String value) throws AttributeExpressionLanguageParsingException {
Expand Down Expand Up @@ -183,15 +183,15 @@ public static void validateExpression(final String value, final boolean allowSur

final Range range = ranges.get(0);
final String expression = value.substring(range.getStart(), range.getEnd() + 1);
Query.compile(expression);
compile(expression);

if (range.getStart() > 0 || range.getEnd() < value.length() - 1) {
throw new AttributeExpressionLanguageParsingException("Found characters outside of Expression");
}
} else {
for (final Range range : extractExpressionRanges(value)) {
final String expression = value.substring(range.getStart(), range.getEnd() + 1);
Query.compile(expression);
compile(expression);
}
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ static String evaluateExpression(final Tree tree, final Evaluator<?> rootEvaluat

static String evaluateExpressions(final String rawValue, Map<String, String> expressionMap, final AttributeValueDecorator decorator, final Map<String, String> stateVariables,
final ParameterLookup parameterLookup) throws ProcessException {
return Query.prepare(rawValue).evaluateExpressions(new StandardEvaluationContext(expressionMap, stateVariables, parameterLookup), decorator);
return prepare(rawValue).evaluateExpressions(new StandardEvaluationContext(expressionMap, stateVariables, parameterLookup), decorator);
}

static String evaluateExpressions(final String rawValue, final Map<String, String> valueLookup, final ParameterLookup parameterLookup) throws ProcessException {
Expand All @@ -240,7 +240,7 @@ static String evaluateExpressions(final String rawValue, final Map<String, Strin

static String evaluateExpressions(final String rawValue, final Map<String, String> valueLookup, final AttributeValueDecorator decorator, final ParameterLookup parameterLookup)
throws ProcessException {
return Query.prepare(rawValue).evaluateExpressions(new StandardEvaluationContext(valueLookup, Collections.emptyMap(), parameterLookup), decorator);
return prepare(rawValue).evaluateExpressions(new StandardEvaluationContext(valueLookup, Collections.emptyMap(), parameterLookup), decorator);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ final class ValueLookup implements Map<String, String> {
}

if (flowFile != null) {
maps.add(ValueLookup.extractFlowFileProperties(flowFile));
maps.add(extractFlowFileProperties(flowFile));
maps.add(flowFile.getAttributes());
}
}

static final Map<String, String> extractFlowFileProperties(final FlowFile flowFile) {
static Map<String, String> extractFlowFileProperties(final FlowFile flowFile) {
final Map<String, String> flowFileProps = new HashMap<>();
flowFileProps.put("flowFileId", String.valueOf(flowFile.getId()));
flowFileProps.put("fileSize", String.valueOf(flowFile.getSize()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public JsonPathDeleteEvaluator(final Evaluator<String> subject, final Evaluator<
public QueryResult<String> evaluate(EvaluationContext context) {
DocumentContext documentContext = getDocumentContext(context);

final JsonPath compiledJsonPath = getJsonPath(context);;
final JsonPath compiledJsonPath = getJsonPath(context);

String result = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class FlowFilePackagerV1 implements FlowFilePackager {

public static final String FILENAME_ATTRIBUTES = "flowfile.attributes";
public static final String FILENAME_CONTENT = "flowfile.content";
@SuppressWarnings("PMD.AvoidUsingOctalValues")
public static final int DEFAULT_TAR_PERMISSIONS = 0644;

private final int tarPermissions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class HashiCorpVaultProperties {
private final int kvVersion;

private HashiCorpVaultProperties(final HashiCorpVaultPropertiesBuilder builder) {
this.uri = Objects.requireNonNull(builder.uri, "Vault URI is required");;
this.uri = Objects.requireNonNull(builder.uri, "Vault URI is required");
this.authPropertiesFilename = Objects.requireNonNull(builder.authPropertiesFilename, "Vault auth properties filename is required");
this.ssl = new HashiCorpVaultSslProperties(builder.keyStore, builder.keyStoreType, builder.keyStorePassword,
builder.trustStore, builder.trustStoreType, builder.trustStorePassword, builder.enabledTlsCipherSuites, builder.enabledTlsProtocols);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class MessageEvaluator implements Evaluator<HL7Message> {

public HL7Message evaluate(final Map<String, Object> objectMap) {
return (HL7Message) objectMap.get(Evaluator.MESSAGE_KEY);
return (HL7Message) objectMap.get(MESSAGE_KEY);
}

public Class<? extends HL7Message> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public List<HL7Segment> evaluate(final Map<String, Object> objectMap) {
return Collections.emptyList();
}

final HL7Message message = (HL7Message) objectMap.get(Evaluator.MESSAGE_KEY);
final HL7Message message = (HL7Message) objectMap.get(MESSAGE_KEY);
final List<HL7Segment> segments = message.getSegments(segmentType);
return (segments == null) ? Collections.<HL7Segment>emptyList() : segments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,13 @@ public Integer getRemoteInputHttpPort() {

final String propertyKey;
if (isSiteToSiteSecure()) {
if (StringUtils.isBlank(getProperty(NiFiProperties.WEB_HTTPS_PORT_FORWARDING))) {
if (StringUtils.isBlank(getProperty(WEB_HTTPS_PORT_FORWARDING))) {
propertyKey = WEB_HTTPS_PORT;
} else {
propertyKey = WEB_HTTPS_PORT_FORWARDING;
}
} else {
if (StringUtils.isBlank(getProperty(NiFiProperties.WEB_HTTP_PORT_FORWARDING))) {
if (StringUtils.isBlank(getProperty(WEB_HTTP_PORT_FORWARDING))) {
propertyKey = WEB_HTTP_PORT;
} else {
propertyKey = WEB_HTTP_PORT_FORWARDING;
Expand Down Expand Up @@ -968,7 +968,7 @@ public String getKerberosServiceKeytabLocation() {
* @return true if the login identity provider has been configured
*/
public boolean isLoginIdentityProviderEnabled() {
return !StringUtils.isBlank(getProperty(NiFiProperties.SECURITY_USER_LOGIN_IDENTITY_PROVIDER));
return !StringUtils.isBlank(getProperty(SECURITY_USER_LOGIN_IDENTITY_PROVIDER));
}

/**
Expand Down Expand Up @@ -1547,7 +1547,7 @@ public boolean isZooKeeperClientSecure() {
final String clientSecure = getProperty(ZOOKEEPER_CLIENT_SECURE, defaultValue).trim();

if (!"true".equalsIgnoreCase(clientSecure) && !"false".equalsIgnoreCase(clientSecure)) {
throw new RuntimeException(String.format("%s was '%s', expected true or false", NiFiProperties.ZOOKEEPER_CLIENT_SECURE, clientSecure));
throw new RuntimeException(String.format("%s was '%s', expected true or false", ZOOKEEPER_CLIENT_SECURE, clientSecure));
}

return Boolean.parseBoolean(clientSecure);
Expand All @@ -1558,18 +1558,18 @@ public boolean isZookeeperClientWithEnsembleTracker() {
final String withEnsembleTracker = getProperty(ZOOKEEPER_CLIENT_ENSEMBLE_TRACKER, defaultValue).trim();

if (!"true".equalsIgnoreCase(withEnsembleTracker) && !"false".equalsIgnoreCase(withEnsembleTracker)) {
throw new RuntimeException(String.format("%s was '%s', expected true or false", NiFiProperties.ZOOKEEPER_CLIENT_ENSEMBLE_TRACKER, withEnsembleTracker));
throw new RuntimeException(String.format("%s was '%s', expected true or false", ZOOKEEPER_CLIENT_ENSEMBLE_TRACKER, withEnsembleTracker));
}

return Boolean.parseBoolean(withEnsembleTracker);
}

public boolean isZooKeeperTlsConfigurationPresent() {
return StringUtils.isNotBlank(getProperty(NiFiProperties.ZOOKEEPER_CLIENT_SECURE))
&& StringUtils.isNotBlank(getProperty(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE))
&& getProperty(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_PASSWD) != null
&& StringUtils.isNotBlank(getProperty(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE))
&& getProperty(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_PASSWD) != null;
return StringUtils.isNotBlank(getProperty(ZOOKEEPER_CLIENT_SECURE))
&& StringUtils.isNotBlank(getProperty(ZOOKEEPER_SECURITY_KEYSTORE))
&& getProperty(ZOOKEEPER_SECURITY_KEYSTORE_PASSWD) != null
&& StringUtils.isNotBlank(getProperty(ZOOKEEPER_SECURITY_TRUSTSTORE))
&& getProperty(ZOOKEEPER_SECURITY_TRUSTSTORE_PASSWD) != null;
}

public boolean isTlsConfigurationPresent() {
Expand Down Expand Up @@ -1835,7 +1835,7 @@ public int size() {

private static void readFromPropertiesFile(String propertiesFilePath, Properties properties) {
final String nfPropertiesFilePath = (propertiesFilePath == null)
? System.getProperty(NiFiProperties.PROPERTIES_FILE_PATH)
? System.getProperty(PROPERTIES_FILE_PATH)
: propertiesFilePath;
if (nfPropertiesFilePath != null) {
final File propertiesFile = new File(nfPropertiesFilePath.trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public static String toTitleCase(String input) {
}
List<String> elements = Arrays.asList(input.trim().toLowerCase().split("\\s"));
return elements.stream()
.filter(word -> !StringUtils.isBlank(word))
.filter(word -> !isBlank(word))
.map(word -> Character.toTitleCase(word.charAt(0)) + word.substring(1))
.collect(Collectors.joining(" "));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static RecordPathSegment compile(final Tree pathTree, final RecordPathSeg
RecordPathSegment parent = root;
for (int i = 0; i < pathTree.getChildCount(); i++) {
final Tree child = pathTree.getChild(i);
parent = RecordPathCompiler.buildPath(child, parent, absolute);
parent = buildPath(child, parent, absolute);
}

// If the given path tree is an operator, create a Filter Function that will be responsible for returning true/false based on the provided operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public void setMapValue(final String fieldName, final String mapKey, final Objec

Object mapObject = values.get(recordField.getFieldName());
if (mapObject == null) {
mapObject = new LinkedHashMap<String, Object>();
mapObject = new LinkedHashMap<>();
}
if (!(mapObject instanceof Map)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.nifi.remote.exception.ProtocolException;
import org.apache.nifi.remote.io.CompressionInputStream;
import org.apache.nifi.remote.io.CompressionOutputStream;
import org.apache.nifi.remote.protocol.CommunicationsSession;
import org.apache.nifi.remote.protocol.DataPacket;
import org.apache.nifi.remote.protocol.Response;
import org.apache.nifi.remote.protocol.ResponseCode;
Expand Down Expand Up @@ -193,7 +192,6 @@ public final void confirm() throws IOException {
+ "; Transaction can only be confirmed when state is " + TransactionState.DATA_EXCHANGED);
}

final CommunicationsSession commsSession = peer.getCommunicationsSession();
if (direction == TransferDirection.RECEIVE) {
if (dataAvailable) {
throw new IllegalStateException("Cannot complete transaction because the sender has already sent more data than client has consumed.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private void restoreInitialPeerStatusCache() {
* @param peerCount the number of peers in the remote instance
* @return the normalized weight of this peer
*/
@SuppressWarnings("PMD.AvoidDecimalLiteralsInBigDecimalConstructor")
private static double calculateNormalizedWeight(TransferDirection direction, long totalFlowFileCount, int flowFileCount, int peerCount) {
// If there is only a single remote, send/receive all data to/from it
if (peerCount == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public void terminate(final EndpointConnection connection) {

@Override
public String toString() {
return "EndpointConnectionPool[Cluster URL=" + siteInfoProvider.getClusterUrls() + "]";
return "EndpointConnectionPool[Cluster URL=" + siteInfoProvider.getClusterUrls() + " LocalAddress=" + localAddress + "]";
}

private class IdEnrichedRemoteDestination implements RemoteDestination {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public enum ResponseCode {
private static final ResponseCode[] codeArray = new ResponseCode[256];

static {
for (final ResponseCode responseCode : ResponseCode.values()) {
for (final ResponseCode responseCode : values()) {
codeArray[responseCode.getCode()] = responseCode;
}
}
Expand Down
Loading

0 comments on commit bf131c9

Please sign in to comment.