From 1dda130b341acabff62bee1c6e48141c4ec2d15a Mon Sep 17 00:00:00 2001 From: Bertil Chapuis Date: Sun, 18 Jun 2023 21:40:03 +0200 Subject: [PATCH] Fix CodeQL and Sonar warnings --- .../baremaps/benchmarks/MBTilesBenchmark.java | 21 ++++++++++++------- .../java/org/apache/baremaps/cli/map/Dev.java | 1 - .../org/apache/baremaps/cli/map/MBTiles.java | 18 ++++++---------- .../java/org/apache/baremaps/cli/map/Map.java | 3 ++- .../org/apache/baremaps/cli/map/Serve.java | 1 - .../tilestore/postgres/PostgresTileStore.java | 2 ++ .../workflow/tasks/ExportVectorTiles.java | 5 +---- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MBTilesBenchmark.java b/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MBTilesBenchmark.java index b529eb663..dc333999e 100644 --- a/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MBTilesBenchmark.java +++ b/baremaps-benchmark/src/main/java/org/apache/baremaps/benchmarks/MBTilesBenchmark.java @@ -12,11 +12,13 @@ package org.apache.baremaps.benchmarks; -import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.SecureRandom; import java.util.ArrayList; -import java.util.Random; import java.util.concurrent.TimeUnit; import org.apache.baremaps.tilestore.TileCoord; import org.apache.baremaps.tilestore.TileStoreException; @@ -33,22 +35,27 @@ @Fork(value = 1, warmups = 1) public class MBTilesBenchmark { - public Random random = new Random(0); + public SecureRandom random = new SecureRandom(); @Param({"10", "100", "1000"}) public int iterations; + private Path file; + private MBTiles mbTiles; @Setup public void setup() throws IOException, TileStoreException { - var sqliteFile = File.createTempFile("baremaps", ".sqlite"); - sqliteFile.deleteOnExit(); - var sqliteDataSource = ExportVectorTiles.createDataSource(sqliteFile.toPath()); - mbTiles = new MBTiles(sqliteDataSource); + file = Files.createTempFile(Paths.get("."), "baremaps", ".mbtiles"); + mbTiles = new MBTiles(ExportVectorTiles.createDataSource(file)); mbTiles.initializeDatabase(); } + @TearDown + public void tearDown() throws IOException, TileStoreException { + Files.delete(file); + } + @Benchmark @BenchmarkMode(Mode.SingleShotTime) public void writeMBTiles(MBTilesBenchmark benchmark) throws TileStoreException { diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java index eaa4e60f5..99f1e38e9 100644 --- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java +++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java @@ -12,7 +12,6 @@ package org.apache.baremaps.cli.map; -import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.contextResolverFor; import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.newContextResolver; import static org.apache.baremaps.utils.ObjectMapperUtils.objectMapper; diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/MBTiles.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/MBTiles.java index f4478ca90..0f8c7f50b 100644 --- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/MBTiles.java +++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/MBTiles.java @@ -12,19 +12,20 @@ package org.apache.baremaps.cli.map; +import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.newContextResolver; +import static org.apache.baremaps.utils.ObjectMapperUtils.objectMapper; + import com.fasterxml.jackson.databind.ObjectMapper; import com.github.benmanes.caffeine.cache.CaffeineSpec; import io.servicetalk.http.netty.HttpServers; import io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder; +import java.nio.file.Path; +import java.util.concurrent.Callable; import org.apache.baremaps.cli.Options; -import org.apache.baremaps.config.ConfigReader; -import org.apache.baremaps.postgres.PostgresUtils; import org.apache.baremaps.server.CorsFilter; import org.apache.baremaps.server.ServerResources; import org.apache.baremaps.tilestore.TileCache; import org.apache.baremaps.tilestore.TileStore; -import org.apache.baremaps.tilestore.postgres.PostgresTileStore; -import org.apache.baremaps.vectortile.tileset.Tileset; import org.apache.baremaps.workflow.tasks.ExportVectorTiles; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; @@ -34,13 +35,6 @@ import picocli.CommandLine.Mixin; import picocli.CommandLine.Option; -import java.nio.file.Path; -import java.util.concurrent.Callable; - -import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.contextResolverFor; -import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.newContextResolver; -import static org.apache.baremaps.utils.ObjectMapperUtils.objectMapper; - @Command(name = "mbtiles", description = "Start a mbtiles server with caching capabilities.") public class MBTiles implements Callable { @@ -57,7 +51,7 @@ public class MBTiles implements Callable { private Path mbtiles; @Option(names = {"--tilejson"}, paramLabel = "TILEJSON", description = "The tileJSON file.", - required = true) + required = true) private Path tileset; @Option(names = {"--style"}, paramLabel = "STYLE", description = "The style file.", diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java index f84dea546..c026d055c 100644 --- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java +++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java @@ -18,7 +18,8 @@ import picocli.CommandLine.Command; @Command(name = "map", description = "Map commands.", - subcommands = {Init.class, Export.class, Serve.class, Dev.class, MBTiles.class}, sortOptions = false) + subcommands = {Init.class, Export.class, Serve.class, Dev.class, MBTiles.class}, + sortOptions = false) public class Map implements Runnable { @Override diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java index ace46dcd7..01cd4d514 100644 --- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java +++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java @@ -12,7 +12,6 @@ package org.apache.baremaps.cli.map; -import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.contextResolverFor; import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.newContextResolver; import static org.apache.baremaps.utils.ObjectMapperUtils.objectMapper; diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java index e4d4485fc..af8796f2e 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java @@ -239,11 +239,13 @@ protected String tileEnvelope(TileCoord tileCoord) { } /** This operation is not supported. */ + @Override public void put(TileCoord tileCoord, ByteBuffer blob) { throw new UnsupportedOperationException("The postgis tile store is read only"); } /** This operation is not supported. */ + @Override public void delete(TileCoord tileCoord) { throw new UnsupportedOperationException("The postgis tile store is read only"); } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java index 5cca2bec5..43040de82 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java @@ -86,12 +86,10 @@ private TileStore sourceTileStore(Tileset tileset, DataSource datasource) { private TileStore targetTileStore(Tileset source) throws TileStoreException, IOException { if (mbtiles) { Files.deleteIfExists(repository); - var dataSource = createDataSource(repository); var tilesStore = new MBTiles(dataSource); tilesStore.initializeDatabase(); tilesStore.writeMetadata(metadata(source)); - return tilesStore; } else { return new FileTileStore(repository); @@ -162,8 +160,7 @@ public static DataSource createDataSource(Path path) { var hikariConfig = new HikariConfig(); hikariConfig.setDataSource(sqliteDataSource); hikariConfig.setMaximumPoolSize(1); - var hikariDataSource = new HikariDataSource(hikariConfig); - return hikariDataSource; + return new HikariDataSource(hikariConfig); } }