Unverified Commit 81e90609 authored by Janice Collins's avatar Janice Collins Committed by GitHub

Suppress analytics flag pass through to analysis server (#123235)

Suppress analytics flag pass through to analysis server
parent 726b7202
......@@ -152,6 +152,7 @@ List<FlutterCommand> generateCommands({
platform: globals.platform,
),
],
suppressAnalytics: globals.flutterUsage.suppressAnalytics,
),
AssembleCommand(verboseHelp: verboseHelp, buildSystem: globals.buildSystem),
AttachCommand(
......
......@@ -29,13 +29,15 @@ class AnalyzeCommand extends FlutterCommand {
required ProcessManager processManager,
required Artifacts artifacts,
required List<ProjectValidator> allProjectValidators,
required bool suppressAnalytics,
}) : _artifacts = artifacts,
_fileSystem = fileSystem,
_processManager = processManager,
_logger = logger,
_terminal = terminal,
_allProjectValidators = allProjectValidators,
_platform = platform {
_platform = platform,
_suppressAnalytics = suppressAnalytics {
argParser.addFlag('flutter-repo',
negatable: false,
help: 'Include all the examples and tests from the Flutter repository.',
......@@ -109,6 +111,7 @@ class AnalyzeCommand extends FlutterCommand {
final ProcessManager _processManager;
final Platform _platform;
final List<ProjectValidator> _allProjectValidators;
final bool _suppressAnalytics;
@override
String get name => 'analyze';
......@@ -181,6 +184,7 @@ class AnalyzeCommand extends FlutterCommand {
processManager: _processManager,
terminal: _terminal,
artifacts: _artifacts,
suppressAnalytics: _suppressAnalytics,
).analyze();
} else {
await AnalyzeOnce(
......@@ -194,6 +198,7 @@ class AnalyzeCommand extends FlutterCommand {
processManager: _processManager,
terminal: _terminal,
artifacts: _artifacts,
suppressAnalytics: _suppressAnalytics,
).analyze();
}
return FlutterCommandResult.success();
......
......@@ -28,6 +28,7 @@ abstract class AnalyzeBase {
required this.processManager,
required this.terminal,
required this.artifacts,
required this.suppressAnalytics,
});
/// The parsed argument results for execution.
......@@ -48,6 +49,8 @@ abstract class AnalyzeBase {
final Terminal terminal;
@protected
final Artifacts artifacts;
@protected
final bool suppressAnalytics;
/// Called by [AnalyzeCommand] to start the analysis process.
Future<void> analyze();
......
......@@ -21,6 +21,7 @@ class AnalyzeContinuously extends AnalyzeBase {
required super.platform,
required super.processManager,
required super.artifacts,
required super.suppressAnalytics,
}) : super(
repoPackages: repoPackages,
repoRoots: repoRoots,
......@@ -63,6 +64,7 @@ class AnalyzeContinuously extends AnalyzeBase {
processManager: processManager,
terminal: terminal,
protocolTrafficLog: protocolTrafficLog,
suppressAnalytics: suppressAnalytics,
);
server.onAnalyzing.listen((bool isAnalyzing) => _handleAnalysisStatus(server, isAnalyzing));
server.onErrors.listen(_handleAnalysisErrors);
......
......@@ -22,6 +22,7 @@ class AnalyzeOnce extends AnalyzeBase {
required super.processManager,
required super.terminal,
required super.artifacts,
required super.suppressAnalytics,
this.workingDirectory,
}) : super(
repoRoots: repoRoots,
......@@ -67,6 +68,7 @@ class AnalyzeOnce extends AnalyzeBase {
processManager: processManager,
terminal: terminal,
protocolTrafficLog: protocolTrafficLog,
suppressAnalytics: suppressAnalytics,
);
Stopwatch? timer;
......
......@@ -25,6 +25,7 @@ class AnalysisServer {
required Logger logger,
required Platform platform,
required Terminal terminal,
required this.suppressAnalytics,
String? protocolTrafficLog,
}) : _fileSystem = fileSystem,
_processManager = processManager,
......@@ -41,6 +42,7 @@ class AnalysisServer {
final Platform _platform;
final Terminal _terminal;
final String? _protocolTrafficLog;
final bool suppressAnalytics;
Process? _process;
final StreamController<bool> _analyzingController =
......@@ -66,6 +68,7 @@ class AnalysisServer {
'--disable-server-feature-search',
'--sdk',
sdkPath,
if (suppressAnalytics) '--suppress-analytics',
if (_protocolTrafficLog != null)
'--protocol-traffic-log=$_protocolTrafficLog',
];
......
......@@ -99,6 +99,7 @@ void main() {
processManager: processManager,
logger: logger,
terminal: terminal,
suppressAnalytics: true,
);
int errorCount = 0;
......@@ -139,6 +140,7 @@ void main() {
processManager: processManager,
logger: logger,
terminal: terminal,
suppressAnalytics: true,
);
int errorCount = 0;
......@@ -166,6 +168,7 @@ void main() {
processManager: processManager,
logger: logger,
terminal: terminal,
suppressAnalytics: true,
);
int errorCount = 0;
......@@ -179,6 +182,44 @@ void main() {
await server.dispose();
});
testUsingContext('Can run AnalysisService without suppressing analytics', () async {
final StreamController<List<int>> stdin = StreamController<List<int>>();
final FakeProcessManager processManager = FakeProcessManager.list(
<FakeCommand>[
FakeCommand(
command: const <String>[
'Artifact.engineDartSdkPath/bin/dart',
'--disable-dart-dev',
'Artifact.engineDartSdkPath/bin/snapshots/analysis_server.dart.snapshot',
'--disable-server-feature-completion',
'--disable-server-feature-search',
'--sdk',
'Artifact.engineDartSdkPath',
],
stdin: IOSink(stdin.sink),
),
]);
final Artifacts artifacts = Artifacts.test();
final AnalyzeCommand command = AnalyzeCommand(
terminal: Terminal.test(),
artifacts: artifacts,
logger: BufferLogger.test(),
platform: FakePlatform(),
fileSystem: MemoryFileSystem.test(),
processManager: processManager,
allProjectValidators: <ProjectValidator>[],
suppressAnalytics: false,
);
final TestFlutterCommandRunner commandRunner = TestFlutterCommandRunner();
commandRunner.addCommand(command);
unawaited(commandRunner.run(<String>['analyze', '--watch']));
await stdin.stream.first;
expect(processManager, hasNoRemainingExpectations);
});
testUsingContext('Can run AnalysisService with customized cache location', () async {
final StreamController<List<int>> stdin = StreamController<List<int>>();
final FakeProcessManager processManager = FakeProcessManager.list(
......@@ -192,6 +233,7 @@ void main() {
'--disable-server-feature-search',
'--sdk',
'Artifact.engineDartSdkPath',
'--suppress-analytics',
],
stdin: IOSink(stdin.sink),
),
......@@ -206,6 +248,7 @@ void main() {
fileSystem: MemoryFileSystem.test(),
processManager: processManager,
allProjectValidators: <ProjectValidator>[],
suppressAnalytics: true,
);
final TestFlutterCommandRunner commandRunner = TestFlutterCommandRunner();
......@@ -235,6 +278,7 @@ void main() {
'--disable-server-feature-search',
'--sdk',
'Artifact.engineDartSdkPath',
'--suppress-analytics',
],
stdin: IOSink(stdin.sink),
stdout: '''
......@@ -254,6 +298,7 @@ void main() {
fileSystem: fileSystem,
processManager: processManager,
allProjectValidators: <ProjectValidator>[],
suppressAnalytics: true,
);
await FakeAsync().run((FakeAsync time) async {
......@@ -288,6 +333,7 @@ void main() {
'--disable-server-feature-search',
'--sdk',
'Artifact.engineDartSdkPath',
'--suppress-analytics',
],
stdin: IOSink(stdin.sink),
stdout: '''
......@@ -307,6 +353,7 @@ void main() {
fileSystem: MemoryFileSystem.test(),
processManager: processManager,
allProjectValidators: <ProjectValidator>[],
suppressAnalytics: true,
);
await FakeAsync().run((FakeAsync time) async {
......
......@@ -98,6 +98,7 @@ void main() {
ProjectValidatorDummy(),
ProjectValidatorSecondDummy()
],
suppressAnalytics: true,
);
final CommandRunner<void> runner = createTestCommandRunner(command);
......@@ -129,6 +130,7 @@ void main() {
allProjectValidators: <ProjectValidator>[
ProjectValidatorCrash(),
],
suppressAnalytics: true,
);
final CommandRunner<void> runner = createTestCommandRunner(command);
......@@ -149,6 +151,7 @@ void main() {
terminal: terminal,
processManager: processManager,
allProjectValidators: <ProjectValidator>[],
suppressAnalytics: true,
);
final CommandRunner<void> runner = createTestCommandRunner(command);
Future<void> result () => runner.run(<String>['analyze', '--suggestions', '--watch']);
......
......@@ -70,6 +70,7 @@ void main() {
processManager: processManager,
terminal: terminal,
allProjectValidators: <ProjectValidator>[],
suppressAnalytics: true,
);
runner = createTestCommandRunner(command);
......@@ -95,6 +96,7 @@ void main() {
'--disable-server-feature-search',
'--sdk',
'Artifact.engineDartSdkPath',
'--suppress-analytics',
],
exitCode: SIGABRT,
stderr: stderr,
......
......@@ -37,6 +37,7 @@ void main() {
terminal: globals.terminal,
processManager: globals.processManager,
allProjectValidators: <ProjectValidator>[GeneralInfoProjectValidator()],
suppressAnalytics: true,
);
final CommandRunner<void> runner = createTestCommandRunner(command);
......@@ -73,6 +74,7 @@ void main() {
allProjectValidators: <ProjectValidator>[
PubDependenciesProjectValidator(globals.processManager),
],
suppressAnalytics: true,
);
final CommandRunner<void> runner = createTestCommandRunner(command);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment