create static method
Implementation
static Future<ToolEnvironment> create({
SdkConfig? dartSdkConfig,
SdkConfig? flutterSdkConfig,
String? pubCacheDir,
String? panaCacheDir,
String? pubHostedUrl,
/// When specified, this version of `dartdoc` will be initialized
/// through `dart pub global activate` and used with `dart pub global run`,
/// otherwise the SDK's will be used.
///
/// Note: To use the latest `dartdoc`, use the version value `any`.
String? dartdocVersion,
}) async {
dartSdkConfig ??= SdkConfig(rootPath: cli.getSdkPath());
flutterSdkConfig ??= SdkConfig();
final resolvedPubCache = await _resolve(pubCacheDir);
final resolvedPanaCache = await _resolve(panaCacheDir);
final origPubEnvValue = Platform.environment[_pubEnvironmentKey] ?? '';
final origPubEnvValues = origPubEnvValue
.split(':')
.map((s) => s.trim())
.where((s) => s.isNotEmpty);
final env = <String, String>{
'CI': 'true', // suppresses analytics for both Dart and Flutter
if (resolvedPubCache != null) _pubCacheKey: resolvedPubCache,
if (pubHostedUrl != null) 'PUB_HOSTED_URL': pubHostedUrl,
_pubEnvironmentKey: [...origPubEnvValues, 'bot.pkg_pana'].join(':'),
};
// Flutter stores its internal SDK in its bin/cache/dart-sdk directory.
// We can use that directory only if Flutter SDK path was specified,
// TODO: remove this after flutter analyze gets machine-readable output.
// https://github.com/flutter/flutter/issues/23664
final flutterSdk = await _FlutterSdk.detect(flutterSdkConfig, env);
if (flutterSdk._dartSdk._config.rootPath == null) {
log.warning(
'Flutter SDK path was not specified, pana will use the default '
'Dart SDK to run `dart analyze` on Flutter packages.');
}
final toolEnv = ToolEnvironment._(
resolvedPubCache,
PanaCache(path: resolvedPanaCache),
await _DartSdk.detect(dartSdkConfig, env),
flutterSdk,
dartdocVersion,
);
await toolEnv._init();
return toolEnv;
}