Unverified Commit 8df0d686 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove globals from pub (#55412)

parent cbc121e3
...@@ -205,7 +205,7 @@ class PackagesPublishCommand extends FlutterCommand { ...@@ -205,7 +205,7 @@ class PackagesPublishCommand extends FlutterCommand {
if (boolArg('force')) '--force', if (boolArg('force')) '--force',
]; ];
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await pub.interactively(<String>['publish', ...args]); await pub.interactively(<String>['publish', ...args], stdio: globals.stdio);
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
} }
...@@ -236,7 +236,7 @@ class PackagesForwardCommand extends FlutterCommand { ...@@ -236,7 +236,7 @@ class PackagesForwardCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await pub.interactively(<String>[_commandName, ...argResults.rest]); await pub.interactively(<String>[_commandName, ...argResults.rest], stdio: globals.stdio);
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
...@@ -264,7 +264,7 @@ class PackagesPassthroughCommand extends FlutterCommand { ...@@ -264,7 +264,7 @@ class PackagesPassthroughCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await pub.interactively(argResults.rest); await pub.interactively(argResults.rest, stdio: globals.stdio);
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
} }
...@@ -167,7 +167,14 @@ Future<T> runInContext<T>( ...@@ -167,7 +167,14 @@ Future<T> runInContext<T>(
processManager: globals.processManager, processManager: globals.processManager,
logger: globals.logger, logger: globals.logger,
), ),
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
botDetector: globals.botDetector,
platform: globals.platform,
usage: globals.flutterUsage,
),
ShutdownHooks: () => ShutdownHooks(logger: globals.logger), ShutdownHooks: () => ShutdownHooks(logger: globals.logger),
Signals: () => Signals(), Signals: () => Signals(),
Stdio: () => Stdio(), Stdio: () => Stdio(),
......
...@@ -129,7 +129,8 @@ class PubResultEvent extends UsageEvent { ...@@ -129,7 +129,8 @@ class PubResultEvent extends UsageEvent {
PubResultEvent({ PubResultEvent({
@required String context, @required String context,
@required String result, @required String result,
}) : super('pub-result', context, label: result, flutterUsage: globals.flutterUsage); @required Usage usage,
}) : super('pub-result', context, label: result, flutterUsage: usage);
} }
/// An event that reports something about a build. /// An event that reports something about a build.
......
...@@ -15,6 +15,7 @@ import 'package:flutter_tools/src/dart/sdk.dart'; ...@@ -15,6 +15,7 @@ import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart'; import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -65,7 +66,15 @@ void main() { ...@@ -65,7 +66,15 @@ void main() {
testUsingContext('AnalysisServer success', () async { testUsingContext('AnalysisServer success', () async {
_createSampleProject(tempDir); _createSampleProject(tempDir);
await const Pub().get(context: PubContext.flutterTests, directory: tempDir.path); final Pub pub = Pub(
fileSystem: fileSystem,
logger: logger,
processManager: processManager,
platform: const LocalPlatform(),
botDetector: globals.botDetector,
usage: globals.flutterUsage,
);
await pub.get(context: PubContext.flutterTests, directory: tempDir.path);
server = AnalysisServer(dartSdkPath, <String>[tempDir.path], server = AnalysisServer(dartSdkPath, <String>[tempDir.path],
fileSystem: fileSystem, fileSystem: fileSystem,
...@@ -90,7 +99,15 @@ void main() { ...@@ -90,7 +99,15 @@ void main() {
testUsingContext('AnalysisServer errors', () async { testUsingContext('AnalysisServer errors', () async {
_createSampleProject(tempDir, brokenCode: true); _createSampleProject(tempDir, brokenCode: true);
await const Pub().get(context: PubContext.flutterTests, directory: tempDir.path); final Pub pub = Pub(
fileSystem: fileSystem,
logger: logger,
processManager: processManager,
platform: const LocalPlatform(),
usage: globals.flutterUsage,
botDetector: globals.botDetector,
);
await pub.get(context: PubContext.flutterTests, directory: tempDir.path);
server = AnalysisServer(dartSdkPath, <String>[tempDir.path], server = AnalysisServer(dartSdkPath, <String>[tempDir.path],
fileSystem: fileSystem, fileSystem: fileSystem,
......
...@@ -86,7 +86,14 @@ void main() { ...@@ -86,7 +86,14 @@ void main() {
); );
return _runFlutterTest(projectDir); return _runFlutterTest(projectDir);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('can create a default project if empty directory exists', () async { testUsingContext('can create a default project if empty directory exists', () async {
...@@ -104,7 +111,14 @@ void main() { ...@@ -104,7 +111,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('creates a module project correctly', () async { testUsingContext('creates a module project correctly', () async {
...@@ -126,7 +140,14 @@ void main() { ...@@ -126,7 +140,14 @@ void main() {
]); ]);
return _runFlutterTest(projectDir); return _runFlutterTest(projectDir);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('cannot create a project if non-empty non-project directory exists with .metadata', () async { testUsingContext('cannot create a project if non-empty non-project directory exists with .metadata', () async {
...@@ -144,7 +165,14 @@ void main() { ...@@ -144,7 +165,14 @@ void main() {
]), ]),
throwsToolExit(message: 'Sorry, unable to detect the type of project to recreate')); throwsToolExit(message: 'Sorry, unable to detect the type of project to recreate'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
...noColorTerminalOverride, ...noColorTerminalOverride,
}); });
...@@ -170,7 +198,14 @@ void main() { ...@@ -170,7 +198,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('detects and recreates an app project correctly', () async { testUsingContext('detects and recreates an app project correctly', () async {
...@@ -195,7 +230,14 @@ void main() { ...@@ -195,7 +230,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('detects and recreates a plugin project correctly', () async { testUsingContext('detects and recreates a plugin project correctly', () async {
...@@ -220,7 +262,14 @@ void main() { ...@@ -220,7 +262,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('detects and recreates a package project correctly', () async { testUsingContext('detects and recreates a package project correctly', () async {
...@@ -251,7 +300,14 @@ void main() { ...@@ -251,7 +300,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('kotlin/swift legacy app project', () async { testUsingContext('kotlin/swift legacy app project', () async {
...@@ -273,7 +329,14 @@ void main() { ...@@ -273,7 +329,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('can create a package project', () async { testUsingContext('can create a package project', () async {
...@@ -303,7 +366,14 @@ void main() { ...@@ -303,7 +366,14 @@ void main() {
); );
return _runFlutterTest(projectDir); return _runFlutterTest(projectDir);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('can create a plugin project', () async { testUsingContext('can create a plugin project', () async {
...@@ -325,7 +395,14 @@ void main() { ...@@ -325,7 +395,14 @@ void main() {
); );
return _runFlutterTest(projectDir.childDirectory('example')); return _runFlutterTest(projectDir.childDirectory('example'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('plugin example app depends on plugin', () async { testUsingContext('plugin example app depends on plugin', () async {
...@@ -344,7 +421,14 @@ void main() { ...@@ -344,7 +421,14 @@ void main() {
final PathDependency pathDependency = pubspec.dependencies[pluginName] as PathDependency; final PathDependency pathDependency = pubspec.dependencies[pluginName] as PathDependency;
expect(pathDependency.path, '../'); expect(pathDependency.path, '../');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('kotlin/swift plugin project', () async { testUsingContext('kotlin/swift plugin project', () async {
...@@ -429,7 +513,14 @@ void main() { ...@@ -429,7 +513,14 @@ void main() {
<String>['lib/main.dart'], <String>['lib/main.dart'],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('module project with pub', () async { testUsingContext('module project with pub', () async {
...@@ -464,7 +555,14 @@ void main() { ...@@ -464,7 +555,14 @@ void main() {
'.android/Flutter/src/main/java/io/flutter/facade/Flutter.java', '.android/Flutter/src/main/java/io/flutter/facade/Flutter.java',
]); ]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
...@@ -1038,7 +1136,14 @@ void main() { ...@@ -1038,7 +1136,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('can re-gen module .ios/ folder, reusing custom org', () async { testUsingContext('can re-gen module .ios/ folder, reusing custom org', () async {
...@@ -1055,7 +1160,14 @@ void main() { ...@@ -1055,7 +1160,14 @@ void main() {
'com.bar.foo.flutterProject', 'com.bar.foo.flutterProject',
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext('can re-gen app android/ folder, reusing custom org', () async { testUsingContext('can re-gen app android/ folder, reusing custom org', () async {
...@@ -1210,7 +1322,14 @@ void main() { ...@@ -1210,7 +1322,14 @@ void main() {
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}); });
testUsingContext( testUsingContext(
...@@ -1227,7 +1346,14 @@ void main() { ...@@ -1227,7 +1346,14 @@ void main() {
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
ProcessManager: () => loggingProcessManager, ProcessManager: () => loggingProcessManager,
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}, },
); );
...@@ -1245,7 +1371,14 @@ void main() { ...@@ -1245,7 +1371,14 @@ void main() {
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
ProcessManager: () => loggingProcessManager, ProcessManager: () => loggingProcessManager,
Pub: () => const Pub(), Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
}, },
); );
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/dart/pub.dart';
import 'package:meta/meta.dart';
class ThrowingPub implements Pub { class ThrowingPub implements Pub {
@override @override
...@@ -34,7 +36,7 @@ class ThrowingPub implements Pub { ...@@ -34,7 +36,7 @@ class ThrowingPub implements Pub {
} }
@override @override
Future<void> interactively(List<String> arguments, {String directory}) { Future<void> interactively(List<String> arguments, {String directory, @required Stdio stdio,}) {
throw UnsupportedError('Attempted to invoke pub during test.'); throw UnsupportedError('Attempted to invoke pub during test.');
} }
} }
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