Skip to content

Commit

Permalink
Add a new command, run, to execute the runIde Gradle task (#7780)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwren authored Nov 11, 2024
1 parent eb1085c commit 2664643
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tool/plugin/lib/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Future<int> main(List<String> args) async {
runner.addCommand(DeployCommand(runner));
runner.addCommand(GenerateCommand(runner));
runner.addCommand(VerifyCommand(runner));
runner.addCommand(RunIdeCommand(runner));

try {
return await runner.run(args) ?? 0;
Expand Down Expand Up @@ -588,6 +589,42 @@ class GenerateCommand extends ProductCommand {
}
}

/// Run the IDE using the gradle task "runIde"
class RunIdeCommand extends ProductCommand {
@override
final BuildCommandRunner runner;

RunIdeCommand(this.runner) : super('run');

@override
String get description => 'Run the IDE plugin';

@override
Future<int> doit() async {
final javaHome = Platform.environment['JAVA_HOME'];
if (javaHome == null) {
log('JAVA_HOME environment variable not set - this is needed by Gradle.');
return 1;
}
log('JAVA_HOME=$javaHome');

// TODO(jwren) The IDE run is determined currently by the isUnitTestTarget
// in the product-matrix.json, while useful, a new field should be added
// into the product-matrix.json instead of re-using this field,
// Or, the run IDE should be passed via the command line (I don't like this
// as much.)
final spec = specs.firstWhere((s) => s.isUnitTestTarget);
return await _runIde(spec);
}

Future<int> _runIde(BuildSpec spec) async {
// run './gradlew runIde'
return await applyEdits(spec, () async {
return await runner.runGradleCommand(['runIde'], spec, '1', 'false');
});
}
}

abstract class ProductCommand extends Command<int> {
@override
final String name;
Expand Down

0 comments on commit 2664643

Please sign in to comment.