From 1e180062aa17416053580c81953411c6373f0c38 Mon Sep 17 00:00:00 2001 From: Nobuhiro Tabuki Date: Tue, 13 Oct 2020 14:03:36 +0900 Subject: [PATCH] [flutter_tools] Support IntelliJ 2020.1 and later on Linux and Windows (#58853) This PR will update IntelliJ IDEA/Community validation logic for 2020.1 and later on Linux and Windows. --- AUTHORS | 1 + .../lib/src/intellij/intellij_validator.dart | 170 +++++++++- .../intellij/intellij_validator_test.dart | 293 ++++++++++++++++-- 3 files changed, 425 insertions(+), 39 deletions(-) diff --git a/AUTHORS b/AUTHORS index 7d0b9e62a90c..0fe69e439379 100644 --- a/AUTHORS +++ b/AUTHORS @@ -67,3 +67,4 @@ Ram Navan meritozh Terrence Addison Tandijono(flotilla) YeungKC +Nobuhiro Tabuki diff --git a/packages/flutter_tools/lib/src/intellij/intellij_validator.dart b/packages/flutter_tools/lib/src/intellij/intellij_validator.dart index e5ae1db939e8..7845c82706c8 100644 --- a/packages/flutter_tools/lib/src/intellij/intellij_validator.dart +++ b/packages/flutter_tools/lib/src/intellij/intellij_validator.dart @@ -47,8 +47,16 @@ abstract class IntelliJValidator extends DoctorValidator { @required PlistParser plistParser, }) { final FileSystemUtils fileSystemUtils = FileSystemUtils(fileSystem: fileSystem, platform: platform); - if (platform.isLinux || platform.isWindows) { - return IntelliJValidatorOnLinuxAndWindows.installed( + if (platform.isWindows) { + return IntelliJValidatorOnWindows.installed( + fileSystem: fileSystem, + fileSystemUtils: fileSystemUtils, + platform: platform, + userMessages: userMessages, + ); + } + if (platform.isLinux) { + return IntelliJValidatorOnLinux.installed( fileSystem: fileSystem, fileSystemUtils: fileSystemUtils, userMessages: userMessages, @@ -124,9 +132,9 @@ abstract class IntelliJValidator extends DoctorValidator { } } -/// A linux and windows specific implementation of the intellij validator. -class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { - IntelliJValidatorOnLinuxAndWindows(String title, this.version, String installPath, this.pluginsPath, { +/// A windows specific implementation of the intellij validator. +class IntelliJValidatorOnWindows extends IntelliJValidator { + IntelliJValidatorOnWindows(String title, this.version, String installPath, this.pluginsPath, { @required FileSystem fileSystem, @required UserMessages userMessages, }) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages); @@ -140,6 +148,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { static Iterable installed({ @required FileSystem fileSystem, @required FileSystemUtils fileSystemUtils, + @required Platform platform, @required UserMessages userMessages, }) { final List validators = []; @@ -148,7 +157,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { } void addValidator(String title, String version, String installPath, String pluginsPath) { - final IntelliJValidatorOnLinuxAndWindows validator = IntelliJValidatorOnLinuxAndWindows( + final IntelliJValidatorOnWindows validator = IntelliJValidatorOnWindows( title, version, installPath, @@ -158,7 +167,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { ); for (int index = 0; index < validators.length; index += 1) { final DoctorValidator other = validators[index]; - if (other is IntelliJValidatorOnLinuxAndWindows && validator.installPath == other.installPath) { + if (other is IntelliJValidatorOnWindows && validator.installPath == other.installPath) { if (validator.version.compareTo(other.version) > 0) { validators[index] = validator; } @@ -168,6 +177,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { validators.add(validator); } + // before IntelliJ 2019 final Directory homeDir = fileSystem.directory(fileSystemUtils.homeDirPath); for (final Directory dir in homeDir.listSync().whereType()) { final String name = fileSystem.path.basename(dir.path); @@ -187,6 +197,152 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { } }); } + + // after IntelliJ 2020 + final Directory cacheDir = fileSystem.directory(fileSystem.path.join(platform.environment['LOCALAPPDATA'], 'JetBrains')); + if (!cacheDir.existsSync()) { + return validators; + } + for (final Directory dir in cacheDir.listSync().whereType()) { + final String name = fileSystem.path.basename(dir.path); + IntelliJValidator._idToTitle.forEach((String id, String title) { + if (name.startsWith(id)) { + final String version = name.substring(id.length); + String installPath; + try { + installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync(); + } on FileSystemException { + // ignored + } + if (installPath != null && fileSystem.isDirectorySync(installPath)) { + String pluginsPath; + final String pluginsPathInAppData = fileSystem.path.join( + platform.environment['APPDATA'], 'JetBrains', name, 'plugins'); + if (fileSystem.isDirectorySync(installPath + '.plugins')) { + // IntelliJ 2020.3 + pluginsPath = installPath + '.plugins'; + addValidator(title, version, installPath, pluginsPath); + } else if (fileSystem.isDirectorySync(pluginsPathInAppData)) { + // IntelliJ 2020.1 ~ 2020.2 + pluginsPath = pluginsPathInAppData; + addValidator(title, version, installPath, pluginsPath); + } + } + } + }); + } + return validators; + } +} + +/// A linux specific implementation of the intellij validator. +class IntelliJValidatorOnLinux extends IntelliJValidator { + IntelliJValidatorOnLinux(String title, this.version, String installPath, this.pluginsPath, { + @required FileSystem fileSystem, + @required UserMessages userMessages, + }) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages); + + @override + final String version; + + @override + final String pluginsPath; + + static Iterable installed({ + @required FileSystem fileSystem, + @required FileSystemUtils fileSystemUtils, + @required UserMessages userMessages, + }) { + final List validators = []; + if (fileSystemUtils.homeDirPath == null) { + return validators; + } + + void addValidator(String title, String version, String installPath, String pluginsPath) { + final IntelliJValidatorOnLinux validator = IntelliJValidatorOnLinux( + title, + version, + installPath, + pluginsPath, + fileSystem: fileSystem, + userMessages: userMessages, + ); + for (int index = 0; index < validators.length; index += 1) { + final DoctorValidator other = validators[index]; + if (other is IntelliJValidatorOnLinux && validator.installPath == other.installPath) { + if (validator.version.compareTo(other.version) > 0) { + validators[index] = validator; + } + return; + } + } + validators.add(validator); + } + + // before IntelliJ 2019 + final Directory homeDir = fileSystem.directory(fileSystemUtils.homeDirPath); + for (final Directory dir in homeDir.listSync().whereType()) { + final String name = fileSystem.path.basename(dir.path); + IntelliJValidator._idToTitle.forEach((String id, String title) { + if (name.startsWith('.$id')) { + final String version = name.substring(id.length + 1); + String installPath; + try { + installPath = fileSystem.file(fileSystem.path.join(dir.path, 'system', '.home')).readAsStringSync(); + } on FileSystemException { + // ignored + } + if (installPath != null && fileSystem.isDirectorySync(installPath)) { + final String pluginsPath = fileSystem.path.join(dir.path, 'config', 'plugins'); + addValidator(title, version, installPath, pluginsPath); + } + } + }); + } + // after IntelliJ 2020 ~ + final Directory cacheDir = fileSystem.directory(fileSystem.path.join(fileSystemUtils.homeDirPath, '.cache', 'JetBrains')); + if (!cacheDir.existsSync()) { + return validators; + } + for (final Directory dir in cacheDir.listSync().whereType()) { + final String name = fileSystem.path.basename(dir.path); + IntelliJValidator._idToTitle.forEach((String id, String title) { + if (name.startsWith(id)) { + final String version = name.substring(id.length); + String installPath; + try { + installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync(); + } on FileSystemException { + // ignored + } + if (installPath != null && fileSystem.isDirectorySync(installPath)) { + final String pluginsPathInUserHomeDir = fileSystem.path.join( + fileSystemUtils.homeDirPath, + '.local', + 'share', + 'JetBrains', + name); + if (installPath.contains(fileSystem.path.join('JetBrains','Toolbox','apps'))) { + // via JetBrains ToolBox app + final String pluginsPathInInstallDir = installPath + '.plugins'; + if (fileSystem.isDirectorySync(pluginsPathInUserHomeDir)) { + // after 2020.2.x + final String pluginsPath = pluginsPathInUserHomeDir; + addValidator(title, version, installPath, pluginsPath); + } else if (fileSystem.isDirectorySync(pluginsPathInInstallDir)) { + // only 2020.1.X + final String pluginsPath = pluginsPathInInstallDir; + addValidator(title, version, installPath, pluginsPath); + } + } else { + // via tar.gz + final String pluginsPath = pluginsPathInUserHomeDir; + addValidator(title, version, installPath, pluginsPath); + } + } + } + }); + } return validators; } } diff --git a/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart b/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart index e5697d3a6224..7a1f2d819cea 100644 --- a/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart +++ b/packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart @@ -20,23 +20,27 @@ final Platform macPlatform = FakePlatform( operatingSystem: 'macos', environment: {'HOME': '/foo/bar'} ); +final Platform linuxPlatform = FakePlatform( + operatingSystem: 'linux', + environment: { + 'HOME': '/foo/bar' + }, +); +final Platform windowsPlatform = FakePlatform( + operatingSystem: 'windows', + environment: { + 'USERPROFILE': 'C:\\Users\\foo', + 'APPDATA': 'C:\\Users\\foo\\AppData\\Roaming', + 'LOCALAPPDATA': 'C:\\Users\\foo\\AppData\\Local' + }, +); void main() { testWithoutContext('Intellij validator can parse plugin manifest from plugin JAR', () async { final FileSystem fileSystem = MemoryFileSystem.test(); // Create plugin JAR file for Flutter and Dart plugin. - final List flutterPluginBytes = utf8.encode(kIntellijFlutterPluginXml); - final Archive flutterPlugins = Archive(); - flutterPlugins.addFile(ArchiveFile('META-INF/plugin.xml', flutterPluginBytes.length, flutterPluginBytes)); - fileSystem.file('plugins/flutter-intellij.jar') - ..createSync(recursive: true) - ..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)); - final List dartPluginBytes = utf8.encode(kIntellijDartPluginXml); - final Archive dartPlugins = Archive(); - dartPlugins.addFile(ArchiveFile('META-INF/plugin.xml', dartPluginBytes.length, dartPluginBytes)); - fileSystem.file('plugins/Dart/lib/Dart.jar') - ..createSync(recursive: true) - ..writeAsBytesSync(ZipEncoder().encode(dartPlugins)); + createIntellijFlutterPluginJar('plugins/flutter-intellij.jar', fileSystem); + createIntellijDartPluginJar('plugins/Dart/lib/Dart.jar', fileSystem); final ValidationResult result = await IntelliJValidatorTestTarget('', 'path/to/intellij', fileSystem).validate(); expect(result.type, ValidationType.partial); @@ -50,6 +54,222 @@ void main() { ]); }); + testWithoutContext('legacy intellij(<2020) plugins check on linux', () async { + const String cachePath = '/foo/bar/.IntelliJIdea2019.10/system'; + const String installPath = '/foo/bar/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-1/2019.10.1'; + const String pluginPath = '/foo/bar/.IntelliJIdea2019.10/config/plugins'; + final FileSystem fileSystem = MemoryFileSystem.test(); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + // Create plugin JAR file for Flutter and Dart plugin. + createIntellijFlutterPluginJar(pluginPath + '/flutter-intellij/lib/flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '/Dart/lib/Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnLinux.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: linuxPlatform), + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + + testWithoutContext('intellij(2020.1) plugins check on linux (installed via JetBrains ToolBox app)', () async { + const String cachePath = '/foo/bar/.cache/JetBrains/IntelliJIdea2020.10'; + const String installPath = '/foo/bar/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-1/2020.10.1'; + const String pluginPath = '/foo/bar/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-1/2020.10.1.plugins'; + final FileSystem fileSystem = MemoryFileSystem.test(); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + // Create plugin JAR file for Flutter and Dart plugin. + createIntellijFlutterPluginJar(pluginPath + '/flutter-intellij/lib/flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '/Dart/lib/Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnLinux.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: linuxPlatform), + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + + testWithoutContext('intellij(>=2020.2) plugins check on linux (installed via JetBrains ToolBox app)', () async { + const String cachePath = '/foo/bar/.cache/JetBrains/IntelliJIdea2020.10'; + const String installPath = '/foo/bar/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-1/2020.10.1'; + const String pluginPath = '/foo/bar/.local/share/JetBrains/IntelliJIdea2020.10'; + final FileSystem fileSystem = MemoryFileSystem.test(); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + // Create plugin JAR file for Flutter and Dart plugin. + createIntellijFlutterPluginJar(pluginPath + '/flutter-intellij/lib/flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '/Dart/lib/Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnLinux.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: linuxPlatform), + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + + testWithoutContext('intellij(2020.1~) plugins check on linux (installed via tar.gz)', () async { + const String cachePath = '/foo/bar/.cache/JetBrains/IdeaIC2020.10'; + const String installPath = '/foo/bar/some/dir/ideaIC-2020.10.1/idea-IC-201.0000.00'; + const String pluginPath = '/foo/bar/.local/share/JetBrains/IdeaIC2020.10'; + final FileSystem fileSystem = MemoryFileSystem.test(); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + // Create plugin JAR file for Flutter and Dart plugin. + createIntellijFlutterPluginJar(pluginPath + '/flutter-intellij/lib/flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '/Dart/lib/Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnLinux.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: linuxPlatform), + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + + testWithoutContext('legacy intellij(<2020) plugins check on windows', () async { + const String cachePath = 'C:\\Users\\foo\\.IntelliJIdea2019.10\\system'; + const String installPath = 'C:\\Program Files\\JetBrains\\IntelliJ IDEA Ultimate Edition 2019.10.1'; + const String pluginPath = 'C:\\Users\\foo\\.IntelliJIdea2019.10\\config\\plugins'; + final FileSystem fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + createIntellijFlutterPluginJar(pluginPath + '/flutter-intellij/lib/flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '/Dart/lib/Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnWindows.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: windowsPlatform), + platform: windowsPlatform, + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + + testWithoutContext('intellij(2020.1 ~ 2020.2) plugins check on windows (installed via JetBrains ToolBox app)', () async { + const String cachePath = 'C:\\Users\\foo\\AppData\\Local\\JetBrains\\IntelliJIdea2020.10'; + const String installPath = 'C:\\Users\\foo\\AppData\\Local\\JetBrains\\Toolbox\\apps\\IDEA-U\\ch-0\\201.0000.00'; + const String pluginPath = 'C:\\Users\\foo\\AppData\\Roaming\\JetBrains\\IntelliJIdea2020.10\\plugins'; + final FileSystem fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + createIntellijFlutterPluginJar(pluginPath + '\\flutter-intellij\\lib\\flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '\\Dart\\lib\\Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnWindows.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: windowsPlatform), + platform: windowsPlatform, + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + + testWithoutContext('intellij(>=2020.3) plugins check on windows (installed via JetBrains ToolBox app and plugins)', () async { + const String cachePath = 'C:\\Users\\foo\\AppData\\Local\\JetBrains\\IntelliJIdea2020.10'; + const String installPath = 'C:\\Users\\foo\\AppData\\Local\\JetBrains\\Toolbox\\apps\\IDEA-U\\ch-0\\201.0000.00'; + const String pluginPath = 'C:\\Users\\foo\\AppData\\Local\\JetBrains\\Toolbox\\apps\\IDEA-U\\ch-0\\201.0000.00.plugins'; + final FileSystem fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + createIntellijFlutterPluginJar(pluginPath + '\\flutter-intellij\\lib\\flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '\\Dart\\lib\\Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnWindows.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: windowsPlatform), + platform: windowsPlatform, + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + + testWithoutContext('intellij(2020.1~) plugins check on windows (installed via installer)', () async { + const String cachePath = 'C:\\Users\\foo\\AppData\\Local\\JetBrains\\IdeaIC2020.10'; + const String installPath = 'C:\\Program Files\\JetBrains\\IntelliJ IDEA Community Edition 2020.10.1'; + const String pluginPath = 'C:\\Users\\foo\\AppData\\Roaming\\JetBrains\\IdeaIC2020.10\\plugins'; + final FileSystem fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); + + final Directory cacheDirectory = fileSystem.directory(cachePath) + ..createSync(recursive: true); + cacheDirectory + .childFile('.home') + .writeAsStringSync(installPath, flush: true); + final Directory installedDirectory = fileSystem.directory(installPath); + installedDirectory.createSync(recursive: true); + createIntellijFlutterPluginJar(pluginPath + '\\flutter-intellij\\lib\\flutter-intellij.jar', fileSystem, version: '50.0'); + createIntellijDartPluginJar(pluginPath + '\\Dart\\lib\\Dart.jar', fileSystem); + + final Iterable installed = IntelliJValidatorOnWindows.installed( + fileSystem: fileSystem, + fileSystemUtils: FileSystemUtils(fileSystem: fileSystem, platform: windowsPlatform), + platform: windowsPlatform, + userMessages: UserMessages(), + ); + expect(1, installed.length); + final ValidationResult result = await installed.toList()[0].validate(); + expect(ValidationType.installed, result.type); + }); + testWithoutContext('Intellij plugins path checking on mac', () async { final FileSystem fileSystem = MemoryFileSystem.test(); final Directory pluginsDirectory = fileSystem.directory('/foo/bar/Library/Application Support/JetBrains/TestID2020.10/plugins') @@ -127,16 +347,18 @@ class IntelliJValidatorTestTarget extends IntelliJValidator { String get version => 'test.test.test'; } - +/// A helper to create a Intellij Flutter plugin jar. +/// /// These file contents were derived from the META-INF/plugin.xml from an Intellij Flutter /// plugin installation. /// -/// The file is loacted in a plugin JAR, which can be located by looking at the plugin +/// The file is located in a plugin JAR, which can be located by looking at the plugin /// path for the Intellij and Android Studio validators. /// /// If more XML contents are needed, prefer modifying these contents over checking /// in another JAR. -const String kIntellijFlutterPluginXml = r''' +void createIntellijFlutterPluginJar(String pluginJarPath, FileSystem fileSystem, {String version = '0.1.3'}) { + final String intellijFlutterPluginXml = ''' io.flutter Flutter @@ -145,35 +367,34 @@ const String kIntellijFlutterPluginXml = r''' Custom Languages - 0.1.3 + $version +'''; - - Dart - 162.2485 - + final List flutterPluginBytes = utf8.encode(intellijFlutterPluginXml); + final Archive flutterPlugins = Archive(); + flutterPlugins.addFile(ArchiveFile('META-INF/plugin.xml', flutterPluginBytes.length, flutterPluginBytes)); + fileSystem.file(pluginJarPath) + ..createSync(recursive: true) + ..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)); - Support for Dart programming language - JetBrains - com.intellij.modules.xml - JavaScriptDebugger - org.jetbrains.plugins.yaml - com.intellij.copyright - com.intellij.modules.coverage - -'''; +} -/// These file contents were derived from the META-INF/plugin.xml from an Intellij Dart +/// A helper to create a Intellij Dart plugin jar. +/// +/// This jar contains META-INF/plugin.xml. +/// Its contents were derived from the META-INF/plugin.xml from an Intellij Dart /// plugin installation. /// -/// The file is loacted in a plugin JAR, which can be located by looking at the plugin +/// The file is located in a plugin JAR, which can be located by looking at the plugin /// path for the Intellij and Android Studio validators. /// /// If more XML contents are needed, prefer modifying these contents over checking /// in another JAR. -const String kIntellijDartPluginXml = r''' +void createIntellijDartPluginJar(String pluginJarPath, FileSystem fileSystem) { + const String intellijDartPluginXml = r''' Dart 162.2485 @@ -188,3 +409,11 @@ const String kIntellijDartPluginXml = r''' com.intellij.modules.coverage '''; + + final List dartPluginBytes = utf8.encode(intellijDartPluginXml); + final Archive dartPlugins = Archive(); + dartPlugins.addFile(ArchiveFile('META-INF/plugin.xml', dartPluginBytes.length, dartPluginBytes)); + fileSystem.file(pluginJarPath) + ..createSync(recursive: true) + ..writeAsBytesSync(ZipEncoder().encode(dartPlugins)); +}