Fix Cache (URL to File could fail if no parent)
authorNiki Roo <niki@nikiroo.be>
Thu, 30 Nov 2017 22:04:25 +0000 (23:04 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 30 Nov 2017 22:04:25 +0000 (23:04 +0100)
VERSION
changelog.md
src/be/nikiroo/utils/Cache.java
src/be/nikiroo/utils/Progress.java
src/be/nikiroo/utils/resources/Bundle.java
src/be/nikiroo/utils/serial/server/ServerBridge.java
src/be/nikiroo/utils/serial/server/ServerObject.java
src/be/nikiroo/utils/serial/server/ServerString.java
src/be/nikiroo/utils/test/SerialServerTest.java

diff --git a/VERSION b/VERSION
index 0aec50e6ede78cfcb00d159fc0932ce35a80cb87..3ad0595adcc26a4d1811520b2bc474ca92c11bb2 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.1.4
+3.1.5
index f762aac195c7bc7fe084eeaf2f80dc271d111ce2..e4354b80316a6ce5b64000203da939d6d9715bae 100644 (file)
@@ -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
index dcbde74ea4b053ae512c7ed9149114af5f4aa77e..393f634dc5a2b011f88b5e1103ab26d6293e8641 100644 (file)
@@ -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 {
index ae5960379f12bcd2cecc17d3f7a81134f38ca018..38ce29f9c8b49e6c4a27dd939fbf4d89d330817f 100644 (file)
@@ -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 &lt; 0 or if min &gt; 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 &lt; min
         */
        public void setMax(int max) {
@@ -181,16 +187,16 @@ public class Progress {
         * @param max
         *            the max
         * 
-        * @throws Error
+        * @throws RuntimeException
         *             if min &lt; 0 or if min &gt; 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));
index 40177da6cbfc23050e4e266d65253fde52060f27..83069f90793bdc9baabce94e76ee4a21846e6951 100644 (file)
@@ -698,7 +698,7 @@ public class Bundle<E extends Enum<E>> {
                        if (snap instanceof Map) {
                                changeMap = (Map<String, String>) 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<E extends Enum<E>> {
                        if (file.exists()) {
                                break;
                        }
-                       
+
                        file = null;
                }
 
index 60312bbe2dc4d0285f85feb79202c6372f2c1cbe..4aa9c41fab5b7cbf9bd934008b4002f5fc366f75 100644 (file)
@@ -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);
        }
 
        /**
index 67dfa4a020d3a0cb8f8a70446298ddb7e0b0f7ee..dec84738865f480d64ae9a11dbd0ea5cd01b1058 100644 (file)
@@ -73,7 +73,7 @@ abstract public class ServerObject extends Server {
 
                        @Override
                        protected void onError(Exception e) {
-                               getTraceHandler().error(e);
+                               ServerObject.this.onError(e);
                        }
                };
        }
index 78436813f584a1220c6bf478f3f567a072e15b24..c19e0ae68077a73841f6581999fa89e88967bd8c 100644 (file)
@@ -74,7 +74,7 @@ abstract public class ServerString extends Server {
 
                        @Override
                        protected void onError(Exception e) {
-                               getTraceHandler().error(e);
+                               ServerString.this.onError(e);
                        }
                };
        }
index 885ee8c0150bf01189113077c4d389f9f2d30834..67ba1610ef7725c4d8939174bfe24f5daa5aa584 100644 (file)
@@ -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();