From 59df2670fff250fa1aba7b4523da4fc8591fd334 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 27 Apr 2023 10:02:00 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=A5=20Remove=20NNBD=20migration=20?= =?UTF-8?q?tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/plugin/lib/build_spec.dart | 2 -- tool/plugin/lib/util.dart | 2 -- tool/plugin/test/plugin_test.dart | 2 -- 3 files changed, 6 deletions(-) diff --git a/tool/plugin/lib/build_spec.dart b/tool/plugin/lib/build_spec.dart index e5fa1c4b96..0b6abfb6ae 100644 --- a/tool/plugin/lib/build_spec.dart +++ b/tool/plugin/lib/build_spec.dart @@ -1,8 +1,6 @@ // Copyright 2017 The Chromium Authors. All rights reserved. Use of this source // code is governed by a BSD-style license that can be found in the LICENSE file. -// @dart = 2.12 - import 'dart:async'; import 'dart:io'; diff --git a/tool/plugin/lib/util.dart b/tool/plugin/lib/util.dart index 3ac4ff0ec8..513d202208 100644 --- a/tool/plugin/lib/util.dart +++ b/tool/plugin/lib/util.dart @@ -1,8 +1,6 @@ // Copyright 2017 The Chromium Authors. All rights reserved. Use of this source // code is governed by a BSD-style license that can be found in the LICENSE file. -// @dart = 2.12 - import 'dart:async'; import 'dart:convert'; import 'dart:io'; diff --git a/tool/plugin/test/plugin_test.dart b/tool/plugin/test/plugin_test.dart index c5083ab779..7b3d01be35 100644 --- a/tool/plugin/test/plugin_test.dart +++ b/tool/plugin/test/plugin_test.dart @@ -1,8 +1,6 @@ // Copyright 2017 The Chromium Authors. All rights reserved. Use of this source // code is governed by a BSD-style license that can be found in the LICENSE file. -// @dart = 2.12 - import 'dart:async'; import 'dart:io'; From d8182bc6b66a0010792baac5423d323d6b53eb38 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 27 Apr 2023 10:05:35 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=94=A5=20Remove=20unused=20methods=20?= =?UTF-8?q?since=20#6681?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/plugin/lib/plugin.dart | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/tool/plugin/lib/plugin.dart b/tool/plugin/lib/plugin.dart index 0f6d0afc25..fa804b4925 100644 --- a/tool/plugin/lib/plugin.dart +++ b/tool/plugin/lib/plugin.dart @@ -55,15 +55,6 @@ List createBuildSpecs(ProductCommand command) { return specs; } -Future deleteBuildContents() async { - final dir = Directory(p.join(rootPath, 'build')); - if (!dir.existsSync()) throw 'No build directory found'; - var args = []; - args.add('-rf'); - args.add(p.join(rootPath, 'build', '*')); - return await exec('rm', args); -} - List findJars(String path) { final dir = Directory(path); return dir @@ -163,16 +154,6 @@ Future jar(String directory, String outFile) async { return await exec('jar', args, cwd: directory); } -Future moveToArtifacts(ProductCommand cmd, BuildSpec spec) async { - final dir = Directory(p.join(rootPath, 'artifacts')); - if (!dir.existsSync()) throw 'No artifacts directory found'; - var file = pluginRegistryIds[spec.pluginId]; - var args = []; - args.add(p.join(rootPath, 'build', file)); - args.add(cmd.releasesFilePath(spec)); - return await exec('mv', args); -} - Future performReleaseChecks(ProductCommand cmd) async { // git must have a release_NN branch where NN is the value of --release // git must have no uncommitted changes @@ -267,13 +248,6 @@ String substituteTemplateVariables(String line, BuildSpec spec) { return line; } -Future zip(String directory, String outFile) async { - var dest = p.absolute(outFile); - createDir(p.dirname(dest)); - var args = ['-r', dest, p.basename(directory)]; - return await exec('zip', args, cwd: p.dirname(directory)); -} - void _copyFile(File file, Directory to, {String filename = ''}) { if (!file.existsSync()) { throw "${file.path} does not exist"; From f09638662fa12f77126d01650a0a61509f73c362 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 27 Apr 2023 10:22:28 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Convert=20`removeAll`?= =?UTF-8?q?=20to=20`FileSystemEntity.deleteAll`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/plugin/lib/plugin.dart | 2 +- tool/plugin/lib/util.dart | 13 ++++++++----- tool/plugin/test/plugin_test.dart | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tool/plugin/lib/plugin.dart b/tool/plugin/lib/plugin.dart index fa804b4925..a9a57b519f 100644 --- a/tool/plugin/lib/plugin.dart +++ b/tool/plugin/lib/plugin.dart @@ -423,7 +423,7 @@ abstract class BuildCommand extends ProductCommand { } separator('Building flutter-intellij.jar'); - await removeAll('build'); + await Directory('build').deleteAll(); log('spec.version: ${spec.version}'); diff --git a/tool/plugin/lib/util.dart b/tool/plugin/lib/util.dart index 513d202208..6cf3f6296d 100644 --- a/tool/plugin/lib/util.dart +++ b/tool/plugin/lib/util.dart @@ -103,11 +103,6 @@ Future curl(String url, {required String to}) async { return await exec('curl', ['-o', to, url]); } -/// Remove the directory without exceptions if it does not exists. -Future removeAll(String dir) async { - await Directory(dir).delete(recursive: true).then((_) {}, onError: (_) {}); -} - bool isNewer(FileSystemEntity newer, FileSystemEntity older) { return newer.statSync().modified.isAfter(older.statSync().modified); } @@ -166,3 +161,11 @@ String _nextRelease() { var val = int.parse(current!) + 1; return '$val.0'; } + +/// A series of extension methods to help improving file manipulations. +extension FileSystemEntityExtension on FileSystemEntity { + /// Remove the file or the directory without exceptions if it does not exists. + Future deleteAll() async { + await delete(recursive: true).then((_) {}, onError: (_) {}); + } +} diff --git a/tool/plugin/test/plugin_test.dart b/tool/plugin/test/plugin_test.dart index 7b3d01be35..49225eec17 100644 --- a/tool/plugin/test/plugin_test.dart +++ b/tool/plugin/test/plugin_test.dart @@ -166,7 +166,7 @@ void main() { cmd = (runner.commands['build'] as TestBuildCommand); }); var spec = cmd.specs[0]; - await removeAll('../../build/classes'); + await Directory('../../build/classes').deleteAll(); await genPluginFiles(spec, 'build/classes'); var file = File("../../build/classes/META-INF/plugin.xml"); expect(file.existsSync(), isTrue); From b498a24b16c6e489e5df5a18e3b93eeae495d7b0 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 27 Apr 2023 10:25:25 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E2=9C=A8=20Handle=20symlinks=20on=20Window?= =?UTF-8?q?s=20for=20products?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/plugin/lib/plugin.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tool/plugin/lib/plugin.dart b/tool/plugin/lib/plugin.dart index a9a57b519f..6d63abfeaa 100644 --- a/tool/plugin/lib/plugin.dart +++ b/tool/plugin/lib/plugin.dart @@ -705,6 +705,7 @@ abstract class ProductCommand extends Command { Future run() async { await _initGlobals(); await _initSpecs(); + _handleSymlinksOnWindows(); try { return await doit(); } catch (ex, stack) { @@ -738,6 +739,26 @@ abstract class ProductCommand extends Command { } return specs.length; } + + void _handleSymlinksOnWindows() { + if (!Platform.isWindows) { + return; + } + const List symlinks = [ + r'flutter-idea\resources', + r'flutter-studio\resources', + ]; + final currentPath = Directory.current.path; + for (final entityPath in symlinks) { + final path = '$currentPath\\$entityPath'; + if (FileSystemEntity.isLinkSync(path)) { + continue; + } + final content = File(path).readAsStringSync(); + File(path).deleteSync(); + Link(path).createSync(content); + } + } } /// A crude rename utility. The IntelliJ feature does not work on the case From ed50245fd640cddba0d3cf057a11589fd63b8dd9 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 27 Apr 2023 19:20:22 +0800 Subject: [PATCH 5/6] =?UTF-8?q?Revert=20"=E2=99=BB=EF=B8=8F=20Convert=20`r?= =?UTF-8?q?emoveAll`=20to=20`FileSystemEntity.deleteAll`"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f09638662fa12f77126d01650a0a61509f73c362. --- tool/plugin/lib/plugin.dart | 2 +- tool/plugin/lib/util.dart | 13 +++++-------- tool/plugin/test/plugin_test.dart | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tool/plugin/lib/plugin.dart b/tool/plugin/lib/plugin.dart index 6d63abfeaa..4d304355e2 100644 --- a/tool/plugin/lib/plugin.dart +++ b/tool/plugin/lib/plugin.dart @@ -423,7 +423,7 @@ abstract class BuildCommand extends ProductCommand { } separator('Building flutter-intellij.jar'); - await Directory('build').deleteAll(); + await removeAll('build'); log('spec.version: ${spec.version}'); diff --git a/tool/plugin/lib/util.dart b/tool/plugin/lib/util.dart index 6cf3f6296d..513d202208 100644 --- a/tool/plugin/lib/util.dart +++ b/tool/plugin/lib/util.dart @@ -103,6 +103,11 @@ Future curl(String url, {required String to}) async { return await exec('curl', ['-o', to, url]); } +/// Remove the directory without exceptions if it does not exists. +Future removeAll(String dir) async { + await Directory(dir).delete(recursive: true).then((_) {}, onError: (_) {}); +} + bool isNewer(FileSystemEntity newer, FileSystemEntity older) { return newer.statSync().modified.isAfter(older.statSync().modified); } @@ -161,11 +166,3 @@ String _nextRelease() { var val = int.parse(current!) + 1; return '$val.0'; } - -/// A series of extension methods to help improving file manipulations. -extension FileSystemEntityExtension on FileSystemEntity { - /// Remove the file or the directory without exceptions if it does not exists. - Future deleteAll() async { - await delete(recursive: true).then((_) {}, onError: (_) {}); - } -} diff --git a/tool/plugin/test/plugin_test.dart b/tool/plugin/test/plugin_test.dart index 49225eec17..7b3d01be35 100644 --- a/tool/plugin/test/plugin_test.dart +++ b/tool/plugin/test/plugin_test.dart @@ -166,7 +166,7 @@ void main() { cmd = (runner.commands['build'] as TestBuildCommand); }); var spec = cmd.specs[0]; - await Directory('../../build/classes').deleteAll(); + await removeAll('../../build/classes'); await genPluginFiles(spec, 'build/classes'); var file = File("../../build/classes/META-INF/plugin.xml"); expect(file.existsSync(), isTrue); From bb17471150561d234ebba9d0ff99dd4c9ef3e064 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Fri, 5 May 2023 10:48:20 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactored=20`EditComm?= =?UTF-8?q?and`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/plugin/lib/edit.dart | 232 ++++++++++++++------------------------ 1 file changed, 86 insertions(+), 146 deletions(-) diff --git a/tool/plugin/lib/edit.dart b/tool/plugin/lib/edit.dart index b652b66a15..0c1bfccdbb 100644 --- a/tool/plugin/lib/edit.dart +++ b/tool/plugin/lib/edit.dart @@ -14,122 +14,102 @@ Set appliedEditCommands = {}; void checkAndClearAppliedEditCommands() { if (appliedEditCommands.length != editCommands.length) { - var commands = {}; + final commands = {}; commands.addAll(editCommands); commands.removeAll(appliedEditCommands); separator("UNUSED EditCommand"); - for (var cmd in commands) { + for (final cmd in commands) { log(cmd.toString()); } } appliedEditCommands.clear(); } +const String _actionThreadEditContent = ''' + + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } +'''; + List editCommands = [ // When using LATEST-EAP-SNAPSHOT, also set baseVersion to LATEST-EAP-SNAPSHOT in the build spec. - Subst( + EditCommand( path: 'build.gradle.kts', - initial: 'version.set(ideVersion)', - replacement: 'version.set("LATEST-EAP-SNAPSHOT")', - version: '2023.1', + initials: ['version.set(ideVersion)'], + replacements: ['version.set("LATEST-EAP-SNAPSHOT")'], + versions: ['2023.1'], ), - Subst( + EditCommand( path: 'flutter-idea/build.gradle.kts', - initial: 'version.set(ideVersion)', - replacement: 'version.set("LATEST-EAP-SNAPSHOT")', - version: '2023.1', + initials: ['version.set(ideVersion)'], + replacements: ['version.set("LATEST-EAP-SNAPSHOT")'], + versions: ['2023.1'], ), - MultiSubst( + EditCommand( path: 'flutter-studio/src/io/flutter/android/AndroidModuleLibraryManager.java', initials: ['//import ', 'extends ProjectImpl '], replacements: ['import ', 'extends ProjectExImpl '], versions: ['2022.1', '2022.2', '2031.1'], ), - Subst( + EditCommand( path: 'flutter-idea/src/io/flutter/vmService/frame/DartVmServiceValue.java', - initial: '@NotNull', - replacement: '', + initials: ['@NotNull'], + replacements: [''], versions: ['2022.1', '2022.2'], ), - Subst( + EditCommand( path: 'flutter-idea/src/io/flutter/analytics/FlutterAnalysisServerListener.java', - initial: '@NotNull', - replacement: '', + initials: ['@NotNull'], + replacements: [''], versions: ['2022.1', '2022.2'], ), - Subst( + EditCommand( path: 'resources/META-INF/plugin_template.xml', - initial: '', - replacement: '', + initials: [''], + replacements: [''], versions: ['2022.1', '2022.2'], ), - Subst( + EditCommand( path: 'flutter-idea/src/io/flutter/actions/AttachDebuggerAction.java', - initial: ''' - public @NotNull ActionUpdateThread getActionUpdateThread() { - return ActionUpdateThread.BGT; - } -''', - replacement: '', - version: '2022.1', + initials: [_actionThreadEditContent], + replacements: [''], + versions: ['2022.1'], ), - Subst( + EditCommand( path: 'flutter-idea/src/io/flutter/actions/DeviceSelectorAction.java', - initial: ''' - public @NotNull ActionUpdateThread getActionUpdateThread() { - return ActionUpdateThread.BGT; - } -''', - replacement: '', - version: '2022.1', + initials: [_actionThreadEditContent], + replacements: [''], + versions: ['2022.1'], ), - Subst( + EditCommand( path: - 'flutter-idea/src/io/flutter/actions/DeviceSelectorRefresherAction.java', - initial: ''' - public @NotNull ActionUpdateThread getActionUpdateThread() { - return ActionUpdateThread.BGT; - } -''', - replacement: '', - version: '2022.1', + 'flutter-idea/src/io/flutter/actions/DeviceSelectorRefresherAction.java', + initials: [_actionThreadEditContent], + replacements: [''], + versions: ['2022.1'], ), - Subst( + EditCommand( path: 'flutter-idea/src/io/flutter/actions/FlutterRetargetAppAction.java', - initial: ''' - public @NotNull ActionUpdateThread getActionUpdateThread() { - return ActionUpdateThread.BGT; - } -''', - replacement: '', - version: '2022.1', + initials: [_actionThreadEditContent], + replacements: [''], + versions: ['2022.1'], ), ]; -// Used to test checkAndClearAppliedEditCommands() -class Unused extends EditCommand { - @override - String get path => 'unused'; - - @override - String? convert(BuildSpec spec) { - return null; - } -} - /// Apply all the editCommands applicable to a given BuildSpec. Future applyEdits(BuildSpec spec, Function compileFn) async { // Handle skipped files. for (String file in spec.filesToSkip) { - var entity = + final entity = FileSystemEntity.isFileSync(file) ? File(file) : Directory(file); if (entity.existsSync()) { await entity.rename('$file~'); log('renamed $file'); if (entity is File) { - var stubFile = File('${file}_stub'); + final stubFile = File('${file}_stub'); if (stubFile.existsSync()) { await stubFile.copy(file); log('copied ${file}_stub'); @@ -138,10 +118,10 @@ Future applyEdits(BuildSpec spec, Function compileFn) async { } } - var edited = {}; + final edited = {}; try { - for (var edit in editCommands) { - var source = edit.convert(spec); + for (final edit in editCommands) { + final source = edit.convert(spec); if (source != null) { edited[edit] = source; appliedEditCommands.add(edit); @@ -157,9 +137,9 @@ Future applyEdits(BuildSpec spec, Function compileFn) async { }); // Restore skipped files. - for (var file in spec.filesToSkip) { - var name = '$file~'; - var entity = + for (final file in spec.filesToSkip) { + final name = '$file~'; + final entity = FileSystemEntity.isFileSync(name) ? File(name) : Directory(name); if (entity.existsSync()) { await entity.rename(file); @@ -169,101 +149,61 @@ Future applyEdits(BuildSpec spec, Function compileFn) async { } /// Make some changes to a source file prior to compiling for a specific IDE. -abstract class EditCommand { - String? convert(BuildSpec spec); - - void restore(String source) { - var processedFile = File(path); - processedFile.writeAsStringSync(source); - } +class EditCommand { + EditCommand({ + required this.path, + required List initials, + required List replacements, + this.versions = const [], + }) : assert(initials.length == replacements.length), + assert(initials.isNotEmpty), + assert(versions.isNotEmpty), + initials = initials.map(_platformAdaptiveString).toList(), + replacements = replacements.map(_platformAdaptiveString).toList(); - String get path; -} + /// The target file path. + final String path; -/// Single substitution in a file for one or more IDE versions. -class Subst extends EditCommand { - @override - String path; - String initial; - String replacement; + final List initials; + final List replacements; /// The list of platform versions to perform the substitution for. - List versions; - - Subst( - {this.versions = const [''], - required this.initial, - required this.replacement, - required this.path, - String? version}) { - if (version != null) { - // Disallow both version and versions keywords. - versions = [version]; - } - } + final List versions; - @override String? convert(BuildSpec spec) { if (versionMatches(spec)) { - var processedFile = File(path); - var source = processedFile.readAsStringSync(); - var original = source; - source = source.replaceAll(initial, replacement); + final processedFile = File(path); + String source = processedFile.readAsStringSync(); + final original = source; + for (int i = 0; i < initials.length; i++) { + source = source.replaceAll(initials[i], replacements[i]); + } processedFile.writeAsStringSync(source); - log('edited $path'); return original; } else { return null; } } - @override - String toString() => "Subst(path: $path, versions: $versions)"; - bool versionMatches(BuildSpec spec) { return versions.any((v) => spec.version.startsWith(v)); } -} - -// TODO Unify Subst and MultiSubst, and find a better name. -class MultiSubst extends EditCommand { - @override - String path; - List initials; - List replacements; - List versions; - - MultiSubst({ - required this.versions, - required this.initials, - required this.replacements, - required this.path, - }) { - assert(initials.length == replacements.length); - assert(versions.isNotEmpty); - assert(initials.isNotEmpty); - } - @override - String? convert(BuildSpec spec) { - if (versionMatches(spec)) { - var processedFile = File(path); - var source = processedFile.readAsStringSync(); - var original = source; - for (var i = 0; i < initials.length; i++) { - source = source.replaceAll(initials[i], replacements[i]); - } - processedFile.writeAsStringSync(source); - return original; - } else { - return null; - } + void restore(String source) { + final processedFile = File(path); + processedFile.writeAsStringSync(source); } @override - String toString() => "Subst(path: $path, versions: $versions)"; + String toString() => "EditCommand(path: $path, versions: $versions)"; +} - bool versionMatches(BuildSpec spec) { - return versions.any((v) => spec.version.startsWith(v)); +String _platformAdaptiveString(String value) { + if (value.isEmpty) { + return value; + } else if (Platform.isWindows) { + return value.replaceAll('\n', '\r\n'); + } else { + return value.replaceAll('\r\n', '\n'); } }