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
XmlDocument document;
try {
document = XmlDocument.parse(manifestString);
} on XmlParserException catch (exception) {
} on XmlException catch (exception) {
String manifestLocation;
if (androidProject.isUsingGradle) {
manifestLocation = fileSystem.path.join(androidProject.hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml');
......
......@@ -84,7 +84,7 @@ class DeferredComponentsGenSnapshotValidator extends DeferredComponentsValidator
XmlDocument document;
try {
document = XmlDocument.parse(appManifestFile.readAsStringSync());
} on XmlParserException {
} on XmlException {
invalidFiles[appManifestFile.path] = 'Error parsing $appManifestFile '
'Please ensure that the android manifest is a valid XML document and '
'try again.';
......
......@@ -136,7 +136,7 @@ class DeferredComponentsPrebuildValidator extends DeferredComponentsValidator {
XmlDocument document;
try {
document = XmlDocument.parse(stringRes.readAsStringSync());
} on XmlParserException {
} on XmlException {
invalidFiles[stringRes.path] = 'Error parsing $stringRes '
'Please ensure that the strings.xml is a valid XML document and '
'try again.';
......
......@@ -958,7 +958,7 @@ String _getLocalArtifactVersion(String pomPath, FileSystem fileSystem) {
XmlDocument document;
try {
document = XmlDocument.parse(pomFile.readAsStringSync());
} on XmlParserException {
} on XmlException {
throwToolExit(
'Error parsing $pomPath. Please ensure that this is a valid XML document.'
);
......
......@@ -93,9 +93,7 @@ bool androidManifestHasNameVariable(final Directory projectDir) {
XmlDocument document;
try {
document = XmlDocument.parse(manifestFile.readAsStringSync());
} on XmlParserException {
return false;
} on XmlTagException {
} on XmlException {
return false;
} on FileSystemException {
return false;
......
......@@ -647,7 +647,7 @@ The detected reason was:
XmlDocument document;
try {
document = XmlDocument.parse(appManifestFile.readAsStringSync());
} on XmlParserException {
} on XmlException {
throwToolExit('Error parsing $appManifestFile '
'Please ensure that the android manifest is a valid XML document and try again.');
} on FileSystemException {
......
......@@ -188,6 +188,16 @@ void main() {
await project.regeneratePlatformSpecificTooling();
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 {
final FlutterProject project = await someProject();
// The default someProject with an empty <manifest> already indicates
......@@ -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');
directory.childDirectory('.dart_tool')
.childFile('package_config.json')
......@@ -781,7 +793,7 @@ Future<FlutterProject> someProject() async {
..createSync(recursive: true);
androidDirectory
.childFile('AndroidManifest.xml')
.writeAsStringSync('<manifest></manifest>');
.writeAsStringSync(androidManifestOverride ?? '<manifest></manifest>');
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