Skip to content

Commit

Permalink
Remove some old build logic that is unused: AntBuildCommand (#7745)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwren authored Oct 29, 2024
1 parent 97401f3 commit 8a76110
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 106 deletions.
117 changes: 42 additions & 75 deletions tool/plugin/lib/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Future<int> main(List<String> args) async {
var runner = BuildCommandRunner();

runner.addCommand(LintCommand(runner));
runner.addCommand(AntBuildCommand(runner));
runner.addCommand(GradleBuildCommand(runner));
runner.addCommand(TestCommand(runner));
runner.addCommand(DeployCommand(runner));
Expand Down Expand Up @@ -292,82 +291,14 @@ void _copyResources(Directory from, Directory to) {
}
}

class AntBuildCommand extends BuildCommand {
AntBuildCommand(BuildCommandRunner runner) : super(runner, 'build');

@override
Future<int> doit() async {
return GradleBuildCommand(runner).doit();
}

@override
Future<int> externalBuildCommand(BuildSpec spec) async {
// Not used
return 0;
}

@override
Future<int> savePluginArtifact(BuildSpec spec) async {
// Not used
return 0;
}
}

class GradleBuildCommand extends BuildCommand {
GradleBuildCommand(BuildCommandRunner runner) : super(runner, 'make');

@override
Future<int> externalBuildCommand(BuildSpec spec) async {
var pluginFile = File('resources/META-INF/plugin.xml');
var studioFile = File('resources/META-INF/studio-contribs.xml');
var pluginSrc = pluginFile.readAsStringSync();
var studioSrc = studioFile.readAsStringSync();
try {
await genPluginFiles(spec, 'resources');
return await runner.buildPlugin(spec, buildVersionNumber(spec));
} finally {
pluginFile.writeAsStringSync(pluginSrc);
studioFile.writeAsStringSync(studioSrc);
}
}

@override
Future<int> savePluginArtifact(BuildSpec spec) async {
final file = File(releasesFilePath(spec));
final version = buildVersionNumber(spec);
var source = File('build/distributions/flutter-intellij-$version.zip');
if (!source.existsSync()) {
// Setting the plugin name in Gradle should eliminate the need for this,
// but it does not.
// TODO(messick) Find a way to make the Kokoro file name: flutter-intellij-DEV.zip
source = File('build/distributions/flutter-intellij-kokoro-$version.zip');
}
_copyFile(
source,
file.parent,
filename: p.basename(file.path),
);
await _stopDaemon();
return 0;
}

Future<int> _stopDaemon() async {
if (Platform.isWindows) {
return await exec('.\\third_party\\gradlew.bat', ['--stop']);
} else {
return await exec('./third_party/gradlew', ['--stop']);
}
}
}

/// Build deployable plugin files. If the --release argument is given
/// then perform additional checks to verify that the release environment
/// is in good order.
abstract class BuildCommand extends ProductCommand {
class GradleBuildCommand extends ProductCommand {
@override
final BuildCommandRunner runner;

BuildCommand(this.runner, String commandName) : super(commandName) {
GradleBuildCommand(this.runner) : super('make') {
argParser.addOption('only-version',
abbr: 'o',
help: 'Only build the specified IntelliJ version; useful for sharding '
Expand All @@ -387,10 +318,6 @@ abstract class BuildCommand extends ProductCommand {
String get description => 'Build a deployable version of the Flutter plugin, '
'compiled against the specified artifacts.';

Future<int> externalBuildCommand(BuildSpec spec);

Future<int> savePluginArtifact(BuildSpec spec);

@override
Future<int> doit() async {
final argResults = this.argResults!;
Expand Down Expand Up @@ -466,9 +393,49 @@ abstract class BuildCommand extends ProductCommand {
if (argResults.option('only-version') == null) {
checkAndClearAppliedEditCommands();
}
return 0;
}

Future<int> externalBuildCommand(BuildSpec spec) async {
var pluginFile = File('resources/META-INF/plugin.xml');
var studioFile = File('resources/META-INF/studio-contribs.xml');
var pluginSrc = pluginFile.readAsStringSync();
var studioSrc = studioFile.readAsStringSync();
try {
await genPluginFiles(spec, 'resources');
return await runner.buildPlugin(spec, buildVersionNumber(spec));
} finally {
pluginFile.writeAsStringSync(pluginSrc);
studioFile.writeAsStringSync(studioSrc);
}
}

Future<int> savePluginArtifact(BuildSpec spec) async {
final file = File(releasesFilePath(spec));
final version = buildVersionNumber(spec);
var source = File('build/distributions/flutter-intellij-$version.zip');
if (!source.existsSync()) {
// Setting the plugin name in Gradle should eliminate the need for this,
// but it does not.
// TODO(messick) Find a way to make the Kokoro file name: flutter-intellij-DEV.zip
source = File('build/distributions/flutter-intellij-kokoro-$version.zip');
}
_copyFile(
source,
file.parent,
filename: p.basename(file.path),
);
await _stopDaemon();
return 0;
}

Future<int> _stopDaemon() async {
if (Platform.isWindows) {
return await exec('.\\third_party\\gradlew.bat', ['--stop']);
} else {
return await exec('./third_party/gradlew', ['--stop']);
}
}
}

/// Either the --release or --channel options must be provided.
Expand Down
47 changes: 16 additions & 31 deletions tool/plugin/test/plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import 'package:test/test.dart';

void main() {
group("create", () {
test('build', () {
expect(AntBuildCommand(BuildCommandRunner()).name, "build");
});

test('make', () {
expect(GradleBuildCommand(BuildCommandRunner()).name, "make");
});
Expand All @@ -35,8 +31,8 @@ void main() {
group("spec", () {
test('build', () async {
var runner = makeTestRunner();
await runner.run(["-r=19", "-d../..", "build"]).whenComplete(() {
var specs = (runner.commands['build'] as ProductCommand).specs;
await runner.run(["-r=19", "-d../..", "make"]).whenComplete(() {
var specs = (runner.commands['make'] as ProductCommand).specs;
expect(specs, isNotNull);
expect(
specs.map((spec) => spec.ideaProduct).toList(),
Expand Down Expand Up @@ -146,9 +142,9 @@ void main() {
group('build', () {
test('plugin.xml', () async {
var runner = makeTestRunner();
late TestBuildCommand cmd;
await runner.run(["-d../..", "build"]).whenComplete(() {
cmd = (runner.commands['build'] as TestBuildCommand);
late TestMakeCommand cmd;
await runner.run(["-d../..", "make"]).whenComplete(() {
cmd = (runner.commands['make'] as TestMakeCommand);
});
var spec = cmd.specs[0];
await removeAll('../../build/classes');
Expand All @@ -163,7 +159,7 @@ void main() {

test('only-version', () async {
ProductCommand command =
makeTestRunner().commands['build'] as ProductCommand;
makeTestRunner().commands['make'] as ProductCommand;
var results = command.argParser.parse(['--only-version=2023.1']);
expect(results['only-version'], '2023.1');
});
Expand All @@ -173,41 +169,41 @@ void main() {
test('parses release', () async {
var runner = makeTestRunner();
late ProductCommand command;
await runner.run(["-d../..", '-r22.0', "build"]).whenComplete(() {
command = (runner.commands['build'] as ProductCommand);
await runner.run(["-d../..", '-r22.0', "make"]).whenComplete(() {
command = (runner.commands['make'] as ProductCommand);
});
expect(command.release, '22.0');
});
test('parses release partial number', () async {
var runner = makeTestRunner();
late ProductCommand command;
await runner.run(["-d../..", '-r22', "build"]).whenComplete(() {
command = (runner.commands['build'] as ProductCommand);
await runner.run(["-d../..", '-r22', "make"]).whenComplete(() {
command = (runner.commands['make'] as ProductCommand);
});
expect(command.release, '22.0');
});

test('isReleaseValid', () async {
var runner = makeTestRunner();
late ProductCommand command;
await runner.run(["-d../..", '-r22.0', "build"]).whenComplete(() {
command = (runner.commands['build'] as ProductCommand);
await runner.run(["-d../..", '-r22.0', "make"]).whenComplete(() {
command = (runner.commands['make'] as ProductCommand);
});
expect(command.isReleaseValid, true);
});
test('isReleaseValid partial version', () async {
var runner = makeTestRunner();
late ProductCommand command;
await runner.run(["-d../..", '-r22', "build"]).whenComplete(() {
command = (runner.commands['build'] as ProductCommand);
await runner.run(["-d../..", '-r22', "make"]).whenComplete(() {
command = (runner.commands['make'] as ProductCommand);
});
expect(command.isReleaseValid, true);
});
test('isReleaseValid bad version', () async {
var runner = makeTestRunner();
late ProductCommand command;
await runner.run(["-d../..", '-r22.0.0', "build"]).whenComplete(() {
command = (runner.commands['build'] as ProductCommand);
await runner.run(["-d../..", '-r22.0.0', "make"]).whenComplete(() {
command = (runner.commands['make'] as ProductCommand);
});
expect(command.isReleaseValid, false);
});
Expand All @@ -216,24 +212,13 @@ void main() {

BuildCommandRunner makeTestRunner() {
var runner = BuildCommandRunner();
runner.addCommand(TestBuildCommand(runner));
runner.addCommand(TestMakeCommand(runner));
runner.addCommand(TestTestCommand(runner));
runner.addCommand(TestDeployCommand(runner));
runner.addCommand(TestGenCommand(runner));
return runner;
}

class TestBuildCommand extends AntBuildCommand {
TestBuildCommand(super.runner);

@override
bool get isTesting => true;

@override
Future<int> doit() async => Future(() => 0);
}

class TestMakeCommand extends GradleBuildCommand {
TestMakeCommand(super.runner);

Expand Down

0 comments on commit 8a76110

Please sign in to comment.