diff --git a/core/src/main/java/com/threerings/getdown/Log.java b/core/src/main/java/com/threerings/getdown/Log.java index da98c90..049c5bf 100644 --- a/core/src/main/java/com/threerings/getdown/Log.java +++ b/core/src/main/java/com/threerings/getdown/Log.java @@ -129,7 +129,7 @@ public final class Log PrintWriter pw = new PrintWriter(sw); record.getThrown().printStackTrace(pw); pw.close(); - buf.append(sw.toString()); + buf.append(sw); } catch (Exception ex) { buf.append("Format failure:").append(ex); } @@ -138,10 +138,10 @@ public final class Log return buf.toString(); } - protected Date _date = new Date(); - protected SimpleDateFormat _format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS"); - protected FieldPosition _fpos = new FieldPosition(SimpleDateFormat.DATE_FIELD); + protected final Date _date = new Date(); + protected final SimpleDateFormat _format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS"); + protected final FieldPosition _fpos = new FieldPosition(SimpleDateFormat.DATE_FIELD); } - protected static final Level[] LEVELS = {Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE}; + private static final Level[] LEVELS = {Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE}; } 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 7760e41..2cfef49 100644 --- a/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/core/src/main/java/com/threerings/getdown/data/Application.java @@ -235,7 +235,7 @@ public class Application /** * Reads the {@code getdown.txt} config file into a {@code Config} object and returns it. */ - public static Config readConfig (EnvConfig envc, boolean checkPlatform) throws IOException { + public static Config readConfig (EnvConfig envc, boolean checkPlatform) { Config config = null; File cfgfile = new File(envc.appDir, CONFIG_FILE); Config.ParseOpts opts = Config.createOpts(checkPlatform); @@ -1332,7 +1332,7 @@ public class Application // is reported by posting runnable actions to the actions queue which is processed by the // main (UI) thread ExecutorService exec = Executors.newFixedThreadPool(SysProps.threadPoolSize()); - final BlockingQueue actions = new LinkedBlockingQueue(); + final BlockingQueue actions = new LinkedBlockingQueue<>(); final int[] completed = new int[1]; long start = System.currentTimeMillis(); @@ -1438,9 +1438,7 @@ public class Application * * @param unpacked a set of resources to skip because they're already unpacked. */ - public void unpackResources (ProgressObserver obs, Set unpacked) - throws InterruptedException - { + public void unpackResources (ProgressObserver obs, Set unpacked) { List rsrcs = getActiveResources(); // remove resources that we don't want to unpack @@ -1793,10 +1791,10 @@ public class Application protected String _javaLocation; protected File _javaLocalDir; - protected List _codes = new ArrayList<>(); - protected List _resources = new ArrayList<>(); - protected List _cleanupPatterns = new ArrayList<>(); - protected List _cpdirs = new ArrayList<>(); + protected final List _codes = new ArrayList<>(); + protected final List _resources = new ArrayList<>(); + protected final List _cleanupPatterns = new ArrayList<>(); + protected final List _cpdirs = new ArrayList<>(); protected int _verifyTimeout = 60; @@ -1804,15 +1802,15 @@ public class Application protected boolean _useCodeCache; protected int _codeCacheRetentionDays; - protected Map _auxgroups = new HashMap<>(); - protected Map _auxactive = new HashMap<>(); + protected final Map _auxgroups = new HashMap<>(); + protected final Map _auxactive = new HashMap<>(); - protected List _jvmargs = new ArrayList<>(); - protected List _appargs = new ArrayList<>(); + protected final List _jvmargs = new ArrayList<>(); + protected final List _appargs = new ArrayList<>(); protected String[] _optimumJvmArgs; - protected List _txtJvmArgs = new ArrayList<>(); + protected final List _txtJvmArgs = new ArrayList<>(); /** Locks gettingdown.lock in the app dir. Held the entire time updating is going on.*/ protected FileLock _lock; @@ -1820,7 +1818,7 @@ public class Application /** Channel to the file underlying _lock. Kept around solely so the lock doesn't close. */ protected FileChannel _lockChannel; - protected Random _rando = new Random(); + protected final Random _rando = new Random(); protected static final String[] EMPTY_STRING_ARRAY = new String[0]; diff --git a/core/src/main/java/com/threerings/getdown/data/Digest.java b/core/src/main/java/com/threerings/getdown/data/Digest.java index e310a52..2c4fee2 100644 --- a/core/src/main/java/com/threerings/getdown/data/Digest.java +++ b/core/src/main/java/com/threerings/getdown/data/Digest.java @@ -219,7 +219,7 @@ public class Digest data.append(path).append(" = ").append(digest).append("\n"); } - protected HashMap _digests = new HashMap<>(); + protected final HashMap _digests = new HashMap<>(); protected String _metaDigest = ""; protected static final String FILE_NAME = "digest"; diff --git a/core/src/main/java/com/threerings/getdown/data/PathBuilder.java b/core/src/main/java/com/threerings/getdown/data/PathBuilder.java index 1f10d0d..ef87c78 100644 --- a/core/src/main/java/com/threerings/getdown/data/PathBuilder.java +++ b/core/src/main/java/com/threerings/getdown/data/PathBuilder.java @@ -40,7 +40,7 @@ public class PathBuilder */ public static ClassPath buildDefaultClassPath (Application app) { - LinkedHashSet classPathEntries = new LinkedHashSet(); + LinkedHashSet classPathEntries = new LinkedHashSet<>(); for (Resource resource : app.getActiveCodeResources()) { classPathEntries.add(resource.getFinalTarget()); } diff --git a/core/src/main/java/com/threerings/getdown/data/Resource.java b/core/src/main/java/com/threerings/getdown/data/Resource.java index 2ea7798..7fa86e4 100644 --- a/core/src/main/java/com/threerings/getdown/data/Resource.java +++ b/core/src/main/java/com/threerings/getdown/data/Resource.java @@ -362,11 +362,14 @@ public class Resource implements Comparable } } - protected String _path; - protected URL _remote; - protected File _local, _localNew, _marker, _unpacked; - protected EnumSet _attrs; - protected boolean _isZip; + protected final String _path; + protected final URL _remote; + protected final File _local; + protected final File _localNew; + protected final File _marker; + protected File _unpacked; + protected final EnumSet _attrs; + protected final boolean _isZip; /** Used to sort the entries in a jar file. */ protected static final Comparator ENTRY_COMP = new Comparator() { diff --git a/core/src/main/java/com/threerings/getdown/tools/JarDiff.java b/core/src/main/java/com/threerings/getdown/tools/JarDiff.java index f0db8ac..845f3a2 100644 --- a/core/src/main/java/com/threerings/getdown/tools/JarDiff.java +++ b/core/src/main/java/com/threerings/getdown/tools/JarDiff.java @@ -406,7 +406,7 @@ public class JarDiff implements JarDiffCodes return thisName; } - private void index () throws IOException { + private void index () { Enumeration entries = _archive.entries(); _nameToEntryMap = new HashMap<>(); diff --git a/core/src/main/java/com/threerings/getdown/tools/JarDiffPatcher.java b/core/src/main/java/com/threerings/getdown/tools/JarDiffPatcher.java index a65cbeb..2bde353 100644 --- a/core/src/main/java/com/threerings/getdown/tools/JarDiffPatcher.java +++ b/core/src/main/java/com/threerings/getdown/tools/JarDiffPatcher.java @@ -292,6 +292,6 @@ public class JarDiffPatcher implements JarDiffCodes protected static final int DEFAULT_READ_SIZE = 2048; - protected static byte[] newBytes = new byte[DEFAULT_READ_SIZE]; + protected static final byte[] newBytes = new byte[DEFAULT_READ_SIZE]; protected static byte[] oldBytes = new byte[DEFAULT_READ_SIZE]; } diff --git a/core/src/main/java/com/threerings/getdown/util/FileUtil.java b/core/src/main/java/com/threerings/getdown/util/FileUtil.java index a38136d..f7c67ef 100644 --- a/core/src/main/java/com/threerings/getdown/util/FileUtil.java +++ b/core/src/main/java/com/threerings/getdown/util/FileUtil.java @@ -154,7 +154,7 @@ public final class FileUtil continue; } - try (BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(efile)); + try (BufferedOutputStream fout = new BufferedOutputStream(Files.newOutputStream(efile.toPath())); InputStream jin = jar.getInputStream(entry)) { StreamUtil.copy(jin, fout); } catch (Exception e) { diff --git a/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java b/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java index cc51794..4ec94fe 100644 --- a/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java +++ b/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.nio.file.Files; import java.util.Locale; import static com.threerings.getdown.Log.log; @@ -52,7 +53,7 @@ public final class LaunchUtil { // create the file that instructs Getdown to upgrade File vfile = new File(appdir, "version.txt"); - try (PrintStream ps = new PrintStream(new FileOutputStream(vfile))) { + try (PrintStream ps = new PrintStream(Files.newOutputStream(vfile.toPath()))) { ps.println(newVersion); } @@ -198,7 +199,7 @@ public final class LaunchUtil /** * Checks whether a Java Virtual Machine can be located in the supplied path. */ - protected static String checkJVMPath (String vmhome, boolean windebug) + private static String checkJVMPath(String vmhome, boolean windebug) { String vmbase = vmhome + File.separator + "bin" + File.separator; String vmpath = vmbase + "java"; @@ -222,11 +223,11 @@ public final class LaunchUtil } /** Flag indicating that we're on Windows; initialized when this class is first loaded. */ - protected static boolean _isWindows; + private static boolean _isWindows; /** Flag indicating that we're on MacOS; initialized when this class is first loaded. */ - protected static boolean _isMacOS; + private static boolean _isMacOS; /** Flag indicating that we're on Linux; initialized when this class is first loaded. */ - protected static boolean _isLinux; + private static boolean _isLinux; static { try { diff --git a/core/src/main/java/com/threerings/getdown/util/MessageUtil.java b/core/src/main/java/com/threerings/getdown/util/MessageUtil.java index f2ee9a2..85e94f5 100644 --- a/core/src/main/java/com/threerings/getdown/util/MessageUtil.java +++ b/core/src/main/java/com/threerings/getdown/util/MessageUtil.java @@ -140,5 +140,5 @@ public final class MessageUtil { /** Text prefixed by this character will be considered tainted when doing recursive * translations and won't be translated. */ - protected static final String TAINT_CHAR = "~"; + private static final String TAINT_CHAR = "~"; } diff --git a/core/src/main/java/com/threerings/getdown/util/ProgressAggregator.java b/core/src/main/java/com/threerings/getdown/util/ProgressAggregator.java index d74b011..8ec6605 100644 --- a/core/src/main/java/com/threerings/getdown/util/ProgressAggregator.java +++ b/core/src/main/java/com/threerings/getdown/util/ProgressAggregator.java @@ -44,7 +44,7 @@ public class ProgressAggregator return totalSize; } - protected ProgressObserver _target; - protected long[] _sizes; - protected int[] _progress; + protected final ProgressObserver _target; + protected final long[] _sizes; + protected final int[] _progress; } diff --git a/core/src/main/java/com/threerings/getdown/util/StringUtil.java b/core/src/main/java/com/threerings/getdown/util/StringUtil.java index 86277c8..0a18f25 100644 --- a/core/src/main/java/com/threerings/getdown/util/StringUtil.java +++ b/core/src/main/java/com/threerings/getdown/util/StringUtil.java @@ -187,7 +187,7 @@ public final class StringUtil { /** * Helper function for the various {@code join} methods. */ - protected static String join (Object[] values, String separator, boolean escape) + private static String join(Object[] values, String separator, boolean escape) { StringBuilder buf = new StringBuilder(); int vlength = values.length; @@ -202,5 +202,5 @@ public final class StringUtil { } /** Used by {@link #hexlate}. */ - protected static final String XLATE = "0123456789abcdef"; + private static final String XLATE = "0123456789abcdef"; } diff --git a/core/src/main/java/com/threerings/getdown/util/VersionUtil.java b/core/src/main/java/com/threerings/getdown/util/VersionUtil.java index b2f2894..b99ab03 100644 --- a/core/src/main/java/com/threerings/getdown/util/VersionUtil.java +++ b/core/src/main/java/com/threerings/getdown/util/VersionUtil.java @@ -12,6 +12,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; +import java.nio.file.Files; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -31,7 +32,7 @@ public final class VersionUtil { long fileVersion = -1; try (BufferedReader bin = - new BufferedReader(new InputStreamReader(new FileInputStream(vfile), UTF_8))) { + new BufferedReader(new InputStreamReader(Files.newInputStream(vfile.toPath()), UTF_8))) { String vstr = bin.readLine(); if (!StringUtil.isBlank(vstr)) { fileVersion = Long.parseLong(vstr); @@ -48,7 +49,7 @@ public final class VersionUtil */ public static void writeVersion (File vfile, long version) throws IOException { - try (PrintStream out = new PrintStream(new FileOutputStream(vfile))) { + try (PrintStream out = new PrintStream(Files.newOutputStream(vfile.toPath()))) { out.println(version); } catch (Exception e) { log.warning("Unable to write version file: " + e.getMessage()); @@ -80,7 +81,7 @@ public final class VersionUtil public static long readReleaseVersion (File relfile, String versRegex) { try (BufferedReader in = - new BufferedReader(new InputStreamReader(new FileInputStream(relfile), UTF_8))) { + new BufferedReader(new InputStreamReader(Files.newInputStream(relfile.toPath()), UTF_8))) { String line = null, relvers = null; while ((line = in.readLine()) != null) { if (line.startsWith("JAVA_VERSION=")) { diff --git a/core/src/test/java/com/threerings/getdown/cache/GarbageCollectorTest.java b/core/src/test/java/com/threerings/getdown/cache/GarbageCollectorTest.java index c7fcf72..d34e584 100644 --- a/core/src/test/java/com/threerings/getdown/cache/GarbageCollectorTest.java +++ b/core/src/test/java/com/threerings/getdown/cache/GarbageCollectorTest.java @@ -77,7 +77,7 @@ public class GarbageCollectorTest assertFalse(_lastAccessedFile.exists()); } - @Rule public TemporaryFolder _folder = new TemporaryFolder(); + @Rule public final TemporaryFolder _folder = new TemporaryFolder(); private File _cachedFile; private File _lastAccessedFile; diff --git a/core/src/test/java/com/threerings/getdown/cache/ResourceCacheTest.java b/core/src/test/java/com/threerings/getdown/cache/ResourceCacheTest.java index 6acffda..54bde28 100644 --- a/core/src/test/java/com/threerings/getdown/cache/ResourceCacheTest.java +++ b/core/src/test/java/com/threerings/getdown/cache/ResourceCacheTest.java @@ -75,7 +75,7 @@ public class ResourceCacheTest assertTrue(lastAccessedFile.lastModified() > lastAccessed); } - @Rule public TemporaryFolder _folder = new TemporaryFolder(); + @Rule public final TemporaryFolder _folder = new TemporaryFolder(); private File _fileToCache; private ResourceCache _cache; diff --git a/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java b/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java index c5998f2..f9b27ee 100644 --- a/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java +++ b/core/src/test/java/com/threerings/getdown/data/ClassPathTest.java @@ -27,7 +27,7 @@ public class ClassPathTest _firstJar = _folder.newFile("a.jar"); _secondJar = _folder.newFile("b.jar"); - LinkedHashSet classPathEntries = new LinkedHashSet(); + LinkedHashSet classPathEntries = new LinkedHashSet<>(); classPathEntries.add(_firstJar); classPathEntries.add(_secondJar); _classPath = new ClassPath(classPathEntries); @@ -40,14 +40,14 @@ public class ClassPathTest _classPath.asArgumentString(_folder.getRoot())); } - @Test public void shouldProvideJarUrls () throws MalformedURLException, URISyntaxException + @Test public void shouldProvideJarUrls () throws URISyntaxException { URL[] actualUrls = _classPath.asUrls(); assertEquals(_firstJar, new File(actualUrls[0].toURI())); assertEquals(_secondJar, new File(actualUrls[1].toURI())); } - @Rule public TemporaryFolder _folder = new TemporaryFolder(); + @Rule public final TemporaryFolder _folder = new TemporaryFolder(); private File _firstJar, _secondJar; private ClassPath _classPath; diff --git a/core/src/test/java/com/threerings/getdown/data/EnvConfigTest.java b/core/src/test/java/com/threerings/getdown/data/EnvConfigTest.java index 04a73d3..1900883 100644 --- a/core/src/test/java/com/threerings/getdown/data/EnvConfigTest.java +++ b/core/src/test/java/com/threerings/getdown/data/EnvConfigTest.java @@ -15,9 +15,9 @@ import static org.junit.Assert.*; public class EnvConfigTest { - static String CWD = System.getProperty("user.dir"); - static String TESTID = "testid"; - static String TESTBASE = "https://test.com/test"; + static final String CWD = System.getProperty("user.dir"); + static final String TESTID = "testid"; + static final String TESTBASE = "https://test.com/test"; private void debugNotes (List notes) { for (EnvConfig.Note note : notes) { @@ -33,7 +33,7 @@ public class EnvConfigTest { } } if (msg.length() > 0) { - fail("Unexpected notes:" + msg.toString()); + fail("Unexpected notes:" + msg); } } private void checkDir (EnvConfig cfg) { diff --git a/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java b/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java index af7e789..5df18eb 100644 --- a/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java +++ b/core/src/test/java/com/threerings/getdown/data/PathBuilderTest.java @@ -7,7 +7,6 @@ package com.threerings.getdown.data; import java.io.File; import java.io.IOException; -import java.nio.file.Path; import java.util.Arrays; import org.junit.*; @@ -16,7 +15,7 @@ import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -55,5 +54,5 @@ public class PathBuilderTest protected File _firstJarFile, _secondJarFile; - @Rule public TemporaryFolder _appdir = new TemporaryFolder(); + @Rule public final TemporaryFolder _appdir = new TemporaryFolder(); } diff --git a/core/src/test/java/com/threerings/getdown/util/ConfigTest.java b/core/src/test/java/com/threerings/getdown/util/ConfigTest.java index cdc5a91..911191f 100644 --- a/core/src/test/java/com/threerings/getdown/util/ConfigTest.java +++ b/core/src/test/java/com/threerings/getdown/util/ConfigTest.java @@ -62,81 +62,81 @@ public class ConfigTest opts.osarch = "i386"; List parsed = Config.parsePairs(toReader(pairs), opts); assertTrue(exists(parsed, linux.key)); - assertTrue(!exists(parsed, mac.key)); + assertFalse(exists(parsed, mac.key)); assertTrue(exists(parsed, linuxAndMac.key)); - assertTrue(!exists(parsed, linux64.key)); - assertTrue(!exists(parsed, linux64s.key)); - assertTrue(!exists(parsed, mac64.key)); - assertTrue(!exists(parsed, win64.key)); + assertFalse(exists(parsed, linux64.key)); + assertFalse(exists(parsed, linux64s.key)); + assertFalse(exists(parsed, mac64.key)); + assertFalse(exists(parsed, win64.key)); assertTrue(exists(parsed, notWin.key)); opts.osarch = "x86_64"; parsed = Config.parsePairs(toReader(pairs), opts); assertTrue(exists(parsed, linux.key)); - assertTrue(!exists(parsed, mac.key)); + assertFalse(exists(parsed, mac.key)); assertTrue(exists(parsed, linuxAndMac.key)); assertTrue(exists(parsed, linux64.key)); assertTrue(exists(parsed, linux64s.key)); - assertTrue(!exists(parsed, mac64.key)); - assertTrue(!exists(parsed, win64.key)); + assertFalse(exists(parsed, mac64.key)); + assertFalse(exists(parsed, win64.key)); assertTrue(exists(parsed, notWin.key)); opts.osarch = "amd64"; parsed = Config.parsePairs(toReader(pairs), opts); assertTrue(exists(parsed, linux.key)); - assertTrue(!exists(parsed, mac.key)); + assertFalse(exists(parsed, mac.key)); assertTrue(exists(parsed, linuxAndMac.key)); - assertTrue(!exists(parsed, linux64.key)); + assertFalse(exists(parsed, linux64.key)); assertTrue(exists(parsed, linux64s.key)); - assertTrue(!exists(parsed, mac64.key)); - assertTrue(!exists(parsed, win64.key)); + assertFalse(exists(parsed, mac64.key)); + assertFalse(exists(parsed, win64.key)); assertTrue(exists(parsed, notWin.key)); opts.osname = "mac os x"; opts.osarch = "x86_64"; parsed = Config.parsePairs(toReader(pairs), opts); - assertTrue(!exists(parsed, linux.key)); + assertFalse(exists(parsed, linux.key)); assertTrue(exists(parsed, mac.key)); assertTrue(exists(parsed, linuxAndMac.key)); - assertTrue(!exists(parsed, linux64.key)); - assertTrue(!exists(parsed, linux64s.key)); + assertFalse(exists(parsed, linux64.key)); + assertFalse(exists(parsed, linux64s.key)); assertTrue(exists(parsed, mac64.key)); - assertTrue(!exists(parsed, win64.key)); + assertFalse(exists(parsed, win64.key)); assertTrue(exists(parsed, notWin.key)); opts.osname = "windows"; opts.osarch = "i386"; parsed = Config.parsePairs(toReader(pairs), opts); - assertTrue(!exists(parsed, linux.key)); - assertTrue(!exists(parsed, mac.key)); - assertTrue(!exists(parsed, linuxAndMac.key)); - assertTrue(!exists(parsed, linux64.key)); - assertTrue(!exists(parsed, linux64s.key)); - assertTrue(!exists(parsed, mac64.key)); - assertTrue(!exists(parsed, win64.key)); - assertTrue(!exists(parsed, notWin.key)); + assertFalse(exists(parsed, linux.key)); + assertFalse(exists(parsed, mac.key)); + assertFalse(exists(parsed, linuxAndMac.key)); + assertFalse(exists(parsed, linux64.key)); + assertFalse(exists(parsed, linux64s.key)); + assertFalse(exists(parsed, mac64.key)); + assertFalse(exists(parsed, win64.key)); + assertFalse(exists(parsed, notWin.key)); opts.osarch = "x86_64"; parsed = Config.parsePairs(toReader(pairs), opts); - assertTrue(!exists(parsed, linux.key)); - assertTrue(!exists(parsed, mac.key)); - assertTrue(!exists(parsed, linuxAndMac.key)); - assertTrue(!exists(parsed, linux64.key)); - assertTrue(!exists(parsed, linux64s.key)); - assertTrue(!exists(parsed, mac64.key)); + assertFalse(exists(parsed, linux.key)); + assertFalse(exists(parsed, mac.key)); + assertFalse(exists(parsed, linuxAndMac.key)); + assertFalse(exists(parsed, linux64.key)); + assertFalse(exists(parsed, linux64s.key)); + assertFalse(exists(parsed, mac64.key)); assertTrue(exists(parsed, win64.key)); - assertTrue(!exists(parsed, notWin.key)); + assertFalse(exists(parsed, notWin.key)); opts.osarch = "amd64"; parsed = Config.parsePairs(toReader(pairs), opts); - assertTrue(!exists(parsed, linux.key)); - assertTrue(!exists(parsed, mac.key)); - assertTrue(!exists(parsed, linuxAndMac.key)); - assertTrue(!exists(parsed, linux64.key)); - assertTrue(!exists(parsed, linux64s.key)); - assertTrue(!exists(parsed, mac64.key)); - assertTrue(!exists(parsed, win64.key)); - assertTrue(!exists(parsed, notWin.key)); + assertFalse(exists(parsed, linux.key)); + assertFalse(exists(parsed, mac.key)); + assertFalse(exists(parsed, linuxAndMac.key)); + assertFalse(exists(parsed, linux64.key)); + assertFalse(exists(parsed, linux64s.key)); + assertFalse(exists(parsed, mac64.key)); + assertFalse(exists(parsed, win64.key)); + assertFalse(exists(parsed, notWin.key)); } protected static boolean exists (List pairs, String key) @@ -167,5 +167,5 @@ public class ConfigTest return _rando.nextBoolean() ? " " : ""; } - protected static Random _rando = new Random(); + protected static final Random _rando = new Random(); } diff --git a/core/src/test/java/com/threerings/getdown/util/FileUtilTest.java b/core/src/test/java/com/threerings/getdown/util/FileUtilTest.java index cfd53a2..41de5ac 100644 --- a/core/src/test/java/com/threerings/getdown/util/FileUtilTest.java +++ b/core/src/test/java/com/threerings/getdown/util/FileUtilTest.java @@ -56,5 +56,5 @@ public class FileUtilTest assertEquals(3, visitor.fileCount); } - @Rule public TemporaryFolder _folder = new TemporaryFolder(); + @Rule public final TemporaryFolder _folder = new TemporaryFolder(); } diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java b/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java index 4bd9f90..a282a1e 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java @@ -80,7 +80,7 @@ public final class AbortPanel extends JFrame } /** Used to look up localized messages. */ - protected String get (String key) + private String get(String key) { // if this string is tainted, we don't translate it, instead we // simply remove the taint character and return it to the caller @@ -95,6 +95,6 @@ public final class AbortPanel extends JFrame } } - protected Getdown _getdown; - protected ResourceBundle _msgs; + private final Getdown _getdown; + private final ResourceBundle _msgs; } 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 59f084d..517abf8 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -679,7 +679,7 @@ public abstract class Getdown /** The last percentage at which we checked for another getdown running, or -1 for not * having checked at all. */ - protected int _lastCheck = -1; + private int _lastCheck = -1; }; if (!dl.download(resources, _app.maxConcurrentDownloads())) { // if we aborted due to detecting another getdown running, we want to report here @@ -1113,13 +1113,13 @@ public abstract class Getdown } /** Used to pass progress on to our user interface. */ - protected ProgressObserver _progobs = new ProgressObserver() { + protected final ProgressObserver _progobs = new ProgressObserver() { public void progress (int percent) { setStatusAsync(null, stepToGlobalPercent(percent), -1L, false); } }; - protected Application _app; + protected final Application _app; protected Application.UpdateInterface _ifc = new Application.UpdateInterface(Config.EMPTY); protected ResourceBundle _msgs; @@ -1134,7 +1134,7 @@ public abstract class Getdown protected boolean _silent; protected boolean _launchInSilent; protected boolean _noUpdate; - protected long _startup; + protected final long _startup; protected Set _toInstallResources; protected boolean _readyToInstall; diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index 3859f6a..a00a4be 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; @@ -54,9 +55,8 @@ public class GetdownApp * Runs Getdown as an application, using the arguments supplie as {@code argv}. * @return the {@code Getdown} instance that is running. {@link Getdown#run} will have been * called on it. - * @throws Exception if anything goes wrong starting Getdown. */ - public static Getdown start (String[] argv) throws Exception { + public static Getdown start (String[] argv) { List notes = new ArrayList<>(); EnvConfig envc = EnvConfig.create(argv, notes); if (envc == null) { @@ -70,7 +70,7 @@ public class GetdownApp File logFile = new File(envc.appDir, "launcher.log"); try { PrintStream logOut = new PrintStream( - new BufferedOutputStream(new FileOutputStream(logFile)), true); + new BufferedOutputStream(Files.newOutputStream(logFile.toPath())), true); System.setOut(logOut); System.setErr(logOut); } catch (IOException ioe) { @@ -244,7 +244,7 @@ public class GetdownApp }); } - protected JFrame _frame; + private JFrame _frame; }; Getdown.run(getdown); return getdown; diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java index 5f18896..1e21e4f 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java @@ -156,7 +156,7 @@ public final class ProxyPanel extends JPanel implements ActionListener } /** Used to look up localized messages. */ - protected String get (String key) + private String get(String key) { // if this string is tainted, we don't translate it, instead we // simply remove the taint character and return it to the caller @@ -188,18 +188,18 @@ public final class ProxyPanel extends JPanel implements ActionListener } } - protected static Dimension clampWidth (Dimension dim, int minWidth) { + private static Dimension clampWidth(Dimension dim, int minWidth) { dim.width = Math.max(dim.width, minWidth); return dim; } - protected final Getdown _getdown; - protected final ResourceBundle _msgs; - protected final boolean _updateAuth; + private final Getdown _getdown; + private final ResourceBundle _msgs; + private final boolean _updateAuth; - protected JTextField _host; - protected JTextField _port; - protected JCheckBox _useAuth; - protected JTextField _username; - protected JPasswordField _password; + private final JTextField _host; + private final JTextField _port; + private final JCheckBox _useAuth; + private final JTextField _username; + private final JPasswordField _password; } diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java index ccacb2e..7b69cba 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java @@ -20,6 +20,7 @@ import java.net.Proxy; import java.net.URL; import java.net.URLConnection; import java.net.UnknownHostException; +import java.nio.file.Files; import java.util.Iterator; import java.util.ServiceLoader; @@ -188,7 +189,7 @@ public final class ProxyUtil { public static void saveProxy (Application app, String host, String port) { File pfile = app.getLocalPath("proxy.txt"); - try (PrintStream pout = new PrintStream(new FileOutputStream(pfile))) { + try (PrintStream pout = new PrintStream(Files.newOutputStream(pfile.toPath()))) { if (!StringUtil.isBlank(host)) { pout.println("host = " + host); } @@ -218,7 +219,7 @@ public final class ProxyUtil { log.info("Using no proxy"); app.conn = new Connector(); } else { - int pp = StringUtil.isBlank(port) ? 80 : Integer.valueOf(port); + int pp = StringUtil.isBlank(port) ? 80 : Integer.parseInt(port); log.info("Using proxy", "host", host, "port", pp, "haveCreds", haveCreds); app.conn = new Connector(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, pp))); } @@ -289,6 +290,6 @@ public final class ProxyUtil { } } - protected static final String PROXY_REGISTRY = + private static final String PROXY_REGISTRY = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; } diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/RotatingBackgrounds.java b/launcher/src/main/java/com/threerings/getdown/launcher/RotatingBackgrounds.java index d64e5f0..762153d 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/RotatingBackgrounds.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/RotatingBackgrounds.java @@ -106,7 +106,7 @@ public final class RotatingBackgrounds return images.length; } - protected void makeEmpty () + private void makeEmpty() { percentages = new int[] {}; minDisplayTime = new int[] {}; @@ -114,19 +114,19 @@ public final class RotatingBackgrounds } /** Time at which the currently displayed image was first displayed in millis. */ - protected long currentDisplayStart; + private long currentDisplayStart; /** The index of the currently displayed image or -1 if we haven't displayed any. */ - protected int current = -1; + private int current = -1; - protected Image[] images; + private Image[] images; /** The image to display if getdown has failed due to an error. */ - protected Image errorImage; + private Image errorImage; /** Percentage at which each image should be displayed. */ - protected int[] percentages; + private int[] percentages; /** Time to show each image in seconds. */ - protected int[] minDisplayTime; + private int[] minDisplayTime; } diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java b/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java index 197dc91..795cc4b 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java @@ -260,15 +260,15 @@ public final class StatusPanel extends JComponent /** * Update the status label. */ - protected void updateStatusLabel () + private void updateStatusLabel() { - String status = _status; + StringBuilder status = new StringBuilder(_status); if (!_displayError) { for (int ii = 0; ii < _statusDots; ii++) { - status += " ."; + status.append(" ."); } } - _newlab = createLabel(status, new Color(_ifc.statusText, true)); + _newlab = createLabel(status.toString(), new Color(_ifc.statusText, true)); // set the width of the label to the width specified int width = _ifc.status.width; if (width == 0) { @@ -285,7 +285,7 @@ public final class StatusPanel extends JComponent /** * Get the y coordinate of a label in the status area. */ - protected int getStatusY (Label label) + private int getStatusY(Label label) { // if the status region is higher than the progress region, we // want to align the label with the bottom of its region @@ -299,7 +299,7 @@ public final class StatusPanel extends JComponent /** * Create a label, taking care of adding the shadow if needed. */ - protected Label createLabel (String text, Color color) + private Label createLabel(String text, Color color) { Label label = new Label(text, color, FONT); if (_ifc.textShadow != 0) { @@ -310,7 +310,7 @@ public final class StatusPanel extends JComponent } /** Used by {@link #setStatus}. */ - protected String xlate (String compoundKey) + private String xlate(String compoundKey) { // to be more efficient about creating unnecessary objects, we // do some checking before splitting @@ -337,7 +337,7 @@ public final class StatusPanel extends JComponent } /** Used by {@link #setStatus}. */ - protected String get (String key, String[] args) + private String get(String key, String[] args) { String msg = get(key); if (msg != null) return MessageFormat.format(MessageUtil.escape(msg), (Object[])args); @@ -345,7 +345,7 @@ public final class StatusPanel extends JComponent } /** Used by {@link #setStatus}, and {@link #setProgress}. */ - protected String get (String key) + private String get(String key) { // if we have no _msgs that means we're probably recovering from a // failure to load the translation messages in the first place, so @@ -368,26 +368,26 @@ public final class StatusPanel extends JComponent } } - protected Image _barimg; - protected RotatingBackgrounds _bg; - protected Dimension _psize; + private Image _barimg; + private RotatingBackgrounds _bg; + private Dimension _psize; - protected ResourceBundle _msgs; + private final ResourceBundle _msgs; - protected int _progress = -1; - protected String _status; - protected int _statusDots = 1; - protected boolean _displayError; - protected Label _label, _newlab; - protected Label _plabel, _newplab; - protected Label _rlabel, _newrlab; + private int _progress = -1; + private String _status; + private int _statusDots = 1; + private boolean _displayError; + private Label _label, _newlab; + private Label _plabel, _newplab; + private Label _rlabel, _newrlab; - protected UpdateInterface _ifc; - protected Timer _timer; + private UpdateInterface _ifc; + private final Timer _timer; - protected long[] _remain = new long[4]; - protected int _ridx; - protected Throttle _rthrottle = new Throttle(1, 1000L); + private final long[] _remain = new long[4]; + private int _ridx; + private Throttle _rthrottle = new Throttle(1, 1000L); - protected static final Font FONT = new Font("SansSerif", Font.BOLD, 12); + static final Font FONT = new Font("SansSerif", Font.BOLD, 12); }