Skip to content

Commit

Permalink
refactor: move native code to its own directory (#1638)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Sep 12, 2023
1 parent 7c822cd commit 8fe0817
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 72 deletions.
2 changes: 2 additions & 0 deletions flutter/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include: package:flutter_lints/flutter.yaml

analyzer:
exclude:
- test/*.mocks.dart
language:
strict-casts: true
strict-inference: true
Expand Down
2 changes: 1 addition & 1 deletion flutter/ffi-cocoa.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: SentryCocoa
description: Sentry Cocoa SDK FFI binding.
language: objc
output: lib/src/sentry_cocoa.dart
output: lib/src/native/cocoa/binding.dart
headers:
entry-points:
- ./cocoa_bindings_temp/Sentry.framework/Versions/A/PrivateHeaders/PrivateSentrySDKOnly.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'dart:async';

import 'package:sentry/sentry.dart';

import '../sentry_native.dart';
import '../sentry_native_channel.dart';
import '../native/sentry_native.dart';

/// EventProcessor that enriches [SentryTransaction] objects with app start
/// measurement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/scheduler.dart';
import 'package:sentry/sentry.dart';

import '../sentry_flutter_options.dart';
import '../sentry_native.dart';
import '../native/sentry_native.dart';
import '../event_processor/native_app_start_event_processor.dart';

/// Integration which handles communication with native frameworks in order to
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:async';

import 'package:meta/meta.dart';

import '../sentry_flutter.dart';
import '../../sentry_flutter.dart';
import 'sentry_native_channel.dart';

/// [SentryNative] holds state that it fetches from to the native SDKs. Always
Expand Down Expand Up @@ -98,3 +98,33 @@ class SentryNative {
_didFetchAppStart = false;
}
}

class NativeAppStart {
NativeAppStart(this.appStartTime, this.isColdStart);

double appStartTime;
bool isColdStart;

factory NativeAppStart.fromJson(Map<String, dynamic> json) {
return NativeAppStart(
json['appStartTime'] as double,
json['isColdStart'] as bool,
);
}
}

class NativeFrames {
NativeFrames(this.totalFrames, this.slowFrames, this.frozenFrames);

int totalFrames;
int slowFrames;
int frozenFrames;

factory NativeFrames.fromJson(Map<String, dynamic> json) {
return NativeFrames(
json['totalFrames'] as int,
json['slowFrames'] as int,
json['frozenFrames'] as int,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';

import '../sentry_flutter.dart';
import '../../sentry_flutter.dart';
import 'sentry_native.dart';
import 'method_channel_helper.dart';

/// Provide typed methods to access native layer.
/// Provide typed methods to access native layer via MethodChannel.
@internal
class SentryNativeChannel {
SentryNativeChannel(this._channel, this._options);
Expand Down Expand Up @@ -149,33 +150,3 @@ class SentryNativeChannel {
);
}
}

class NativeAppStart {
NativeAppStart(this.appStartTime, this.isColdStart);

double appStartTime;
bool isColdStart;

factory NativeAppStart.fromJson(Map<String, dynamic> json) {
return NativeAppStart(
json['appStartTime'] as double,
json['isColdStart'] as bool,
);
}
}

class NativeFrames {
NativeFrames(this.totalFrames, this.slowFrames, this.frozenFrames);

int totalFrames;
int slowFrames;
int frozenFrames;

factory NativeFrames.fromJson(Map<String, dynamic> json) {
return NativeFrames(
json['totalFrames'] as int,
json['slowFrames'] as int,
json['frozenFrames'] as int,
);
}
}
3 changes: 1 addition & 2 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:flutter/widgets.dart';

import '../../sentry_flutter.dart';
import '../sentry_native.dart';
import '../sentry_native_channel.dart';
import '../native/sentry_native.dart';

/// This key must be used so that the web interface displays the events nicely
/// See https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/
Expand Down
12 changes: 6 additions & 6 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'event_processor/android_platform_exception_event_processor.dart';
import 'event_processor/flutter_exception_event_processor.dart';
import 'event_processor/platform_exception_event_processor.dart';
import 'integrations/screenshot_integration.dart';
import 'native_scope_observer.dart';
import 'native/native_scope_observer.dart';
import 'renderer/renderer.dart';
import 'sentry_native.dart';
import 'sentry_native_channel.dart';
import 'native/sentry_native.dart';
import 'native/sentry_native_channel.dart';

import 'integrations/integrations.dart';
import 'event_processor/flutter_enricher_event_processor.dart';
Expand Down Expand Up @@ -47,10 +47,10 @@ mixin SentryFlutter {
flutterOptions.rendererWrapper = rendererWrapper;
}

final nativeChannel = SentryNativeChannel(channel, flutterOptions);
if (flutterOptions.platformChecker.hasNativeIntegration) {
final native = SentryNative();
native.nativeChannel = nativeChannel;
// Set a default native channel to the singleton SentryNative instance.
SentryNative().nativeChannel =
SentryNativeChannel(channel, flutterOptions);
}

final platformDispatcher = PlatformDispatcher.instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/integrations/native_app_start_integration.dart';
import 'package:sentry_flutter/src/sentry_native.dart';
import 'package:sentry_flutter/src/sentry_native_channel.dart';
import 'package:sentry_flutter/src/native/sentry_native.dart';
import 'package:sentry/src/sentry_tracer.dart';

import '../mocks.dart';
Expand Down
2 changes: 1 addition & 1 deletion flutter/test/method_channel_helper_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/src/method_channel_helper.dart';
import 'package:sentry_flutter/src/native/method_channel_helper.dart';
import 'package:collection/collection.dart';

void main() {
Expand Down
4 changes: 2 additions & 2 deletions flutter/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:sentry/src/sentry_tracer.dart';
import 'package:meta/meta.dart';
import 'package:sentry_flutter/src/binding_wrapper.dart';
import 'package:sentry_flutter/src/renderer/renderer.dart';
import 'package:sentry_flutter/src/sentry_native.dart';
import 'package:sentry_flutter/src/sentry_native_channel.dart';
import 'package:sentry_flutter/src/native/sentry_native.dart';
import 'package:sentry_flutter/src/native/sentry_native_channel.dart';

import 'mocks.mocks.dart';
import 'no_such_method_provider.dart';
Expand Down
41 changes: 29 additions & 12 deletions flutter/test/mocks.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import 'package:sentry/sentry.dart' as _i2;
import 'package:sentry/src/protocol.dart' as _i3;
import 'package:sentry/src/sentry_envelope.dart' as _i7;
import 'package:sentry/src/sentry_tracer.dart' as _i8;
import 'package:sentry_flutter/src/sentry_native.dart' as _i10;
import 'package:sentry_flutter/src/sentry_native_channel.dart' as _i11;
import 'package:sentry_flutter/src/native/sentry_native.dart' as _i10;
import 'package:sentry_flutter/src/native/sentry_native_channel.dart' as _i11;

import 'mocks.dart' as _i12;

Expand Down Expand Up @@ -112,8 +112,18 @@ class _FakeSentryId_7 extends _i1.SmartFake implements _i3.SentryId {
);
}

class _FakeHub_8 extends _i1.SmartFake implements _i2.Hub {
_FakeHub_8(
class _FakeScope_8 extends _i1.SmartFake implements _i2.Scope {
_FakeScope_8(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}

class _FakeHub_9 extends _i1.SmartFake implements _i2.Hub {
_FakeHub_9(
Object parent,
Invocation parentInvocation,
) : super(
Expand Down Expand Up @@ -144,7 +154,6 @@ class MockTransport extends _i1.Mock implements _i2.Transport {
/// A class which mocks [SentryTracer].
///
/// See the documentation for Mockito's code generation for more information.
// ignore: invalid_use_of_internal_member
class MockSentryTracer extends _i1.Mock implements _i8.SentryTracer {
MockSentryTracer() {
_i1.throwOnMissingStub(this);
Expand Down Expand Up @@ -526,13 +535,13 @@ class MockSentryNative extends _i1.Mock implements _i10.SentryNative {
returnValue: false,
) as bool);
@override
_i6.Future<_i11.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod(
_i6.Future<_i10.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod(
Invocation.method(
#fetchNativeAppStart,
[],
),
returnValue: _i6.Future<_i11.NativeAppStart?>.value(),
) as _i6.Future<_i11.NativeAppStart?>);
returnValue: _i6.Future<_i10.NativeAppStart?>.value(),
) as _i6.Future<_i10.NativeAppStart?>);
@override
_i6.Future<void> beginNativeFramesCollection() => (super.noSuchMethod(
Invocation.method(
Expand All @@ -543,15 +552,15 @@ class MockSentryNative extends _i1.Mock implements _i10.SentryNative {
returnValueForMissingStub: _i6.Future<void>.value(),
) as _i6.Future<void>);
@override
_i6.Future<_i11.NativeFrames?> endNativeFramesCollection(
_i6.Future<_i10.NativeFrames?> endNativeFramesCollection(
_i3.SentryId? traceId) =>
(super.noSuchMethod(
Invocation.method(
#endNativeFramesCollection,
[traceId],
),
returnValue: _i6.Future<_i11.NativeFrames?>.value(),
) as _i6.Future<_i11.NativeFrames?>);
returnValue: _i6.Future<_i10.NativeFrames?>.value(),
) as _i6.Future<_i10.NativeFrames?>);
@override
_i6.Future<void> setContexts(
String? key,
Expand Down Expand Up @@ -695,6 +704,14 @@ class MockHub extends _i1.Mock implements _i2.Hub {
),
) as _i3.SentryId);
@override
_i2.Scope get scope => (super.noSuchMethod(
Invocation.getter(#scope),
returnValue: _FakeScope_8(
this,
Invocation.getter(#scope),
),
) as _i2.Scope);
@override
_i6.Future<_i3.SentryId> captureEvent(
_i3.SentryEvent? event, {
dynamic stackTrace,
Expand Down Expand Up @@ -828,7 +845,7 @@ class MockHub extends _i1.Mock implements _i2.Hub {
#clone,
[],
),
returnValue: _FakeHub_8(
returnValue: _FakeHub_9(
this,
Invocation.method(
#clone,
Expand Down
2 changes: 1 addition & 1 deletion flutter/test/native_scope_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import 'package:flutter_test/flutter_test.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry_flutter/src/native_scope_observer.dart';
import 'package:sentry_flutter/src/native/native_scope_observer.dart';

import 'mocks.dart';

Expand Down
2 changes: 1 addition & 1 deletion flutter/test/sentry_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/integrations/integrations.dart';
import 'package:sentry_flutter/src/integrations/screenshot_integration.dart';
import 'package:sentry_flutter/src/renderer/renderer.dart';
import 'package:sentry_flutter/src/sentry_native.dart';
import 'package:sentry_flutter/src/native/sentry_native.dart';
import 'package:sentry_flutter/src/version.dart';
import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_integration.dart';
import 'mocks.dart';
Expand Down
2 changes: 1 addition & 1 deletion flutter/test/sentry_flutter_util.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/file_system_transport.dart';
import 'package:sentry_flutter/src/native_scope_observer.dart';
import 'package:sentry_flutter/src/native/native_scope_observer.dart';

void testTransport({
required Transport transport,
Expand Down
6 changes: 3 additions & 3 deletions flutter/test/sentry_native_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/method_channel_helper.dart';
import 'package:sentry_flutter/src/sentry_native.dart';
import 'package:sentry_flutter/src/sentry_native_channel.dart';
import 'package:sentry_flutter/src/native/method_channel_helper.dart';
import 'package:sentry_flutter/src/native/sentry_native.dart';
import 'package:sentry_flutter/src/native/sentry_native_channel.dart';
import 'mocks.mocks.dart';

void main() {
Expand Down
3 changes: 1 addition & 2 deletions flutter/test/sentry_native_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/sentry_native.dart';
import 'package:sentry_flutter/src/sentry_native_channel.dart';
import 'package:sentry_flutter/src/native/sentry_native.dart';
import 'mocks.dart';

void main() {
Expand Down
3 changes: 1 addition & 2 deletions flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/sentry_native.dart';
import 'package:sentry_flutter/src/sentry_native_channel.dart';
import 'package:sentry_flutter/src/native/sentry_native.dart';
import 'package:sentry/src/sentry_tracer.dart';

import 'mocks.dart';
Expand Down

0 comments on commit 8fe0817

Please sign in to comment.