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

Upgrade maven-pmd-plugin to 3.22.0 which uses PMD 7 by default #7577

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c6fdd5a
Upgrade maven-pmd-plugin to 3.22.0 which uses PMD 7 by default
mprins Apr 25, 2024
052610c
The EmptyControlStatement rule replaces the rules EmptyFinallyBlock, …
mprins Apr 25, 2024
24faeab
The EmptyStatementNotInLoop rule is replaced by UnnecessarySemicolon
mprins Apr 25, 2024
4eeac44
UnnecessarySemicolon is now a codestyle rule
mprins Apr 25, 2024
6987ed8
Use stCarolas/setup-maven@v5
mprins Apr 25, 2024
ddac9a9
Use a comma instead of a pipe symbol to separate class names
mprins Apr 25, 2024
7636d7f
first bunch of PMD fixes
mprins Apr 25, 2024
9eb01c1
fix Unnecessary cast (int) and other fixes
mprins Apr 25, 2024
0c258f7
Fix ruleset and try to report pmd violations as pr comment
mprins Apr 25, 2024
cf6d453
remove superfluous semicolons, use isEmpty() instead of size==0 on co…
mprins Apr 26, 2024
94bd73b
suppress ReplaceVectorWithList on Stack usage
mprins Apr 26, 2024
1600de7
Fix another bunch of UseDiamondOperator violations
mprins Apr 26, 2024
16c5a31
suppress ReplaceVectorWithList on Stack usage
mprins Apr 26, 2024
5676ed9
fix UnusedLocalVariable violations
mprins Apr 26, 2024
3971119
ignore some UnusedPrivateField violations
mprins Apr 26, 2024
a8ebe45
fix UnnecessaryCast violations
mprins Apr 26, 2024
e824b44
fix UnnecessaryReturn violations
mprins Apr 26, 2024
cbcfa39
fix StringInstantiation violations
mprins Apr 26, 2024
d1d88c2
fix SimplifiableTestAssertion violations
mprins Apr 26, 2024
8a4e640
fix EmptyControlStatement violations
mprins Apr 26, 2024
5e2ddca
fix/ignore UseDiamondOperator violations + reformatting
mprins Apr 26, 2024
bc04a4d
ignore UnnecessaryCast
mprins Apr 26, 2024
ddd6241
Parameter 'outputEncoding' (user property 'outputEncoding') is read-o…
mprins Apr 26, 2024
8e88c95
fix many more UseDiamondOperator violations, redundant casts and othe…
mprins Apr 26, 2024
80a6a84
Updating web/core to PMD7
aaime Apr 29, 2024
772faa9
Switch gs-wms to PMD 7
aaime Apr 29, 2024
ae39226
Upgrading a bunch of web modules to PMD 7
aaime May 4, 2024
15c764f
Fixing the other web modules for PMD 7 as well
aaime May 4, 2024
4a8dacc
PMD 7 updates for WPS
aaime May 4, 2024
2ff2ee2
Updating restconfig to PMD7
aaime May 26, 2024
66475fa
Fixing app-schema tests for PMD 7
aaime May 26, 2024
77d8065
Fixing excel output format for PMD 7
aaime May 26, 2024
bdbeae0
Fixing DXF for PMD7
aaime May 26, 2024
8e52f6b
Fixing security modules for PMD7
aaime May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 10 additions & 5 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ env:

jobs:
QA:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'temurin'
- name: Set up Maven
uses: stCarolas/setup-maven@v4.5
uses: stCarolas/setup-maven@v5
with:
maven-version: 3.9.5
- name: Maven repository caching
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: gs-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
Expand All @@ -33,6 +33,11 @@ jobs:
run: |
mvn -B -ntp -nsu -U -T4 -fae -Dspotless.action=check -Dpom.fmt.action=verify -DskipTests -Prelease,communityRelease -f src/community/pom.xml clean install
- name: Remove SNAPSHOT jars from repository
if: always()
run: |
find ~/.m2/repository -name "*SNAPSHOT*" -type d | xargs rm -rf {}


- uses: lcollins/pmd-github-action@v2
if: always()
with:
path: '**/pmd.xml'
2 changes: 1 addition & 1 deletion build/qa/pmd-junit-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ GeoTools Junit ruleset. See https://pmd.github.io/latest/pmd_userdocs_understand
<rule name="DisallowJunit3"
language="java"
message="Avoid using JUnit3"
class="net.sourceforge.pmd.lang.rule.XPathRule" >
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule" >
<description>
Don't use JUnit3, use JUnit4 instead
</description>
Expand Down
20 changes: 6 additions & 14 deletions build/qa/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
<!-- The rule reports false positives for closeable arguments that are used -->
<!-- closed within the method body. This suppression tries to avoid false positives for -->
<!-- this case, until we can switch to Java 9 and just use try(variable) {...} without -->
<!-- the need to instatiate the variable in the try -->
<!-- the need to instantiate the variable in the try -->
<property name="violationSuppressXPath">
<value>
<![CDATA[
Expand All @@ -46,7 +46,7 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
]
[ pmd-java:typeIs('java.lang.AutoCloseable') and
fn:substring-before(@Image, '.') = ancestor::MethodDeclaration/MethodDeclarator//VariableDeclaratorId/@Name
]"/>
]
]]>
</value>
</property>
Expand All @@ -71,22 +71,15 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
<rule ref="category/java/codestyle.xml/IdenticalCatchBranches" />
<rule ref="category/java/codestyle.xml/UseShortArrayInitializer" />
<rule ref="category/java/codestyle.xml/UnnecessaryImport" />
<rule ref="category/java/codestyle.xml/EmptyControlStatement"/>
<rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/>
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/>
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/>
<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/>
<rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
<rule ref="category/java/errorprone.xml/CheckSkipResult"/>
<rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray"/>
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
<rule ref="category/java/errorprone.xml/EmptyFinallyBlock"/>
<rule ref="category/java/errorprone.xml/EmptyIfStmt"/>
<rule ref="category/java/errorprone.xml/EmptyInitializer"/>
<rule ref="category/java/errorprone.xml/EmptyStatementBlock"/>
<rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop"/>
<rule ref="category/java/errorprone.xml/EmptySwitchStatements"/>
<rule ref="category/java/errorprone.xml/EmptySynchronizedBlock"/>
<rule ref="category/java/errorprone.xml/EmptyTryBlock"/>
<rule ref="category/java/errorprone.xml/EmptyWhileStmt"/>
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
<rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode"/>
Expand All @@ -100,7 +93,7 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
<!-- When calling the store to close, PMD wants the full prefix before the call to -->
<!-- the method to match, so let's try to use common var names for store ... -->
<property name="closeTargets" value="releaseConnection,store.releaseConnection,closeQuietly,closeConnection,closeSafe,store.closeSafe,dataStore.closeSafe,getDataStore().closeSafe,close,closeResultSet,closeStmt,closeFinally,JDBCUtils.close"/>
<property name="allowedResourceTypes" value="java.io.ByteArrayOutputStream|java.io.ByteArrayInputStream|java.io.StringWriter|java.io.CharArrayWriter|java.util.stream.Stream|java.util.stream.IntStream|java.util.stream.LongStream|java.util.stream.DoubleStream|java.io.StringReader" />
<property name="allowedResourceTypes" value="java.io.ByteArrayOutputStream,java.io.ByteArrayInputStream,java.io.StringWriter,java.io.CharArrayWriter,java.util.stream.Stream,java.util.stream.IntStream,java.util.stream.LongStream,java.util.stream.DoubleStream,java.io.StringReader" />
</properties>
</rule>
<rule ref="category/java/multithreading.xml/AvoidThreadGroup"/>
Expand All @@ -109,13 +102,12 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
<rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation"/>
<rule ref="category/java/performance.xml/StringInstantiation"/>
<rule name="wildcards" language="java" message="No Wildcard Imports" class="net.sourceforge.pmd.lang.rule.XPathRule">
<rule name="wildcards" language="java" message="No Wildcard Imports" class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Don't use wildcard imports
</description>
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//ImportDeclaration[@ImportedName=@PackageName]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
@TestSetup(run = TestSetupFrequency.REPEAT)
public class DataDirectoryGeoServerLoaderTest extends GeoServerSystemTestSupport {

static interface TestService1 extends ServiceInfo {};
static interface TestService1 extends ServiceInfo {}

static interface TestService2 extends ServiceInfo {};
static interface TestService2 extends ServiceInfo {}

@SuppressWarnings("serial")
static class TestService1Impl extends ServiceInfoImpl implements TestService1 {};
static class TestService1Impl extends ServiceInfoImpl implements TestService1 {}

@SuppressWarnings("serial")
static class TestService2Impl extends ServiceInfoImpl implements TestService2 {};
static class TestService2Impl extends ServiceInfoImpl implements TestService2 {}

private WorkspaceInfo testWs1, testWs2;

Expand Down Expand Up @@ -254,7 +254,7 @@ public Class<TestService1> getServiceClass() {
protected TestService1 createServiceFromScratch(GeoServer gs) {
return new TestService1Impl();
}
};
}

static final class TestServiceLoader2 extends XStreamServiceLoader<TestService2> {

Expand All @@ -271,5 +271,5 @@ public Class<TestService2> getServiceClass() {
protected TestService2 createServiceFromScratch(GeoServer gs) {
return new TestService2Impl();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,8 @@ public void tearDown() {
/** Writes catalog.xml to the data directory. */
private void setUpCatalog() {
CatalogWriter writer = new CatalogWriter();
writer.dataStores(
datastoreParams, datastoreNamespacePrefixes, Collections.<String>emptySet());
writer.coverageStores(
new HashMap<String, Map<String, String>>(),
new HashMap<String, String>(),
Collections.<String>emptySet());
writer.dataStores(datastoreParams, datastoreNamespacePrefixes, Collections.emptySet());
writer.coverageStores(new HashMap<>(), new HashMap<>(), Collections.emptySet());
writer.namespaces(namespaces, isolatedNamespaces);
writer.styles(layerStyles);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ private void initMappingFS(FeatureSource fs) {
}
}

@SuppressWarnings("PMD.CloseResource")
private void testNestedIterators(FeatureIterator iterator) throws IOException {
assertTrue(iterator instanceof DataAccessMappingFeatureIterator);
DataAccessMappingFeatureIterator mappingIt = (DataAccessMappingFeatureIterator) iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Gsml32BoreholeIntervalMockData extends AbstractAppSchemaMockData {

protected static final Map<String, String> GSML32_NAMESPACES =
Collections.unmodifiableMap(
new TreeMap<String, String>() {
new TreeMap<>() {
/** serialVersionUID */
private static final long serialVersionUID = -4796243306761831446L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Gsml32BoreholeMockData extends AbstractAppSchemaMockData {

protected static final Map<String, String> GSML32_NAMESPACES =
Collections.unmodifiableMap(
new TreeMap<String, String>() {
new TreeMap<>() {
/** serialVersionUID */
private static final long serialVersionUID = -4796243306761831446L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ String toString(Geometry g) throws IOException {
}

/** Convert geom to a hex string for saving to the DB. */
@SuppressWarnings("PMD.StringInstantiation")
public static String toHexString(byte[] bytes) {
final char[] hexArray = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ protected void setUpCatalog() throws IOException {
writer.dataStores(
Map.of(DATASTORE_NAME, SampleDataAccessFactory.PARAMS),
Map.of(DATASTORE_NAME, SampleDataAccessData.NAMESPACE_PREFIX),
Collections.<String>emptySet());
writer.coverageStores(
new HashMap<String, Map<String, String>>(),
new HashMap<String, String>(),
Collections.<String>emptySet());
Collections.emptySet());
writer.coverageStores(new HashMap<>(), new HashMap<>(), Collections.emptySet());
writer.namespaces(
Map.of(SampleDataAccessData.NAMESPACE_PREFIX, SampleDataAccessData.NAMESPACE_URI));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean requestIncoming(Request request, long timeout) {
synchronized (this) {
for (String key : queues.keySet()) {
TimedBlockingQueue tbq = queues.get(key);
if (now - tbq.lastModified > maxAge && tbq.size() == 0) {
if (now - tbq.lastModified > maxAge && tbq.isEmpty()) {
queues.remove(key);
cleanupCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum ThreadState {
TIMED_OUT,
PROCESSING,
COMPLETE
};
}

FlowController[] controllers;
boolean proceed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected AbstractFeatureCollection(T memberType) {
@Override
@SuppressWarnings("unchecked")
public FeatureIterator<F> features() {
FeatureIterator iter = new DelegateFeatureIterator(openIterator());
FeatureIterator iter = new DelegateFeatureIterator<>(openIterator());
getOpenIterators().add(iter);
return iter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void createAttribute(

if (index == path.length - 1) {
if (descriptor.getType() instanceof ComplexType) {
fillTreeNodes(value, descriptor, (List<TreeNode>) treenodes);
fillTreeNodes(value, descriptor, treenodes);
// wrap simple content in complex attribute
AttributeType simpleType =
new AttributeTypeImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ private String[] getLayers(GetFeatureRequest gft) {
if (gft.getFormatOptions().get("LAYERS") instanceof String) {
layers = ((String) gft.getFormatOptions().get("LAYERS")).split(",");
} else if (gft.getFormatOptions().get("LAYERS") instanceof List) {
layers =
(String[]) ((List) gft.getFormatOptions().get("LAYERS")).toArray(new String[0]);
layers = ((List<String>) gft.getFormatOptions().get("LAYERS")).toArray(new String[0]);
}
return layers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void testExcelOutputFormat(Workbook wb) throws IOException {
assertEquals(feautureRows + 1, sheet.getPhysicalNumberOfRows());

// check the header is what we expect
final SimpleFeatureType schema = (SimpleFeatureType) fs.getSchema();
final SimpleFeatureType schema = fs.getSchema();
final Row header = sheet.getRow(0);
assertEquals("FID", header.getCell(0).getRichStringCellValue().toString());
for (int i = 0; i < schema.getAttributeCount(); i++) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public void testExcel2007MultipleFeatureTypes() throws Exception {
getAsServletResponse(
"wfs?request=GetFeature&typeName=sf:PrimitiveGeoFeature,sf:GenericEntity&outputFormat=excel2007");
try (InputStream in = getBinaryInputStream(resp);
Workbook wb = new XSSFWorkbook(in); ) {
Workbook wb = new XSSFWorkbook(in)) {
testMultipleFeatureTypes(wb);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ protected List<Property<FilteredProcess>> getProperties() {
props.add(new BeanProperty<>("name", "name"));
props.add(new BeanProperty<>("description", "description"));
props.add(
new AbstractProperty<FilteredProcess>("roles") {
new AbstractProperty<>("roles") {
@Override
public Object getPropertyValue(FilteredProcess item) {
return item.getRoles();
}

@Override
public IModel getModel(IModel itemModel) {
return new PropertyModel(itemModel, "roles");
return new PropertyModel<>(itemModel, "roles");
}
});
props.add(new PropertyPlaceholder<>("edit"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum ParameterType {
RASTER_LAYER,
REFERENCE,
SUBPROCESS;
};
}

Name processName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected List<Property<ProcessGroupInfo>> getProperties() {
List<Property<ProcessGroupInfo>> props = new ArrayList<>();
props.add(new BeanProperty<>("enabled", "enabled"));
props.add(
new AbstractProperty<ProcessGroupInfo>("prefix") {
new AbstractProperty<>("prefix") {

@Override
public Object getPropertyValue(ProcessGroupInfo item) {
Expand Down Expand Up @@ -74,7 +74,7 @@ public Object getPropertyValue(ProcessGroupInfo item) {
}
});
props.add(
new AbstractProperty<ProcessGroupInfo>("title") {
new AbstractProperty<>("title") {

@Override
public Object getPropertyValue(ProcessGroupInfo item) {
Expand All @@ -95,7 +95,7 @@ public Object getPropertyValue(ProcessGroupInfo item) {
}
});
props.add(
new AbstractProperty<ProcessGroupInfo>("summary") {
new AbstractProperty<>("summary") {

@Override
public Object getPropertyValue(final ProcessGroupInfo item) {
Expand Down Expand Up @@ -141,15 +141,15 @@ protected String load() {
}
});
props.add(
new AbstractProperty<ProcessGroupInfo>("roles") {
new AbstractProperty<>("roles") {
@Override
public Object getPropertyValue(ProcessGroupInfo item) {
return item.getRoles();
}

@Override
public IModel getModel(IModel itemModel) {
return new PropertyModel(itemModel, "roles");
return new PropertyModel<>(itemModel, "roles");
}
});
props.add(new PropertyPlaceholder<>("edit"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public ProcessLimitsPage(Page returnPage, final FilteredProcess process) {
setReturnPage(returnPage);
this.process = process;

Form form = new Form("form");
Form form = new Form<>("form");
add(form);

final List<InputLimit> inputLimits = buildInputLimits(process);
GeoServerDataProvider<InputLimit> inputLimitsProvider =
new GeoServerDataProvider<ProcessLimitsPage.InputLimit>() {
new GeoServerDataProvider<>() {

@Override
protected List<
Expand All @@ -94,7 +94,7 @@ protected List<InputLimit> getItems() {
};

table =
new GeoServerTablePanel<InputLimit>("table", inputLimitsProvider) {
new GeoServerTablePanel<>("table", inputLimitsProvider) {

@Override
protected Component getComponentForProperty(
Expand Down