Skip to content

Commit

Permalink
Dartfmt on Dart sources in tool dir (#7786)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwren authored Nov 15, 2024
1 parent 9a6aff3 commit 8293462
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 61 deletions.
19 changes: 10 additions & 9 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void checkUrls() async {
log('checking: $url...');
if (response.statusCode != 200) {
fail(
'$url GET failed: [${response.statusCode}] ${response.reasonPhrase}');
'$url GET failed: [${response.statusCode}] ${response
.reasonPhrase}');
}
}
}
Expand Down Expand Up @@ -54,19 +55,18 @@ void outlineIcons() async {
}
}

void _createPng(
File sourceSvg,
String targetName, {
required int? size,
bool forLight = false,
}) {
void _createPng(File sourceSvg,
String targetName, {
required int? size,
bool forLight = false,
}) {
File targetFile = joinFile(sourceSvg.parent, [targetName]);

String color = forLight ? '#7a7a7a' : '#9e9e9e';

String originalContent = sourceSvg.readAsStringSync();
String newContent =
originalContent.replaceAll('<svg ', '<svg fill="$color" ');
originalContent.replaceAll('<svg ', '<svg fill="$color" ');

sourceSvg.writeAsStringSync(newContent);

Expand All @@ -80,7 +80,8 @@ void _createPng(

if (result.exitCode != 0) {
print(
'Error resizing image with imagemagick: ${result.stdout}\n${result.stderr}');
'Error resizing image with imagemagick: ${result.stdout}\n${result
.stderr}');
exit(1);
}
} finally {
Expand Down
10 changes: 5 additions & 5 deletions tool/plugin/lib/build_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BuildSpec {
// TODO (jwren) can we get rid of "name"
final String name;
// TODO (jwren) these two can be consilidated

final String version;
final String? ijVersion;
final bool isTestTarget;
Expand All @@ -21,6 +22,7 @@ class BuildSpec {
final String ideaVersion;
final String androidPluginVersion;
final String dartPluginVersion;

// TODO (jwren) can baseVersion be removed?
final String baseVersion;

Expand Down Expand Up @@ -129,11 +131,9 @@ class BuildSpec {
class SyntheticBuildSpec extends BuildSpec {
late final BuildSpec alternate;

SyntheticBuildSpec.fromJson(
super.json,
super.releaseNum,
List<BuildSpec> specs,
) : super.fromJson() {
SyntheticBuildSpec.fromJson(super.json,
super.releaseNum,
List<BuildSpec> specs,) : super.fromJson() {
try {
// 'isUnitTestTarget' should always be in the spec for the latest IntelliJ (not AS).
alternate = specs.firstWhere((s) => s.isUnitTestTarget);
Expand Down
7 changes: 4 additions & 3 deletions tool/plugin/lib/edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Future<int> applyEdits(BuildSpec spec, Future<int> Function() compileFn) async {
// Handle skipped files.
for (String file in spec.filesToSkip) {
final entity =
FileSystemEntity.isFileSync(file) ? File(file) : Directory(file);
FileSystemEntity.isFileSync(file) ? File(file) : Directory(file);
if (entity.existsSync()) {
await entity.rename('$file~');
log('renamed $file');
Expand Down Expand Up @@ -82,7 +82,7 @@ Future<int> applyEdits(BuildSpec spec, Future<int> Function() compileFn) async {
for (final file in spec.filesToSkip) {
final name = '$file~';
final entity =
FileSystemEntity.isFileSync(name) ? File(name) : Directory(name);
FileSystemEntity.isFileSync(name) ? File(name) : Directory(name);
if (entity.existsSync()) {
await entity.rename(file);
}
Expand All @@ -97,7 +97,8 @@ class EditCommand {
required List<String> initials,
required List<String> replacements,
this.versions = const [],
}) : assert(initials.length == replacements.length),
})
: assert(initials.length == replacements.length),
assert(initials.isNotEmpty),
assert(versions.isNotEmpty),
initials = initials.map(_platformAdaptiveString).toList(),
Expand Down
4 changes: 3 additions & 1 deletion tool/plugin/lib/lint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class LintCommand extends Command<int> {
final usages = <String, List<String>>{};

imports.split('\n').forEach((String line) {
if (line.trim().isEmpty) {
if (line
.trim()
.isEmpty) {
return;
}

Expand Down
42 changes: 25 additions & 17 deletions tool/plugin/lib/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ Future<void> genPluginXml(BuildSpec spec, String destDir, String path) async {
var templatePath =
'${path.substring(0, path.length - '.xml'.length)}_template.xml';
var file =
await File(p.join(rootPath, destDir, path)).create(recursive: true);
await File(p.join(rootPath, destDir, path)).create(recursive: true);
log('writing ${p.relative(file.path)}');
var dest = file.openWrite();
dest.writeln(
"<!-- Do not edit; instead, modify ${p.basename(templatePath)}, and run './bin/plugin generate'. -->");
"<!-- Do not edit; instead, modify ${p.basename(
templatePath)}, and run './bin/plugin generate'. -->");
dest.writeln();
await utf8.decoder
.bind(File(p.join(rootPath, 'resources', templatePath)).openRead())
Expand All @@ -110,7 +111,7 @@ bool genPresubmitYaml(List<BuildSpec> specs) {
}

var templateFile =
File(p.join(rootPath, '.github', 'workflows', 'presubmit.yaml.template'));
File(p.join(rootPath, '.github', 'workflows', 'presubmit.yaml.template'));
var templateContents = templateFile.readAsStringSync();
// If we need to make many changes consider something like genPluginXml().
templateContents =
Expand Down Expand Up @@ -169,7 +170,8 @@ Future<bool> performReleaseChecks(ProductCommand cmd) async {
return false;
}
if (!cmd.isReleaseValid) {
log('the release identifier ("${cmd.release}") must be of the form xx.x (major.minor)');
log('the release identifier ("${cmd
.release}") must be of the form xx.x (major.minor)');
return false;
}
var gitDir = await GitDir.fromExisting(rootPath);
Expand All @@ -178,7 +180,7 @@ Future<bool> performReleaseChecks(ProductCommand cmd) async {
var branch = await gitDir.currentBranch();
var name = branch.branchName;
var expectedName =
cmd.isDevChannel ? 'master' : "release_${cmd.releaseMajor}";
cmd.isDevChannel ? 'master' : "release_${cmd.releaseMajor}";
var result = name == expectedName;
if (!result) {
result = name.startsWith("release_${cmd.releaseMajor}") &&
Expand All @@ -201,22 +203,23 @@ Future<bool> performReleaseChecks(ProductCommand cmd) async {
}
// Finally, check that a jxbrowser.properties exists
var jxBrowserFile =
File(p.join(rootPath, 'resources', 'jxbrowser', 'jxbrowser.properties'));
File(p.join(rootPath, 'resources', 'jxbrowser', 'jxbrowser.properties'));
var jxBrowserFileContents = jxBrowserFile.readAsStringSync();
if (jxBrowserFile.existsSync() &&
jxBrowserFileContents.isNotEmpty &&
jxBrowserFileContents.contains('jxbrowser.license.key=') &&
!jxBrowserFileContents.contains('jxbrowser.license.key=<KEY>')) {
return true;
} else {
log('Release mode requires the jxbrowser.properties file to exist and include a key.');
log(
'Release mode requires the jxbrowser.properties file to exist and include a key.');
}
return false;
}

List<Map<String, Object?>> readProductMatrix() {
var contents =
File(p.join(rootPath, 'product-matrix.json')).readAsStringSync();
File(p.join(rootPath, 'product-matrix.json')).readAsStringSync();
var map = json.decode(contents);
return (map['list'] as List<Object?>).cast<Map<String, Object?>>();
}
Expand All @@ -236,8 +239,8 @@ String substituteTemplateVariables(String line, BuildSpec spec) {
case 'CHANGELOG':
return spec.changeLog;
case 'DEPEND':
// If found, this is the module that triggers loading the Android Studio
// support. The public sources and the installable plugin use different ones.
// If found, this is the module that triggers loading the Android Studio
// support. The public sources and the installable plugin use different ones.
return spec.isSynthetic
? 'com.intellij.modules.androidstudio'
: 'com.android.tools.apk';
Expand Down Expand Up @@ -426,7 +429,7 @@ class GradleBuildCommand extends ProductCommand {
log('Content generated in ./build/distributions:\n${result.stdout}');

var source = File('build/distributions/flutter-intellij.zip');
if(!source.existsSync()) {
if (!source.existsSync()) {
source = File('build/distributions/flutter-intellij-kokoro.zip');
}
_copyFile(
Expand Down Expand Up @@ -516,7 +519,11 @@ https://plugins.jetbrains.com/plugin/uploadPlugin
log('Upload failed: ${processResult.stderr} for file: $filePath');
}
final out = processResult.stdout as String;
var message = out.trim().split('\n').last.trim();
var message = out
.trim()
.split('\n')
.last
.trim();
log(message);
return processResult.exitCode;
}
Expand All @@ -537,9 +544,9 @@ class GenerateCommand extends ProductCommand {
@override
String get description =>
'Generate plugin.xml, .github/workflows/presubmit.yaml, '
'and resources/liveTemplates/flutter_miscellaneous.xml files for the '
'Flutter plugin.\nThe plugin.xml.template and product-matrix.json are '
'used as input.';
'and resources/liveTemplates/flutter_miscellaneous.xml files for the '
'Flutter plugin.\nThe plugin.xml.template and product-matrix.json are '
'used as input.';

@override
Future<int> doit() async {
Expand Down Expand Up @@ -567,7 +574,7 @@ class GenerateCommand extends ProductCommand {
.cast<File>()
.toList();
final templateFile =
File(p.join('resources', 'liveTemplates', 'flutter_miscellaneous.xml'));
File(p.join('resources', 'liveTemplates', 'flutter_miscellaneous.xml'));
var contents = templateFile.readAsStringSync();

log('writing ${p.relative(templateFile.path)}');
Expand All @@ -585,7 +592,8 @@ class GenerateCommand extends ProductCommand {
final regexp = RegExp('<template name="$name" value="([^"]+)"');
final match = regexp.firstMatch(contents);
if (match == null) {
throw 'No entry found for "$name" live template in ${templateFile.path}';
throw 'No entry found for "$name" live template in ${templateFile
.path}';
}

// Replace the existing content in the xml live template file with the
Expand Down
16 changes: 7 additions & 9 deletions tool/plugin/lib/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'util.dart';
class BuildCommandRunner extends CommandRunner<int> {
BuildCommandRunner()
: super('plugin',
'A script to build, test, and deploy the Flutter IntelliJ plugin.') {
'A script to build, test, and deploy the Flutter IntelliJ plugin.') {
argParser.addOption(
'release',
abbr: 'r',
Expand All @@ -30,9 +30,9 @@ class BuildCommandRunner extends CommandRunner<int> {

void writeJxBrowserKeyToFile() {
final jxBrowserKey =
readTokenFromKeystore('FLUTTER_KEYSTORE_JXBROWSER_KEY_NAME');
readTokenFromKeystore('FLUTTER_KEYSTORE_JXBROWSER_KEY_NAME');
final propertiesFile =
File("$rootPath/resources/jxbrowser/jxbrowser.properties");
File("$rootPath/resources/jxbrowser/jxbrowser.properties");
if (jxBrowserKey.isNotEmpty) {
final contents = '''
jxbrowser.license.key=$jxBrowserKey
Expand All @@ -47,12 +47,10 @@ jxbrowser.license.key=$jxBrowserKey
['buildPlugin', '--stacktrace'], spec, version, 'false');
}

Future<int> runGradleCommand(
List<String> command,
BuildSpec spec,
String version,
String testing,
) async {
Future<int> runGradleCommand(List<String> command,
BuildSpec spec,
String version,
String testing,) async {
final contents = '''
name = "flutter-intellij
buildSpec=${spec.version}
Expand Down
47 changes: 35 additions & 12 deletions tool/plugin/lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Future<String> makeDevLog(BuildSpec spec) async {
var gitDir = await GitDir.fromExisting(rootPath);
var since = lastReleaseName;
var processResult =
await gitDir.runCommand(['log', '--oneline', '$since..HEAD']);
await gitDir.runCommand(['log', '--oneline', '$since..HEAD']);
String out = processResult.stdout as String;
var messages = out.trim().split('\n');
var devLog = StringBuffer();
Expand All @@ -51,30 +51,46 @@ Future<DateTime> dateOfLastRelease() async {
var processResult = await gitDir
.runCommand(['branch', '--list', '-v', '--no-abbrev', lastReleaseName]);
String out = processResult.stdout as String;
var logLine = out.trim().split('\n').first.trim();
var logLine = out
.trim()
.split('\n')
.first
.trim();
var match =
RegExp(r'release_\d+\s+([A-Fa-f\d]{40})\s').matchAsPrefix(logLine);
RegExp(r'release_\d+\s+([A-Fa-f\d]{40})\s').matchAsPrefix(logLine);
var commitHash = match!.group(1);
processResult =
await gitDir.runCommand(['show', '--pretty=tformat:"%cI"', commitHash!]);
await gitDir.runCommand(['show', '--pretty=tformat:"%cI"', commitHash!]);
out = processResult.stdout as String;
var date = out.trim().split('\n').first.trim();
var date = out
.trim()
.split('\n')
.first
.trim();
return DateTime.parse(date.replaceAll('"', ''));
}

Future<String> lastRelease() async {
_checkGitDir();
var gitDir = await GitDir.fromExisting(rootPath);
var processResult =
await gitDir.runCommand(['branch', '--list', 'release_*']);
await gitDir.runCommand(['branch', '--list', 'release_*']);
String out = processResult.stdout as String;
var release = out.trim().split('\n').last.trim();
var release = out
.trim()
.split('\n')
.last
.trim();
if (release.isNotEmpty) return release;
processResult =
await gitDir.runCommand(['branch', '--list', '-a', '*release_*']);
await gitDir.runCommand(['branch', '--list', '-a', '*release_*']);
out = processResult.stdout as String;
var remote =
out.trim().split('\n').last.trim(); // "remotes/origin/release_43"
out
.trim()
.split('\n')
.last
.trim(); // "remotes/origin/release_43"
release = remote.substring(remote.lastIndexOf('/') + 1);
await gitDir.runCommand(['branch', '--track', release, remote]);
return release;
Expand Down Expand Up @@ -109,7 +125,12 @@ Future<void> removeAll(String dir) async {
}

bool isNewer(FileSystemEntity newer, FileSystemEntity older) {
return newer.statSync().modified.isAfter(older.statSync().modified);
return newer
.statSync()
.modified
.isAfter(older
.statSync()
.modified);
}

void _checkGitDir() async {
Expand Down Expand Up @@ -142,7 +163,9 @@ int get devBuildNumber {
// The dev channel is automatically refreshed weekly, so the build number
// is just the number of weeks since the last stable release.
var today = DateTime.now();
var daysSinceRelease = today.difference(lastReleaseDate).inDays;
var daysSinceRelease = today
.difference(lastReleaseDate)
.inDays;
var weekNumber = daysSinceRelease ~/ 7 + 1;
return weekNumber;
}
Expand All @@ -162,7 +185,7 @@ String buildVersionNumber(BuildSpec spec) {

String _nextRelease() {
var current =
RegExp(r'release_(\d+)').matchAsPrefix(lastReleaseName)!.group(1);
RegExp(r'release_(\d+)').matchAsPrefix(lastReleaseName)!.group(1);
var val = int.parse(current!) + 1;
return '$val.0';
}
Loading

0 comments on commit 8293462

Please sign in to comment.