1010
1111import java .nio .file .Files ;
1212import java .nio .file .Path ;
13- import java .util .Collection ;
14- import java .util .Collections ;
15- import java .util .HashMap ;
1613import java .util .List ;
17- import java .util .Map ;
1814import java .util .Set ;
1915
2016/**
2319 */
2420public abstract class PluginBasedCommandlet extends LocalToolCommandlet {
2521
26- private Map <String , PluginDescriptor > pluginsMap ;
27-
28- private Collection <PluginDescriptor > configuredPlugins ;
22+ private PluginMaps pluginsMap ;
2923
3024 /**
3125 * The constructor.
@@ -40,10 +34,10 @@ public PluginBasedCommandlet(IdeContext context, String tool, Set<Tag> tags) {
4034 super (context , tool , tags );
4135 }
4236
43- protected Map < String , PluginDescriptor > getPluginsMap () {
37+ protected PluginMaps getPluginsMap () {
4438
4539 if (this .pluginsMap == null ) {
46- Map < String , PluginDescriptor > map = new HashMap <>( );
40+ PluginMaps map = new PluginMaps ( context );
4741
4842 // Load project-specific plugins
4943 Path pluginsPath = getPluginsConfigPath ();
@@ -60,16 +54,13 @@ protected Map<String, PluginDescriptor> getPluginsMap() {
6054 return this .pluginsMap ;
6155 }
6256
63- private void loadPluginsFromDirectory (Map < String , PluginDescriptor > map , Path pluginsPath ) {
57+ private void loadPluginsFromDirectory (PluginMaps map , Path pluginsPath ) {
6458
6559 List <Path > children = this .context .getFileAccess ()
6660 .listChildren (pluginsPath , p -> p .getFileName ().toString ().endsWith (IdeContext .EXT_PROPERTIES ));
6761 for (Path child : children ) {
6862 PluginDescriptor descriptor = PluginDescriptorImpl .of (child , this .context , isPluginUrlNeeded ());
69- PluginDescriptor duplicate = map .put (descriptor .getName (), descriptor );
70- if (duplicate != null ) {
71- this .context .info ("Plugin {} from project is overridden by {}" , descriptor .getName (), child );
72- }
63+ map .add (descriptor );
7364 }
7465 }
7566
@@ -94,17 +85,6 @@ private Path getUserHomePluginsConfigPath() {
9485 return this .context .getUserHomeIde ().resolve ("settings" ).resolve (this .tool ).resolve (IdeContext .FOLDER_PLUGINS );
9586 }
9687
97- /**
98- * @return the immutable {@link Collection} of {@link PluginDescriptor}s configured for this IDE tool.
99- */
100- public Collection <PluginDescriptor > getConfiguredPlugins () {
101-
102- if (this .configuredPlugins == null ) {
103- this .configuredPlugins = Collections .unmodifiableCollection (getPluginsMap ().values ());
104- }
105- return this .configuredPlugins ;
106- }
107-
10888 /**
10989 * @return the {@link Path} where the plugins of this {@link IdeToolCommandlet} shall be installed.
11090 */
@@ -152,14 +132,17 @@ public PluginDescriptor getPlugin(String key) {
152132 if (key .endsWith (IdeContext .EXT_PROPERTIES )) {
153133 key = key .substring (0 , key .length () - IdeContext .EXT_PROPERTIES .length ());
154134 }
155- PluginDescriptor pluginDescriptor = getPluginsMap ().get (key );
135+
136+ PluginMaps pluginMaps = getPluginsMap ();
137+ PluginDescriptor pluginDescriptor = pluginMaps .getByName (key );
156138 if (pluginDescriptor == null ) {
157139 throw new CliException (
158140 "Could not find plugin " + key + " at " + getPluginsConfigPath ().resolve (key ) + ".properties" );
159141 }
160142 return pluginDescriptor ;
161143 }
162144
145+
163146 @ Override
164147 protected boolean doInstall (boolean silent ) {
165148
@@ -173,7 +156,8 @@ protected boolean doInstall(boolean silent) {
173156 installPlugins = true ;
174157 }
175158 if (installPlugins ) {
176- for (PluginDescriptor plugin : getPluginsMap ().values ()) {
159+ PluginMaps pluginMaps = getPluginsMap ();
160+ for (PluginDescriptor plugin : pluginMaps .getPlugins ()) {
177161 if (plugin .isActive ()) {
178162 installPlugin (plugin );
179163 } else {
0 commit comments