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