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

[GEOT-7598] Update PMD to version 7.2 #4813

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


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

jobs:
build:
runs-on: [ubuntu-20.04]
runs-on: [ubuntu-22.04]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11
Expand All @@ -35,3 +35,7 @@ jobs:
- name: Remove SNAPSHOT jars from repository
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
7 changes: 3 additions & 4 deletions build/qa/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />

<rule ref="category/java/codestyle.xml/EmptyControlStatement"/>
<rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/>
<rule ref="category/java/codestyle.xml/ExtendsObject"/>
<rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop"/>
<rule ref="category/java/codestyle.xml/UnnecessaryFullyQualifiedName"/>
Expand Down Expand Up @@ -78,8 +79,7 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
<properties>
<!-- 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"/>
<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>
<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 @@ -89,13 +89,12 @@ GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_ru
<rule ref="category/java/performance.xml/UseArrayListInsteadOfVector" />
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
<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
2 changes: 1 addition & 1 deletion docs/src/main/java/org/geotools/api/FeatureExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Flag {
public String name;
public int classification;
public double height;
};
}

GeometryFactory geomFactory = JTSFactoryFinder.getGeometryFactory();

Expand Down
17 changes: 9 additions & 8 deletions docs/src/main/java/org/geotools/swing/JExampleWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public void preDisplayPanel() {
field.setText(x.toString());
}
field.addKeyListener(getJWizard().getController());
};
}

@Override
public void preClosePanel() {
field.removeKeyListener(getJWizard().getController());
};
}

public boolean isValid() {
try {
Expand All @@ -99,8 +99,9 @@ public boolean isValid() {
} catch (NumberFormatException invalid) {
return false;
}
};
};
}
}

// page1 end
// page2 start
class Page2 extends JPage {
Expand All @@ -126,12 +127,12 @@ public void preDisplayPanel() {
field.setText(y.toString());
}
field.addKeyListener(getJWizard().getController());
};
}

@Override
public void preClosePanel() {
field.removeKeyListener(getJWizard().getController());
};
}

@Override
public boolean isValid() {
Expand All @@ -142,8 +143,8 @@ public boolean isValid() {
} catch (NumberFormatException invalid) {
return false;
}
};
};
}
}
// page2 end

public static void main(String[] args) {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/java/org/geotools/tutorial/csv/CSVTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void example6() throws Exception {
SimpleFeatureCollection featureCollection = featureSource.getFeatures();

List<String> list = new ArrayList<>();
try (SimpleFeatureIterator features = featureCollection.features(); ) {
try (SimpleFeatureIterator features = featureCollection.features()) {
while (features.hasNext()) {
list.add(features.next().getID());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CSVFileState {

private static CoordinateReferenceSystem DEFAULT_CRS() throws FactoryException {
return CRS.decode("EPSG:4326");
};
}

private final File file;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private enum GeomType {
POINT,
LINE,
POLYGON
};
}

/*
* Some default style variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public InputSource resolveEntity(String publicId, String systemId)
throw new UnsupportedOperationException(
"Misconfigured parser: EntityResolver2 interface must be used "
+ "so that relative URLs are resolved correctly");
};
}

/**
* Always returns null to indicate that there is no external subset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public void run() {
// ignore, no resolve
}
}
};
}

protected static String referenceToIdentifier(String reference) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void processNamespaces(String baseURL, String filename, Set<String> eval
else evaluatedURLs.add(url.toExternalForm());
AppSchemaDataAccessDTO config = configReader.parse(url);
for (Entry<String, String> stringStringEntry : config.getNamespaces().entrySet()) {
Entry entry = (Entry) stringStringEntry;
Entry entry = stringStringEntry;
String prefix = (String) entry.getKey();
String namespace = (String) entry.getValue();
if (namespaces.getURI(prefix) == null) namespaces.declarePrefix(prefix, namespace);
Expand Down Expand Up @@ -762,7 +762,7 @@ private Map<Name, Expression> getClientProperties(

if (dto.getClientProperties().size() > 0) {
for (Entry<String, String> stringStringEntry : dto.getClientProperties().entrySet()) {
Entry entry = (Entry) stringStringEntry;
Entry entry = stringStringEntry;
String name = (String) entry.getKey();
Name qName = Types.degloseName(name, namespaces);
String cqlExpression = (String) entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void testParseBoreholeSchema() throws Exception {
expectedNamesAndTypes.put(name(XMMLNS, "log"), typeName(XMMLNS, "LogPropertyType"));

for (Entry<Name, Name> nameNameEntry : expectedNamesAndTypes.entrySet()) {
Entry entry = (Entry) nameNameEntry;
Entry entry = nameNameEntry;
Name dName = (Name) entry.getKey();
Name tName = (Name) entry.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void testFeatureChaining() throws Exception {
String[] guIds = this.mfToGuMap.get(mfId).split(";");

// make sure we have the right number of nested features
nestedGuFeatures = (Collection<Property>) mfFeature.getProperties(NESTED_LINK);
nestedGuFeatures = mfFeature.getProperties(NESTED_LINK);
assertEquals(guIds.length, nestedGuFeatures.size());

ArrayList<String> nestedGuIds = new ArrayList<>();
Expand All @@ -240,8 +240,7 @@ public void testFeatureChaining() throws Exception {
/** Test compositional part */
// make sure the right number of nested features are there
String[] cpIds = this.guToCpMap.get(guId).split(";");
nestedCpFeatures =
(Collection<Property>) guFeature.getProperties("composition");
nestedCpFeatures = guFeature.getProperties("composition");
assertEquals(cpIds.length, nestedCpFeatures.size());

ArrayList<String> nestedCpIds = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
*/
public class UnmappingFilterVisitorTest extends AppSchemaTestSupport {

private static FilterFactory ff = (FilterFactory) CommonFactoryFinder.getFilterFactory(null);
private static FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

private UnmappingFilterVisitor visitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FillBuilder extends AbstractStyleBuilder<org.geotools.api.style.Fil

Expression opacity;

GraphicBuilder graphic = (GraphicBuilder) new GraphicBuilder(this).unset();
GraphicBuilder graphic = new GraphicBuilder(this).unset();

/** Create a FillBuilder on its own; not part of a larger data structure. */
public FillBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ public GraphicBuilder reset(org.geotools.api.style.Graphic graphic) {
Symbol symbol = (Symbol) graphicalSymbol;
Builder<? extends Symbol> builder;
if (symbol instanceof Mark) {
builder =
(Builder<? extends Symbol>) new MarkBuilder(this).reset((Mark) symbol);
builder = new MarkBuilder(this).reset((Mark) symbol);
} else if (symbol instanceof ExternalGraphic) {
builder = new ExternalGraphicBuilder(this).reset((ExternalGraphic) symbol);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class PointSymbolizerBuilder extends SymbolizerBuilder<PointSymbolizer> {
Expression geometry;

GraphicBuilder graphic = (GraphicBuilder) new GraphicBuilder(this).unset();
GraphicBuilder graphic = new GraphicBuilder(this).unset();

Unit<Length> uom = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public RasterSymbolizerBuilder raster() {
public ExtensionSymbolizerBuilder extension() {
unset = false;
if (symbolizerBuilder != null) symbolizers.add(symbolizerBuilder.build());
symbolizerBuilder = (Builder<? extends Symbolizer>) new ExtensionSymbolizerBuilder(this);
symbolizerBuilder = new ExtensionSymbolizerBuilder(this);
return (ExtensionSymbolizerBuilder) symbolizerBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class StrokeBuilder extends AbstractStyleBuilder<Stroke> {

Expression dashOffset;

GraphicBuilder graphicFill = (GraphicBuilder) new GraphicBuilder(this).unset();
GraphicBuilder graphicFill = new GraphicBuilder(this).unset();

GraphicBuilder graphicStroke = (GraphicBuilder) new GraphicBuilder(this).unset();
GraphicBuilder graphicStroke = new GraphicBuilder(this).unset();

public StrokeBuilder() {
this(null);
Expand Down Expand Up @@ -87,7 +87,7 @@ public StrokeBuilder reset(Stroke stroke) {
lineCap = stroke.getLineCap();
lineJoin = stroke.getLineJoin();
dashArray = stroke.getDashArray();
dashArrayExpressions = (stroke instanceof Stroke) ? ((Stroke) stroke).dashArray() : null;
dashArrayExpressions = (stroke instanceof Stroke) ? stroke.dashArray() : null;
dashOffset = stroke.getDashOffset();
graphicFill.reset(stroke.getGraphicFill());
graphicStroke.reset(stroke.getGraphicStroke());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class TextSymbolizerBuilder extends SymbolizerBuilder<TextSymbolizer> {

Unit<Length> uom;

GraphicBuilder shield = (GraphicBuilder) new GraphicBuilder(this).unset();
GraphicBuilder shield = new GraphicBuilder(this).unset();

Builder<? extends LabelPlacement> placement = new PointPlacementBuilder(this).unset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Object visit(PropertyName name, Object data) {
return new LiteralExpressionImpl(index);
}
return name;
};
}
};
Expression indexedExpression = (Expression) getExpression(2).accept(indexVisitor, null);
result.add(indexedExpression.evaluate(feature));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ComplexFeatureTypeImpl(

{
add(ComplexFeatureConstants.FEATURE_CHAINING_LINK);
};
}
},
defaultGeometry,
isAbstract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ private void createFoundationTypes() {

protected void importSchema(Schema schema) {
for (Entry<Name, AttributeType> nameAttributeTypeEntry : schema.entrySet()) {
Entry entry = (Entry) nameAttributeTypeEntry;
Entry entry = nameAttributeTypeEntry;
Name key = (Name) entry.getKey();
Object value = entry.getValue();
if (typeRegistry.containsKey(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public void test_0() {
GraphVisitor visitor =
component -> {
Assert.assertTrue(component.isVisited());
Assert.assertEquals(
iterator.getCost(component), (double) component.getID(), 0d);
Assert.assertEquals(iterator.getCost(component), component.getID(), 0d);
if (component.getID() == 0) Assert.assertNull(iterator.getParent(component));
else
Assert.assertEquals(
Expand Down Expand Up @@ -141,8 +140,7 @@ public int visit(Graphable element, GraphTraversal traversal) {
visitor =
component -> {
Assert.assertTrue(component.isVisited());
Assert.assertEquals(
iterator.getCost(component), (double) component.getID(), 0d);
Assert.assertEquals(iterator.getCost(component), component.getID(), 0d);
if (component.getID() == 0) Assert.assertNull(iterator.getParent(component));
else
Assert.assertEquals(
Expand Down Expand Up @@ -397,8 +395,7 @@ public void test_6() {
component -> {
Graphable parent = iterator.getParent(component);
if (component.getID() < 50 && component.getID() > 0) {
Assert.assertEquals(
iterator.getCost(component), (double) component.getID(), 0d);
Assert.assertEquals(iterator.getCost(component), component.getID(), 0d);
Assert.assertEquals(parent.getID(), component.getID() - 1, 0d);
} else if (component.getID() > 50 && component.getID() < 99) {
Assert.assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class MBObjectParser {
*/
public MBObjectParser(Class<?> context) {
this.context = context;
this.sf = (StyleFactory) CommonFactoryFinder.getStyleFactory();
this.sf = CommonFactoryFinder.getStyleFactory();
this.ff = CommonFactoryFinder.getFilterFactory();
}

Expand All @@ -97,10 +97,7 @@ public MBObjectParser(Class<?> context) {
*/
public MBObjectParser(Class<MBFilter> context, MBObjectParser parse) {
this.context = context;
sf =
parse == null
? (StyleFactory) CommonFactoryFinder.getStyleFactory()
: parse.getStyleFactory();
sf = parse == null ? CommonFactoryFinder.getStyleFactory() : parse.getStyleFactory();
ff = parse == null ? CommonFactoryFinder.getFilterFactory() : parse.getFilterFactory();
}

Expand Down
Loading
Loading