kopia lustrzana https://github.com/JOSM/MapWithAI
Fix some errorprone issues
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
690e99503c
commit
e8e3985460
|
@ -25,7 +25,7 @@ import org.openstreetmap.josm.tools.Destroyable;
|
||||||
public final class DownloadListener implements DataSourceListener, Destroyable {
|
public final class DownloadListener implements DataSourceListener, Destroyable {
|
||||||
|
|
||||||
final WeakReference<DataSet> ds;
|
final WeakReference<DataSet> ds;
|
||||||
private double BBOX_SIMILARITY_DEGREES = 0.001;
|
private static final double BBOX_SIMILARITY_DEGREES = 0.001;
|
||||||
private static final Collection<DownloadListener> LISTENERS = new HashSet<>();
|
private static final Collection<DownloadListener> LISTENERS = new HashSet<>();
|
||||||
|
|
||||||
public DownloadListener(DataSet dataSet) {
|
public DownloadListener(DataSet dataSet) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.openstreetmap.josm.tools.Utils;
|
||||||
*/
|
*/
|
||||||
public class ESRISourceReader implements Closeable {
|
public class ESRISourceReader implements Closeable {
|
||||||
private final MapWithAIInfo source;
|
private final MapWithAIInfo source;
|
||||||
private List<CachedFile> cachedFiles = new ArrayList<>();
|
private final List<CachedFile> cachedFiles = new ArrayList<>();
|
||||||
private boolean fastFail;
|
private boolean fastFail;
|
||||||
private final List<MapWithAICategory> ignoreConflationCategories;
|
private final List<MapWithAICategory> ignoreConflationCategories;
|
||||||
private static final String JSON_QUERY_PARAM = "?f=json";
|
private static final String JSON_QUERY_PARAM = "?f=json";
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -64,17 +65,21 @@ public class MapPaintUtils {
|
||||||
private final Color color;
|
private final Color color;
|
||||||
|
|
||||||
SafeColors(Color color) {
|
SafeColors(Color color) {
|
||||||
this.color = color;
|
this.color = new Color(color.getRGB());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the safe color
|
* Get the safe color
|
||||||
*/
|
*/
|
||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return this.color;
|
return new Color(this.color.getRGB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MapPaintUtils() {
|
||||||
|
// This is a utils class. Don't allow constructing.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a paintstyle from the jar
|
* Add a paintstyle from the jar
|
||||||
*/
|
*/
|
||||||
|
@ -149,8 +154,8 @@ public class MapPaintUtils {
|
||||||
.distinct().collect(Collectors.toList());
|
.distinct().collect(Collectors.toList());
|
||||||
StyleSource styleSource = getMapWithAIPaintStyle();
|
StyleSource styleSource = getMapWithAIPaintStyle();
|
||||||
/* TODO Depends upon JOSM-19547 */
|
/* TODO Depends upon JOSM-19547 */
|
||||||
if (Version.getInstance().getVersion() < 20_000
|
if ((Version.getInstance().getVersion() < 20_000
|
||||||
&& Version.getInstance().getVersion() == Version.JOSM_UNKNOWN_VERSION || styleSource == null) {
|
&& Version.getInstance().getVersion() == Version.JOSM_UNKNOWN_VERSION) || styleSource == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!styleSource.isLoaded()) {
|
if (!styleSource.isLoaded()) {
|
||||||
|
@ -183,7 +188,8 @@ public class MapPaintUtils {
|
||||||
} catch (ZipException e) {
|
} catch (ZipException e) {
|
||||||
// Assume that it is a standard file, not a zip file.
|
// Assume that it is a standard file, not a zip file.
|
||||||
OutputStream out = new FileOutputStream(file.getName() + ".tmp");
|
OutputStream out = new FileOutputStream(file.getName() + ".tmp");
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
|
new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||||
writeData(out, bufferedReader, group, sources);
|
writeData(out, bufferedReader, group, sources);
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
out.close();
|
out.close();
|
||||||
|
@ -216,7 +222,8 @@ public class MapPaintUtils {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
out.putNextEntry(new ZipEntry(MAPWITHAI_MAPCSS_ZIP_NAME));
|
out.putNextEntry(new ZipEntry(MAPWITHAI_MAPCSS_ZIP_NAME));
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file.getInputStream(current)));
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
|
new InputStreamReader(file.getInputStream(current), StandardCharsets.UTF_8));
|
||||||
writeData(out, bufferedReader, group, sources);
|
writeData(out, bufferedReader, group, sources);
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
out.closeEntry();
|
out.closeEntry();
|
||||||
|
@ -230,21 +237,21 @@ public class MapPaintUtils {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String line = bufferedReader.readLine();
|
String line = bufferedReader.readLine();
|
||||||
while (!line.contains("End Settings for the paint style")) {
|
while (!line.contains("End Settings for the paint style")) {
|
||||||
out.write(line.getBytes());
|
out.write(line.getBytes(StandardCharsets.UTF_8));
|
||||||
out.write(System.lineSeparator().getBytes());
|
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
|
||||||
line = bufferedReader.readLine();
|
line = bufferedReader.readLine();
|
||||||
}
|
}
|
||||||
/* Finish writing the comment */
|
/* Finish writing the comment */
|
||||||
while (!line.endsWith("*/")) {
|
while (!line.endsWith("*/")) {
|
||||||
out.write(line.getBytes());
|
out.write(line.getBytes(StandardCharsets.UTF_8));
|
||||||
out.write(System.lineSeparator().getBytes());
|
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
|
||||||
line = bufferedReader.readLine();
|
line = bufferedReader.readLine();
|
||||||
}
|
}
|
||||||
out.write(line.getBytes());
|
out.write(line.getBytes(StandardCharsets.UTF_8));
|
||||||
out.write(System.lineSeparator().getBytes());
|
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
for (String source : sources) {
|
for (String source : sources) {
|
||||||
out.write(System.lineSeparator().getBytes());
|
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
|
||||||
String simpleSource = source.replaceAll("[() /\\${}:]", "_");
|
String simpleSource = source.replaceAll("[() /\\${}:]", "_");
|
||||||
StringBuilder sb = new StringBuilder("setting::").append(simpleSource).append("{").append("type:color;")
|
StringBuilder sb = new StringBuilder("setting::").append(simpleSource).append("{").append("type:color;")
|
||||||
.append("default:").append(simpleSource).append(ColorHelper.color2html(getRandomColor(source)))
|
.append("default:").append(simpleSource).append(ColorHelper.color2html(getRandomColor(source)))
|
||||||
|
@ -253,17 +260,17 @@ public class MapPaintUtils {
|
||||||
sb.append("group:\"").append(group).append("\";");
|
sb.append("group:\"").append(group).append("\";");
|
||||||
}
|
}
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
out.write(sb.toString().getBytes());
|
out.write(sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
out.write(System.lineSeparator().getBytes());
|
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
|
||||||
sb = new StringBuilder(
|
sb = new StringBuilder(
|
||||||
"*[/^(source|mapwithai:source)$/][any(tag(\"source\"), tag(\"mapwithai:source\"))=\"")
|
"*[/^(source|mapwithai:source)$/][any(tag(\"source\"), tag(\"mapwithai:source\"))=\"")
|
||||||
.append(source).append("\"]{set_color_programatic:setting(\"").append(simpleSource)
|
.append(source).append("\"]{set_color_programatic:setting(\"").append(simpleSource)
|
||||||
.append("\");}");
|
.append("\");}");
|
||||||
out.write(sb.toString().getBytes());
|
out.write(sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
out.write(line.getBytes());
|
out.write(line.getBytes(StandardCharsets.UTF_8));
|
||||||
out.write(System.lineSeparator().getBytes());
|
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +282,7 @@ public class MapPaintUtils {
|
||||||
SafeColors[] colors = Stream.of(SafeColors.values()).filter(c -> SafeColors.AI_MAGENTA != c)
|
SafeColors[] colors = Stream.of(SafeColors.values()).filter(c -> SafeColors.AI_MAGENTA != c)
|
||||||
.toArray(SafeColors[]::new);
|
.toArray(SafeColors[]::new);
|
||||||
CRC32 crc = new CRC32();
|
CRC32 crc = new CRC32();
|
||||||
crc.update(sourceName.getBytes());
|
crc.update(sourceName.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
double bucket = crc.getValue() / CRC_DIVIDE_TO_TEN_K_MAX;
|
double bucket = crc.getValue() / CRC_DIVIDE_TO_TEN_K_MAX;
|
||||||
double bucket_size = 10_000 / colors.length;
|
double bucket_size = 10_000 / colors.length;
|
||||||
|
|
|
@ -251,7 +251,7 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
@Override
|
@Override
|
||||||
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
|
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
|
||||||
if (wireMock != null && !request.getUrl().endsWith("/capabilities")
|
if (wireMock != null && !request.getUrl().endsWith("/capabilities")
|
||||||
&& (!response.getHeaders().getContentTypeHeader().mimeTypePart().contains("application/zip"))) {
|
&& !response.getHeaders().getContentTypeHeader().mimeTypePart().contains("application/zip")) {
|
||||||
String origBody = response.getBodyAsString();
|
String origBody = response.getBodyAsString();
|
||||||
String newBody = origBody.replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/");
|
String newBody = origBody.replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/");
|
||||||
return Response.Builder.like(response).but().body(newBody).build();
|
return Response.Builder.like(response).but().body(newBody).build();
|
||||||
|
|
Ładowanie…
Reference in New Issue