Unverified Commit cadb264d authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] Catch more general XmlException rather than XmlParserException (#107574)

parent b26346f2
...@@ -139,7 +139,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag ...@@ -139,7 +139,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
XmlDocument document; XmlDocument document;
try { try {
document = XmlDocument.parse(manifestString); document = XmlDocument.parse(manifestString);
} on XmlParserException catch (exception) { } on XmlException catch (exception) {
String manifestLocation; String manifestLocation;
if (androidProject.isUsingGradle) { if (androidProject.isUsingGradle) {
manifestLocation = fileSystem.path.join(androidProject.hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml'); manifestLocation = fileSystem.path.join(androidProject.hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml');
......
...@@ -84,7 +84,7 @@ class DeferredComponentsGenSnapshotValidator extends DeferredComponentsValidator ...@@ -84,7 +84,7 @@ class DeferredComponentsGenSnapshotValidator extends DeferredComponentsValidator
XmlDocument document; XmlDocument document;
try { try {
document = XmlDocument.parse(appManifestFile.readAsStringSync()); document = XmlDocument.parse(appManifestFile.readAsStringSync());
} on XmlParserException { } on XmlException {
invalidFiles[appManifestFile.path] = 'Error parsing $appManifestFile ' invalidFiles[appManifestFile.path] = 'Error parsing $appManifestFile '
'Please ensure that the android manifest is a valid XML document and ' 'Please ensure that the android manifest is a valid XML document and '
'try again.'; 'try again.';
......
...@@ -136,7 +136,7 @@ class DeferredComponentsPrebuildValidator extends DeferredComponentsValidator { ...@@ -136,7 +136,7 @@ class DeferredComponentsPrebuildValidator extends DeferredComponentsValidator {
XmlDocument document; XmlDocument document;
try { try {
document = XmlDocument.parse(stringRes.readAsStringSync()); document = XmlDocument.parse(stringRes.readAsStringSync());
} on XmlParserException { } on XmlException {
invalidFiles[stringRes.path] = 'Error parsing $stringRes ' invalidFiles[stringRes.path] = 'Error parsing $stringRes '
'Please ensure that the strings.xml is a valid XML document and ' 'Please ensure that the strings.xml is a valid XML document and '
'try again.'; 'try again.';
......
...@@ -958,7 +958,7 @@ String _getLocalArtifactVersion(String pomPath, FileSystem fileSystem) { ...@@ -958,7 +958,7 @@ String _getLocalArtifactVersion(String pomPath, FileSystem fileSystem) {
XmlDocument document; XmlDocument document;
try { try {
document = XmlDocument.parse(pomFile.readAsStringSync()); document = XmlDocument.parse(pomFile.readAsStringSync());
} on XmlParserException { } on XmlException {
throwToolExit( throwToolExit(
'Error parsing $pomPath. Please ensure that this is a valid XML document.' 'Error parsing $pomPath. Please ensure that this is a valid XML document.'
); );
......
...@@ -93,9 +93,7 @@ bool androidManifestHasNameVariable(final Directory projectDir) { ...@@ -93,9 +93,7 @@ bool androidManifestHasNameVariable(final Directory projectDir) {
XmlDocument document; XmlDocument document;
try { try {
document = XmlDocument.parse(manifestFile.readAsStringSync()); document = XmlDocument.parse(manifestFile.readAsStringSync());
} on XmlParserException { } on XmlException {
return false;
} on XmlTagException {
return false; return false;
} on FileSystemException { } on FileSystemException {
return false; return false;
......
...@@ -647,7 +647,7 @@ The detected reason was: ...@@ -647,7 +647,7 @@ The detected reason was:
XmlDocument document; XmlDocument document;
try { try {
document = XmlDocument.parse(appManifestFile.readAsStringSync()); document = XmlDocument.parse(appManifestFile.readAsStringSync());
} on XmlParserException { } on XmlException {
throwToolExit('Error parsing $appManifestFile ' throwToolExit('Error parsing $appManifestFile '
'Please ensure that the android manifest is a valid XML document and try again.'); 'Please ensure that the android manifest is a valid XML document and try again.');
} on FileSystemException { } on FileSystemException {
......
...@@ -188,6 +188,16 @@ void main() { ...@@ -188,6 +188,16 @@ void main() {
await project.regeneratePlatformSpecificTooling(); await project.regeneratePlatformSpecificTooling();
expectExists(project.android.hostAppGradleRoot.childFile('local.properties')); expectExists(project.android.hostAppGradleRoot.childFile('local.properties'));
}); });
_testInMemory('checkForDeprecation fails on invalid android app manifest file', () async {
// This is not a valid Xml document
const String invalidManifest = '<manifest></application>';
final FlutterProject project = await someProject(androidManifestOverride: invalidManifest);
expect(
() => project.checkForDeprecation(deprecationBehavior: DeprecationBehavior.ignore),
throwsToolExit(message: 'Please ensure that the android manifest is a valid XML document and try again.'),
);
});
_testInMemory('Android project not on v2 embedding shows a warning', () async { _testInMemory('Android project not on v2 embedding shows a warning', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
// The default someProject with an empty <manifest> already indicates // The default someProject with an empty <manifest> already indicates
...@@ -769,7 +779,9 @@ apply plugin: 'kotlin-android' ...@@ -769,7 +779,9 @@ apply plugin: 'kotlin-android'
}); });
} }
Future<FlutterProject> someProject() async { Future<FlutterProject> someProject({
String androidManifestOverride,
}) async {
final Directory directory = globals.fs.directory('some_project'); final Directory directory = globals.fs.directory('some_project');
directory.childDirectory('.dart_tool') directory.childDirectory('.dart_tool')
.childFile('package_config.json') .childFile('package_config.json')
...@@ -781,7 +793,7 @@ Future<FlutterProject> someProject() async { ...@@ -781,7 +793,7 @@ Future<FlutterProject> someProject() async {
..createSync(recursive: true); ..createSync(recursive: true);
androidDirectory androidDirectory
.childFile('AndroidManifest.xml') .childFile('AndroidManifest.xml')
.writeAsStringSync('<manifest></manifest>'); .writeAsStringSync(androidManifestOverride ?? '<manifest></manifest>');
return FlutterProject.fromDirectory(directory); return FlutterProject.fromDirectory(directory);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment