Skip to content

Commit e7f4db3

Browse files
authored
Use shared workspace and analysis options for repo tools (flutter#7714)
There's likely some restructuring and other cleanup that could be made, but this is just a simple resolving of the new diagnostics from the shared analysis options.
1 parent 565542e commit e7f4db3

File tree

12 files changed

+92
-94
lines changed

12 files changed

+92
-94
lines changed

flutter-idea/testData/sample_tests/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Sample tests used as test data for the Flutter IntelliJ plugin.
33
version: 0.0.1
44

55
environment:
6-
sdk: '>=3.5.0-0.0 <4.0.0'
6+
sdk: ^3.5.0
77

88
dev_dependencies:
99
lints: ^5.0.0

pubspec.yaml

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
name: flutter_intellij
22
version: 0.1.0
3+
publish_to: none
34

45
environment:
5-
sdk: '>=3.5.0-0.0 <4.0.0'
6+
sdk: ^3.5.0
7+
8+
workspace:
9+
- tool/plugin
610

711
dependencies:
812
args: any
913
path: any
1014

1115
dev_dependencies:
12-
grinder: ^0.9.0
13-
http: ^1.1.2
16+
grinder: ^0.9.3
17+
http: ^1.2.0
1418
lints: ^5.0.0
1519
meta: any

tool/grind.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ void main(List<String> args) => grind(args);
1212
@Task('Check plugin URLs for live-ness')
1313
void checkUrls() async {
1414
log('checking URLs in FlutterBundle.properties...');
15-
var lines =
16-
await File('flutter-idea/src/io/flutter/FlutterBundle.properties').readAsLines();
15+
var lines = await File('flutter-idea/src/io/flutter/FlutterBundle.properties')
16+
.readAsLines();
1717
for (var line in lines) {
1818
var split = line.split('=');
1919
if (split.length == 2) {

tool/plugin/analysis_options.yaml

-6
This file was deleted.

tool/plugin/lib/build_spec.dart

+28-25
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ class BuildSpec {
2626
final String untilBuild;
2727
final String pluginId = 'io.flutter';
2828
final String? release;
29-
final List<dynamic> filesToSkip;
29+
final List<String> filesToSkip;
3030
String channel;
3131
String? _changeLog;
3232

33-
BuildSpec.fromJson(Map json, this.release)
34-
: name = json['name'],
35-
channel = json['channel'],
36-
version = json['version'],
37-
ijVersion = json['ijVersion'],
38-
ideaProduct = json['ideaProduct'],
39-
ideaVersion = json['ideaVersion'],
40-
baseVersion = json['baseVersion'] ?? json['ideaVersion'],
41-
androidPluginVersion = json['androidPluginVersion'],
42-
dartPluginVersion = json['dartPluginVersion'],
43-
sinceBuild = json['sinceBuild'],
44-
untilBuild = json['untilBuild'],
45-
filesToSkip = json['filesToSkip'] ?? [],
46-
isUnitTestTarget = (json['isUnitTestTarget'] ?? 'false') == 'true',
47-
isTestTarget = (json['isTestTarget'] ?? 'false') == 'true';
33+
BuildSpec.fromJson(Map<String, Object?> json, this.release)
34+
: name = json['name'] as String,
35+
channel = json['channel'] as String,
36+
version = json['version'] as String,
37+
ijVersion = json['ijVersion'] as String?,
38+
ideaProduct = json['ideaProduct'] as String,
39+
ideaVersion = json['ideaVersion'] as String,
40+
baseVersion = (json['baseVersion'] ?? json['ideaVersion']) as String,
41+
androidPluginVersion = json['androidPluginVersion'] as String,
42+
dartPluginVersion = json['dartPluginVersion'] as String,
43+
sinceBuild = json['sinceBuild'] as String,
44+
untilBuild = json['untilBuild'] as String,
45+
filesToSkip = json['filesToSkip'] as List<String>? ?? [],
46+
isUnitTestTarget = json['isUnitTestTarget'] == 'true',
47+
isTestTarget = json['isTestTarget'] == 'true';
4848

4949
bool get copyIjVersion => isAndroidStudio && ijVersion != null;
5050

@@ -61,15 +61,15 @@ class BuildSpec {
6161
String get productFile => isAndroidStudio ? "$ideaProduct-ide" : ideaProduct;
6262

6363
String get changeLog {
64-
if (_changeLog == null) {
65-
if (channel == 'stable') {
66-
_changeLog = _parseChangelog();
67-
} else {
68-
_changeLog = '';
69-
}
64+
if (_changeLog case final changelog?) {
65+
return changelog;
7066
}
7167

72-
return _changeLog!;
68+
if (channel == 'stable') {
69+
return _changeLog = _parseChangelog();
70+
} else {
71+
return _changeLog = '';
72+
}
7373
}
7474

7575
String _parseChangelog() {
@@ -124,10 +124,13 @@ class BuildSpec {
124124
/// last one is the latest used during development. This BuildSpec combines
125125
/// those two.
126126
class SyntheticBuildSpec extends BuildSpec {
127-
late BuildSpec alternate;
127+
late final BuildSpec alternate;
128128

129129
SyntheticBuildSpec.fromJson(
130-
super.json, super.releaseNum, List<BuildSpec> specs) :super.fromJson() {
130+
super.json,
131+
super.releaseNum,
132+
List<BuildSpec> specs,
133+
) : super.fromJson() {
131134
try {
132135
// 'isUnitTestTarget' should always be in the spec for the latest IntelliJ (not AS).
133136
alternate = specs.firstWhere((s) => s.isUnitTestTarget);

tool/plugin/lib/edit.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ void checkAndClearAppliedEditCommands() {
2626
}
2727

2828
List<EditCommand> editCommands = [
29-
3029
// When using LATEST-EAP-SNAPSHOT, also set baseVersion to LATEST-EAP-SNAPSHOT in the build spec.
3130
// EditCommand(
3231
// path: 'build.gradle.kts',
@@ -43,7 +42,7 @@ List<EditCommand> editCommands = [
4342
];
4443

4544
/// Apply all the editCommands applicable to a given BuildSpec.
46-
Future<int> applyEdits(BuildSpec spec, Function compileFn) async {
45+
Future<int> applyEdits(BuildSpec spec, Future<int> Function() compileFn) async {
4746
// Handle skipped files.
4847
for (String file in spec.filesToSkip) {
4948
final entity =

tool/plugin/lib/lint.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:args/command_runner.dart';
99
import 'runner.dart';
1010
import 'util.dart';
1111

12-
class LintCommand extends Command {
12+
class LintCommand extends Command<int> {
1313
@override
1414
final BuildCommandRunner runner;
1515

@@ -43,7 +43,7 @@ class LintCommand extends Command {
4343
// Note: extra quotes added so grep doesn't match this file.
4444
['grep', 'import com.jetbrains.' 'lang.dart.'],
4545
);
46-
final String imports = result.stdout.trim();
46+
final String imports = (result.stdout as String).trim();
4747

4848
// path:import
4949
final usages = <String, List<String>>{};
@@ -107,7 +107,7 @@ class LintCommand extends Command {
107107
['grep', 'import $import'],
108108
);
109109

110-
final String results = result.stdout.trim();
110+
final String results = (result.stdout as String).trim();
111111
if (results.isNotEmpty) {
112112
print('Found proscribed imports:\n');
113113
print(results);
@@ -129,7 +129,7 @@ class LintCommand extends Command {
129129
['grep', 'import $import'],
130130
);
131131

132-
final String results = result.stdout.trim();
132+
final String results = (result.stdout as String).trim();
133133
if (results.isNotEmpty) {
134134
print('Found proscribed imports:\n');
135135
print(results);

tool/plugin/lib/plugin.dart

+32-28
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Future<bool> genPluginFiles(BuildSpec spec, String destDir) async {
8181
return true;
8282
}
8383

84-
Future<File> genPluginXml(BuildSpec spec, String destDir, String path) async {
84+
Future<void> genPluginXml(BuildSpec spec, String destDir, String path) async {
8585
var templatePath =
8686
'${path.substring(0, path.length - '.xml'.length)}_template.xml';
8787
var file =
@@ -96,7 +96,7 @@ Future<File> genPluginXml(BuildSpec spec, String destDir, String path) async {
9696
.transform(LineSplitter())
9797
.forEach((l) => dest.writeln(substituteTemplateVariables(l, spec)));
9898
await dest.close();
99-
return await dest.done;
99+
await dest.done;
100100
}
101101

102102
bool genPresubmitYaml(List<BuildSpec> specs) {
@@ -200,21 +200,24 @@ Future<bool> performReleaseChecks(ProductCommand cmd) async {
200200
log('the current working directory is not managed by git: $rootPath');
201201
}
202202
// Finally, check that a jxbrowser.properties exists
203-
var jxBrowserFile = File(p.join(rootPath, 'resources', 'jxbrowser', 'jxbrowser.properties'));
203+
var jxBrowserFile =
204+
File(p.join(rootPath, 'resources', 'jxbrowser', 'jxbrowser.properties'));
204205
var jxBrowserFileContents = jxBrowserFile.readAsStringSync();
205-
if(jxBrowserFile.existsSync() && jxBrowserFileContents.isNotEmpty && !jxBrowserFileContents.contains("<KEY>")) {
206+
if (jxBrowserFile.existsSync() &&
207+
jxBrowserFileContents.isNotEmpty &&
208+
!jxBrowserFileContents.contains("<KEY>")) {
206209
return true;
207210
} else {
208211
log('Release mode requires the jxbrowser.properties file to exist and include a key.');
209212
}
210213
return false;
211214
}
212215

213-
List readProductMatrix() {
216+
List<Map<String, Object?>> readProductMatrix() {
214217
var contents =
215218
File(p.join(rootPath, 'product-matrix.json')).readAsStringSync();
216219
var map = json.decode(contents);
217-
return map['list'];
220+
return (map['list'] as List<Object?>).cast<Map<String, Object?>>();
218221
}
219222

220223
String substituteTemplateVariables(String line, BuildSpec spec) {
@@ -389,8 +392,9 @@ abstract class BuildCommand extends ProductCommand {
389392

390393
@override
391394
Future<int> doit() async {
395+
final argResults = this.argResults!;
392396
if (isReleaseMode) {
393-
if (argResults!['unpack']) {
397+
if (argResults.flag('unpack')) {
394398
separator('Release mode (--release) implies --unpack');
395399
}
396400
if (!await performReleaseChecks(this)) {
@@ -399,7 +403,7 @@ abstract class BuildCommand extends ProductCommand {
399403
}
400404

401405
// Check to see if we should only be building a specific version.
402-
String? onlyVersion = argResults!['only-version'];
406+
final onlyVersion = argResults.option('only-version');
403407

404408
var buildSpecs = specs;
405409
if (onlyVersion != null && onlyVersion.isNotEmpty) {
@@ -410,7 +414,7 @@ abstract class BuildCommand extends ProductCommand {
410414
}
411415
}
412416

413-
String? minorNumber = argResults!['minor'];
417+
final minorNumber = argResults.option('minor');
414418
if (minorNumber != null) {
415419
pluginCount = int.parse(minorNumber) - 1;
416420
}
@@ -458,7 +462,7 @@ abstract class BuildCommand extends ProductCommand {
458462
separator('Built artifact');
459463
log(releasesFilePath(spec));
460464
}
461-
if (argResults!['only-version'] == null) {
465+
if (argResults.option('only-version') == null) {
462466
checkAndClearAppliedEditCommands();
463467
}
464468

@@ -534,7 +538,7 @@ https://plugins.jetbrains.com/plugin/uploadPlugin
534538
if (processResult.exitCode != 0) {
535539
log('Upload failed: ${processResult.stderr} for file: $filePath');
536540
}
537-
String out = processResult.stdout;
541+
final out = processResult.stdout as String;
538542
var message = out.trim().split('\n').last.trim();
539543
log(message);
540544
return processResult.exitCode;
@@ -577,9 +581,6 @@ class GenerateCommand extends ProductCommand {
577581
return 0;
578582
}
579583

580-
SyntheticBuildSpec makeSyntheticSpec(List specs) =>
581-
SyntheticBuildSpec.fromJson(specs[0], release, specs[2]);
582-
583584
void generateLiveTemplates() {
584585
// Find all the live templates.
585586
final templateFragments = Directory(p.join('resources', 'liveTemplates'))
@@ -623,7 +624,7 @@ class GenerateCommand extends ProductCommand {
623624
}
624625
}
625626

626-
abstract class ProductCommand extends Command {
627+
abstract class ProductCommand extends Command<int> {
627628
@override
628629
final String name;
629630
late List<BuildSpec> specs;
@@ -636,16 +637,16 @@ abstract class ProductCommand extends Command {
636637
defaultsTo: 'stable');
637638
}
638639

639-
String get channel => argResults!['channel'];
640+
String get channel => argResults!.option('channel')!;
640641

641642
bool get isDevChannel => channel == 'dev';
642643

643644
/// Returns true when running in the context of a unit test.
644645
bool get isTesting => false;
645646

646-
bool get isForAndroidStudio => argResults!['as'];
647+
bool get isForAndroidStudio => argResults!.flag('as');
647648

648-
bool get isForIntelliJ => argResults!['ij'];
649+
bool get isForIntelliJ => argResults!.flag('ij');
649650

650651
DateTime get releaseDate => lastReleaseDate;
651652

@@ -660,10 +661,10 @@ abstract class ProductCommand extends Command {
660661
return rel == RegExp(r'^\d+\.\d(?:-dev.\d)?$').stringMatch(rel);
661662
}
662663

663-
bool get isTestMode => globalResults!['cwd'] != null;
664+
bool get isTestMode => globalResults!.option('cwd') != null;
664665

665666
String? get release {
666-
String? rel = globalResults!['release'];
667+
var rel = globalResults!.option('release');
667668

668669
if (rel != null) {
669670
if (rel.startsWith('=')) {
@@ -729,7 +730,7 @@ abstract class ProductCommand extends Command {
729730
// Initialization constraint: rootPath depends on arg parsing, and
730731
// lastReleaseName and lastReleaseDate depend on rootPath.
731732
rootPath = Directory.current.path;
732-
var rel = globalResults!['cwd'];
733+
var rel = globalResults!.option('cwd');
733734
if (rel != null) {
734735
rootPath = p.normalize(p.join(rootPath, rel));
735736
}
@@ -799,11 +800,14 @@ class RenamePackageCommand extends ProductCommand {
799800

800801
@override
801802
Future<int> doit() async {
802-
if (argResults!['studio']) baseDir = p.join(baseDir, 'flutter-studio/src');
803-
oldName = argResults!['package'];
804-
newName = argResults!.wasParsed('new-name')
805-
? argResults!['new-name']
806-
: oldName + argResults!['append'];
803+
final argResults = this.argResults!;
804+
if (argResults.flag('studio')) {
805+
baseDir = p.join(baseDir, 'flutter-studio/src');
806+
}
807+
oldName = argResults.option('package')!;
808+
newName = argResults.wasParsed('new-name')
809+
? argResults.option('new-name')!
810+
: oldName + argResults.option('append')!;
807811
if (oldName == newName) {
808812
log('Nothing to do; new name is same as old name');
809813
return 1;
@@ -901,8 +905,8 @@ class TestCommand extends ProductCommand {
901905
log('JAVA_HOME=$javaHome');
902906

903907
final spec = specs.firstWhere((s) => s.isUnitTestTarget);
904-
if (!argResults!['skip']) {
905-
if (argResults!['integration']) {
908+
if (!argResults!.flag('skip')) {
909+
if (argResults!.flag('integration')) {
906910
return await _runIntegrationTests();
907911
} else {
908912
return await _runUnitTests(spec);

tool/plugin/lib/runner.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'build_spec.dart';
1010
import 'globals.dart';
1111
import 'util.dart';
1212

13-
class BuildCommandRunner extends CommandRunner {
13+
class BuildCommandRunner extends CommandRunner<int> {
1414
BuildCommandRunner()
1515
: super('plugin',
1616
'A script to build, test, and deploy the Flutter IntelliJ plugin.') {
@@ -43,7 +43,8 @@ jxbrowser.license.key=$jxBrowserKey
4343

4444
Future<int> buildPlugin(BuildSpec spec, String version) async {
4545
writeJxBrowserKeyToFile();
46-
return await runGradleCommand(['buildPlugin', '--stacktrace'], spec, version, 'false');
46+
return await runGradleCommand(
47+
['buildPlugin', '--stacktrace'], spec, version, 'false');
4748
}
4849

4950
Future<int> runGradleCommand(

0 commit comments

Comments
 (0)