Skip to content

Commit ff7cce3

Browse files
committed
Merge pull request #1285 from crankycoder/features/fdroid-buildhost
Features/fdroid buildhost
2 parents a069e2b + 06a6169 commit ff7cce3

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

android/build.gradle

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
def versionMajor = 1
33
def versionMinor = 5 // minor feature releases
44
def versionPatch = 0 // This should be bumped for hot fixes
5-
def buildHost = ""
6-
try
7-
{
8-
buildHost = InetAddress.localHost.hostName
9-
} catch (Exception ex) {
10-
// Some machines are ridiculous.
11-
buildHost = "localhost"
12-
}
13-
buildHost = buildHost.replaceAll("[^a-zA-Z0-9_-]","")
145

156
// Double check the versioning
167
for (versionPart in [versionPatch, versionMinor, versionMajor]) {
@@ -62,7 +53,7 @@ android {
6253
targetSdkVersion 18
6354

6455
versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100
65-
versionName "${versionMajor}.${versionMinor}.${versionPatch}.${buildHost}"
56+
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
6657

6758
buildConfigField "boolean", "ROBOLECTRIC", "false"
6859
buildConfigField "String", "MOZILLA_API_KEY", "\"\""

android/src/main/java/org/mozilla/mozstumbler/client/Updater.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,16 @@ public void onPostExecute(IResponse response) {
102102
return true;
103103
}
104104

105-
private String stripBuildHostName(String installedVersion) {
106-
return installedVersion.substring(0,installedVersion.lastIndexOf("."));
105+
String stripBuildHostName(String installedVersion) {
106+
// Some versions had the old buildhost stuff in there, we need
107+
// to strip out anything pase the 3rd integer part.
108+
String[] parts = installedVersion.split("\\.");
109+
if (parts.length < 3) {
110+
throw new RuntimeException("Unexpected version string: [" + installedVersion + "] parts:" + parts.length);
111+
}
112+
return parts[0] + "." + parts[1] + "." + parts[2];
107113
}
108114

109-
110115
private boolean isVersionGreaterThan(String a, String b) {
111116
if (a == null) {
112117
return false;
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
14
package org.mozilla.mozstumbler.client;
25

36
import org.junit.Before;
47
import org.junit.Test;
58
import org.junit.runner.RunWith;
6-
9+
import org.mozilla.mozstumbler.client.navdrawer.MainDrawerActivity;
710
import org.mozilla.mozstumbler.service.core.http.IHttpUtil;
811
import org.mozilla.mozstumbler.service.core.http.MockHttpUtil;
9-
import org.mozilla.mozstumbler.client.navdrawer.MainDrawerActivity;
10-
1112
import org.robolectric.Robolectric;
1213
import org.robolectric.RobolectricTestRunner;
1314
import org.robolectric.annotation.Config;
1415

16+
import static junit.framework.Assert.assertEquals;
1517
import static org.junit.Assert.assertFalse;
1618
import static org.junit.Assert.assertNotNull;
1719
import static org.junit.Assert.assertTrue;
1820

21+
1922
@Config(emulateSdk = 18)
2023
@RunWith(RobolectricTestRunner.class)
21-
public class MainDrawerActivityTest {
24+
public class UpdaterTest {
25+
class TestUpdater extends Updater {
26+
public TestUpdater(IHttpUtil simpleHttp) {
27+
super(simpleHttp);
28+
}
29+
30+
@Override
31+
public boolean wifiExclusiveAndUnavailable() {
32+
return false;
33+
}
34+
}
2235

2336
private MainDrawerActivity activity;
2437

@@ -32,28 +45,23 @@ public void activityShouldNotBeNull() {
3245
assertNotNull(activity);
3346
}
3447

35-
3648
@Test
3749
public void testUpdater() {
38-
39-
class TestUpdater extends Updater {
40-
public TestUpdater(IHttpUtil simpleHttp) {
41-
super(simpleHttp);
42-
}
43-
44-
@Override
45-
public boolean wifiExclusiveAndUnavailable() {
46-
return false;
47-
}
48-
}
49-
5050
IHttpUtil mockHttp = new MockHttpUtil();
51-
52-
5351
Updater upd = new TestUpdater(mockHttp);
5452
assertFalse(upd.checkForUpdates(activity, ""));
5553
assertFalse(upd.checkForUpdates(activity, null));
5654
assertTrue(upd.checkForUpdates(activity, "anything_else"));
55+
56+
assertEquals("1.3.0", upd.stripBuildHostName("1.3.0.Victors-MBPr"));
57+
assertEquals("1.3.0", upd.stripBuildHostName("1.3.0"));
58+
59+
}
60+
61+
@Test(expected=RuntimeException.class)
62+
public void testUpdaterThrowsExceptions() {
63+
Updater upd = new TestUpdater(null);
64+
upd.stripBuildHostName("1.0");
5765
}
5866

5967
}

0 commit comments

Comments
 (0)