33// BSD-style license that can be found in the LICENSE file.
44
55import 'package:analyzer/file_system/file_system.dart' ;
6- import 'package:analyzer/file_system/physical_file_system.dart' ;
76import 'package:analyzer/src/dart/analysis/experiments.dart' ;
87import 'package:analyzer/src/util/file_paths.dart' as file_paths;
98import 'package:analyzer/utilities/package_config_file_builder.dart' ;
109import 'package:analyzer_testing/mock_packages/mock_packages.dart' ;
11- import 'package:analyzer_testing/package_root.dart' as package_root;
1210import 'package:analyzer_testing/utilities/extensions/resource_provider.dart' ;
1311
1412/// A mixin adding functionality to write `.dart_tool/package_config.json`
1513/// files along with mock packages to a [ResourceProvider] .
1614mixin ConfigurationFilesMixin on MockPackagesMixin {
17- String get latestLanguageVersion =>
18- '${ExperimentStatus .currentVersion .major }.'
19- '${ExperimentStatus .currentVersion .minor }' ;
20-
21- String get testPackageLanguageVersion => latestLanguageVersion;
15+ /// The Dart language version of the test package being used for testing.
16+ String get testPackageLanguageVersion => _latestLanguageVersion;
2217
2318 /// The path to the test package being used for testing.
2419 String get testPackageRootPath;
2520
26- String convertPath (String fileName) => resourceProvider.convertPath (fileName);
27-
28- String toUriStr (String filePath) =>
29- pathContext.toUri (convertPath (filePath)).toString ();
21+ String get _latestLanguageVersion =>
22+ '${ExperimentStatus .currentVersion .major }.'
23+ '${ExperimentStatus .currentVersion .minor }' ;
3024
3125 /// Writes a package_config.json for the package at [projectFolderPath] . If
3226 /// [packageName] is not supplied, the last segment of [projectFolderPath] is
@@ -43,9 +37,8 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
4337 bool meta = false ,
4438 bool pedantic = false ,
4539 bool vector_math = false ,
46- bool macro = false ,
4740 }) {
48- projectFolderPath = convertPath (projectFolderPath);
41+ projectFolderPath = resourceProvider. convertPath (projectFolderPath);
4942
5043 if (config == null ) {
5144 config = PackageConfigFileBuilder ();
@@ -66,14 +59,11 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
6659 }
6760
6861 if (flutter) {
69- {
70- var libFolder = addUI ();
71- config.add (name: 'ui' , rootPath: libFolder.parent.path);
72- }
73- {
74- var libFolder = addFlutter ();
75- config.add (name: 'flutter' , rootPath: libFolder.parent.path);
76- }
62+ var uiLibFolder = addUI ();
63+ config.add (name: 'ui' , rootPath: uiLibFolder.parent.path);
64+
65+ var flutterLibFolder = addFlutter ();
66+ config.add (name: 'flutter' , rootPath: flutterLibFolder.parent.path);
7767 }
7868
7969 if (flutter_test) {
@@ -91,30 +81,18 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
9181 config.add (name: 'vector_math' , rootPath: libFolder.parent.path);
9282 }
9383
94- if (macro ) {
95- // TODO(dantup): This code may need to change/be removed depending on how
96- // we ultimately reference the macro packages/libraries.
97- var physical = PhysicalResourceProvider .INSTANCE ;
98- var packageRoot = physical.pathContext.normalize (
99- package_root.packageRoot,
100- );
101-
102- for (var package in ['macros' , '_macros' ]) {
103- var destination = resourceProvider.getFolder (
104- convertPath ('$packagesRootPath /$package ' ),
105- );
106- physical
107- .getFolder (packageRoot)
108- .getChildAssumingFolder (package)
109- .copyTo (destination.parent);
110- config.add (name: package, rootPath: destination.path);
111- }
112- }
113-
114- _newPackageConfigJsonFile (
115- projectFolderPath,
116- config.toContent (toUriStr: toUriStr),
84+ var content = config.toContent (
85+ toUriStr:
86+ (p) => pathContext.toUri (resourceProvider.convertPath (p)).toString (),
11787 );
88+
89+ var projectFolder = resourceProvider.getFolder (projectFolderPath);
90+ var dartToolFolder = projectFolder.getChildAssumingFolder (
91+ file_paths.dotDartTool,
92+ )..create ();
93+ dartToolFolder
94+ .getChildAssumingFile (file_paths.packageConfigJson)
95+ .writeAsStringSync (content);
11896 }
11997
12098 /// Writes a package_config.json for the package under test (considered
@@ -127,7 +105,6 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
127105 bool meta = false ,
128106 bool pedantic = false ,
129107 bool vector_math = false ,
130- bool macro = false ,
131108 }) {
132109 writePackageConfig (
133110 testPackageRootPath,
@@ -139,20 +116,6 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
139116 meta: meta,
140117 pedantic: pedantic,
141118 vector_math: vector_math,
142- macro : macro ,
143- );
144- }
145-
146- File _newPackageConfigJsonFile (String packageRootPath, String content) {
147- var dartToolDirectoryPath = pathContext.join (
148- packageRootPath,
149- file_paths.dotDartTool,
150- );
151- var filePath = pathContext.join (
152- dartToolDirectoryPath,
153- file_paths.packageConfigJson,
154119 );
155- resourceProvider.getFolder (dartToolDirectoryPath).create ();
156- return resourceProvider.getFile (filePath)..writeAsStringSync (content);
157120 }
158121}
0 commit comments