Skip to content

[CQ] (tall-style) dart re-format #7917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ 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 @@ -55,18 +54,19 @@ 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,8 +80,7 @@ void _createPng(File sourceSvg,

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
7 changes: 3 additions & 4 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,8 +97,7 @@ 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
40 changes: 16 additions & 24 deletions tool/plugin/lib/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ 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 @@ -111,7 +110,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 @@ -170,8 +169,7 @@ 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 @@ -180,7 +178,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 @@ -203,23 +201,22 @@ 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 @@ -239,8 +236,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 @@ -523,11 +520,7 @@ 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 @@ -548,9 +541,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 @@ -578,7 +571,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 @@ -596,8 +589,7 @@ 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: 9 additions & 7 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,10 +47,12 @@ 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: 12 additions & 35 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,46 +51,30 @@ 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 @@ -125,12 +109,7 @@ 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 @@ -163,9 +142,7 @@ 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 @@ -185,7 +162,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';
}
5 changes: 3 additions & 2 deletions tool/plugin/lib/verify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ class VerifyCommand extends ProductCommand {
}
log('\nverifyPlugin for $spec:');
result =
await runner.runGradleCommand(['verifyPlugin'], spec, '1', 'false');
await runner.runGradleCommand(['verifyPlugin'], spec, '1', 'false');
if (result != 0) {
return result;
}
}

var verifiedVersions = buildSpecs.map((spec) => spec.name).toList().join(', ');
var verifiedVersions =
buildSpecs.map((spec) => spec.name).toList().join(', ');
log('\nVerification of the ${buildSpecs.length} builds was '
'successful: $verifiedVersions.');
return result;
Expand Down