Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d5a0fcd5
Unverified
Commit
d5a0fcd5
authored
Aug 08, 2023
by
Lau Ching Jun
Committed by
GitHub
Aug 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Locate the template directory using a TemplatePathProvider. (#132156)
So that the paths can be overridden.
parent
547bdefb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
34 deletions
+44
-34
application_package.dart
packages/flutter_tools/lib/src/ios/application_package.dart
+1
-1
template.dart
packages/flutter_tools/lib/src/template.dart
+38
-29
template_test.dart
packages/flutter_tools/test/general.shard/template_test.dart
+5
-4
No files found.
packages/flutter_tools/lib/src/ios/application_package.dart
View file @
d5a0fcd5
...
...
@@ -191,7 +191,7 @@ class BuildableIOSApp extends IOSApp {
// Template asset's images are in flutter_template_images package.
Future
<
String
>
_templateImageAssetDirNameForImages
(
String
asset
)
async
{
final
Directory
imageTemplate
=
await
template
I
mageDirectory
(
null
,
globals
.
fs
,
globals
.
logger
);
final
Directory
imageTemplate
=
await
template
PathProvider
.
i
mageDirectory
(
null
,
globals
.
fs
,
globals
.
logger
);
return
globals
.
fs
.
path
.
join
(
imageTemplate
.
path
,
_templateImageAssetDirNameSuffix
(
asset
));
}
...
...
packages/flutter_tools/lib/src/template.dart
View file @
d5a0fcd5
...
...
@@ -7,6 +7,7 @@ import 'package:package_config/package_config.dart';
import
'package:package_config/package_config_types.dart'
;
import
'base/common.dart'
;
import
'base/context.dart'
;
import
'base/file_system.dart'
;
import
'base/logger.dart'
;
import
'base/template.dart'
;
...
...
@@ -19,6 +20,38 @@ import 'dart/package_map.dart';
/// https://kotlinlang.org/docs/keyword-reference.html
const
List
<
String
>
kReservedKotlinKeywords
=
<
String
>[
'when'
,
'in'
,
'is'
];
/// Provides the path where templates used by flutter_tools are stored.
class
TemplatePathProvider
{
const
TemplatePathProvider
();
/// Returns the directory containing the 'name' template directory.
Directory
directoryInPackage
(
String
name
,
FileSystem
fileSystem
)
{
final
String
templatesDir
=
fileSystem
.
path
.
join
(
Cache
.
flutterRoot
!,
'packages'
,
'flutter_tools'
,
'templates'
);
return
fileSystem
.
directory
(
fileSystem
.
path
.
join
(
templatesDir
,
name
));
}
/// Returns the directory containing the 'name' template directory in
/// flutter_template_images, to resolve image placeholder against.
/// if 'name' is null, return the parent template directory.
Future
<
Directory
>
imageDirectory
(
String
?
name
,
FileSystem
fileSystem
,
Logger
logger
)
async
{
final
String
toolPackagePath
=
fileSystem
.
path
.
join
(
Cache
.
flutterRoot
!,
'packages'
,
'flutter_tools'
);
final
String
packageFilePath
=
fileSystem
.
path
.
join
(
toolPackagePath
,
'.dart_tool'
,
'package_config.json'
);
final
PackageConfig
packageConfig
=
await
loadPackageConfigWithLogging
(
fileSystem
.
file
(
packageFilePath
),
logger:
logger
,
);
final
Uri
?
imagePackageLibDir
=
packageConfig
[
'flutter_template_images'
]?.
packageUriRoot
;
final
Directory
templateDirectory
=
fileSystem
.
directory
(
imagePackageLibDir
)
.
parent
.
childDirectory
(
'templates'
);
return
name
==
null
?
templateDirectory
:
templateDirectory
.
childDirectory
(
name
);
}
}
TemplatePathProvider
get
templatePathProvider
=>
context
.
get
<
TemplatePathProvider
>()
??
const
TemplatePathProvider
();
/// Expands templates in a directory to a destination. All files that must
/// undergo template expansion should end with the '.tmpl' extension. All files
/// that should be replaced with the corresponding image from
...
...
@@ -100,8 +133,8 @@ class Template {
required
TemplateRenderer
templateRenderer
,
})
async
{
// All named templates are placed in the 'templates' directory
final
Directory
templateDir
=
_templateD
irectoryInPackage
(
name
,
fileSystem
);
final
Directory
imageDir
=
await
template
I
mageDirectory
(
name
,
fileSystem
,
logger
);
final
Directory
templateDir
=
templatePathProvider
.
d
irectoryInPackage
(
name
,
fileSystem
);
final
Directory
imageDir
=
await
template
PathProvider
.
i
mageDirectory
(
name
,
fileSystem
,
logger
);
return
Template
.
_
(
<
Directory
>[
templateDir
],
<
Directory
>[
imageDir
],
...
...
@@ -122,12 +155,12 @@ class Template {
return
Template
.
_
(
<
Directory
>[
for
(
final
String
name
in
names
)
_templateD
irectoryInPackage
(
name
,
fileSystem
),
templatePathProvider
.
d
irectoryInPackage
(
name
,
fileSystem
),
],
<
Directory
>[
for
(
final
String
name
in
names
)
if
((
await
template
I
mageDirectory
(
name
,
fileSystem
,
logger
)).
existsSync
())
await
template
I
mageDirectory
(
name
,
fileSystem
,
logger
),
if
((
await
template
PathProvider
.
i
mageDirectory
(
name
,
fileSystem
,
logger
)).
existsSync
())
await
template
PathProvider
.
i
mageDirectory
(
name
,
fileSystem
,
logger
),
],
fileSystem:
fileSystem
,
logger:
logger
,
...
...
@@ -344,30 +377,6 @@ class Template {
}
}
Directory
_templateDirectoryInPackage
(
String
name
,
FileSystem
fileSystem
)
{
final
String
templatesDir
=
fileSystem
.
path
.
join
(
Cache
.
flutterRoot
!,
'packages'
,
'flutter_tools'
,
'templates'
);
return
fileSystem
.
directory
(
fileSystem
.
path
.
join
(
templatesDir
,
name
));
}
/// Returns the directory containing the 'name' template directory in
/// flutter_template_images, to resolve image placeholder against.
/// if 'name' is null, return the parent template directory.
Future
<
Directory
>
templateImageDirectory
(
String
?
name
,
FileSystem
fileSystem
,
Logger
logger
)
async
{
final
String
toolPackagePath
=
fileSystem
.
path
.
join
(
Cache
.
flutterRoot
!,
'packages'
,
'flutter_tools'
);
final
String
packageFilePath
=
fileSystem
.
path
.
join
(
toolPackagePath
,
'.dart_tool'
,
'package_config.json'
);
final
PackageConfig
packageConfig
=
await
loadPackageConfigWithLogging
(
fileSystem
.
file
(
packageFilePath
),
logger:
logger
,
);
final
Uri
?
imagePackageLibDir
=
packageConfig
[
'flutter_template_images'
]?.
packageUriRoot
;
final
Directory
templateDirectory
=
fileSystem
.
directory
(
imagePackageLibDir
)
.
parent
.
childDirectory
(
'templates'
);
return
name
==
null
?
templateDirectory
:
templateDirectory
.
childDirectory
(
name
);
}
String
_escapeKotlinKeywords
(
String
androidIdentifier
)
{
final
List
<
String
>
segments
=
androidIdentifier
.
split
(
'.'
);
final
List
<
String
>
correctedSegments
=
segments
.
map
(
...
...
packages/flutter_tools/test/general.shard/template_test.dart
View file @
d5a0fcd5
...
...
@@ -51,8 +51,9 @@ void main() {
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
};
const
TemplatePathProvider
templatePathProvider
=
TemplatePathProvider
();
testUsingContext
(
'template
I
mageDirectory returns parent template directory if passed null name'
,
()
async
{
testUsingContext
(
'template
PathProvider.i
mageDirectory returns parent template directory if passed null name'
,
()
async
{
final
String
packageConfigPath
=
globals
.
fs
.
path
.
join
(
Cache
.
flutterRoot
!,
'packages'
,
...
...
@@ -77,7 +78,7 @@ void main() {
}
'''
);
expect
(
(
await
template
I
mageDirectory
(
null
,
globals
.
fs
,
globals
.
logger
)).
path
,
(
await
template
PathProvider
.
i
mageDirectory
(
null
,
globals
.
fs
,
globals
.
logger
)).
path
,
globals
.
fs
.
path
.
absolute
(
'flutter_template_images'
,
'templates'
,
...
...
@@ -85,7 +86,7 @@ void main() {
);
},
overrides:
overrides
);
testUsingContext
(
'template
I
mageDirectory returns the directory containing the `name` template directory'
,
()
async
{
testUsingContext
(
'template
PathProvider.i
mageDirectory returns the directory containing the `name` template directory'
,
()
async
{
final
String
packageConfigPath
=
globals
.
fs
.
path
.
join
(
Cache
.
flutterRoot
!,
'packages'
,
...
...
@@ -109,7 +110,7 @@ void main() {
}
'''
);
expect
(
(
await
template
I
mageDirectory
(
'app_shared'
,
globals
.
fs
,
globals
.
logger
)).
path
,
(
await
template
PathProvider
.
i
mageDirectory
(
'app_shared'
,
globals
.
fs
,
globals
.
logger
)).
path
,
globals
.
fs
.
path
.
absolute
(
'flutter_template_images'
,
'templates'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment