Skip to content

Commit

Permalink
Converted to Guava as our main java library, enabled ProGuard on debu…
Browse files Browse the repository at this point in the history
…g builds (so we can actually use Guava), and removed a bunch of out-dated dependencies.
  • Loading branch information
codeka committed Oct 12, 2014
1 parent d93af4b commit 01cc975
Show file tree
Hide file tree
Showing 128 changed files with 536 additions and 733 deletions.
7 changes: 2 additions & 5 deletions client/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/planet-render"/>
<classpathentry exported="true" kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry exported="true" kind="lib" path="libs/validation-api-1.0.0.GA.jar"/>
<classpathentry exported="true" kind="lib" path="libs/commons-codec-1.4.jar"/>
<classpathentry exported="true" kind="lib" path="libs/commons-io-2.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/commons-lang3-3.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/json_simple-1.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/joda-time-2.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/commons-collections-3.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/gcm.jar"/>
<classpathentry exported="true" kind="lib" path="libs/protobuf-java-2.5.0.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry exported="true" kind="lib" path="libs/joda-convert-1.2.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.jdt.annotation_1.1.0.v20130513-1648.jar"/>
<classpathentry kind="lib" path="libs/gson-2.1.jar"/>
<classpathentry kind="lib" path="libs/guava-18.0.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion client/assets/warworlds.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ iap.reset_empire_big=reset_empire_big
iap.decorate_empire=decorate_empire

# When true, adds the debug realms and a few other debugging options as well.
debug=false
debug=true

# URL of the "announcements" RSS feed that we display in the welcome activity.
#welcome.rss=http://www.war-worlds.com/forum/announcements/rss
Expand Down
8 changes: 8 additions & 0 deletions client/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@

<import file="${sdk.dir}/tools/ant/build.xml" />

<target name="-debug-obfuscation-check">
<!-- enable proguard even in debug mode -->
<property name="proguard.enabled" value="true"/>

<!-- Secondary dx input (jar files) is empty since all the jar files will be in the obfuscated jar -->
<path id="out.dex.jar.input.ref" />
</target>

<target name="-pre-build">
<if>
<condition><equals arg1="${build.target}" arg2="release" /></condition>
Expand Down
1 change: 0 additions & 1 deletion client/libs/commons-codec-1.4.jar

This file was deleted.

1 change: 0 additions & 1 deletion client/libs/commons-collections-3.2.1.jar

This file was deleted.

1 change: 0 additions & 1 deletion client/libs/commons-io-2.1.jar

This file was deleted.

1 change: 0 additions & 1 deletion client/libs/commons-lang3-3.1.jar

This file was deleted.

Binary file added client/libs/gson-2.1.jar
Binary file not shown.
Binary file added client/libs/guava-18.0.jar
Binary file not shown.
1 change: 0 additions & 1 deletion client/libs/joda-convert-1.2.jar

This file was deleted.

Binary file added client/libs/joda-convert-1.2.jar
Binary file not shown.
1 change: 0 additions & 1 deletion client/libs/joda-time-2.1.jar

This file was deleted.

Binary file added client/libs/joda-time-2.1.jar
Binary file not shown.
1 change: 0 additions & 1 deletion client/libs/json_simple-1.1.jar

This file was deleted.

1 change: 0 additions & 1 deletion client/libs/protobuf-java-2.5.0.jar

This file was deleted.

Binary file added client/libs/protobuf-java-2.5.0.jar
Binary file not shown.
8 changes: 5 additions & 3 deletions client/proguard-project.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html


# keep source file line numbers at least (they're very useful!)
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
Expand All @@ -23,8 +22,11 @@
@au.com.codeka.warworlds.eventbus.EventHandler <methods>;
}

# This references lots of classes for some reason.
-dontwarn org.apache.commons.collections.BeanMap
# The following are required for guava
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn sun.misc.Unsafe
#-dontwarn com.google.common.collect.MinMaxPriorityQueue

# The following are required by the Google Play Services library.
-keep class * extends java.util.ListResourceBundle {
Expand Down
6 changes: 3 additions & 3 deletions client/src/au/com/codeka/BackgroundRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang3.exception.ExceptionUtils;

import android.os.Handler;
import android.os.Message;
import android.os.Process;
import au.com.codeka.common.Log;

import com.google.common.base.Throwables;

/**
* This class is similar to AsyncTask, except we get to control all the parameters.
*/
Expand Down Expand Up @@ -55,7 +55,7 @@ public Thread newThread(Runnable r) {

public BackgroundRunner() {
if (sThreadDebug) {
mCreatorStackTrace = ExceptionUtils.getStackTrace(new Throwable());
mCreatorStackTrace = Throwables.getStackTraceAsString(new Throwable());
}

mWorker = new Callable<Result>() {
Expand Down
7 changes: 4 additions & 3 deletions client/src/au/com/codeka/warworlds/api/ApiClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.com.codeka.warworlds.api;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -10,7 +11,6 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.entity.ByteArrayEntity;
Expand All @@ -19,6 +19,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.google.common.io.CharStreams;
import com.google.protobuf.Message;

/**
Expand All @@ -42,8 +43,8 @@ public static String getString(String url) throws ApiException {
builderFactory.setValidating(false);

try {
InputStream ins = res.getResponse().getEntity().getContent();
return IOUtils.toString(ins, "utf-8");
return CharStreams.toString(new InputStreamReader(
res.getResponse().getEntity().getContent(), "utf-8"));
} catch (Exception e) {
throw new ApiException(e);
} finally {
Expand Down
8 changes: 4 additions & 4 deletions client/src/au/com/codeka/warworlds/ctrl/FleetListRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.Locale;

import org.apache.commons.lang3.StringUtils;

import android.content.Context;
import android.graphics.Bitmap;
import android.text.Html;
Expand Down Expand Up @@ -35,6 +33,8 @@
import au.com.codeka.warworlds.model.StarManager;
import au.com.codeka.warworlds.model.StarSummary;

import com.google.common.base.CaseFormat;

public class FleetListRow extends RelativeLayout {
private Context context;
private Fleet fleet;
Expand Down Expand Up @@ -184,8 +184,8 @@ private static void populateFleetDestinationRow(Context context, LinearLayout ro

public static void populateFleetStanceRow(Context context, LinearLayout row, Fleet fleet) {
String text = String.format("%s (stance: %s)",
StringUtils.capitalize(fleet.getState().toString().toLowerCase(Locale.ENGLISH)),
StringUtils.capitalize(fleet.getStance().toString().toLowerCase(Locale.ENGLISH)));
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, fleet.getState().toString()),
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, fleet.getStance().toString()));
addTextToRow(context, row, text, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.apache.commons.lang3.StringUtils;

import android.content.Context;
import android.graphics.Color;
Expand All @@ -24,8 +21,10 @@
import au.com.codeka.warworlds.R;
import au.com.codeka.warworlds.ctrl.FleetList.OnFleetActionListener;
import au.com.codeka.warworlds.model.Fleet;
import au.com.codeka.warworlds.model.Star;
import au.com.codeka.warworlds.model.FleetUpgrade.BoostFleetUpgrade;
import au.com.codeka.warworlds.model.Star;

import com.google.common.base.CaseFormat;

/** Control displayed below a fleet list with controls to interact with the selected fleet. */
public class FleetSelectionPanel extends FrameLayout {
Expand Down Expand Up @@ -251,7 +250,7 @@ private TextView getCommonView(int position, View convertView, ViewGroup parent)
}

Fleet.Stance value = mValues[position];
view.setText(StringUtils.capitalize(value.toString().toLowerCase(Locale.ENGLISH)));
view.setText(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, value.toString()));
return view;
}
}
Expand Down
15 changes: 5 additions & 10 deletions client/src/au/com/codeka/warworlds/ctrl/TransparentWebView.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package au.com.codeka.warworlds.ctrl;

import java.io.InputStream;
import java.io.StringWriter;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.io.IOUtils;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Color;
Expand All @@ -15,6 +13,8 @@
import android.view.View;
import android.webkit.WebView;

import com.google.common.io.CharStreams;

/**
* A \c WebView with a transparent background. It's a little tricky and the method
* for getting a transparent background seems to be totally different depending on
Expand Down Expand Up @@ -49,17 +49,12 @@ public void loadHtml(String templateFileName, String html) {
loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
}

/**
* Loads a template HTML file from within your assets folder.
*/
/** Loads a template HTML file from within your assets folder. */
public static String getHtmlFile(Context context, String fileName) {
try {
AssetManager assetManager = context.getAssets();
InputStream is = assetManager.open(fileName);

StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
return writer.toString();
return CharStreams.toString(new InputStreamReader(is, "utf-8"));
} catch (Exception e) {
// any errors (shouldn't be...) and we'll return a "blank" template.
return "";
Expand Down
10 changes: 5 additions & 5 deletions client/src/au/com/codeka/warworlds/model/FleetUpgrade.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package au.com.codeka.warworlds.model;

import org.json.simple.JSONObject;

import au.com.codeka.common.model.BaseFleet;
import au.com.codeka.common.model.BaseFleetUpgrade;
import au.com.codeka.common.protobuf.Messages;

import com.google.gson.JsonObject;

public class FleetUpgrade extends BaseFleetUpgrade {

/** This is a specific upgrade for the 'boost' upgrade. */
Expand All @@ -20,9 +20,9 @@ public boolean isBoosting() {
public void fromProtocolBuffer(BaseFleet fleet, Messages.FleetUpgrade pb) {
super.fromProtocolBuffer(fleet, pb);

JSONObject extra = getExtraJson();
if (extra != null && extra.containsKey("is_boosting")) {
mIsBoosting = (Boolean) extra.get("is_boosting");
JsonObject extra = getExtraJson();
if (extra != null && extra.has("is_boosting")) {
mIsBoosting = extra.get("is_boosting").getAsBoolean();
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions common/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<classpathentry kind="lib" path="libs/protobuf-java-2.5.0.jar"/>
<classpathentry kind="lib" path="libs/joda-convert-1.2.jar"/>
<classpathentry kind="lib" path="libs/joda-time-2.1.jar"/>
<classpathentry kind="lib" path="libs/commons-codec-1.4.jar"/>
<classpathentry kind="lib" path="libs/commons-collections-3.2.1.jar"/>
<classpathentry kind="lib" path="libs/commons-io-2.1.jar"/>
<classpathentry kind="lib" path="libs/commons-lang3-3.1.jar"/>
<classpathentry kind="lib" path="libs/json_simple-1.1.jar"/>
<classpathentry kind="lib" path="libs/gson-2.1.jar"/>
<classpathentry kind="lib" path="libs/guava-18.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file removed common/libs/commons-codec-1.4.jar
Binary file not shown.
Binary file removed common/libs/commons-collections-3.2.1.jar
Binary file not shown.
Binary file removed common/libs/commons-io-2.1.jar
Binary file not shown.
Binary file removed common/libs/commons-lang3-3.1.jar
Binary file not shown.
Binary file added common/libs/gson-2.1.jar
Binary file not shown.
Binary file added common/libs/guava-18.0.jar
Binary file not shown.
Binary file removed common/libs/jregex1.2_01.jar
Binary file not shown.
Binary file removed common/libs/json_simple-1.1.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions common/src/au/com/codeka/common/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public void debug(String fmt, Object... args) {
mImpl.write(mTag, DEBUG, formatMsg(fmt, args));
}

public boolean isDebugEnabled() {
return mImpl != null && mImpl.isLoggable(mTag, DEBUG);
}

/**
* Formats the given message. If the last argument is an exception, we'll append
* the exception to the end of the message.
Expand Down
5 changes: 3 additions & 2 deletions common/src/au/com/codeka/common/model/BaseChatMessage.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package au.com.codeka.common.model;

import org.apache.commons.lang3.StringEscapeUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import com.google.common.html.HtmlEscapers;

import au.com.codeka.common.protobuf.Messages;

public class BaseChatMessage {
Expand Down Expand Up @@ -102,7 +103,7 @@ public void fromProtocolBuffer(Messages.ChatMessage pb) {
public void toProtocolBuffer(Messages.ChatMessage.Builder pb, boolean encodeHtml) {
pb.setId(mID);
if (encodeHtml) {
pb.setMessage(StringEscapeUtils.escapeHtml4(mMessage));
pb.setMessage(HtmlEscapers.htmlEscaper().escape(mMessage));
} else {
pb.setMessage(mMessage);
}
Expand Down
8 changes: 4 additions & 4 deletions common/src/au/com/codeka/common/model/BaseFleetUpgrade.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package au.com.codeka.common.model;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import au.com.codeka.common.protobuf.Messages;

Expand All @@ -23,13 +23,13 @@ public int getStarID() {
public String getExtra() {
return mExtra;
}
public JSONObject getExtraJson() {
public JsonObject getExtraJson() {
if (mExtra == null) {
return null;
}

try {
return (JSONObject) new JSONParser().parse(mExtra);
return new JsonParser().parse(mExtra).getAsJsonObject();
} catch (Exception e) {
return null;
}
Expand Down
7 changes: 3 additions & 4 deletions common/src/au/com/codeka/common/protoformat/PbFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.codec.binary.Base64;

import com.google.common.io.BaseEncoding;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;
Expand Down Expand Up @@ -1093,7 +1092,7 @@ private Object handleObject(Tokenizer tokenizer,
* sequences.
*/
static String escapeBytes(ByteString input) {
return Base64.encodeBase64String(input.toByteArray()).replace("\r\n", "");
return BaseEncoding.base64().encode(input.toByteArray());
}

/**
Expand All @@ -1102,7 +1101,7 @@ static String escapeBytes(ByteString input) {
* "\x") are also recognized.
*/
static ByteString unescapeBytes(CharSequence input) {
return ByteString.copyFrom(Base64.decodeBase64(input.toString()));
return ByteString.copyFrom(BaseEncoding.base64().decode(input.toString()));
}

/**
Expand Down
Binary file added control-field/out/control-field.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions driver/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<classpathentry kind="lib" path="libs/junit.jar"/>
<classpathentry kind="lib" path="libs/servlet.jar"/>
<classpathentry kind="lib" path="libs/swtgraphics2d.jar"/>
<classpathentry kind="lib" path="/common/libs/httpclient-4.2.2.jar"/>
<classpathentry kind="lib" path="/common/libs/httpcore-4.2.2.jar"/>
<classpathentry kind="lib" path="/common/libs/jcl-over-slf4j-1.7.5.jar"/>
<classpathentry kind="lib" path="/common/libs/protobuf-java-2.5.0.jar"/>
<classpathentry kind="lib" path="libs/httpclient-4.2.2.jar"/>
<classpathentry kind="lib" path="libs/httpcore-4.2.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion planet-render-android/libs/slf4j-api-1.7.5.jar

This file was deleted.

Binary file added planet-render/out/planet-render.jar
Binary file not shown.
Loading

0 comments on commit 01cc975

Please sign in to comment.