Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 4 | import 'dart:convert'; |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 5 | |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 6 | import 'package:archive/archive.dart'; |
| 7 | import 'package:file/file.dart'; |
| 8 | import 'package:file/memory.dart'; |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 9 | import 'package:flutter_tools/src/base/file_system.dart'; |
| 10 | import 'package:flutter_tools/src/doctor.dart'; |
| 11 | import 'package:flutter_tools/src/intellij/intellij.dart'; |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 12 | |
Ian Hickson | d919e69 | 2019-07-13 11:51:44 -0700 | [diff] [blame] | 13 | import '../../src/common.dart'; |
| 14 | import '../../src/context.dart'; |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 15 | |
| 16 | void main() { |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 17 | FileSystem fs; |
| 18 | |
| 19 | void writeFileCreatingDirectories(String path, List<int> bytes) { |
| 20 | final File file = fs.file(path); |
| 21 | file.parent.createSync(recursive: true); |
| 22 | file.writeAsBytesSync(bytes); |
| 23 | } |
| 24 | |
| 25 | setUp(() { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 26 | fs = MemoryFileSystem(); |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 27 | }); |
| 28 | |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 29 | group('IntelliJ', () { |
| 30 | group('plugins', () { |
| 31 | testUsingContext('found', () async { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 32 | final IntelliJPlugins plugins = IntelliJPlugins(_kPluginsPath); |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 33 | |
| 34 | final Archive dartJarArchive = |
| 35 | buildSingleFileArchive('META-INF/plugin.xml', r''' |
| 36 | <idea-plugin version="2"> |
| 37 | <name>Dart</name> |
| 38 | <version>162.2485</version> |
| 39 | </idea-plugin> |
| 40 | '''); |
| 41 | writeFileCreatingDirectories( |
| 42 | fs.path.join(_kPluginsPath, 'Dart', 'lib', 'Dart.jar'), |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 43 | ZipEncoder().encode(dartJarArchive)); |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 44 | |
| 45 | final Archive flutterJarArchive = |
| 46 | buildSingleFileArchive('META-INF/plugin.xml', r''' |
| 47 | <idea-plugin version="2"> |
| 48 | <name>Flutter</name> |
| 49 | <version>0.1.3</version> |
| 50 | </idea-plugin> |
| 51 | '''); |
| 52 | writeFileCreatingDirectories( |
| 53 | fs.path.join(_kPluginsPath, 'flutter-intellij.jar'), |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 54 | ZipEncoder().encode(flutterJarArchive)); |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 55 | |
| 56 | final List<ValidationMessage> messages = <ValidationMessage>[]; |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 57 | plugins.validatePackage(messages, <String>['Dart'], 'Dart'); |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 58 | plugins.validatePackage(messages, |
| 59 | <String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter', |
| 60 | minVersion: IntelliJPlugins.kMinFlutterPluginVersion); |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 61 | |
| 62 | ValidationMessage message = messages |
| 63 | .firstWhere((ValidationMessage m) => m.message.startsWith('Dart ')); |
| 64 | expect(message.message, 'Dart plugin version 162.2485'); |
| 65 | |
| 66 | message = messages.firstWhere( |
| 67 | (ValidationMessage m) => m.message.startsWith('Flutter ')); |
| 68 | expect(message.message, contains('Flutter plugin version 0.1.3')); |
| 69 | expect(message.message, contains('recommended minimum version')); |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 70 | }, overrides: <Type, Generator>{ |
| 71 | FileSystem: () => fs, |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 72 | }); |
| 73 | |
| 74 | testUsingContext('not found', () async { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 75 | final IntelliJPlugins plugins = IntelliJPlugins(_kPluginsPath); |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 76 | |
| 77 | final List<ValidationMessage> messages = <ValidationMessage>[]; |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 78 | plugins.validatePackage(messages, <String>['Dart'], 'Dart'); |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 79 | plugins.validatePackage(messages, |
| 80 | <String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter', |
| 81 | minVersion: IntelliJPlugins.kMinFlutterPluginVersion); |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 82 | |
| 83 | ValidationMessage message = messages |
| 84 | .firstWhere((ValidationMessage m) => m.message.startsWith('Dart ')); |
| 85 | expect(message.message, contains('Dart plugin not installed')); |
| 86 | |
| 87 | message = messages.firstWhere( |
| 88 | (ValidationMessage m) => m.message.startsWith('Flutter ')); |
| 89 | expect(message.message, contains('Flutter plugin not installed')); |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 90 | }, overrides: <Type, Generator>{ |
| 91 | FileSystem: () => fs, |
Konstantin Scheglov | 4658ec0 | 2018-04-04 10:48:46 -0700 | [diff] [blame] | 92 | }); |
| 93 | }); |
| 94 | }); |
| 95 | } |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 96 | |
| 97 | const String _kPluginsPath = '/data/intellij/plugins'; |
| 98 | |
| 99 | Archive buildSingleFileArchive(String path, String content) { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 100 | final Archive archive = Archive(); |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 101 | |
| 102 | final List<int> bytes = utf8.encode(content); |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 103 | archive.addFile(ArchiveFile(path, bytes.length, bytes)); |
Konstantin Scheglov | d121cbc | 2018-04-08 09:46:11 -0700 | [diff] [blame] | 104 | |
| 105 | return archive; |
| 106 | } |