Skip to content

Commit

Permalink
[flutter_tools] Support IntelliJ 2020.1 and later on Linux and Windows (
Browse files Browse the repository at this point in the history
#58853)

This PR will update IntelliJ IDEA/Community validation logic for 2020.1 and later on Linux and Windows.
  • Loading branch information
jparound30 committed Oct 13, 2020
1 parent 081c47b commit 1e18006
Show file tree
Hide file tree
Showing 3 changed files with 425 additions and 39 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -67,3 +67,4 @@ Ram Navan <hiramprasad@gmail.com>
meritozh <ah841814092@gmail.com>
Terrence Addison Tandijono(flotilla) <terrenceaddison32@gmail.com>
YeungKC <flutter@yeungkc.com>
Nobuhiro Tabuki <japanese.around30@gmail.com>
170 changes: 163 additions & 7 deletions packages/flutter_tools/lib/src/intellij/intellij_validator.dart
Expand Up @@ -47,8 +47,16 @@ abstract class IntelliJValidator extends DoctorValidator {
@required PlistParser plistParser,
}) {
final FileSystemUtils fileSystemUtils = FileSystemUtils(fileSystem: fileSystem, platform: platform);
if (platform.isLinux || platform.isWindows) {
return IntelliJValidatorOnLinuxAndWindows.installed(
if (platform.isWindows) {
return IntelliJValidatorOnWindows.installed(
fileSystem: fileSystem,
fileSystemUtils: fileSystemUtils,
platform: platform,
userMessages: userMessages,
);
}
if (platform.isLinux) {
return IntelliJValidatorOnLinux.installed(
fileSystem: fileSystem,
fileSystemUtils: fileSystemUtils,
userMessages: userMessages,
Expand Down Expand Up @@ -124,9 +132,9 @@ abstract class IntelliJValidator extends DoctorValidator {
}
}

/// A linux and windows specific implementation of the intellij validator.
class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
IntelliJValidatorOnLinuxAndWindows(String title, this.version, String installPath, this.pluginsPath, {
/// A windows specific implementation of the intellij validator.
class IntelliJValidatorOnWindows extends IntelliJValidator {
IntelliJValidatorOnWindows(String title, this.version, String installPath, this.pluginsPath, {
@required FileSystem fileSystem,
@required UserMessages userMessages,
}) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages);
Expand All @@ -140,6 +148,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
static Iterable<DoctorValidator> installed({
@required FileSystem fileSystem,
@required FileSystemUtils fileSystemUtils,
@required Platform platform,
@required UserMessages userMessages,
}) {
final List<DoctorValidator> validators = <DoctorValidator>[];
Expand All @@ -148,7 +157,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
}

void addValidator(String title, String version, String installPath, String pluginsPath) {
final IntelliJValidatorOnLinuxAndWindows validator = IntelliJValidatorOnLinuxAndWindows(
final IntelliJValidatorOnWindows validator = IntelliJValidatorOnWindows(
title,
version,
installPath,
Expand All @@ -158,7 +167,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
);
for (int index = 0; index < validators.length; index += 1) {
final DoctorValidator other = validators[index];
if (other is IntelliJValidatorOnLinuxAndWindows && validator.installPath == other.installPath) {
if (other is IntelliJValidatorOnWindows && validator.installPath == other.installPath) {
if (validator.version.compareTo(other.version) > 0) {
validators[index] = validator;
}
Expand All @@ -168,6 +177,7 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
validators.add(validator);
}

// before IntelliJ 2019
final Directory homeDir = fileSystem.directory(fileSystemUtils.homeDirPath);
for (final Directory dir in homeDir.listSync().whereType<Directory>()) {
final String name = fileSystem.path.basename(dir.path);
Expand All @@ -187,6 +197,152 @@ class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
}
});
}

// after IntelliJ 2020
final Directory cacheDir = fileSystem.directory(fileSystem.path.join(platform.environment['LOCALAPPDATA'], 'JetBrains'));
if (!cacheDir.existsSync()) {
return validators;
}
for (final Directory dir in cacheDir.listSync().whereType<Directory>()) {
final String name = fileSystem.path.basename(dir.path);
IntelliJValidator._idToTitle.forEach((String id, String title) {
if (name.startsWith(id)) {
final String version = name.substring(id.length);
String installPath;
try {
installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync();
} on FileSystemException {
// ignored
}
if (installPath != null && fileSystem.isDirectorySync(installPath)) {
String pluginsPath;
final String pluginsPathInAppData = fileSystem.path.join(
platform.environment['APPDATA'], 'JetBrains', name, 'plugins');
if (fileSystem.isDirectorySync(installPath + '.plugins')) {
// IntelliJ 2020.3
pluginsPath = installPath + '.plugins';
addValidator(title, version, installPath, pluginsPath);
} else if (fileSystem.isDirectorySync(pluginsPathInAppData)) {
// IntelliJ 2020.1 ~ 2020.2
pluginsPath = pluginsPathInAppData;
addValidator(title, version, installPath, pluginsPath);
}
}
}
});
}
return validators;
}
}

/// A linux specific implementation of the intellij validator.
class IntelliJValidatorOnLinux extends IntelliJValidator {
IntelliJValidatorOnLinux(String title, this.version, String installPath, this.pluginsPath, {
@required FileSystem fileSystem,
@required UserMessages userMessages,
}) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages);

@override
final String version;

@override
final String pluginsPath;

static Iterable<DoctorValidator> installed({
@required FileSystem fileSystem,
@required FileSystemUtils fileSystemUtils,
@required UserMessages userMessages,
}) {
final List<DoctorValidator> validators = <DoctorValidator>[];
if (fileSystemUtils.homeDirPath == null) {
return validators;
}

void addValidator(String title, String version, String installPath, String pluginsPath) {
final IntelliJValidatorOnLinux validator = IntelliJValidatorOnLinux(
title,
version,
installPath,
pluginsPath,
fileSystem: fileSystem,
userMessages: userMessages,
);
for (int index = 0; index < validators.length; index += 1) {
final DoctorValidator other = validators[index];
if (other is IntelliJValidatorOnLinux && validator.installPath == other.installPath) {
if (validator.version.compareTo(other.version) > 0) {
validators[index] = validator;
}
return;
}
}
validators.add(validator);
}

// before IntelliJ 2019
final Directory homeDir = fileSystem.directory(fileSystemUtils.homeDirPath);
for (final Directory dir in homeDir.listSync().whereType<Directory>()) {
final String name = fileSystem.path.basename(dir.path);
IntelliJValidator._idToTitle.forEach((String id, String title) {
if (name.startsWith('.$id')) {
final String version = name.substring(id.length + 1);
String installPath;
try {
installPath = fileSystem.file(fileSystem.path.join(dir.path, 'system', '.home')).readAsStringSync();
} on FileSystemException {
// ignored
}
if (installPath != null && fileSystem.isDirectorySync(installPath)) {
final String pluginsPath = fileSystem.path.join(dir.path, 'config', 'plugins');
addValidator(title, version, installPath, pluginsPath);
}
}
});
}
// after IntelliJ 2020 ~
final Directory cacheDir = fileSystem.directory(fileSystem.path.join(fileSystemUtils.homeDirPath, '.cache', 'JetBrains'));
if (!cacheDir.existsSync()) {
return validators;
}
for (final Directory dir in cacheDir.listSync().whereType<Directory>()) {
final String name = fileSystem.path.basename(dir.path);
IntelliJValidator._idToTitle.forEach((String id, String title) {
if (name.startsWith(id)) {
final String version = name.substring(id.length);
String installPath;
try {
installPath = fileSystem.file(fileSystem.path.join(dir.path, '.home')).readAsStringSync();
} on FileSystemException {
// ignored
}
if (installPath != null && fileSystem.isDirectorySync(installPath)) {
final String pluginsPathInUserHomeDir = fileSystem.path.join(
fileSystemUtils.homeDirPath,
'.local',
'share',
'JetBrains',
name);
if (installPath.contains(fileSystem.path.join('JetBrains','Toolbox','apps'))) {
// via JetBrains ToolBox app
final String pluginsPathInInstallDir = installPath + '.plugins';
if (fileSystem.isDirectorySync(pluginsPathInUserHomeDir)) {
// after 2020.2.x
final String pluginsPath = pluginsPathInUserHomeDir;
addValidator(title, version, installPath, pluginsPath);
} else if (fileSystem.isDirectorySync(pluginsPathInInstallDir)) {
// only 2020.1.X
final String pluginsPath = pluginsPathInInstallDir;
addValidator(title, version, installPath, pluginsPath);
}
} else {
// via tar.gz
final String pluginsPath = pluginsPathInUserHomeDir;
addValidator(title, version, installPath, pluginsPath);
}
}
}
});
}
return validators;
}
}
Expand Down

0 comments on commit 1e18006

Please sign in to comment.