Skip to content
Merged
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
36 changes: 0 additions & 36 deletions product-matrix.json

This file was deleted.

32 changes: 0 additions & 32 deletions tool/plugin/lib/build_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,3 @@ class BuildSpec {
}
}

/// This represents a BuildSpec that is used to generate the plugin.xml
/// that is used during development. It needs to span all possible versions.
/// The product-matrix.json file lists the versions in increasing build order.
/// The first one is the earliest version used during development and the
/// last one is the latest used during development. This BuildSpec combines
/// those two.
class SyntheticBuildSpec extends BuildSpec {
late final BuildSpec alternate;

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);
} on StateError catch (_) {
log('No build spec defines "isUnitTestTarget"');
exit(1);
}
}

@override
String get sinceBuild => alternate.sinceBuild;

@override
String get untilBuild => alternate.untilBuild;

@override
bool get isSynthetic => true;
}
120 changes: 6 additions & 114 deletions tool/plugin/lib/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// code is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:args/args.dart';
Expand All @@ -11,7 +10,6 @@ import 'package:git/git.dart';
import 'package:path/path.dart' as p;

import 'build_spec.dart';
import 'edit.dart';
import 'globals.dart';
import 'lint.dart';
import 'runner.dart';
Expand All @@ -21,7 +19,6 @@ Future<int> main(List<String> args) async {
var runner = BuildCommandRunner();

runner.addCommand(LintCommand(runner));
runner.addCommand(TestCommand(runner));
runner.addCommand(DeployCommand(runner));
runner.addCommand(GenerateCommand(runner));

Expand All @@ -47,15 +44,6 @@ void copyResources({required String from, required String to}) {
_copyResources(Directory(from), Directory(to));
}

List<BuildSpec> createBuildSpecs(ProductCommand command) {
var specs = <BuildSpec>[];
var input = readProductMatrix();
for (var json in input) {
specs.add(BuildSpec.fromJson(json, command.release));
}
return specs;
}

List<File> findJars(String path) {
final dir = Directory(path);
return dir
Expand All @@ -74,18 +62,10 @@ List<String> findJavaFiles(String path) {
.toList();
}

bool isTravisFileValid() {
var travisPath = p.join(rootPath, '.github/workflows/presubmit.yaml');
var travisFile = File(travisPath);
if (!travisFile.existsSync()) {
return false;
}
var matrixPath = p.join(rootPath, 'product-matrix.json');
var matrixFile = File(matrixPath);
if (!matrixFile.existsSync()) {
throw 'product-matrix.json is missing';
}
return isNewer(travisFile, matrixFile);
bool isPresubmitFileValid() {
var presubmitPath = p.join(rootPath, '.github/workflows/presubmit.yaml');
var presubmitFile = File(presubmitPath);
return presubmitFile.existsSync();
}

Future<int> jar(String directory, String outFile) async {
Expand Down Expand Up @@ -130,7 +110,7 @@ Future<bool> performReleaseChecks(ProductCommand cmd) async {
name.lastIndexOf(RegExp(r"\.[0-9]")) == name.length - 2;
}
if (result) {
if (isTravisFileValid()) {
if (isPresubmitFileValid()) {
return result;
} else {
log('the presubmit.yaml file needs updating: plugin generate');
Expand Down Expand Up @@ -162,13 +142,6 @@ Future<bool> performReleaseChecks(ProductCommand cmd) async {
return false;
}

List<Map<String, Object?>> readProductMatrix() {
var contents =
File(p.join(rootPath, 'product-matrix.json')).readAsStringSync();
var map = json.decode(contents);
return (map['list'] as List<Object?>).cast<Map<String, Object?>>();
}

void _copyFile(File file, Directory to, {String filename = ''}) {
if (!file.existsSync()) {
throw "${file.path} does not exist";
Expand Down Expand Up @@ -278,12 +251,7 @@ https://plugins.jetbrains.com/plugin/uploadPlugin
}
}

/// Generate the plugin.xml from the plugin.xml.template file. If the --release
/// argument is given, create a git branch and commit the new file to it,
/// assuming the release checks pass.
///
/// Note: The product-matrix.json file includes a build spec for the EAP version
/// at the end. When the EAP version is released that needs to be updated.
/// This is only used to generate live templates for the Flutter plugin.
class GenerateCommand extends ProductCommand {
@override
final BuildCommandRunner runner;
Expand Down Expand Up @@ -353,7 +321,6 @@ class GenerateCommand extends ProductCommand {
abstract class ProductCommand extends Command<int> {
@override
final String name;
late List<BuildSpec> specs;

ProductCommand(this.name) {
addProductFlags(argParser, name[0].toUpperCase() + name.substring(1));
Expand Down Expand Up @@ -448,7 +415,6 @@ abstract class ProductCommand extends Command<int> {
@override
Future<int> run() async {
await _initGlobals();
await _initSpecs();
try {
return await doit();
} catch (ex, stack) {
Expand All @@ -471,17 +437,6 @@ abstract class ProductCommand extends Command<int> {
lastReleaseDate = await dateOfLastRelease();
}
}

Future<int> _initSpecs() async {
specs = createBuildSpecs(this);
for (var i = 0; i < specs.length; i++) {
if (isDevChannel) {
specs[i].buildForDev();
}
await specs[i].initChangeLog();
}
return specs.length;
}
}

/// A crude rename utility. The IntelliJ feature does not work on the case
Expand Down Expand Up @@ -597,66 +552,3 @@ class RenamePackageCommand extends ProductCommand {
}
}
}

/// Build the tests if necessary then run them and return any failure code.
class TestCommand extends ProductCommand {
@override
final BuildCommandRunner runner;

TestCommand(this.runner) : super('test') {
argParser.addFlag(
'skip',
negatable: false,
help: 'Do not run tests, just unpack artifaccts',
abbr: 's',
);
argParser.addFlag('setup', abbr: 'p', defaultsTo: true);
}

@override
String get description => 'Run the tests for the Flutter plugin.';

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

log('JAVA_HOME=$javaHome');

// Case 1: Handle skipping tests
if (argResults != null && argResults!.flag('skip')) {
log('Skipping unit tests as requested.');
return 0;
}

// Filter for all unit test targets
final unitTestTargets = specs.where((s) => s.isUnitTestTarget).toList();

// Case 2: Zero unit test targets
if (unitTestTargets.isEmpty) {
log('ERROR: No unit test target found in the specifications. Cannot run tests.');
return 1;
}

// Case 3: More than one unit test target
if (unitTestTargets.length > 1) {
final targetNames = unitTestTargets.map((s) => s.name).join(', ');
log('ERROR: More than one unit test target found: $targetNames. Please specify which one to run, or ensure only one exists.');
return 1;
}

// Happy Case: Exactly one unit test target
final spec = unitTestTargets.first;
return await _runUnitTests(spec);
}

Future<int> _runUnitTests(BuildSpec spec) async {
// run './gradlew test'
return await applyEdits(spec, () async {
return await runner.runGradleCommand(['test'], spec, '1', 'true');
});
}
}
72 changes: 1 addition & 71 deletions tool/plugin/test/plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import 'dart:io';

import 'package:plugin_tool/plugin.dart';
import 'package:plugin_tool/runner.dart';
import 'package:string_validator/string_validator.dart' as validator;
import 'package:test/test.dart';

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

test('deploy', () {
expect(DeployCommand(BuildCommandRunner()).name, "deploy");
});
Expand All @@ -24,60 +19,6 @@ void main() {
});
});

group("spec", () {
/// This method has assertions which can be made for all commands in this
/// test group.
void buildSpecAssertions(BuildCommandRunner runner, String command) {
var specs = (runner.commands[command] as ProductCommand).specs;
expect(specs, isList);
expect(specs, isNotEmpty);

// channel should be set to stable in the product-matrix.json
for (String channel in specs.map((spec) => spec.channel).toList()) {
expect(channel, anyOf('stable'));
}

// name should be set to stable in the product-matrix.json
for (String name in specs.map((spec) => spec.name).toList()) {
expect(name, isNotEmpty);
expect(name.length, 6);
expect(name, validator.isFloat);
}

// ideaProduct should be android-studio or IC
for (String ideaProduct
in specs.map((spec) => spec.ideaProduct).toList()) {
expect(ideaProduct, anyOf('android-studio', 'IC'));
}

// sinceBuild should be in the form of '243'
for (String sinceBuild in specs.map((spec) => spec.sinceBuild).toList()) {
expect(sinceBuild.length, 3);
expect(sinceBuild, validator.isNumeric);
}

// untilBuild should be in the form of '243.*'
for (String untilBuild in specs.map((spec) => spec.untilBuild).toList()) {
expect(untilBuild.length, 5);
expect(untilBuild.substring(0, 2), validator.isNumeric);
}
}

test('test', () async {
var runner = makeTestRunner();
await runner.run(["-r=19", "-d../..", "test"]).whenComplete(() {
buildSpecAssertions(runner, "test");
});
});

test('deploy', () async {
var runner = makeTestRunner();
await runner.run(["-r19", "-d../..", "deploy"]).whenComplete(() {
buildSpecAssertions(runner, "deploy");
});
});
});

group('release', () {
test('simple', () async {
var runner = makeTestRunner();
Expand Down Expand Up @@ -144,8 +85,7 @@ void main() {

BuildCommandRunner makeTestRunner() {
var runner = BuildCommandRunner();
runner.addCommand(TestTestCommand(runner));
runner.addCommand(TestDeployCommand(runner));
runner.addCommand(TestDeployCommand(runner));
runner.addCommand(TestGenCommand(runner));
return runner;
}
Expand Down Expand Up @@ -188,13 +128,3 @@ class TestGenCommand extends GenerateCommand {
@override
Future<int> doit() async => Future(() => 0);
}

class TestTestCommand extends TestCommand {
TestTestCommand(super.runner);

@override
bool get isTesting => true;

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