From d827da2aba3d8b0e4a76426b5a76a9045ca584b2 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 30 Nov 2017 23:04:25 +0100 Subject: [PATCH] Fix Cache (URL to File could fail if no parent) --- VERSION | 2 +- changelog.md | 5 ++++ src/be/nikiroo/utils/Cache.java | 6 ++++- src/be/nikiroo/utils/Progress.java | 26 ++++++++++++------- src/be/nikiroo/utils/resources/Bundle.java | 4 +-- .../utils/serial/server/ServerBridge.java | 13 ++++++---- .../utils/serial/server/ServerObject.java | 2 +- .../utils/serial/server/ServerString.java | 2 +- .../nikiroo/utils/test/SerialServerTest.java | 18 ++++++++++++- 9 files changed, 56 insertions(+), 22 deletions(-) diff --git a/VERSION b/VERSION index 0aec50e6..3ad0595a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.4 +3.1.5 diff --git a/changelog.md b/changelog.md index f762aac1..e4354b80 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # nikiroo-utils +## Version 3.1.5 + +- Fix Cache with no-parent file +- Fix Progress (Error <> RuntimeException) + ## Version 3.1.4 - Fix error handling for tracers in Server diff --git a/src/be/nikiroo/utils/Cache.java b/src/be/nikiroo/utils/Cache.java index dcbde74e..393f634d 100644 --- a/src/be/nikiroo/utils/Cache.java +++ b/src/be/nikiroo/utils/Cache.java @@ -328,7 +328,11 @@ public class Cache { if (name == null || name.isEmpty()) { // File File file = new File(url.getFile()); - subdir = new File(file.getParent().replace("..", "__")); + if (file.getParent() == null) { + subdir = new File("+"); + } else { + subdir = new File(file.getParent().replace("..", "__")); + } subdir = new File(dir, allowedChars(subdir.getPath())); name = allowedChars(url.getFile()); } else { diff --git a/src/be/nikiroo/utils/Progress.java b/src/be/nikiroo/utils/Progress.java index ae596037..38ce29f9 100644 --- a/src/be/nikiroo/utils/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -14,6 +14,12 @@ import java.util.Set; * @author niki */ public class Progress { + /** + * This event listener is designed to report progress events from + * {@link Progress}. + * + * @author niki + */ public interface ProgressListener extends EventListener { /** * A progression event. @@ -125,17 +131,17 @@ public class Progress { * the min to set * * - * @throws Error + * @throws RuntimeException * if min < 0 or if min > max */ public void setMin(int min) { if (min < 0) { - throw new Error("negative values not supported"); + throw new RuntimeException("negative values not supported"); } synchronized (getLock()) { if (min > max) { - throw new Error( + throw new RuntimeException( "The minimum progress value must be <= the maximum progress value"); } @@ -159,7 +165,7 @@ public class Progress { * the max to set * * - * @throws Error + * @throws RuntimeException * if max < min */ public void setMax(int max) { @@ -181,16 +187,16 @@ public class Progress { * @param max * the max * - * @throws Error + * @throws RuntimeException * if min < 0 or if min > max */ public void setMinMax(int min, int max) { if (min < 0) { - throw new Error("negative values not supported"); + throw new RuntimeException("negative values not supported"); } if (min > max) { - throw new Error( + throw new RuntimeException( "The minimum progress value must be <= the maximum progress value"); } @@ -378,20 +384,20 @@ public class Progress { * {@link Progress#getMax()} scale) of this child * {@link Progress} in relation to its parent * - * @throws Error + * @throws RuntimeException * if weight exceed {@link Progress#getMax()} or if progress * already has a parent */ public void addProgress(Progress progress, double weight) { if (weight < min || weight > max) { - throw new Error(String.format( + throw new RuntimeException(String.format( "Progress object %s cannot have a weight of %f, " + "it is outside of its parent (%s) range (%f)", progress.name, weight, name, max)); } if (progress.parent != null) { - throw new Error(String.format( + throw new RuntimeException(String.format( "Progress object %s cannot be added to %s, " + "as it already has a parent (%s)", progress.name, name, progress.parent.name)); diff --git a/src/be/nikiroo/utils/resources/Bundle.java b/src/be/nikiroo/utils/resources/Bundle.java index 40177da6..83069f90 100644 --- a/src/be/nikiroo/utils/resources/Bundle.java +++ b/src/be/nikiroo/utils/resources/Bundle.java @@ -698,7 +698,7 @@ public class Bundle> { if (snap instanceof Map) { changeMap = (Map) snap; } else { - throw new Error( + throw new RuntimeException( "Restoring changes in a Bundle must be done on a changes snapshot, " + "or NULL to discard current changes"); } @@ -740,7 +740,7 @@ public class Bundle> { if (file.exists()) { break; } - + file = null; } diff --git a/src/be/nikiroo/utils/serial/server/ServerBridge.java b/src/be/nikiroo/utils/serial/server/ServerBridge.java index 60312bbe..4aa9c41f 100644 --- a/src/be/nikiroo/utils/serial/server/ServerBridge.java +++ b/src/be/nikiroo/utils/serial/server/ServerBridge.java @@ -127,11 +127,14 @@ public class ServerBridge extends Server { onSend(serverVersion, fromServer); bridge.send(fromServer); } + + getTraceHandler().trace("=== DONE", 1); + getTraceHandler().trace("", 1); } @Override protected void onError(Exception e) { - getTraceHandler().error(e); + ServerBridge.this.onError(e); } }.connect(); } @@ -145,7 +148,7 @@ public class ServerBridge extends Server { * the client version */ protected void onClientContact(Version clientVersion) { - getTraceHandler().trace("<<< CLIENT " + clientVersion); + getTraceHandler().trace(">>> CLIENT " + clientVersion); } /** @@ -155,7 +158,7 @@ public class ServerBridge extends Server { * the server version */ protected void onServerContact(Version serverVersion) { - getTraceHandler().trace(">>> SERVER " + serverVersion); + getTraceHandler().trace("<<< SERVER " + serverVersion); getTraceHandler().trace(""); } @@ -168,7 +171,7 @@ public class ServerBridge extends Server { * the data sent by the client */ protected void onRec(Version clientVersion, String data) { - trace("<<< CLIENT (" + clientVersion + ")", data); + trace(">>> CLIENT (" + clientVersion + ")", data); } /** @@ -181,7 +184,7 @@ public class ServerBridge extends Server { * the data sent by the client */ protected void onSend(Version serverVersion, String data) { - trace(">>> SERVER (" + serverVersion + ")", data); + trace("<<< SERVER (" + serverVersion + ")", data); } /** diff --git a/src/be/nikiroo/utils/serial/server/ServerObject.java b/src/be/nikiroo/utils/serial/server/ServerObject.java index 67dfa4a0..dec84738 100644 --- a/src/be/nikiroo/utils/serial/server/ServerObject.java +++ b/src/be/nikiroo/utils/serial/server/ServerObject.java @@ -73,7 +73,7 @@ abstract public class ServerObject extends Server { @Override protected void onError(Exception e) { - getTraceHandler().error(e); + ServerObject.this.onError(e); } }; } diff --git a/src/be/nikiroo/utils/serial/server/ServerString.java b/src/be/nikiroo/utils/serial/server/ServerString.java index 78436813..c19e0ae6 100644 --- a/src/be/nikiroo/utils/serial/server/ServerString.java +++ b/src/be/nikiroo/utils/serial/server/ServerString.java @@ -74,7 +74,7 @@ abstract public class ServerString extends Server { @Override protected void onError(Exception e) { - getTraceHandler().error(e); + ServerString.this.onError(e); } }; } diff --git a/src/be/nikiroo/utils/test/SerialServerTest.java b/src/be/nikiroo/utils/test/SerialServerTest.java index 885ee8c0..67ba1610 100644 --- a/src/be/nikiroo/utils/test/SerialServerTest.java +++ b/src/be/nikiroo/utils/test/SerialServerTest.java @@ -30,6 +30,10 @@ class SerialServerTest extends TestLauncher { throws Exception { return null; } + + @Override + protected void onError(Exception e) { + } }; int port = server.getPort(); @@ -292,6 +296,10 @@ class SerialServerTest extends TestLauncher { throws Exception { return null; } + + @Override + protected void onError(Exception e) { + } }; int port = server.getPort(); @@ -301,7 +309,11 @@ class SerialServerTest extends TestLauncher { ServerBridge br = null; if (bridge) { - br = new ServerBridge(0, ssl, "", port, ssl); + br = new ServerBridge(0, ssl, "", port, ssl) { + @Override + protected void onError(Exception e) { + } + }; port = br.getPort(); br.start(); } @@ -314,6 +326,10 @@ class SerialServerTest extends TestLauncher { throws Exception { rec[0] = true; } + + @Override + protected void onError(Exception e) { + } }.connect(); } finally { server.stop(); -- 2.27.0