Skip to content

Commit

Permalink
Merge pull request #1285 from crankycoder/features/fdroid-buildhost
Browse files Browse the repository at this point in the history
Features/fdroid buildhost
  • Loading branch information
crankycoder committed Nov 25, 2014
2 parents a069e2b + 06a6169 commit ff7cce3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
11 changes: 1 addition & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
def versionMajor = 1
def versionMinor = 5 // minor feature releases
def versionPatch = 0 // This should be bumped for hot fixes
def buildHost = ""
try
{
buildHost = InetAddress.localHost.hostName
} catch (Exception ex) {
// Some machines are ridiculous.
buildHost = "localhost"
}
buildHost = buildHost.replaceAll("[^a-zA-Z0-9_-]","")

// Double check the versioning
for (versionPart in [versionPatch, versionMinor, versionMajor]) {
Expand Down Expand Up @@ -62,7 +53,7 @@ android {
targetSdkVersion 18

versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100
versionName "${versionMajor}.${versionMinor}.${versionPatch}.${buildHost}"
versionName "${versionMajor}.${versionMinor}.${versionPatch}"

buildConfigField "boolean", "ROBOLECTRIC", "false"
buildConfigField "String", "MOZILLA_API_KEY", "\"\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@ public void onPostExecute(IResponse response) {
return true;
}

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


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

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.mozilla.mozstumbler.client.navdrawer.MainDrawerActivity;
import org.mozilla.mozstumbler.service.core.http.IHttpUtil;
import org.mozilla.mozstumbler.service.core.http.MockHttpUtil;
import org.mozilla.mozstumbler.client.navdrawer.MainDrawerActivity;

import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;


@Config(emulateSdk = 18)
@RunWith(RobolectricTestRunner.class)
public class MainDrawerActivityTest {
public class UpdaterTest {
class TestUpdater extends Updater {
public TestUpdater(IHttpUtil simpleHttp) {
super(simpleHttp);
}

@Override
public boolean wifiExclusiveAndUnavailable() {
return false;
}
}

private MainDrawerActivity activity;

Expand All @@ -32,28 +45,23 @@ public void activityShouldNotBeNull() {
assertNotNull(activity);
}


@Test
public void testUpdater() {

class TestUpdater extends Updater {
public TestUpdater(IHttpUtil simpleHttp) {
super(simpleHttp);
}

@Override
public boolean wifiExclusiveAndUnavailable() {
return false;
}
}

IHttpUtil mockHttp = new MockHttpUtil();


Updater upd = new TestUpdater(mockHttp);
assertFalse(upd.checkForUpdates(activity, ""));
assertFalse(upd.checkForUpdates(activity, null));
assertTrue(upd.checkForUpdates(activity, "anything_else"));

assertEquals("1.3.0", upd.stripBuildHostName("1.3.0.Victors-MBPr"));
assertEquals("1.3.0", upd.stripBuildHostName("1.3.0"));

}

@Test(expected=RuntimeException.class)
public void testUpdaterThrowsExceptions() {
Updater upd = new TestUpdater(null);
upd.stripBuildHostName("1.0");
}

}

0 comments on commit ff7cce3

Please sign in to comment.