convert getdown to being completely type-safe, yarr.
This commit is contained in:
@@ -43,7 +43,9 @@
|
||||
<javac srcdir="${src.dir}" destdir="${deploy.dir}/classes"
|
||||
debug="on" optimize="off" deprecation="on"
|
||||
classpathref="clazzpath" includeAntRuntime="no"
|
||||
source="1.5" target="1.5"/>
|
||||
source="1.5" target="1.5">
|
||||
<compilerarg value="-Xlint:unchecked"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- build the javadoc documentation -->
|
||||
|
||||
@@ -123,6 +123,7 @@ public class Application
|
||||
try {
|
||||
return createResource(CONFIG_FILE, false);
|
||||
} catch (Exception e) {
|
||||
Thread.dumpStack();
|
||||
throw new RuntimeException("Invalid appbase '" + _vappbase + "'.");
|
||||
}
|
||||
}
|
||||
@@ -131,7 +132,7 @@ public class Application
|
||||
* Returns a list of the code {@link Resource} objects used by this
|
||||
* application.
|
||||
*/
|
||||
public List getCodeResources ()
|
||||
public List<Resource> getCodeResources ()
|
||||
{
|
||||
return _codes;
|
||||
}
|
||||
@@ -140,7 +141,7 @@ public class Application
|
||||
* Returns a list of the non-code {@link Resource} objects used by
|
||||
* this application.
|
||||
*/
|
||||
public List getResources ()
|
||||
public List<Resource> getResources ()
|
||||
{
|
||||
return _resources;
|
||||
}
|
||||
@@ -188,7 +189,7 @@ public class Application
|
||||
throws IOException
|
||||
{
|
||||
// parse our configuration file
|
||||
HashMap cdata = null;
|
||||
HashMap<String, Object> cdata = null;
|
||||
try {
|
||||
cdata = ConfigUtil.parseConfig(_config, checkPlatform);
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
@@ -319,9 +320,10 @@ public class Application
|
||||
File file = getLocalPath("extra.txt");
|
||||
if (file.exists()) {
|
||||
try {
|
||||
List args = ConfigUtil.parsePairs(file, false);
|
||||
for (Iterator iter = args.iterator(); iter.hasNext(); ) {
|
||||
String[] pair = (String[])iter.next();
|
||||
List<String[]> args = ConfigUtil.parsePairs(file, false);
|
||||
for (Iterator<String[]> iter = args.iterator();
|
||||
iter.hasNext();) {
|
||||
String[] pair = iter.next();
|
||||
_jvmargs.add(pair[0] + "=" + pair[1]);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
@@ -423,15 +425,15 @@ public class Application
|
||||
{
|
||||
// create our classpath
|
||||
StringBuffer cpbuf = new StringBuffer();
|
||||
for (Iterator iter = _codes.iterator(); iter.hasNext(); ) {
|
||||
for (Iterator<Resource> iter = _codes.iterator(); iter.hasNext(); ) {
|
||||
if (cpbuf.length() > 0) {
|
||||
cpbuf.append(File.pathSeparator);
|
||||
}
|
||||
Resource rsrc = (Resource)iter.next();
|
||||
Resource rsrc = iter.next();
|
||||
cpbuf.append(rsrc.getLocal().getAbsolutePath());
|
||||
}
|
||||
|
||||
ArrayList args = new ArrayList();
|
||||
ArrayList<String> args = new ArrayList<String>();
|
||||
|
||||
// reconstruct the path to the JVM
|
||||
args.add(LaunchUtil.getJVMPath(_windebug));
|
||||
@@ -468,16 +470,16 @@ public class Application
|
||||
}
|
||||
|
||||
// add the JVM arguments
|
||||
for (Iterator iter = _jvmargs.iterator(); iter.hasNext(); ) {
|
||||
args.add(processArg((String)iter.next()));
|
||||
for (Iterator<String> iter = _jvmargs.iterator(); iter.hasNext(); ) {
|
||||
args.add(processArg(iter.next()));
|
||||
}
|
||||
|
||||
// add the application class name
|
||||
args.add(_class);
|
||||
|
||||
// finally add the application arguments
|
||||
for (Iterator iter = _appargs.iterator(); iter.hasNext(); ) {
|
||||
args.add(processArg((String)iter.next()));
|
||||
for (Iterator<String> iter = _appargs.iterator(); iter.hasNext(); ) {
|
||||
args.add(processArg(iter.next()));
|
||||
}
|
||||
|
||||
String[] sargs = new String[args.size()];
|
||||
@@ -618,20 +620,21 @@ public class Application
|
||||
*/
|
||||
public List verifyResources (ProgressObserver obs)
|
||||
{
|
||||
ArrayList rsrcs = new ArrayList(), failures = new ArrayList();
|
||||
ArrayList<Resource> rsrcs = new ArrayList<Resource>();
|
||||
ArrayList<Resource> failures = new ArrayList<Resource>();
|
||||
rsrcs.addAll(_codes);
|
||||
rsrcs.addAll(_resources);
|
||||
|
||||
// total up the file size of the resources to validate
|
||||
long totalSize = 0L;
|
||||
for (Iterator iter = rsrcs.iterator(); iter.hasNext(); ) {
|
||||
Resource rsrc = (Resource)iter.next();
|
||||
for (Iterator<Resource> iter = rsrcs.iterator(); iter.hasNext(); ) {
|
||||
Resource rsrc = iter.next();
|
||||
totalSize += rsrc.getLocal().length();
|
||||
}
|
||||
|
||||
MetaProgressObserver mpobs = new MetaProgressObserver(obs, totalSize);
|
||||
for (Iterator iter = rsrcs.iterator(); iter.hasNext(); ) {
|
||||
Resource rsrc = (Resource)iter.next();
|
||||
for (Iterator<Resource> iter = rsrcs.iterator(); iter.hasNext(); ) {
|
||||
Resource rsrc = iter.next();
|
||||
mpobs.startElement(rsrc.getLocal().length());
|
||||
|
||||
if (rsrc.isMarkedValid()) {
|
||||
@@ -684,10 +687,10 @@ public class Application
|
||||
|
||||
/** Clears all validation marker files for the resources in the
|
||||
* supplied iterator. */
|
||||
protected void clearValidationMarkers (Iterator iter)
|
||||
protected void clearValidationMarkers (Iterator<Resource> iter)
|
||||
{
|
||||
while (iter.hasNext()) {
|
||||
((Resource)iter.next()).clearMarker();
|
||||
iter.next().clearMarker();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,7 +764,8 @@ public class Application
|
||||
}
|
||||
|
||||
/** Used to parse rectangle specifications from the config file. */
|
||||
protected Rectangle parseRect (HashMap cdata, String name, Rectangle def)
|
||||
protected Rectangle parseRect (HashMap<String, Object> cdata,
|
||||
String name, Rectangle def)
|
||||
{
|
||||
String value = (String)cdata.get(name);
|
||||
if (!StringUtil.isBlank(value)) {
|
||||
@@ -777,7 +781,8 @@ public class Application
|
||||
}
|
||||
|
||||
/** Used to parse color specifications from the config file. */
|
||||
protected Color parseColor (HashMap cdata, String name, Color def)
|
||||
protected Color parseColor (HashMap<String, Object> cdata, String name,
|
||||
Color def)
|
||||
{
|
||||
String value = (String)cdata.get(name);
|
||||
if (!StringUtil.isBlank(value)) {
|
||||
@@ -804,9 +809,9 @@ public class Application
|
||||
protected String _name;
|
||||
protected boolean _windebug;
|
||||
|
||||
protected ArrayList _codes = new ArrayList();
|
||||
protected ArrayList _resources = new ArrayList();
|
||||
protected ArrayList<Resource> _codes = new ArrayList<Resource>();
|
||||
protected ArrayList<Resource> _resources = new ArrayList<Resource>();
|
||||
|
||||
protected ArrayList _jvmargs = new ArrayList();
|
||||
protected ArrayList _appargs = new ArrayList();
|
||||
protected ArrayList<String> _jvmargs = new ArrayList<String>();
|
||||
protected ArrayList<String> _appargs = new ArrayList<String>();
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class Digest
|
||||
{
|
||||
try {
|
||||
String cmd5 = resource.computeDigest(getMessageDigest(), obs);
|
||||
String emd5 = (String)_digests.get(resource.getPath());
|
||||
String emd5 = _digests.get(resource.getPath());
|
||||
if (cmd5.equals(emd5)) {
|
||||
return true;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class Digest
|
||||
* Creates a digest file at the specified location using the supplied
|
||||
* list of resources.
|
||||
*/
|
||||
public static void createDigest (List resources, File output)
|
||||
public static void createDigest (List<Resource> resources, File output)
|
||||
throws IOException
|
||||
{
|
||||
MessageDigest md = getMessageDigest();
|
||||
@@ -111,8 +111,8 @@ public class Digest
|
||||
new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
|
||||
|
||||
// compute and append the MD5 digest of each resource in the list
|
||||
for (Iterator iter = resources.iterator(); iter.hasNext(); ) {
|
||||
Resource rsrc = (Resource)iter.next();
|
||||
for (Iterator<Resource> iter = resources.iterator(); iter.hasNext();) {
|
||||
Resource rsrc = iter.next();
|
||||
String path = rsrc.getPath();
|
||||
try {
|
||||
String digest = rsrc.computeDigest(md, null);
|
||||
@@ -152,6 +152,6 @@ public class Digest
|
||||
data.append(path).append(" = ").append(digest).append("\n");
|
||||
}
|
||||
|
||||
protected HashMap _digests = new HashMap();
|
||||
protected HashMap<String, String> _digests = new HashMap<String, String>();
|
||||
protected String _metaDigest = "";
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@@ -204,7 +203,8 @@ public class Resource
|
||||
if (target.getPath().endsWith(".jar")) {
|
||||
JarFile jar = new JarFile(target);
|
||||
try {
|
||||
SortableArrayList entries = new SortableArrayList();
|
||||
SortableArrayList<JarEntry> entries =
|
||||
new SortableArrayList<JarEntry>();
|
||||
CollectionUtil.addAll(entries, jar.entries());
|
||||
entries.sort(ENTRY_COMP);
|
||||
|
||||
@@ -272,10 +272,9 @@ public class Resource
|
||||
protected boolean _unpack;
|
||||
|
||||
/** Used to sort the entries in a jar file. */
|
||||
protected static final Comparator ENTRY_COMP = new Comparator() {
|
||||
public int compare (Object o1, Object o2) {
|
||||
JarEntry e1 = (JarEntry)o1;
|
||||
JarEntry e2 = (JarEntry)o2;
|
||||
protected static final Comparator<JarEntry> ENTRY_COMP =
|
||||
new Comparator<JarEntry>() {
|
||||
public int compare (JarEntry e1, JarEntry e2) {
|
||||
return e1.getName().compareTo(e2.getName());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,11 +12,9 @@ import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.samskivert.swing.GroupLayout;
|
||||
import com.samskivert.swing.Spacer;
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
@@ -26,7 +25,6 @@ import java.io.PrintStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -390,7 +388,7 @@ public class Getdown extends Thread
|
||||
final Resource patch = _app.getPatchResource();
|
||||
if (patch != null) {
|
||||
// download the patch file...
|
||||
ArrayList list = new ArrayList();
|
||||
ArrayList<Resource> list = new ArrayList<Resource>();
|
||||
list.add(patch);
|
||||
download(list);
|
||||
|
||||
@@ -495,8 +493,7 @@ public class Getdown extends Thread
|
||||
InputStream stderr = proc.getErrorStream();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(stderr));
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
while (reader.readLine() != null) {
|
||||
// nothing doing!
|
||||
}
|
||||
Log.info("Process exited: " + proc.waitFor());
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
package com.threerings.getdown.launcher;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
|
||||
package com.threerings.getdown.tools;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
@@ -75,13 +73,13 @@ public class Differ
|
||||
|
||||
Application oapp = new Application(ovdir, null);
|
||||
oapp.init(false);
|
||||
ArrayList orsrcs = new ArrayList();
|
||||
ArrayList<Resource> orsrcs = new ArrayList<Resource>();
|
||||
orsrcs.addAll(oapp.getCodeResources());
|
||||
orsrcs.addAll(oapp.getResources());
|
||||
|
||||
Application napp = new Application(nvdir, null);
|
||||
napp.init(false);
|
||||
ArrayList nrsrcs = new ArrayList();
|
||||
ArrayList<Resource> nrsrcs = new ArrayList<Resource>();
|
||||
nrsrcs.addAll(napp.getCodeResources());
|
||||
nrsrcs.addAll(napp.getResources());
|
||||
|
||||
@@ -95,7 +93,7 @@ public class Differ
|
||||
// for each file in the new application, it either already
|
||||
// exists in the old application, or it is new
|
||||
for (int ii = 0; ii < nrsrcs.size(); ii++) {
|
||||
Resource rsrc = (Resource)nrsrcs.get(ii);
|
||||
Resource rsrc = nrsrcs.get(ii);
|
||||
int oidx = orsrcs.indexOf(rsrc);
|
||||
Resource orsrc = (oidx == -1) ?
|
||||
null : (Resource)orsrcs.remove(oidx);
|
||||
@@ -147,7 +145,7 @@ public class Differ
|
||||
|
||||
// now any file remaining in orsrcs needs to be removed
|
||||
for (int ii = 0; ii < orsrcs.size(); ii++) {
|
||||
Resource rsrc = (Resource)orsrcs.get(ii);
|
||||
Resource rsrc = orsrcs.get(ii);
|
||||
// simply add an entry with the resource name and the
|
||||
// deletion suffix
|
||||
if (verbose) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.apache.tools.ant.Task;
|
||||
|
||||
import com.threerings.getdown.data.Application;
|
||||
import com.threerings.getdown.data.Digest;
|
||||
import com.threerings.getdown.data.Resource;
|
||||
|
||||
/**
|
||||
* An ant task used to create a <code>digest.txt</code> for a Getdown
|
||||
@@ -60,7 +61,7 @@ public class DigesterTask extends Task
|
||||
Application app = new Application(appdir, null);
|
||||
app.init(false);
|
||||
|
||||
ArrayList rsrcs = new ArrayList();
|
||||
ArrayList<Resource> rsrcs = new ArrayList<Resource>();
|
||||
rsrcs.add(app.getConfigResource());
|
||||
rsrcs.addAll(app.getCodeResources());
|
||||
rsrcs.addAll(app.getResources());
|
||||
|
||||
@@ -62,21 +62,21 @@ public class JarDiffPatcher
|
||||
JarOutputStream jos = new JarOutputStream(target);
|
||||
JarFile oldJar = new JarFile(oldFile);
|
||||
JarFile jarDiff = new JarFile(diffFile);
|
||||
Set ignoreSet = new HashSet();
|
||||
Set<String> ignoreSet = new HashSet<String>();
|
||||
|
||||
Map renameMap = new HashMap();
|
||||
Map<String, String> renameMap = new HashMap<String, String>();
|
||||
determineNameMapping(jarDiff, ignoreSet, renameMap);
|
||||
|
||||
// get all keys in renameMap
|
||||
Object[] keys = renameMap.keySet().toArray();
|
||||
|
||||
// Files to implicit move
|
||||
Set oldjarNames = new HashSet();
|
||||
Set<String> oldjarNames = new HashSet<String>();
|
||||
|
||||
Enumeration oldEntries = oldJar.entries();
|
||||
Enumeration<JarEntry> oldEntries = oldJar.entries();
|
||||
if (oldEntries != null) {
|
||||
while (oldEntries.hasMoreElements()) {
|
||||
oldjarNames.add(((JarEntry)oldEntries.nextElement()).getName());
|
||||
oldjarNames.add(oldEntries.nextElement().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,10 +94,10 @@ public class JarDiffPatcher
|
||||
size -= ignoreSet.size();
|
||||
|
||||
// Add content from JARDiff
|
||||
Enumeration entries = jarDiff.entries();
|
||||
Enumeration<JarEntry> entries = jarDiff.entries();
|
||||
if (entries != null) {
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = (JarEntry)entries.nextElement();
|
||||
JarEntry entry = entries.nextElement();
|
||||
if (!INDEX_NAME.equals(entry.getName())) {
|
||||
updateObserver(observer, currentEntry, size);
|
||||
currentEntry++;
|
||||
@@ -188,55 +188,56 @@ public class JarDiffPatcher
|
||||
}
|
||||
}
|
||||
|
||||
protected void determineNameMapping (JarFile jarDiff, Set ignoreSet,
|
||||
Map renameMap)
|
||||
protected void determineNameMapping (JarFile jarDiff, Set<String> ignoreSet,
|
||||
Map<String, String> renameMap)
|
||||
throws IOException
|
||||
{
|
||||
InputStream is = jarDiff.getInputStream(jarDiff.getEntry(INDEX_NAME));
|
||||
if (is == null) {
|
||||
throw new IOException("error.noindex");
|
||||
}
|
||||
throw new IOException("error.noindex");
|
||||
}
|
||||
|
||||
LineNumberReader indexReader =
|
||||
new LineNumberReader(new InputStreamReader(is, "UTF-8"));
|
||||
String line = indexReader.readLine();
|
||||
if (line == null || !line.equals(VERSION_HEADER)) {
|
||||
throw new IOException("jardiff.error.badheader: " + line);
|
||||
throw new IOException("jardiff.error.badheader: " + line);
|
||||
}
|
||||
|
||||
while ((line = indexReader.readLine()) != null) {
|
||||
if (line.startsWith(REMOVE_COMMAND)) {
|
||||
List sub = getSubpaths(
|
||||
List<String> sub = getSubpaths(
|
||||
line.substring(REMOVE_COMMAND.length()));
|
||||
|
||||
if (sub.size() != 1) {
|
||||
throw new IOException("error.badremove: " + line);
|
||||
throw new IOException("error.badremove: " + line);
|
||||
}
|
||||
ignoreSet.add(sub.get(0));
|
||||
|
||||
} else if (line.startsWith(MOVE_COMMAND)) {
|
||||
List sub = getSubpaths(line.substring(MOVE_COMMAND.length()));
|
||||
List<String> sub = getSubpaths(line.substring(
|
||||
MOVE_COMMAND.length()));
|
||||
if (sub.size() != 2) {
|
||||
throw new IOException("error.badmove: " + line);
|
||||
throw new IOException("error.badmove: " + line);
|
||||
}
|
||||
|
||||
// target of move should be the key
|
||||
// target of move should be the key
|
||||
if (renameMap.put(sub.get(1), sub.get(0)) != null) {
|
||||
// invalid move - should not move to same target twice
|
||||
throw new IOException("error.badmove: " + line);
|
||||
}
|
||||
// invalid move - should not move to same target twice
|
||||
throw new IOException("error.badmove: " + line);
|
||||
}
|
||||
|
||||
} else if (line.length() > 0) {
|
||||
throw new IOException("error.badcommand: " + line);
|
||||
throw new IOException("error.badcommand: " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List getSubpaths (String path)
|
||||
protected List<String> getSubpaths (String path)
|
||||
{
|
||||
int index = 0;
|
||||
int length = path.length();
|
||||
ArrayList sub = new ArrayList();
|
||||
ArrayList<String> sub = new ArrayList<String>();
|
||||
|
||||
while (index < length) {
|
||||
while (index < length && Character.isWhitespace
|
||||
|
||||
@@ -33,10 +33,10 @@ public class ConfigUtil
|
||||
* @return a list of <code>String[]</code> instances containing the
|
||||
* key/value pairs in the order they were parsed from the file.
|
||||
*/
|
||||
public static List parsePairs (File config, boolean checkPlatform)
|
||||
public static List<String[]> parsePairs (File config, boolean checkPlatform)
|
||||
throws IOException
|
||||
{
|
||||
ArrayList pairs = new ArrayList();
|
||||
ArrayList<String[]> pairs = new ArrayList<String[]>();
|
||||
String osname = System.getProperty("os.name");
|
||||
osname = (osname == null) ? "" : osname.toLowerCase();
|
||||
|
||||
@@ -118,12 +118,16 @@ public class ConfigUtil
|
||||
* of strings if more than one key/value pair in the config file was
|
||||
* associated with the same key.
|
||||
*/
|
||||
public static HashMap parseConfig (File config, boolean checkPlatform)
|
||||
public static HashMap<String, Object> parseConfig (File config,
|
||||
boolean checkPlatform)
|
||||
throws IOException
|
||||
{
|
||||
List pairs = parsePairs(config, checkPlatform);
|
||||
HashMap data = new HashMap();
|
||||
List<String[]> pairs = parsePairs(config, checkPlatform);
|
||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
// I thought that we could use HashMap<String, String[]> and put
|
||||
// new String[] {pair[1]} for the null case, but it mysteriously dies
|
||||
// on launch, so leaving it as HashMap<String, Object> for now
|
||||
for (Iterator iter = pairs.iterator(); iter.hasNext(); ) {
|
||||
String[] pair = (String[])iter.next();
|
||||
Object value = data.get(pair[0]);
|
||||
|
||||
Reference in New Issue
Block a user