Unverified Commit 9a2d9c81 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate intellij_validator to null safety (#79813)

parent 39ad3a72
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
...@@ -17,8 +15,8 @@ import 'intellij.dart'; ...@@ -17,8 +15,8 @@ import 'intellij.dart';
/// A doctor validator for both Intellij and Android Studio. /// A doctor validator for both Intellij and Android Studio.
abstract class IntelliJValidator extends DoctorValidator { abstract class IntelliJValidator extends DoctorValidator {
IntelliJValidator(String title, this.installPath, { IntelliJValidator(String title, this.installPath, {
@required FileSystem fileSystem, required FileSystem fileSystem,
@required UserMessages userMessages, required UserMessages userMessages,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
_userMessages = userMessages, _userMessages = userMessages,
super(title); super(title);
...@@ -29,7 +27,7 @@ abstract class IntelliJValidator extends DoctorValidator { ...@@ -29,7 +27,7 @@ abstract class IntelliJValidator extends DoctorValidator {
String get version; String get version;
String get pluginsPath; String? get pluginsPath;
static const Map<String, String> _idToTitle = <String, String>{ static const Map<String, String> _idToTitle = <String, String>{
'IntelliJIdea': 'IntelliJ IDEA Ultimate Edition', 'IntelliJIdea': 'IntelliJ IDEA Ultimate Edition',
...@@ -43,10 +41,10 @@ abstract class IntelliJValidator extends DoctorValidator { ...@@ -43,10 +41,10 @@ abstract class IntelliJValidator extends DoctorValidator {
/// On platforms other than macOS, Linux, and Windows this returns an /// On platforms other than macOS, Linux, and Windows this returns an
/// empty list. /// empty list.
static Iterable<DoctorValidator> installedValidators({ static Iterable<DoctorValidator> installedValidators({
@required FileSystem fileSystem, required FileSystem fileSystem,
@required Platform platform, required Platform platform,
@required UserMessages userMessages, required UserMessages userMessages,
@required PlistParser plistParser, required PlistParser plistParser,
}) { }) {
final FileSystemUtils fileSystemUtils = FileSystemUtils(fileSystem: fileSystem, platform: platform); final FileSystemUtils fileSystemUtils = FileSystemUtils(fileSystem: fileSystem, platform: platform);
if (platform.isWindows) { if (platform.isWindows) {
...@@ -84,7 +82,7 @@ abstract class IntelliJValidator extends DoctorValidator { ...@@ -84,7 +82,7 @@ abstract class IntelliJValidator extends DoctorValidator {
} else { } else {
messages.add(ValidationMessage(_userMessages.intellijLocation(installPath))); messages.add(ValidationMessage(_userMessages.intellijLocation(installPath)));
final IntelliJPlugins plugins = IntelliJPlugins(pluginsPath, fileSystem: _fileSystem); final IntelliJPlugins plugins = IntelliJPlugins(pluginsPath!, fileSystem: _fileSystem);
plugins.validatePackage( plugins.validatePackage(
messages, messages,
<String>['flutter-intellij', 'flutter-intellij.jar'], <String>['flutter-intellij', 'flutter-intellij.jar'],
...@@ -123,7 +121,7 @@ abstract class IntelliJValidator extends DoctorValidator { ...@@ -123,7 +121,7 @@ abstract class IntelliJValidator extends DoctorValidator {
return; return;
} }
final Version installedVersion = Version.parse(version); final Version? installedVersion = Version.parse(version);
if (installedVersion == null) { if (installedVersion == null) {
return; return;
} }
...@@ -137,8 +135,8 @@ abstract class IntelliJValidator extends DoctorValidator { ...@@ -137,8 +135,8 @@ abstract class IntelliJValidator extends DoctorValidator {
/// A windows specific implementation of the intellij validator. /// A windows specific implementation of the intellij validator.
class IntelliJValidatorOnWindows extends IntelliJValidator { class IntelliJValidatorOnWindows extends IntelliJValidator {
IntelliJValidatorOnWindows(String title, this.version, String installPath, this.pluginsPath, { IntelliJValidatorOnWindows(String title, this.version, String installPath, this.pluginsPath, {
@required FileSystem fileSystem, required FileSystem fileSystem,
@required UserMessages userMessages, required UserMessages userMessages,
}) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages); }) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages);
@override @override
...@@ -148,10 +146,10 @@ class IntelliJValidatorOnWindows extends IntelliJValidator { ...@@ -148,10 +146,10 @@ class IntelliJValidatorOnWindows extends IntelliJValidator {
final String pluginsPath; final String pluginsPath;
static Iterable<DoctorValidator> installed({ static Iterable<DoctorValidator> installed({
@required FileSystem fileSystem, required FileSystem fileSystem,
@required FileSystemUtils fileSystemUtils, required FileSystemUtils fileSystemUtils,
@required Platform platform, required Platform platform,
@required UserMessages userMessages, required UserMessages userMessages,
}) { }) {
final List<DoctorValidator> validators = <DoctorValidator>[]; final List<DoctorValidator> validators = <DoctorValidator>[];
if (fileSystemUtils.homeDirPath == null) { if (fileSystemUtils.homeDirPath == null) {
...@@ -186,7 +184,7 @@ class IntelliJValidatorOnWindows extends IntelliJValidator { ...@@ -186,7 +184,7 @@ class IntelliJValidatorOnWindows extends IntelliJValidator {
IntelliJValidator._idToTitle.forEach((String id, String title) { IntelliJValidator._idToTitle.forEach((String id, String title) {
if (name.startsWith('.$id')) { if (name.startsWith('.$id')) {
final String version = name.substring(id.length + 1); final String version = name.substring(id.length + 1);
String installPath; String? installPath;
try { try {
installPath = fileSystem.file(fileSystem.path.join(dir.path, 'system', '.home')).readAsStringSync(); installPath = fileSystem.file(fileSystem.path.join(dir.path, 'system', '.home')).readAsStringSync();
} on FileSystemException { } on FileSystemException {
...@@ -201,7 +199,10 @@ class IntelliJValidatorOnWindows extends IntelliJValidator { ...@@ -201,7 +199,10 @@ class IntelliJValidatorOnWindows extends IntelliJValidator {
} }
// after IntelliJ 2020 // after IntelliJ 2020
final Directory cacheDir = fileSystem.directory(fileSystem.path.join(platform.environment['LOCALAPPDATA'], 'JetBrains')); if (!platform.environment.containsKey('LOCALAPPDATA')) {
return validators;
}
final Directory cacheDir = fileSystem.directory(fileSystem.path.join(platform.environment['LOCALAPPDATA']!, 'JetBrains'));
if (!cacheDir.existsSync()) { if (!cacheDir.existsSync()) {
return validators; return validators;
} }
...@@ -210,7 +211,7 @@ class IntelliJValidatorOnWindows extends IntelliJValidator { ...@@ -210,7 +211,7 @@ class IntelliJValidatorOnWindows extends IntelliJValidator {
IntelliJValidator._idToTitle.forEach((String id, String title) { IntelliJValidator._idToTitle.forEach((String id, String title) {
if (name.startsWith(id)) { if (name.startsWith(id)) {
final String version = name.substring(id.length); final String version = name.substring(id.length);
String installPath; String? installPath;
try { try {
installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync(); installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync();
} on FileSystemException { } on FileSystemException {
...@@ -218,16 +219,18 @@ class IntelliJValidatorOnWindows extends IntelliJValidator { ...@@ -218,16 +219,18 @@ class IntelliJValidatorOnWindows extends IntelliJValidator {
} }
if (installPath != null && fileSystem.isDirectorySync(installPath)) { if (installPath != null && fileSystem.isDirectorySync(installPath)) {
String pluginsPath; String pluginsPath;
final String pluginsPathInAppData = fileSystem.path.join(
platform.environment['APPDATA'], 'JetBrains', name, 'plugins');
if (fileSystem.isDirectorySync(installPath + '.plugins')) { if (fileSystem.isDirectorySync(installPath + '.plugins')) {
// IntelliJ 2020.3 // IntelliJ 2020.3
pluginsPath = installPath + '.plugins'; pluginsPath = installPath + '.plugins';
addValidator(title, version, installPath, pluginsPath); addValidator(title, version, installPath, pluginsPath);
} else if (fileSystem.isDirectorySync(pluginsPathInAppData)) { } else if (platform.environment.containsKey('APPDATA')) {
// IntelliJ 2020.1 ~ 2020.2 final String pluginsPathInAppData = fileSystem.path.join(
pluginsPath = pluginsPathInAppData; platform.environment['APPDATA']!, 'JetBrains', name, 'plugins');
addValidator(title, version, installPath, pluginsPath); if (fileSystem.isDirectorySync(pluginsPathInAppData)) {
// IntelliJ 2020.1 ~ 2020.2
pluginsPath = pluginsPathInAppData;
addValidator(title, version, installPath, pluginsPath);
}
} }
} }
} }
...@@ -240,8 +243,8 @@ class IntelliJValidatorOnWindows extends IntelliJValidator { ...@@ -240,8 +243,8 @@ class IntelliJValidatorOnWindows extends IntelliJValidator {
/// A linux specific implementation of the intellij validator. /// A linux specific implementation of the intellij validator.
class IntelliJValidatorOnLinux extends IntelliJValidator { class IntelliJValidatorOnLinux extends IntelliJValidator {
IntelliJValidatorOnLinux(String title, this.version, String installPath, this.pluginsPath, { IntelliJValidatorOnLinux(String title, this.version, String installPath, this.pluginsPath, {
@required FileSystem fileSystem, required FileSystem fileSystem,
@required UserMessages userMessages, required UserMessages userMessages,
}) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages); }) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages);
@override @override
...@@ -251,12 +254,13 @@ class IntelliJValidatorOnLinux extends IntelliJValidator { ...@@ -251,12 +254,13 @@ class IntelliJValidatorOnLinux extends IntelliJValidator {
final String pluginsPath; final String pluginsPath;
static Iterable<DoctorValidator> installed({ static Iterable<DoctorValidator> installed({
@required FileSystem fileSystem, required FileSystem fileSystem,
@required FileSystemUtils fileSystemUtils, required FileSystemUtils fileSystemUtils,
@required UserMessages userMessages, required UserMessages userMessages,
}) { }) {
final List<DoctorValidator> validators = <DoctorValidator>[]; final List<DoctorValidator> validators = <DoctorValidator>[];
if (fileSystemUtils.homeDirPath == null) { final String? homeDirPath = fileSystemUtils.homeDirPath;
if (homeDirPath == null) {
return validators; return validators;
} }
...@@ -282,13 +286,13 @@ class IntelliJValidatorOnLinux extends IntelliJValidator { ...@@ -282,13 +286,13 @@ class IntelliJValidatorOnLinux extends IntelliJValidator {
} }
// before IntelliJ 2019 // before IntelliJ 2019
final Directory homeDir = fileSystem.directory(fileSystemUtils.homeDirPath); final Directory homeDir = fileSystem.directory(homeDirPath);
for (final Directory dir in homeDir.listSync().whereType<Directory>()) { for (final Directory dir in homeDir.listSync().whereType<Directory>()) {
final String name = fileSystem.path.basename(dir.path); final String name = fileSystem.path.basename(dir.path);
IntelliJValidator._idToTitle.forEach((String id, String title) { IntelliJValidator._idToTitle.forEach((String id, String title) {
if (name.startsWith('.$id')) { if (name.startsWith('.$id')) {
final String version = name.substring(id.length + 1); final String version = name.substring(id.length + 1);
String installPath; String? installPath;
try { try {
installPath = fileSystem.file(fileSystem.path.join(dir.path, 'system', '.home')).readAsStringSync(); installPath = fileSystem.file(fileSystem.path.join(dir.path, 'system', '.home')).readAsStringSync();
} on FileSystemException { } on FileSystemException {
...@@ -302,7 +306,7 @@ class IntelliJValidatorOnLinux extends IntelliJValidator { ...@@ -302,7 +306,7 @@ class IntelliJValidatorOnLinux extends IntelliJValidator {
}); });
} }
// after IntelliJ 2020 ~ // after IntelliJ 2020 ~
final Directory cacheDir = fileSystem.directory(fileSystem.path.join(fileSystemUtils.homeDirPath, '.cache', 'JetBrains')); final Directory cacheDir = fileSystem.directory(fileSystem.path.join(homeDirPath, '.cache', 'JetBrains'));
if (!cacheDir.existsSync()) { if (!cacheDir.existsSync()) {
return validators; return validators;
} }
...@@ -311,7 +315,7 @@ class IntelliJValidatorOnLinux extends IntelliJValidator { ...@@ -311,7 +315,7 @@ class IntelliJValidatorOnLinux extends IntelliJValidator {
IntelliJValidator._idToTitle.forEach((String id, String title) { IntelliJValidator._idToTitle.forEach((String id, String title) {
if (name.startsWith(id)) { if (name.startsWith(id)) {
final String version = name.substring(id.length); final String version = name.substring(id.length);
String installPath; String? installPath;
try { try {
installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync(); installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync();
} on FileSystemException { } on FileSystemException {
...@@ -319,7 +323,7 @@ class IntelliJValidatorOnLinux extends IntelliJValidator { ...@@ -319,7 +323,7 @@ class IntelliJValidatorOnLinux extends IntelliJValidator {
} }
if (installPath != null && fileSystem.isDirectorySync(installPath)) { if (installPath != null && fileSystem.isDirectorySync(installPath)) {
final String pluginsPathInUserHomeDir = fileSystem.path.join( final String pluginsPathInUserHomeDir = fileSystem.path.join(
fileSystemUtils.homeDirPath, homeDirPath,
'.local', '.local',
'share', 'share',
'JetBrains', 'JetBrains',
...@@ -352,17 +356,17 @@ class IntelliJValidatorOnLinux extends IntelliJValidator { ...@@ -352,17 +356,17 @@ class IntelliJValidatorOnLinux extends IntelliJValidator {
/// A macOS specific implementation of the intellij validator. /// A macOS specific implementation of the intellij validator.
class IntelliJValidatorOnMac extends IntelliJValidator { class IntelliJValidatorOnMac extends IntelliJValidator {
IntelliJValidatorOnMac(String title, this.id, String installPath, { IntelliJValidatorOnMac(String title, this.id, String installPath, {
@required FileSystem fileSystem, required FileSystem fileSystem,
@required UserMessages userMessages, required UserMessages userMessages,
@required PlistParser plistParser, required PlistParser plistParser,
@required String homeDirPath, required String? homeDirPath,
}) : _plistParser = plistParser, }) : _plistParser = plistParser,
_homeDirPath = homeDirPath, _homeDirPath = homeDirPath,
super(title, installPath, fileSystem: fileSystem, userMessages: userMessages); super(title, installPath, fileSystem: fileSystem, userMessages: userMessages);
final String id; final String id;
final PlistParser _plistParser; final PlistParser _plistParser;
final String _homeDirPath; final String? _homeDirPath;
static const Map<String, String> _dirNameToId = <String, String>{ static const Map<String, String> _dirNameToId = <String, String>{
'IntelliJ IDEA.app': 'IntelliJIdea', 'IntelliJ IDEA.app': 'IntelliJIdea',
...@@ -371,22 +375,25 @@ class IntelliJValidatorOnMac extends IntelliJValidator { ...@@ -371,22 +375,25 @@ class IntelliJValidatorOnMac extends IntelliJValidator {
}; };
static Iterable<DoctorValidator> installed({ static Iterable<DoctorValidator> installed({
@required FileSystem fileSystem, required FileSystem fileSystem,
@required FileSystemUtils fileSystemUtils, required FileSystemUtils fileSystemUtils,
@required UserMessages userMessages, required UserMessages userMessages,
@required PlistParser plistParser, required PlistParser plistParser,
}) { }) {
final List<DoctorValidator> validators = <DoctorValidator>[]; final List<DoctorValidator> validators = <DoctorValidator>[];
final String? homeDirPath = fileSystemUtils.homeDirPath;
final List<String> installPaths = <String>[ final List<String> installPaths = <String>[
'/Applications', '/Applications',
fileSystem.path.join(fileSystemUtils.homeDirPath, 'Applications'), if (homeDirPath != null)
fileSystem.path.join(homeDirPath, 'Applications'),
]; ];
void checkForIntelliJ(Directory dir) { void checkForIntelliJ(Directory dir) {
final String name = fileSystem.path.basename(dir.path); final String name = fileSystem.path.basename(dir.path);
_dirNameToId.forEach((String dirName, String id) { _dirNameToId.forEach((String dirName, String id) {
if (name == dirName) { if (name == dirName) {
final String title = IntelliJValidator._idToTitle[id]; assert(IntelliJValidator._idToTitle.containsKey(id));
final String title = IntelliJValidator._idToTitle[id]!;
validators.add(IntelliJValidatorOnMac( validators.add(IntelliJValidatorOnMac(
title, title,
id, id,
...@@ -394,7 +401,7 @@ class IntelliJValidatorOnMac extends IntelliJValidator { ...@@ -394,7 +401,7 @@ class IntelliJValidatorOnMac extends IntelliJValidator {
fileSystem: fileSystem, fileSystem: fileSystem,
userMessages: userMessages, userMessages: userMessages,
plistParser: plistParser, plistParser: plistParser,
homeDirPath: fileSystemUtils.homeDirPath, homeDirPath: homeDirPath,
)); ));
} }
}); });
...@@ -430,9 +437,9 @@ class IntelliJValidatorOnMac extends IntelliJValidator { ...@@ -430,9 +437,9 @@ class IntelliJValidatorOnMac extends IntelliJValidator {
@visibleForTesting @visibleForTesting
String get plistFile { String get plistFile {
_plistFile ??= _fileSystem.path.join(installPath, 'Contents', 'Info.plist'); _plistFile ??= _fileSystem.path.join(installPath, 'Contents', 'Info.plist');
return _plistFile; return _plistFile!;
} }
String _plistFile; String? _plistFile;
@override @override
String get version { String get version {
...@@ -441,20 +448,20 @@ class IntelliJValidatorOnMac extends IntelliJValidator { ...@@ -441,20 +448,20 @@ class IntelliJValidatorOnMac extends IntelliJValidator {
PlistParser.kCFBundleShortVersionStringKey, PlistParser.kCFBundleShortVersionStringKey,
) ?? 'unknown'; ) ?? 'unknown';
} }
String _version; String? _version;
@override @override
String get pluginsPath { String? get pluginsPath {
if (_pluginsPath != null) { if (_pluginsPath != null) {
return _pluginsPath; return _pluginsPath!;
} }
final String altLocation = _plistParser final String? altLocation = _plistParser
.getValueFromFile(plistFile, 'JetBrainsToolboxApp'); .getValueFromFile(plistFile, 'JetBrainsToolboxApp');
if (altLocation != null) { if (altLocation != null) {
_pluginsPath = altLocation + '.plugins'; _pluginsPath = altLocation + '.plugins';
return _pluginsPath; return _pluginsPath!;
} }
final List<String> split = version.split('.'); final List<String> split = version.split('.');
...@@ -464,27 +471,29 @@ class IntelliJValidatorOnMac extends IntelliJValidator { ...@@ -464,27 +471,29 @@ class IntelliJValidatorOnMac extends IntelliJValidator {
final String major = split[0]; final String major = split[0];
final String minor = split[1]; final String minor = split[1];
final String homeDirPath = _homeDirPath; final String? homeDirPath = _homeDirPath;
String pluginsPath = _fileSystem.path.join( if (homeDirPath != null) {
homeDirPath, String pluginsPath = _fileSystem.path.join(
'Library',
'Application Support',
'JetBrains',
'$id$major.$minor',
'plugins',
);
// Fallback to legacy location from < 2020.
if (!_fileSystem.isDirectorySync(pluginsPath)) {
pluginsPath = _fileSystem.path.join(
homeDirPath, homeDirPath,
'Library', 'Library',
'Application Support', 'Application Support',
'JetBrains',
'$id$major.$minor', '$id$major.$minor',
'plugins',
); );
// Fallback to legacy location from < 2020.
if (!_fileSystem.isDirectorySync(pluginsPath)) {
pluginsPath = _fileSystem.path.join(
homeDirPath,
'Library',
'Application Support',
'$id$major.$minor',
);
}
_pluginsPath = pluginsPath;
} }
_pluginsPath = pluginsPath;
return _pluginsPath; return _pluginsPath;
} }
String _pluginsPath; String? _pluginsPath;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment