Remove unused PubDependenciesProjectValidator
. (#157516)
Closes https://github.com/flutter/flutter/issues/157479. This came up while I was looking at parsing the results of `dart pub deps --json`, turns out it isn't used.
This commit is contained in:
parent
b98d9a37ac
commit
a4167b7cf2
@ -2,17 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'base/file_system.dart';
|
||||
import 'base/io.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'cache.dart';
|
||||
import 'convert.dart';
|
||||
import 'dart_pub_json_formatter.dart';
|
||||
import 'flutter_manifest.dart';
|
||||
import 'project.dart';
|
||||
import 'project_validator_result.dart';
|
||||
@ -211,74 +204,3 @@ class GeneralInfoProjectValidator extends ProjectValidator {
|
||||
@override
|
||||
String get title => 'General Info';
|
||||
}
|
||||
|
||||
class PubDependenciesProjectValidator extends ProjectValidator {
|
||||
const PubDependenciesProjectValidator(this._processManager);
|
||||
final ProcessManager _processManager;
|
||||
|
||||
@override
|
||||
Future<List<ProjectValidatorResult>> start(FlutterProject project) async {
|
||||
const String name = 'Dart dependencies';
|
||||
final ProcessResult processResult = await _processManager.run(<String>['dart', 'pub', 'deps', '--json']);
|
||||
if (processResult.stdout is! String) {
|
||||
return <ProjectValidatorResult>[
|
||||
_createProjectValidatorError(name, 'Command dart pub deps --json failed')
|
||||
];
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, dynamic> jsonResult;
|
||||
final List<ProjectValidatorResult> result = <ProjectValidatorResult>[];
|
||||
try {
|
||||
jsonResult = json.decode(
|
||||
processResult.stdout.toString()
|
||||
) as LinkedHashMap<String, dynamic>;
|
||||
} on FormatException {
|
||||
result.add(_createProjectValidatorError(name, processResult.stderr.toString()));
|
||||
return result;
|
||||
}
|
||||
|
||||
final DartPubJson dartPubJson = DartPubJson(jsonResult);
|
||||
final List <String> dependencies = <String>[];
|
||||
|
||||
// Information retrieved from the pubspec.lock file if a dependency comes from
|
||||
// the hosted url https://pub.dartlang.org we ignore it or if the package
|
||||
// is the current directory being analyzed (root).
|
||||
final Set<String> hostedDependencies = <String>{'hosted', 'root'};
|
||||
|
||||
for (final DartDependencyPackage package in dartPubJson.packages) {
|
||||
if (!hostedDependencies.contains(package.source)) {
|
||||
dependencies.addAll(package.dependencies);
|
||||
}
|
||||
}
|
||||
|
||||
final String value;
|
||||
if (dependencies.isNotEmpty) {
|
||||
final String verb = dependencies.length == 1 ? 'is' : 'are';
|
||||
value = '${dependencies.join(', ')} $verb not hosted';
|
||||
} else {
|
||||
value = 'All pub dependencies are hosted on https://pub.dartlang.org';
|
||||
}
|
||||
|
||||
result.add(
|
||||
ProjectValidatorResult(
|
||||
name: name,
|
||||
value: value,
|
||||
status: StatusProjectValidator.info,
|
||||
)
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
bool supportsProject(FlutterProject project) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
String get title => 'Pub dependencies';
|
||||
|
||||
ProjectValidatorResult _createProjectValidatorError(String name, String value) {
|
||||
return ProjectValidatorResult(name: name, value: value, status: StatusProjectValidator.error);
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/project_validator.dart';
|
||||
import 'package:flutter_tools/src/project_validator_result.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
|
||||
group('PubDependenciesProjectValidator', () {
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
testWithoutContext('success when all dependencies are hosted', () async {
|
||||
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['dart', 'pub', 'deps', '--json'],
|
||||
stdout: '{"packages": [{"dependencies": ["abc"], "source": "hosted"}]}',
|
||||
),
|
||||
]);
|
||||
final PubDependenciesProjectValidator validator = PubDependenciesProjectValidator(processManager);
|
||||
|
||||
final List<ProjectValidatorResult> result = await validator.start(
|
||||
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)
|
||||
);
|
||||
const String expected = 'All pub dependencies are hosted on https://pub.dartlang.org';
|
||||
expect(result.length, 1);
|
||||
expect(result[0].value, expected);
|
||||
expect(result[0].status, StatusProjectValidator.info);
|
||||
});
|
||||
|
||||
testWithoutContext('error when command dart pub deps fails', () async {
|
||||
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['dart', 'pub', 'deps', '--json'],
|
||||
stderr: 'command fail',
|
||||
),
|
||||
]);
|
||||
final PubDependenciesProjectValidator validator = PubDependenciesProjectValidator(processManager);
|
||||
|
||||
final List<ProjectValidatorResult> result = await validator.start(
|
||||
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)
|
||||
);
|
||||
const String expected = 'command fail';
|
||||
expect(result.length, 1);
|
||||
expect(result[0].value, expected);
|
||||
expect(result[0].status, StatusProjectValidator.error);
|
||||
});
|
||||
|
||||
testWithoutContext('info on dependencies not hosted', () async {
|
||||
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['dart', 'pub', 'deps', '--json'],
|
||||
stdout: '{"packages": [{"dependencies": ["dep1", "dep2"], "source": "other"}]}',
|
||||
),
|
||||
]);
|
||||
final PubDependenciesProjectValidator validator = PubDependenciesProjectValidator(processManager);
|
||||
|
||||
final List<ProjectValidatorResult> result = await validator.start(
|
||||
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)
|
||||
);
|
||||
const String expected = 'dep1, dep2 are not hosted';
|
||||
expect(result.length, 1);
|
||||
expect(result[0].value, expected);
|
||||
expect(result[0].status, StatusProjectValidator.info);
|
||||
});
|
||||
});
|
||||
}
|
@ -63,38 +63,6 @@ void main() {
|
||||
|
||||
expect(loggerTest.statusText, contains(expected));
|
||||
});
|
||||
|
||||
testUsingContext('PubDependenciesProjectValidator success ', () async {
|
||||
final BufferLogger loggerTest = BufferLogger.test();
|
||||
final AnalyzeCommand command = AnalyzeCommand(
|
||||
artifacts: globals.artifacts!,
|
||||
fileSystem: fileSystem,
|
||||
logger: loggerTest,
|
||||
platform: globals.platform,
|
||||
terminal: globals.terminal,
|
||||
processManager: globals.processManager,
|
||||
allProjectValidators: <ProjectValidator>[
|
||||
PubDependenciesProjectValidator(globals.processManager),
|
||||
],
|
||||
suppressAnalytics: true,
|
||||
);
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>[
|
||||
'analyze',
|
||||
'--no-pub',
|
||||
'--no-current-package',
|
||||
'--suggestions',
|
||||
'../../dev/integration_tests/flutter_gallery',
|
||||
]);
|
||||
|
||||
const String expected = '\n'
|
||||
'┌────────────────────────────────────────────────────────────────────────────────────┐\n'
|
||||
'│ Pub dependencies │\n'
|
||||
'│ [✓] Dart dependencies: All pub dependencies are hosted on https://pub.dartlang.org │\n'
|
||||
'└────────────────────────────────────────────────────────────────────────────────────┘\n';
|
||||
expect(loggerTest.statusText, contains(expected));
|
||||
});
|
||||
});
|
||||
|
||||
group('analyze --suggestions --machine command integration', () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user