analyze method
Future<PackageApi>
analyze(
- ArgResults argResults,
- PreparedPackageRef preparedRef, {
- bool doAnalyzePlatformConstraints = true,
inherited
Analyzes the given prepared Package ref
.
doMergeBaseClasses
defines if base classes should be merged into derived ones. This allows to remove private base classes from the list of interface declarations.
doAnalyzePlatformConstraints
defines if the platform constraints of the package shall be analyzed.
Implementation
Future<PackageApi> analyze(
ArgResults argResults,
PreparedPackageRef preparedRef, {
bool doAnalyzePlatformConstraints = true,
}) async {
final stdoutSession = StdoutSession();
final forceUseFlutterTool =
(argResults[_flagNameForceUseFlutter] as bool?) ?? false;
String? path;
if (preparedRef.packageRef.isDirectoryPath) {
path = preparedRef.packageRef.ref;
}
if (preparedRef.packageRef.isPubRef) {
path = PubInteraction.getPackagePathInCache(
preparedRef.packageRef.pubPackage!,
preparedRef.packageRef.pubVersion);
}
if (preparedRef.packageRef.isGitRef) {
// For git references, use the temp directory where the repository was cloned
path = preparedRef.tempDirectory;
}
if (path == null) {
throw ArgumentError(
'Don\'t know how to handle ${preparedRef.packageRef.ref}');
}
String packagePath = preparedRef.packageDirectory ?? path;
// The analysis options might limit the scope of dart_apitool
final analysisOptionsFile =
File(p.join(packagePath, 'analysis_options.yaml'));
if (await analysisOptionsFile.exists()) {
await analysisOptionsFile.delete();
}
final packageConfig =
await package_config.findPackageConfig(Directory(packagePath));
// Check if the package_config.json is already present from the preparation step
if (packageConfig == null) {
await stdoutSession.writeln('Running pub get');
await PubInteraction.runPubGetIndirectly(
packagePath,
stdoutSession: stdoutSession,
forceUseFlutterTool: forceUseFlutterTool,
);
} else {
await stdoutSession
.writeln('Omitting pub get (package config already present)');
}
await stdoutSession.writeln('Analyzing $path');
final analyzer = PackageApiAnalyzer(
packagePath: packagePath,
doAnalyzePlatformConstraints: doAnalyzePlatformConstraints,
);
return await analyzer.analyze();
}