Skip to content

Conversation

@jparound30
Copy link
Contributor

Description

This PR suggests improving the IntelliJ plugin "jar" detection logic.

Previously:
The IntelliJ Flutter plugin was contained flutter-intellij.jar.
Currently:
It is named flutter-intellij-X.Y.Z.jar and does not contain META-INF/plugin.xml.
META-INF/plugin.xml is included in flutter-idea-X.Y.Z.jar.

So this PR changes the rules for searching the plugin's jar file.
Concretely, it looks for the jar file containing META-INF/plugin.xml in the plugin's package directory and reads the package version from its META-INF/plugin.xml.

Related Issues

[#67918] (already fixed and closed via #67931)

Tests

I added the following tests:

packages/flutter_tools/test/general.shard/intellij/intellij_test.dart

  • 'IntelliJPlugins can read the package version of the flutter-intellij 50.0+/IntelliJ 2020.2+ layout'
  • 'IntelliJPlugins can read the package version of the flutter-intellij 50.0+/IntelliJ 2020.2+ layout(priority is given to packages with the same prefix as packageName)'

I changed the following test:

  • 'IntelliJPlugins does not crash if no plugin file found'

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@google-cla google-cla bot added the cla: yes label Oct 13, 2020
@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 13, 2020
@jparound30
Copy link
Contributor Author

Hi @jonahwilliams
If you have time, I'd appreciate your comments on this pull request.

@jonahwilliams jonahwilliams self-requested a review October 14, 2020 03:59
@jonahwilliams
Copy link
Contributor

I'll take a look!

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, just a few suggestions.

Could you also leave a longer comment in intellij.dart describing the newer plugin structure and some example files you need to check?

// Collect the files with a file suffix of .jar/.zip that contains the plugin.xml file
final List<FileSystemEntity> pluginJarPaths = _fileSystem
.directory(_fileSystem.path.join(pluginsPath, packageName, 'lib'))
.listSync()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you only care about Files, you can add whereType<File>() to filter the iterable down to just them. Then you can skip the stat check here and make pluginJarPaths a List of files:

_fileSystem
    .directory(_fileSystem.path.join(pluginsPath, packageName, 'lib'))
    .listSync()
    .whereType<File>()
    .where((File file) {
     final String fileExt= _fileSystem.path.extension(file.path);
     return fileExt == '.jar' || fileExt == '.zip';
   })
   .toList()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I fixed it like you commented.

return null;
}
// Prefer file with the same suffix as the package name
pluginJarPaths.sort((FileSystemEntity a, FileSystemEntity b) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the names don't match at all is it worth including them in the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.
The reason is that there are several variations of the jar file containing META-INF/plugin.xml.
Currently, we need to check at least three files: flutter-intellij.jar / flutter-intellij-X.Y.Z.jar / flutter-idea-X.Y.Z.jar.

try {

final Iterator<String> itr = mainJarPathList.iterator;
while (itr.moveNext()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Assuming you change the list to one of files). I would stick with the for-in loop instead of manipulating the iterable directly.

for (final File file in mainJarPathList) {
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I fixed it like you commented.

@jparound30
Copy link
Contributor Author

Could you also leave a longer comment in intellij.dart describing the newer plugin structure and some example files you need to check?

I've added a comment in intellij.dart.
Please check it out.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thank you once again for your contribution 😄

/// This searches on the provided plugin path for a JAR archive, then
/// unzips it to parse the META-INF/plugin.xml for version information.
///
/// In particular, the Intellij Flutter plugin has a different structure depending on the version.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the details here, this is a great comment

@jonahwilliams
Copy link
Contributor

The Mac tool_tests issue is a flake, landing this now

@jonahwilliams jonahwilliams merged commit 4e2f82c into flutter:master Oct 19, 2020
@jparound30 jparound30 deleted the fix-intellij-plugin-detection branch October 22, 2020 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants