mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:39:48 +00:00
Stop using a file path as a plugin id
Change-Id: I14077207e3c7163aceeeaad7491aa4d7b8d852ee Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308965 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
324cef773c
commit
802a139912
|
@ -6,6 +6,7 @@ import 'dart:convert';
|
|||
|
||||
import 'package:analysis_server/src/analytics/percentile_calculator.dart';
|
||||
import 'package:analysis_server/src/plugin/plugin_manager.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
/// Data about the plugins associated with the context roots.
|
||||
class PluginData {
|
||||
|
@ -34,7 +35,7 @@ class PluginData {
|
|||
for (var i = 0; i < plugins.length; i++) {
|
||||
var info = plugins[i];
|
||||
usageCounts
|
||||
.putIfAbsent(info.pluginId, () => PercentileCalculator())
|
||||
.putIfAbsent(info.safePluginId, () => PercentileCalculator())
|
||||
.addValue(info.contextRoots.length);
|
||||
}
|
||||
}
|
||||
|
@ -48,3 +49,21 @@ class PluginData {
|
|||
return encoded;
|
||||
}
|
||||
}
|
||||
|
||||
extension on PluginInfo {
|
||||
/// Return an id for this plugin that doesn't contain any PII.
|
||||
///
|
||||
/// If the plugin is installed in the pub cache, then the returned name will
|
||||
/// be the name and version of the containing package as listed on `pub.dev`.
|
||||
/// If not, then it might be an internal name so we default to 'unknown'.
|
||||
String get safePluginId {
|
||||
var components = path.split(pluginId);
|
||||
if (components.contains('.pub-cache')) {
|
||||
var index = components.lastIndexOf('analyzer_plugin');
|
||||
if (index > 1 && components[index - 1] == 'tools') {
|
||||
return components[index - 2];
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import 'package:analyzer/src/test_utilities/mock_sdk.dart';
|
|||
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
|
||||
import 'package:http/src/response.dart' as http;
|
||||
import 'package:linter/src/rules.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unified_analytics/unified_analytics.dart';
|
||||
|
@ -316,8 +317,8 @@ class AnalyticsManagerTest with ResourceProviderMixin {
|
|||
Future<void> test_startup_withPlugins() async {
|
||||
_defaultStartup();
|
||||
manager.changedPlugins(_MockPluginManager(plugins: [
|
||||
_MockPluginInfo('a'),
|
||||
_MockPluginInfo('b'),
|
||||
_MockPluginInfo(path.join('.pub-cache', 'a', 'tools', 'analyzer_plugin')),
|
||||
_MockPluginInfo(path.join('.pub-cache', 'b', 'tools', 'analyzer_plugin')),
|
||||
]));
|
||||
await manager.shutdown();
|
||||
var counts =
|
||||
|
|
Loading…
Reference in a new issue