[flutter_tools] remove unused JSON schema (#70480)
This commit is contained in:
@@ -10,7 +10,6 @@ import 'base/file_system.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/user_messages.dart';
|
||||
import 'base/utils.dart';
|
||||
import 'cache.dart';
|
||||
import 'plugins.dart';
|
||||
|
||||
/// A wrapper around the `flutter` section in the `pubspec.yaml` file.
|
||||
@@ -347,24 +346,7 @@ class FontAsset {
|
||||
String toString() => '$runtimeType(asset: ${assetUri.path}, weight; $weight, style: $style)';
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
String buildSchemaDir(FileSystem fileSystem) {
|
||||
return fileSystem.path.join(
|
||||
fileSystem.path.absolute(Cache.flutterRoot), 'packages', 'flutter_tools', 'schema',
|
||||
);
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
String buildSchemaPath(FileSystem fileSystem) {
|
||||
return fileSystem.path.join(
|
||||
buildSchemaDir(fileSystem),
|
||||
'pubspec_yaml.json',
|
||||
);
|
||||
}
|
||||
|
||||
/// This method should be kept in sync with the schema in
|
||||
/// `$FLUTTER_ROOT/packages/flutter_tools/schema/pubspec_yaml.json`,
|
||||
/// but avoid introducing dependencies on packages for simple validation.
|
||||
bool _validate(dynamic manifest, Logger logger) {
|
||||
final List<String> errors = <String>[];
|
||||
if (manifest is! YamlMap) {
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$comment": "This should be kept in sync with the validator in packages/flutter_tools/lib/src/flutter_manifest.dart",
|
||||
"title": "pubspec.yaml",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"flutter": {
|
||||
"oneOf": [
|
||||
{ "type": "object" },
|
||||
{ "type": "null" }
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"uses-material-design": { "type": "boolean" },
|
||||
"assets": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"services": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"fonts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"family": { "type": "string" },
|
||||
"fonts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"asset": { "type": "string" },
|
||||
"weight": { "enum": [ 100, 200, 300, 400, 500, 600, 700, 800, 900 ] },
|
||||
"style": { "enum": [ "normal", "italic" ] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"androidX": { "type": "boolean" },
|
||||
"androidPackage": { "type": "string" },
|
||||
"iosBundleIdentifier": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"plugin": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"platforms": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"android": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"package": {"type": "string"},
|
||||
"pluginClass": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"ios": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"pluginClass": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"linux": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"pluginClass": {"type": "string"},
|
||||
"dartPluginClass": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"macos": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"pluginClass": {"type": "string"},
|
||||
"dartPluginClass": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"windows": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"pluginClass": {"type": "string"},
|
||||
"dartPluginClass": {"type": "string"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"androidPackage": { "type": "string" },
|
||||
"iosPrefix": { "type": "string" },
|
||||
"macosPrefix": { "type": "string" },
|
||||
"pluginClass": { "type": "string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import 'package:process/process.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/mocks.dart';
|
||||
import '../../src/pubspec_schema.dart';
|
||||
|
||||
void main() {
|
||||
Cache.flutterRoot = getFlutterRoot();
|
||||
@@ -553,8 +552,6 @@ include ':app'
|
||||
manifestFile.createSync(recursive: true);
|
||||
manifestFile.writeAsStringSync(manifest);
|
||||
|
||||
// write schemaData otherwise pubspec.yaml file can't be loaded
|
||||
writeEmptySchemaFile(fs);
|
||||
|
||||
updateLocalProperties(
|
||||
project: FlutterProject.fromPath('path/to/project'),
|
||||
|
||||
@@ -14,7 +14,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/pubspec_schema.dart';
|
||||
|
||||
void main() {
|
||||
String fixPath(String path) {
|
||||
@@ -106,8 +105,6 @@ $fontsSection
|
||||
});
|
||||
|
||||
testUsingContext('App includes neither font manifest nor fonts when no defines fonts', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
@@ -122,8 +119,6 @@ $fontsSection
|
||||
});
|
||||
|
||||
testUsingContext('App font uses font file from package', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
const String fontsSection = '''
|
||||
- family: foo
|
||||
fonts:
|
||||
@@ -150,8 +145,6 @@ $fontsSection
|
||||
});
|
||||
|
||||
testUsingContext('App font uses local font file and package font file', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
const String fontsSection = '''
|
||||
- family: foo
|
||||
fonts:
|
||||
@@ -182,8 +175,6 @@ $fontsSection
|
||||
});
|
||||
|
||||
testUsingContext('App uses package font with own font file', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
const String fontsSection = '''
|
||||
@@ -215,8 +206,6 @@ $fontsSection
|
||||
});
|
||||
|
||||
testUsingContext('App uses package font with font file from another package', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/\ntest_package2:p2/p/lib/');
|
||||
const String fontsSection = '''
|
||||
@@ -249,8 +238,6 @@ $fontsSection
|
||||
});
|
||||
|
||||
testUsingContext('App uses package font with properties and own font file', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -284,8 +271,6 @@ $fontsSection
|
||||
});
|
||||
|
||||
testUsingContext('App uses local font and package font with own font file.', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
const String fontsSection = '''
|
||||
- family: foo
|
||||
fonts:
|
||||
|
||||
@@ -14,7 +14,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/pubspec_schema.dart';
|
||||
|
||||
void main() {
|
||||
String fixPath(String path) {
|
||||
@@ -115,8 +114,6 @@ $assetsSection
|
||||
|
||||
group('AssetBundle assets from packages', () {
|
||||
testUsingContext('No assets are bundled when the package has no assets', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
@@ -139,8 +136,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext('No assets are bundled when the package has an asset that is not listed', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
@@ -167,8 +162,6 @@ $assetsSection
|
||||
|
||||
testUsingContext('One asset is bundled when the package has and lists one '
|
||||
'asset its pubspec', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -195,8 +188,6 @@ $assetsSection
|
||||
|
||||
testUsingContext('One asset is bundled when the package has one asset, '
|
||||
"listed in the app's pubspec", () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
final List<String> assetEntries = <String>['packages/test_package/a/foo'];
|
||||
writePubspecFile(
|
||||
'pubspec.yaml',
|
||||
@@ -223,8 +214,6 @@ $assetsSection
|
||||
|
||||
testUsingContext('One asset and its variant are bundled when the package '
|
||||
'has an asset and a variant, and lists the asset in its pubspec', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
writePubspecFile(
|
||||
@@ -251,8 +240,6 @@ $assetsSection
|
||||
|
||||
testUsingContext('One asset and its variant are bundled when the package '
|
||||
'has an asset and a variant, and the app lists the asset in its pubspec', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile(
|
||||
'pubspec.yaml',
|
||||
'test',
|
||||
@@ -282,8 +269,6 @@ $assetsSection
|
||||
|
||||
testUsingContext('Two assets are bundled when the package has and lists '
|
||||
'two assets in its pubspec', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -310,8 +295,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext("Two assets are bundled when the package has two assets, listed in the app's pubspec", () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
final List<String> assetEntries = <String>[
|
||||
'packages/test_package/a/foo',
|
||||
'packages/test_package/a/bar',
|
||||
@@ -345,8 +328,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext('Two assets are bundled when two packages each have and list an asset their pubspec', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile(
|
||||
'pubspec.yaml',
|
||||
'test',
|
||||
@@ -384,8 +365,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext("Two assets are bundled when two packages each have an asset, listed in the app's pubspec", () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
final List<String> assetEntries = <String>[
|
||||
'packages/test_package/a/foo',
|
||||
'packages/test_package2/a/foo',
|
||||
@@ -427,7 +406,6 @@ $assetsSection
|
||||
|
||||
testUsingContext('One asset is bundled when the app depends on a package, '
|
||||
'listing in its pubspec an asset from another package', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
writePubspecFile(
|
||||
'pubspec.yaml',
|
||||
'test',
|
||||
@@ -462,8 +440,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext('Asset paths can contain URL reserved characters', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -491,8 +467,6 @@ $assetsSection
|
||||
|
||||
group('AssetBundle assets from scanned paths', () {
|
||||
testUsingContext('Two assets are bundled when scanning their directory', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -521,8 +495,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext('Two assets are bundled when listing one and scanning second directory', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -551,8 +523,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext('One asset is bundled with variant, scanning wrong directory', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -580,8 +550,6 @@ $assetsSection
|
||||
|
||||
group('AssetBundle assets from scanned paths with MemoryFileSystem', () {
|
||||
testUsingContext('One asset is bundled with variant, scanning directory', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -609,8 +577,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext('No asset is bundled with variant, no assets or directories are listed', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
@@ -637,8 +603,6 @@ $assetsSection
|
||||
});
|
||||
|
||||
testUsingContext('Expect error generating manifest, wrong non-existing directory is listed', () async {
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/pubspec_schema.dart';
|
||||
|
||||
void main() {
|
||||
String fixPath(String path) {
|
||||
@@ -38,10 +37,6 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('main asset and variants', () async {
|
||||
// Setting flutterRoot here so that it picks up the MemoryFileSystem's
|
||||
// path separator.
|
||||
writeEmptySchemaFile(globals.fs);
|
||||
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(
|
||||
|
||||
@@ -19,7 +19,6 @@ import 'package:process/process.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/mocks.dart' as mocks;
|
||||
import '../../src/pubspec_schema.dart';
|
||||
|
||||
const String xcodebuild = '/usr/bin/xcodebuild';
|
||||
|
||||
@@ -803,9 +802,6 @@ Information about project "Runner":
|
||||
manifestFile.createSync(recursive: true);
|
||||
manifestFile.writeAsStringSync(manifestString);
|
||||
|
||||
// write schemaData otherwise pubspec.yaml file can't be loaded
|
||||
writeEmptySchemaFile(fs);
|
||||
|
||||
await updateGeneratedXcodeProperties(
|
||||
project: FlutterProject.fromPath('path/to/project'),
|
||||
buildInfo: buildInfo,
|
||||
|
||||
@@ -792,10 +792,6 @@ void _testInMemory(String description, Future<void> testMethod()) {
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools')
|
||||
.childDirectory('templates'), testFileSystem);
|
||||
transfer(globals.fs.directory(Cache.flutterRoot)
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools')
|
||||
.childDirectory('schema'), testFileSystem);
|
||||
// Set up enough of the packages to satisfy the templating code.
|
||||
final File packagesFile = testFileSystem.directory(Cache.flutterRoot)
|
||||
.childDirectory('packages')
|
||||
|
||||
@@ -2,31 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/flutter_manifest.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:yaml/yaml.dart';
|
||||
import 'common.dart';
|
||||
|
||||
/// Writes a schemaData used for validating pubspec.yaml files when parsing
|
||||
/// asset information.
|
||||
void writeSchemaFile(FileSystem filesystem, String schemaData) {
|
||||
final String schemaPath = buildSchemaPath(filesystem);
|
||||
final File schemaFile = filesystem.file(schemaPath);
|
||||
|
||||
final String schemaDir = buildSchemaDir(filesystem);
|
||||
|
||||
filesystem.directory(schemaDir).createSync(recursive: true);
|
||||
schemaFile.writeAsStringSync(schemaData);
|
||||
}
|
||||
|
||||
/// Writes an empty schemaData that will validate any pubspec.yaml file.
|
||||
void writeEmptySchemaFile(FileSystem filesystem) {
|
||||
writeSchemaFile(filesystem, '{}');
|
||||
}
|
||||
|
||||
/// Check if the pubspec.yaml file under the `projectDir` is valid for a plugin project.
|
||||
void validatePubspecForPlugin({@required String projectDir, @required String pluginClass, @required List<String> expectedPlatforms, List<String> unexpectedPlatforms = const <String>[], String androidIdentifier, String webFileName}) {
|
||||
final FlutterManifest manifest = FlutterManifest.createFromPath(projectDir+'/pubspec.yaml', fileSystem: globals.fs, logger: globals.logger);
|
||||
|
||||
Reference in New Issue
Block a user