From f7a5092116319b1cd08a68807132e8d47f73ba79 Mon Sep 17 00:00:00 2001 From: sergiorussia <22471371+sergiorussia@users.noreply.github.com> Date: Wed, 1 May 2019 00:18:47 +0300 Subject: [PATCH] review fixes --- .editorconfig | 20 -------- .../threerings/getdown/data/Application.java | 29 +++++++----- .../threerings/getdown/launcher/Getdown.java | 47 ++++++++++++------- 3 files changed, 47 insertions(+), 49 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 181f63e..0000000 --- a/.editorconfig +++ /dev/null @@ -1,20 +0,0 @@ -[*] -charset=utf-8 -end_of_line=lf -indent_size=2 -indent_style=space -insert_final_newline=true -trim_trailing_whitespace = true - -[*.java] -indent_size=4 - -# also configure imports order manually as follows: -# import java.* -# -# import javax.* -# -# import com.samskivert.* -# import com.threerings.* -# import all other imports -# import static all other imports diff --git a/core/src/main/java/com/threerings/getdown/data/Application.java b/core/src/main/java/com/threerings/getdown/data/Application.java index 75f23b0..8660aaf 100644 --- a/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/core/src/main/java/com/threerings/getdown/data/Application.java @@ -211,10 +211,10 @@ public class Application * Used by {@link #verifyMetadata} to communicate status in circumstances where it needs to * take network actions. */ - public interface StatusDisplay + public static interface StatusDisplay { /** Requests that the specified status message be displayed. */ - void updateStatus (String message); + public void updateStatus (String message); } /** @@ -238,8 +238,9 @@ public class Application public Proxy proxy = Proxy.NO_PROXY; /** - * Creates an application instance which records the location of the {@code getdown.txt} + * Creates an application instance which records the location of the getdown.txt * configuration file from the supplied application directory. + * */ public Application (EnvConfig envc) { _envc = envc; @@ -367,7 +368,8 @@ public class Application */ public List getActiveCodeResources () { - List codes = new ArrayList<>(getCodeResources()); + ArrayList codes = new ArrayList<>(); + codes.addAll(getCodeResources()); for (AuxGroup aux : getAuxGroups()) { if (isAuxGroupActive(aux.name)) { codes.addAll(aux.codes); @@ -395,7 +397,8 @@ public class Application */ public List getActiveResources () { - List rsrcs = new ArrayList<>(getResources()); + ArrayList rsrcs = new ArrayList<>(); + rsrcs.addAll(getResources()); for (AuxGroup aux : getAuxGroups()) { if (isAuxGroupActive(aux.name)) { rsrcs.addAll(aux.rsrcs); @@ -598,7 +601,7 @@ public class Application _vappbase = createVAppBase(_version); } catch (MalformedURLException mue) { String err = MessageUtil.tcompose("m.invalid_appbase", _appbase); - throw new IOException(err, mue); + throw (IOException) new IOException(err).initCause(mue); } // check for a latest config URL @@ -763,7 +766,7 @@ public class Application /** * Adds strings of the form pair0=pair1 to collector for each pair parsed out of pairLocation. */ - protected void fillAssignmentListFromPairs (String pairLocation, Collection collector) + protected void fillAssignmentListFromPairs (String pairLocation, List collector) { File pairFile = getLocalPath(pairLocation); if (pairFile.exists()) { @@ -899,7 +902,7 @@ public class Application _vappbase = createVAppBase(_targetVersion); } catch (MalformedURLException mue) { String err = MessageUtil.tcompose("m.invalid_appbase", _appbase); - throw new IOException(err, mue); + throw (IOException) new IOException(err).initCause(mue); } try { @@ -1430,7 +1433,7 @@ public class Application protected URL createVAppBase (long version) throws MalformedURLException { - String url = version < 0 ? _appbase : _appbase.replace("%VERSION%", String.valueOf(version)); + String url = version < 0 ? _appbase : _appbase.replace("%VERSION%", "" + version); return HostWhitelist.verify(new URL(url)); } @@ -1601,7 +1604,7 @@ public class Application } catch (Exception e) { log.warning("Requested to download invalid control file", "appbase", _vappbase, "path", path, "error", e); - throw new IOException("Invalid path '" + path + "'.", e); + throw (IOException) new IOException("Invalid path '" + path + "'.").initCause(e); } log.info("Attempting to refetch '" + path + "' from '" + targetURL + "'."); @@ -1636,9 +1639,11 @@ public class Application } /** Helper function to add all values in {@code values} (if non-null) to {@code target}. */ - protected static void addAll (String[] values, Collection target) { + protected static void addAll (String[] values, List target) { if (values != null) { - Collections.addAll(target, values); + for (String value : values) { + target.add(value); + } } } diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java index d5be7b3..5ff873c 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -161,7 +161,20 @@ public abstract class Getdown extends Thread } catch (Exception e) { log.warning("run() failed.", e); - fail(e); + String msg = e.getMessage(); + if (msg == null) { + msg = MessageUtil.compose("m.unknown_error", _ifc.installError); + } else if (!msg.startsWith("m.")) { + // try to do something sensible based on the type of error + if (e instanceof FileNotFoundException) { + msg = MessageUtil.compose( + "m.missing_resource", MessageUtil.taint(msg), _ifc.installError); + } else { + msg = MessageUtil.compose( + "m.init_error", MessageUtil.taint(msg), _ifc.installError); + } + } + fail(msg); } } @@ -410,7 +423,22 @@ public abstract class Getdown extends Thread } catch (Exception e) { log.warning("getdown() failed.", e); - fail(e); + String msg = e.getMessage(); + if (msg == null) { + msg = MessageUtil.compose("m.unknown_error", _ifc.installError); + } else if (!msg.startsWith("m.")) { + // try to do something sensible based on the type of error + if (e instanceof FileNotFoundException) { + msg = MessageUtil.compose( + "m.missing_resource", MessageUtil.taint(msg), _ifc.installError); + } else { + msg = MessageUtil.compose( + "m.init_error", MessageUtil.taint(msg), _ifc.installError); + } + } + // Since we're dead, clear off the 'time remaining' label along with displaying the + // error message + fail(msg); _app.releaseLock(); } } @@ -808,21 +836,6 @@ public abstract class Getdown extends Thread } } - private void fail(Exception e) { - String msg = e.getMessage(); - if (msg == null) { - msg = MessageUtil.compose("m.unknown_error", _ifc.installError); - } else if (!msg.startsWith("m.")) { - // try to do something sensible based on the type of error - if (e instanceof FileNotFoundException) { - msg = MessageUtil.compose("m.missing_resource", MessageUtil.taint(msg), _ifc.installError); - } else { - msg = MessageUtil.compose("m.init_error", MessageUtil.taint(msg), _ifc.installError); - } - } - fail(msg); - } - /** * Update the status to indicate getdown has failed for the reason in message. */