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
- Refactored assembly module phases to align with standard lifecycle behavior
  • Loading branch information
exceptionfactory committed Dec 14, 2024
1 parent e4cb5a3 commit d0b5bf7
Show file tree
Hide file tree
Showing 155 changed files with 518 additions and 532 deletions.
39 changes: 3 additions & 36 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,41 +36,13 @@ 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
--no-snapshot-updates
--no-transfer-progress
--fail-fast
-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 +95,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 @@ -188,10 +161,8 @@ jobs:
-Dfrontend.skipTests=${{ steps.changes.outputs.frontend == 'true' && 'false' || 'true' }}
run: >
${{ env.MAVEN_COMMAND }}
${{ env.MAVEN_VERIFY_COMMAND }}
${{ env.MAVEN_BUILD_PROFILES }}
${{ env.MAVEN_VERIFY_COMMAND }}
-P python-unit-tests
${{ env.MAVEN_PROJECTS }}
- name: Upload Test Reports
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -266,9 +237,7 @@ jobs:
run: >-
${{ env.MAVEN_COMMAND }}
${{ 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 @@ -341,8 +310,6 @@ jobs:
run: >-
${{ 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
2 changes: 2 additions & 0 deletions .github/workflows/docker-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ env:
install
MAVEN_BUILD_PROJECTS: >-
-pl nifi-assembly
-pl nifi-registry/nifi-registry-extensions/nifi-registry-aws/nifi-registry-aws-assembly
-pl nifi-registry/nifi-registry-assembly
-pl nifi-toolkit/nifi-toolkit-assembly
-pl minifi/minifi-assembly
Expand All @@ -70,6 +71,7 @@ env:
clean
MAVEN_CLEAN_PROJECTS: >-
-pl -nifi-assembly
-pl -nifi-registry/nifi-registry-extensions/nifi-registry-aws/nifi-registry-aws-assembly
-pl -nifi-registry/nifi-registry-assembly
-pl -nifi-toolkit/nifi-toolkit-assembly
-pl -nifi-toolkit/nifi-toolkit-cli
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
4 changes: 2 additions & 2 deletions minifi/minifi-docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<executions>
<execution>
<id>copy-markdown</id>
<phase>generate-resources</phase>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
Expand All @@ -57,7 +57,7 @@
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<phase>process-resources</phase>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dependencies.xml</descriptor>
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 @@ -38,7 +38,7 @@ limitations under the License.
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<phase>process-resources</phase>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dependencies.xml</descriptor>
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
23 changes: 1 addition & 22 deletions 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 Expand Up @@ -1133,27 +1133,6 @@ language governing permissions and limitations under the License. -->
</plugins>
</build>
</profile>
<profile>
<id>skip-nifi-bin-assembly</id>
<activation>
<property>
<name>skip-nifi-bin-assembly</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make shared resource</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>include-all</id>
<properties>
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
Loading

0 comments on commit d0b5bf7

Please sign in to comment.