Unverified Commit b4e4e8d9 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] do not crash validator if intellij JAR file is missing (#67931)

This failure has been happening for a while but was covered by the overly broad catch. Removing that revealed that newer intellij versions have a different plugins file. The tool still can't find the file, but it won't crash now

Fixes #67918
parent 7668f06f
......@@ -73,11 +73,14 @@ class IntelliJPlugins {
final String jarPath = packageName.endsWith('.jar')
? _fileSystem.path.join(pluginsPath, packageName)
: _fileSystem.path.join(pluginsPath, packageName, 'lib', '$packageName.jar');
final File file = _fileSystem.file(jarPath);
if (!file.existsSync()) {
return null;
}
try {
final Archive archive =
ZipDecoder().decodeBytes(_fileSystem.file(jarPath).readAsBytesSync());
final ArchiveFile file = archive.findFile('META-INF/plugin.xml');
final String content = utf8.decode(file.content as List<int>);
final Archive archive = ZipDecoder().decodeBytes(file.readAsBytesSync());
final ArchiveFile archiveFile = archive.findFile('META-INF/plugin.xml');
final String content = utf8.decode(archiveFile.content as List<int>);
const String versionStartTag = '<version>';
final int start = content.indexOf(versionStartTag);
final int end = content.indexOf('</version>', start);
......
......@@ -89,6 +89,27 @@ void main() {
expect(message.message, contains('Flutter plugin can be installed from'));
expect(message.contextUrl, isNotNull);
});
testWithoutContext('IntelliJPlugins does not crash if no plugin file found', () async {
final IntelliJPlugins plugins = IntelliJPlugins(_kPluginsPath, fileSystem: fileSystem);
final Archive dartJarArchive =
buildSingleFileArchive('META-INF/plugin.xml', r'''
<idea-plugin version="2">
<name>Dart</name>
<version>162.2485</version>
</idea-plugin>
''');
writeFileCreatingDirectories(
fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Other.jar'),
ZipEncoder().encode(dartJarArchive),
);
expect(
() => plugins.validatePackage(<ValidationMessage>[], <String>['Dart'], 'Dart', 'download-Dart'),
returnsNormally,
);
});
}
const String _kPluginsPath = '/data/intellij/plugins';
......
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