Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
753d0ea
Remove deprecated calls from tests
sebr72 Oct 1, 2025
793caec
Use Files.readString() and reactivate ColorParserTest
sebr72 Oct 1, 2025
19427df
Use String.repeat()
sebr72 Oct 1, 2025
ebe6b11
Use SequenceCollection methods
sebr72 Oct 1, 2025
4d0f8d3
Use text blocks
sebr72 Oct 1, 2025
5fbd1cc
Use Set.copyOf
sebr72 Oct 1, 2025
f3a5e89
Use Objects.requireNonNullElse
sebr72 Oct 1, 2025
09ab1b3
Use switch rather that if
sebr72 Oct 1, 2025
4865002
Remove code noise
sebr72 Oct 1, 2025
548821a
Use Objects.equals
sebr72 Oct 1, 2025
087fea9
Use enhanced switch
sebr72 Oct 2, 2025
a0a232d
Remove unnecessary cast
sebr72 Oct 2, 2025
e9873d5
Replace Anonymous type with lambda
sebr72 Oct 2, 2025
99753f9
Replace lambda expression with a method reference
sebr72 Oct 2, 2025
6205225
Use new Map.computeIfAbsent() method
sebr72 Oct 2, 2025
7db1daf
Use expression lambda rather than statement expression
sebr72 Oct 2, 2025
a6f52b7
Avoid raw use of parameterized class
sebr72 Oct 2, 2025
c73d900
Remove unnecessary throw clauses
sebr72 Oct 2, 2025
176eb41
Add Java 21 to the CI
sebr72 Oct 2, 2025
021de1f
Use record when possible, and adapt CreateMapPagesFailOnErrorProcesso…
sebr72 Oct 2, 2025
67eba48
Use Java 21 switch enhancement
sebr72 Oct 2, 2025
1e609bc
Migrate more classes to record
sebr72 Oct 3, 2025
10ca922
Fix: Match the code with the comment above
sebr72 Oct 3, 2025
80e90f9
Fix: keep the float value, rather than casting to int
sebr72 Oct 3, 2025
608649b
Fix: calculate and test the rollLongitude result
sebr72 Oct 6, 2025
5223e8b
Use round() method only where it makes sense
sebr72 Oct 6, 2025
8e0085a
Remove dead code
sebr72 Oct 6, 2025
96407f5
Remove obsolete annotations
sebr72 Oct 6, 2025
0f60ef4
Make test classes static when possible. Clarify test
sebr72 Oct 6, 2025
f27012d
Use StandardCharsets constant
sebr72 Oct 6, 2025
de74b92
Remove redundant variable declaration
sebr72 Oct 6, 2025
8c50545
Use isEmpty() when possible
sebr72 Oct 6, 2025
9f2ef74
Use static method call
sebr72 Oct 6, 2025
d8a1c40
Remove redundant catch or throws clauses
sebr72 Oct 6, 2025
f8e941b
Remove protected and final from methods in final classes
sebr72 Oct 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'

- uses: actions/setup-python@v6
with:
python-version: '3.13'
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/mapfish/print/FontTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -62,7 +63,7 @@ public static List<FontConfigDescription> listFontConfigFonts(final String famil
String[] commands = {"fc-list", "-b", family};
Process process = Runtime.getRuntime().exec(commands);

inputStreamReader = new InputStreamReader(process.getInputStream(), "utf-8");
inputStreamReader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8);
stdInput = new BufferedReader(inputStreamReader);
String inputLine;
FontConfigDescription description = null;
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/mapfish/print/SvgUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ private static class BufferedImageTranscoder extends ImageTranscoder {

@Override
public BufferedImage createImage(final int w, final int h) {
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
return bi;
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
}

@Override
Expand Down
12 changes: 4 additions & 8 deletions core/src/main/java/org/mapfish/print/URIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -54,13 +55,8 @@ public static Multimap<String, String> getParameters(final String rawQuery) {
key = pair;
value = "";
} else {

try {
key = URLDecoder.decode(pair.substring(0, pos), "UTF-8");
value = URLDecoder.decode(pair.substring(pos + 1), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new PrintException("Failed to get parameters for query " + rawQuery, e);
}
key = URLDecoder.decode(pair.substring(0, pos), StandardCharsets.UTF_8);
value = URLDecoder.decode(pair.substring(pos + 1), StandardCharsets.UTF_8);
}

result.put(key, value);
Expand Down Expand Up @@ -214,7 +210,7 @@ public static URI setQueryParams(
final URI initialUri, final Multimap<String, String> queryParams) {
StringBuilder queryString = new StringBuilder();
for (Map.Entry<String, String> entry : queryParams.entries()) {
if (queryString.length() > 0) {
if (!queryString.isEmpty()) {
queryString.append("&");
}
queryString.append(entry.getKey()).append("=").append(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/** An attribute that can contain an array of strings. [[examples=verboseExample]] */
public class StringArrayAttribute extends PrimitiveAttribute<String[]> {
/** Constructor. */
@SuppressWarnings("unchecked")
public StringArrayAttribute() {
super(String[].class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public final void setMaxLength(final int maxLength) {

@Override
public final void validateValue(final Object value) {
if (this.maxLength >= 0 && value instanceof String) {
String text = (String) value;
if (this.maxLength >= 0 && value instanceof String text) {
if (text.length() > this.maxLength) {
throw new IllegalArgumentException(
"text contains more than " + this.maxLength + " characters");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static org.mapfish.print.Constants.PDF_DPI;

import com.google.common.annotations.VisibleForTesting;
import java.awt.Rectangle;
import java.util.Objects;
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.referencing.operation.TransformException;
import org.geotools.geometry.Position2D;
Expand Down Expand Up @@ -179,12 +181,21 @@ private ReferencedEnvelope computeGeodeticBBox(
}
}

private double rollLongitude(final double x) {
return x - (((int) (x + Math.signum(x) * 180)) / 360) * 360.0;
@VisibleForTesting
double rollLongitude(final double x) {
return modulo(x + 180, 360.0) - 180;
}

private double rollLatitude(final double y) {
return y - (((int) (y + Math.signum(y) * 90)) / 180) * 180.0;
private static double modulo(final double a, final double b) {
return b - ((-a % b) + b) % b;
}

@VisibleForTesting
double rollLatitude(final double y) {
if (y > 90 || y < -90) {
throw new IllegalArgumentException("Latitude must be between -90 and 90");
}
return y;
}

@Override
Expand All @@ -201,10 +212,10 @@ public boolean equals(final Object o) {

final CenterScaleMapBounds that = (CenterScaleMapBounds) o;

if (this.center != null ? !this.center.equals(that.center) : that.center != null) {
if (!Objects.equals(this.center, that.center)) {
return false;
}
return this.scale != null ? this.scale.equals(that.scale) : that.scale == null;
return Objects.equals(this.scale, that.scale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public final class MapAttribute extends GenericMapAttribute {
ZoomLevelSnapStrategy.CLOSEST_LOWER_SCALE_ON_TIE;
private static final boolean DEFAULT_SNAP_GEODETIC = false;

@SuppressWarnings("unchecked")
@Override
public Class<MapAttributeValues> getValueType() {
return MapAttributeValues.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ public AffineTransform getTransform() {
final AffineTransform transform = AffineTransform.getTranslateInstance(0.0, 0.0);
// move to the center of the original map rectangle (this is the actual
// size of the graphic)
transform.translate(this.mapSize.width / 2, this.mapSize.height / 2);
transform.translate(this.mapSize.width / 2.0, this.mapSize.height / 2.0);

// then rotate around this center
transform.rotate(this.rotation);

// then move to an artificial origin (0,0) which might be outside the actual
// painting area. this origin still keeps the center of the original map area
// at the center of the rotated map area.
transform.translate(-rotatedMapSize.width / 2, -rotatedMapSize.height / 2);
transform.translate(-rotatedMapSize.width / 2.0, -rotatedMapSize.height / 2.0);

return transform;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void setStyle(final String style) {
this.style = style;
}

@SuppressWarnings("unchecked")
@Override
public Class<OverviewMapAttributeValues> getValueType() {
return OverviewMapAttributeValues.class;
Expand Down
23 changes: 7 additions & 16 deletions core/src/main/java/org/mapfish/print/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,13 @@ private static void printUsage(final int exitCode) {

private static void configureLogs(final String verbose) {
final ClassLoader classLoader = Main.class.getClassLoader();
URL logfile;
switch (Integer.parseInt(verbose)) {
case LOGLEVEL_QUIET:
logfile = classLoader.getResource("shell-quiet-log.xml");
break;
case LOGLEVEL_INFO:
logfile = classLoader.getResource("shell-info-log.xml");
break;
case LOGLEVEL_VERBOSE:
logfile = classLoader.getResource("shell-verbose-log.xml");
break;
case LOGLEVEL_DEFAULT:
default:
logfile = classLoader.getResource("shell-default-log.xml");
break;
}
URL logfile =
switch (Integer.parseInt(verbose)) {
case LOGLEVEL_QUIET -> classLoader.getResource("shell-quiet-log.xml");
case LOGLEVEL_INFO -> classLoader.getResource("shell-info-log.xml");
case LOGLEVEL_VERBOSE -> classLoader.getResource("shell-verbose-log.xml");
default -> classLoader.getResource("shell-default-log.xml");
};

LoggerContext loggerContext = getLoggerContext(logfile);
new StatusPrinter2().printInCaseOfErrorsOrWarnings(loggerContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public final Configuration getConfig(final File configFile, final InputStream co
errors.append("\n\t* ").append(throwable.getMessage());
LOGGER.error("Configuration Error found", throwable);
}
throw new Error(errors.toString(), validate.get(0));
throw new Error(errors.toString(), validate.getFirst());
}
}
return config;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/mapfish/print/config/PDFConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public String getKeywordsAsString() {
public void setKeywords(final List<String> keywords) {
StringBuilder builder = new StringBuilder();
for (String keyword : keywords) {
if (builder.length() > 0) {
if (!builder.isEmpty()) {
builder.append(',');
}
builder.append(keyword.trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ public AccessAssertion setRequiredRoles(final Collection<String> assertionRequir
if (assertionRequiredRoles == null) {
this.requiredRoles = Collections.unmodifiableSet(Collections.emptySet());
} else {
if (assertionRequiredRoles instanceof Set) {
Set roles = (Set) assertionRequiredRoles;
if (assertionRequiredRoles instanceof Set roles) {
this.requiredRoles = Collections.unmodifiableSet(roles);
} else {
this.requiredRoles = Collections.unmodifiableSet(new HashSet<>(assertionRequiredRoles));
this.requiredRoles = Set.copyOf(assertionRequiredRoles);
}
}
return this;
Expand Down Expand Up @@ -135,7 +134,7 @@ public int hashCode() {
@Override
public AccessAssertion copy() {
RoleAccessAssertion assertion = new RoleAccessAssertion();
assertion.requiredRoles = Collections.unmodifiableSet(new HashSet<>(this.requiredRoles));
assertion.requiredRoles = Set.copyOf(this.requiredRoles);
return assertion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,8 @@ public URI getURI() {
return this.uri;
}

private static class ConfigFileResolverHttpResponse implements ClientHttpResponse {
private final InputStream is;
private final HttpHeaders headers;

ConfigFileResolverHttpResponse(final InputStream is, final HttpHeaders headers) {
this.headers = headers;
this.is = is;
}
private record ConfigFileResolverHttpResponse(InputStream is, HttpHeaders headers)
implements ClientHttpResponse {

@Override
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ protected Response executeInternal(@Nonnull final HttpHeaders headers) throws IO
}
}
}
if (this.request instanceof HttpEntityEnclosingRequest) {
final HttpEntityEnclosingRequest entityEnclosingRequest =
(HttpEntityEnclosingRequest) this.request;
if (this.request instanceof HttpEntityEnclosingRequest entityEnclosingRequest) {
final HttpEntity requestEntity = new ByteArrayEntity(this.outputStream.toByteArray());
entityEnclosingRequest.setEntity(requestEntity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static String getUserAgent() {
LOGGER.error("Error getting MapFishPrint version", e);
}

final String userAgent = String.format("%s/%s %s", AGENT_NAME, mfpRelease, httpClientUserAgent);
return userAgent;
return String.format("%s/%s %s", AGENT_NAME, mfpRelease, httpClientUserAgent);
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/mapfish/print/http/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private Utils() {}
* @param headers The headers
*/
public static List<String> getPrintableHeadersList(final Map<String, List<String>> headers) {
final List<String> result = new ArrayList<String>();
final List<String> result = new ArrayList<>();
for (String header : headers.keySet()) {
List<String> value = headers.get(header);
if (AUTH_HEADERS.contains(header.toLowerCase())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ private static char numberToChar(final int number) {
if (number > 26 || number < 0) {
return '\0';
}
char c = (char) ('A' + number - 1);
return c;
return (char) ('A' + number - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,14 @@ public final List<? extends Layer> getLayers(

public final void setFeatureCollection(final SimpleFeatureCollection featureCollection) {
this.featureSourceSupplier =
new FeatureSourceSupplier() {
@Nonnull
@Override
public FeatureSource<?, ?> load(
@Nonnull final MfClientHttpRequestFactory requestFactory,
@Nonnull final MapfishMapContext mapContext) {
// GeoTools is not always thread safe. In particular the
// DefaultFeatureCollection.getBounds
// method. If multiple maps are sharing the same features, this would cause
// zoomToFeature
// to result in funky bboxes. To avoid that, we use a copy of the featureCollection
final SimpleFeatureCollection copy = DataUtilities.collection(featureCollection);
return new CollectionFeatureSource(copy);
}
(requestFactory, mapContext) -> {
// GeoTools is not always thread safe. In particular the
// DefaultFeatureCollection.getBounds
// method. If multiple maps are sharing the same features, this would cause
// zoomToFeature
// to result in funky bboxes. To avoid that, we use a copy of the featureCollection
final SimpleFeatureCollection copy = DataUtilities.collection(featureCollection);
return new CollectionFeatureSource(copy);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ protected abstract List<? extends Layer> getLayers(
MfClientHttpRequestFactory httpRequestFactory,
MapfishMapContext transformer,
Processor.ExecutionContext context,
LayerContext layerContext)
throws Exception;
LayerContext layerContext);

@Override
public boolean supportsNativeRotation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import static org.mapfish.print.Constants.Style.Raster.NAME;

import org.geotools.api.style.Style;
import org.mapfish.print.OptionalUtils;
import org.mapfish.print.config.Template;
import org.mapfish.print.http.MfClientHttpRequestFactory;
import org.mapfish.print.map.style.StyleParser;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -25,15 +23,12 @@ public abstract class AbstractGridCoverageLayerPlugin {
*/
protected final <T> StyleSupplier<T> createStyleSupplier(
final Template template, final String styleRef) {
return new StyleSupplier<T>() {
@Override
public Style load(final MfClientHttpRequestFactory requestFactory, final T featureSource) {
final StyleParser parser = AbstractGridCoverageLayerPlugin.this.styleParser;
return OptionalUtils.or(
() -> template.getStyle(styleRef),
() -> parser.loadStyle(template.getConfiguration(), requestFactory, styleRef))
.orElse(template.getConfiguration().getDefaultStyle(NAME));
}
return (requestFactory, featureSource) -> {
final StyleParser parser = AbstractGridCoverageLayerPlugin.this.styleParser;
return OptionalUtils.or(
() -> template.getStyle(styleRef),
() -> parser.loadStyle(template.getConfiguration(), requestFactory, styleRef))
.orElse(template.getConfiguration().getDefaultStyle(NAME));
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ static CoordinateReferenceSystem parseCoordinateReferenceSystem(
return CRS.parseWKT(wkt);
} catch (FactoryException e) {
LOGGER.warn(
"Unable to load linked CRS from geojson: \n{}\n\nWKT loaded" + " from:\n{}",
"""
Unable to load linked CRS from geojson:\s
{}

WKT loaded from:
{}\
""",
crsJson,
wkt);
}
Expand All @@ -120,7 +126,7 @@ static CoordinateReferenceSystem parseCoordinateReferenceSystem(
"Error reading the required elements to parse crs of the geojson: \n{}", geojson, e);
}
try {
if (code.length() > 0) {
if (!code.isEmpty()) {
crs = CRS.decode(code.toString(), forceLongitudeFirst);
}
} catch (NoSuchAuthorityCodeException e) {
Expand Down
Loading
Loading