Skip to content

Commit

Permalink
Merge branch 'v5' into tom/enabled-breadcrumb-types-auto-only
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlongridge committed Mar 10, 2020
2 parents 0a5be8f + d480662 commit 0849b12
Show file tree
Hide file tree
Showing 30 changed files with 176 additions and 56 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,22 @@ Files are generated into`<module>/build/outputs/aar`.

### Building with custom ABIs

By default, the NDK module will be built with the following ABIs:

- arm64-v8a
- armeabi-v7a
- x86
- x86_64

To build the NDK module with specific ABIs, use the `ABI_FILTERS` project
option:

```shell
./gradlew assembleRelease -PABI_FILTERS=x86,arm64-v8a
```

For release purposes, the Makefile's build command includes the "armeabi" ABI for compatibility with devices using r16 and below of the NDK.

## Testing

Full details of how to build and run tests can be found in [the testing guide](TESTING.md)
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ all: build
.PHONY: build test clean bump release

build:
./gradlew build
./gradlew build -PABI_FILTERS=arm64-v8a,armeabi,armeabi-v7a,x86,x86_64

clean:
./gradlew clean
Expand Down Expand Up @@ -63,4 +63,5 @@ endif
@git commit -m "Release v$(VERSION)"
@git tag v$(VERSION)
@git push origin master v$(VERSION)
@./gradlew assembleRelease publish bintrayUpload && ./gradlew assembleRelease publish bintrayUpload -PreleaseNdkArtefact=true
@./gradlew assembleRelease publish bintrayUpload -PABI_FILTERS=arm64-v8a,armeabi,armeabi-v7a,x86,x86_64 \
&& ./gradlew assembleRelease publish bintrayUpload -PABI_FILTERS=arm64-v8a,armeabi,armeabi-v7a,x86,x86_64 -PreleaseNdkArtefact=true
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class BreadcrumbStateTest {
var count = 0

for (breadcrumb in store) {
if (MANUAL == breadcrumb.type && "manual" == breadcrumb.message
&& breadcrumb.metadata!!["message"] == "Hello World") {
if (MANUAL == breadcrumb.type && "Hello World" == breadcrumb.message) {
count++
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ public void testMaxBreadcrumbs() {

Breadcrumb poll = client.breadcrumbState.getStore().poll();
assertEquals(BreadcrumbType.MANUAL, poll.getType());
assertEquals("manual", poll.getMessage());
assertEquals("another", poll.getMetadata().get("message"));
assertEquals("another", poll.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateConfiguration;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import androidx.annotation.NonNull;
import androidx.test.core.app.ApplicationProvider;
Expand Down Expand Up @@ -41,6 +43,7 @@ public void setUp() {
breadcrumbTypes.add(BreadcrumbType.LOG);
breadcrumbTypes.add(BreadcrumbType.MANUAL);
config.setEnabledBreadcrumbTypes(breadcrumbTypes);
config.addMetadata("foo", "bar", true);
client = new Client(ApplicationProvider.getApplicationContext(), config);
observer = new BugsnagTestObserver();
client.registerObserver(observer);
Expand All @@ -51,6 +54,31 @@ public void tearDown() {
client.close();
}

@SuppressWarnings("EmptyCatchBlock")
@Test
public void testSyncInitialState() {
try {
assertNull(findMessageInQueue(StateEvent.UpdateUser.class));
fail("UpdateUser message not expected");
} catch (Throwable ignored) {
}
try {
assertNull(findMessageInQueue(StateEvent.AddMetadata.class));
fail("AddMetadata message not expected");
} catch (Throwable ignored) {
}
try {
assertNull(findMessageInQueue(StateEvent.UpdateContext.class));
fail("UpdateContext message not expected");
} catch (Throwable ignored) {
}

client.syncInitialState();
assertNotNull(findMessageInQueue(StateEvent.UpdateUser.class));
assertNotNull(findMessageInQueue(StateEvent.AddMetadata.class));
assertNotNull(findMessageInQueue(StateEvent.UpdateContext.class));
}

@Test
public void testAddMetadataSendsMessage() {
client.addMetadata("foo", "bar", "baz");
Expand Down Expand Up @@ -137,9 +165,8 @@ public void testLeaveStringBreadcrumbSendsMessage() {
client.leaveBreadcrumb("Drift 4 units left");
StateEvent.AddBreadcrumb crumb = findMessageInQueue(StateEvent.AddBreadcrumb.class);
assertEquals(BreadcrumbType.MANUAL, crumb.getType());
assertEquals("manual", crumb.getMessage());
assertEquals(1, crumb.getMetadata().size());
assertEquals("Drift 4 units left", crumb.getMetadata().get("message"));
assertEquals("Drift 4 units left", crumb.getMessage());
assertTrue(crumb.getMetadata().isEmpty());
}

@Test
Expand All @@ -148,9 +175,8 @@ public void testLeaveStringBreadcrumbDirectlySendsMessage() {
client.breadcrumbState.add(obj);
StateEvent.AddBreadcrumb crumb = findMessageInQueue(StateEvent.AddBreadcrumb.class);
assertEquals(BreadcrumbType.MANUAL, crumb.getType());
assertEquals("manual", crumb.getMessage());
assertEquals(1, crumb.getMetadata().size());
assertEquals("Drift 4 units left", crumb.getMetadata().get("message"));
assertEquals("Drift 4 units left", crumb.getMessage());
assertTrue(crumb.getMetadata().isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal class BreadcrumbInternal internal constructor(
) : JsonStream.Streamable {

internal constructor(message: String) : this(
"manual",
message,
BreadcrumbType.MANUAL,
mutableMapOf(Pair("message", message)),
mutableMapOf(),
Date()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ public Unit invoke(String oldOrientation, String newOrientation) {

void sendNativeSetupNotification() {
clientObservable.postNdkInstall(immutableConfig);
metadataState.initObservableMessages();
try {
Async.run(new Runnable() {
@Override
Expand All @@ -354,6 +353,15 @@ void registerObserver(Observer observer) {
deliveryDelegate.addObserver(observer);
}

/**
* Sends initial state values for Metadata/User/Context to any registered observers.
*/
void syncInitialState() {
metadataState.emitObservableEvent();
contextState.emitObservableEvent();
userState.emitObservableEvent();
}

/**
* Starts tracking a new session. You should disable automatic session tracking via
* {@link Configuration#setAutoTrackSessions(boolean)} if you call this method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ internal class ContextState(context: String? = null) : BaseObservable() {
var context = context
set(value) {
field = value
notifyObservers(StateEvent.UpdateContext(context))
emitObservableEvent()
}

fun emitObservableEvent() = notifyObservers(StateEvent.UpdateContext(context))

fun copy() = ContextState(context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ class ErrorTypes(
* Sets whether Bugsnag should automatically capture and report unhandled errors.
* By default, this value is true.
*/
var unhandledExceptions: Boolean = true
var unhandledExceptions: Boolean = true,


/**
* Sets whether Bugsnag should automatically capture and report unhandled promise rejections.
* This only applies to React Native apps.
* By default, this value is true.
*/
var unhandledRejections: Boolean = true
) {
internal constructor(detectErrors: Boolean) : this(detectErrors, detectErrors, detectErrors)
internal constructor(detectErrors: Boolean) : this(detectErrors, detectErrors, detectErrors, detectErrors)

internal fun copy() = ErrorTypes(anrs, ndkCrashes, unhandledExceptions)
internal fun copy() = ErrorTypes(anrs, ndkCrashes, unhandledExceptions, unhandledRejections)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal data class MetadataState(val metadata: Metadata = Metadata()) : BaseObs
* Fires the initial observable messages for all the metadata which has been added before an
* Observer was added. This is used initially to populate the NDK with data.
*/
fun initObservableMessages() {
fun emitObservableEvent() {
val sections = metadata.store.keys

for (section in sections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ internal class UserState(private val userRepository: UserRepository) : BaseObser
fun setUser(id: String?, email: String?, name: String?) {
user = User(id, email, name)
userRepository.save(user)
notifyObservers(StateEvent.UpdateUser(user))
emitObservableEvent()
}

fun emitObservableEvent() = notifyObservers(StateEvent.UpdateUser(user))

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BreadcrumbStateTest {

val crumbs = breadcrumbState.store.toList()
assertEquals(3, crumbs.size)
assertEquals(longStr, crumbs[2].metadata!!["message"])
assertEquals(longStr, crumbs[2].message)
}

/**
Expand All @@ -50,8 +50,8 @@ class BreadcrumbStateTest {
}

val crumbs = breadcrumbState.store.toList()
assertEquals("2", crumbs.first().metadata!!["message"])
assertEquals("6", crumbs.last().metadata!!["message"])
assertEquals("2", crumbs.first().message)
assertEquals("6", crumbs.last().message)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class EnabledErrorTypesTest {
assertTrue(config.enabledErrorTypes.anrs)
assertFalse(config.enabledErrorTypes.ndkCrashes)
assertTrue(config.enabledErrorTypes.unhandledExceptions)
assertTrue(config.enabledErrorTypes.unhandledRejections)
}

@Test
Expand All @@ -25,6 +26,7 @@ class EnabledErrorTypesTest {
assertTrue(anrs)
assertFalse(ndkCrashes)
assertTrue(unhandledExceptions)
assertTrue(unhandledRejections)
}
}

Expand All @@ -36,6 +38,7 @@ class EnabledErrorTypesTest {
assertFalse(anrs)
assertFalse(ndkCrashes)
assertFalse(unhandledExceptions)
assertFalse(unhandledRejections)
}
}

Expand All @@ -45,6 +48,7 @@ class EnabledErrorTypesTest {
assertFalse(anrs)
assertFalse(ndkCrashes)
assertFalse(unhandledExceptions)
assertFalse(unhandledRejections)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal class MetadataStateTest {
data.add(msg.section)
}

state.initObservableMessages()
state.emitObservableEvent()
assertEquals(setOf("foo", "bar"), data)
}
}
2 changes: 1 addition & 1 deletion bugsnag-plugin-android-anr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
externalNativeBuild.cmake.arguments "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_STL=c++_static"
ndk.abiFilters = project.hasProperty("ABI_FILTERS") ? project.ABI_FILTERS.split(",") :
["arm64-v8a", "armeabi-v7a", "armeabi", "x86", "x86_64"]
["arm64-v8a", "armeabi-v7a", "x86", "x86_64"]
}
externalNativeBuild.cmake.path = "CMakeLists.txt"
}
Expand Down
2 changes: 1 addition & 1 deletion bugsnag-plugin-android-ndk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
externalNativeBuild.cmake.arguments "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_STL=c++_static"
ndk.abiFilters = project.hasProperty("ABI_FILTERS") ? project.ABI_FILTERS.split(",") :
["arm64-v8a", "armeabi-v7a", "armeabi", "x86", "x86_64"]
["arm64-v8a", "armeabi-v7a", "x86", "x86_64"]
}
externalNativeBuild.cmake.path = "CMakeLists.txt"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class NdkPlugin : Plugin {
nativeBridge = NativeBridge()
client.registerObserver(nativeBridge)
client.sendNativeSetupNotification()
client.syncInitialState()
}
enableCrashReporting()
client.logger.i("Initialised NDK Plugin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BugsnagReactNativePlugin : Plugin {

fun registerForMessageEvents(cb: (MessageEvent) -> Unit) {
client.registerObserver(BugsnagReactNativeBridge(client, cb))
client.syncInitialState()
}

fun leaveBreadcrumb(map: Map<String, Any?>?) {
Expand Down
4 changes: 3 additions & 1 deletion dockerfiles/Dockerfile.android-builder
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ COPY scripts/ scripts/

RUN scripts/install-ndk.sh

ENV ANDROID_NDK_HOME=${ANDROID_HOME}/ndk-bundle

ENV GRADLE_OPTS="-Dorg.gradle.daemon=false"

RUN ./gradlew
Expand All @@ -48,7 +50,7 @@ RUN echo "signing.secretKeyRingFile=/root/.gnupg/secring.gpg" >> ~/.gradle/gradl

# Build and upload to the local maven as version 9.9.9
RUN sed -i -e 's/VERSION_NAME=.*/VERSION_NAME=9.9.9/g' gradle.properties
RUN ./gradlew assembleRelease publishToMavenLocal
RUN ./gradlew assembleRelease publishToMavenLocal -PABI_FILTERS=arm64-v8a,armeabi,armeabi-v7a,x86,x86_64

COPY tests/features/ /app/features

Expand Down
1 change: 0 additions & 1 deletion dockerfiles/Dockerfile.android-instrumentation-tests
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ ENV GRADLE_OPTS="-Dorg.gradle.daemon=false"
RUN ./gradlew

# Everything above this point should be derived from android-base
RUN sed --in-place="" --expression='s/"armeabi",//' bugsnag-plugin-android-anr/build.gradle bugsnag-plugin-android-ndk/build.gradle
CMD ./scripts/build-instrumentation-tests.sh && ./scripts/run-instrumentation-test.sh
5 changes: 0 additions & 5 deletions dockerfiles/Dockerfile.android-jvm
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,3 @@ RUN apt-get install -y cppcheck

COPY examples/sdk-app-example/ examples/sdk-app-example/
COPY config/ config/

RUN sed --in-place="" --expression="s/'armeabi',//" bugsnag-plugin-android-anr/build.gradle \
bugsnag-plugin-android-ndk/build.gradle examples/sdk-app-example/build.gradle


6 changes: 4 additions & 2 deletions dockerfiles/Dockerfile.android-sizer
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ COPY scripts/ scripts/

RUN scripts/install-ndk.sh

ENV ANDROID_NDK_HOME=${ANDROID_HOME}/ndk-bundle

ENV GRADLE_OPTS="-Dorg.gradle.daemon=false"

RUN ./gradlew
Expand All @@ -48,7 +50,7 @@ RUN echo "signing.secretKeyRingFile=/root/.gnupg/secring.gpg" >> ~/.gradle/gradl

# Build and upload to the local maven as version 9.9.9
RUN sed -i -e 's/VERSION_NAME=.*/VERSION_NAME=9.9.9/g' gradle.properties
RUN ./gradlew assembleRelease publishToMavenLocal
RUN ./gradlew assembleRelease publishToMavenLocal -PABI_FILTERS=arm64-v8a,armeabi,armeabi-v7a,x86,x86_64

COPY tests/features/ tests/features

Expand All @@ -64,4 +66,4 @@ RUN bundle install

COPY .git .git

CMD bundle exec danger
CMD bundle exec danger
5 changes: 2 additions & 3 deletions examples/sdk-app-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.compileSdkVersion
signingConfig signingConfigs.config
ndk {
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
ndk.abiFilters = project.hasProperty("ABI_FILTERS") ? project.ABI_FILTERS.split(",") :
["arm64-v8a", "armeabi-v7a", "x86", "x86_64"]
}
buildTypes {
release {
Expand Down
Loading

0 comments on commit 0849b12

Please sign in to comment.