janhoy commented on code in PR #4067:
URL: https://github.com/apache/solr/pull/4067#discussion_r2712279917


##########
solr/core/src/java/org/apache/solr/core/SolrCore.java:
##########
@@ -3614,32 +3614,112 @@ public void cleanupOldIndexDirectories(boolean reload) 
{
     }
   }
 
+  /**
+   * Parses implicit plugin definitions from a JSON map and converts them to 
PluginInfo objects.
+   *
+   * @param implicitPluginsInfo the parsed JSON map containing plugin 
definitions
+   * @return an unmodifiable list of PluginInfo objects for request handlers
+   * @throws NullPointerException if requestHandlers section is missing
+   */
+  static List<PluginInfo> parseImplicitPlugins(Map<String, ?> 
implicitPluginsInfo) {
+    @SuppressWarnings("unchecked")
+    Map<String, Map<String, Object>> requestHandlers =
+        (Map<String, Map<String, Object>>) 
implicitPluginsInfo.get(SolrRequestHandler.TYPE);
+
+    if (requestHandlers == null) {
+      throw new NullPointerException("No requestHandler section found in 
implicit plugins");
+    }
+
+    List<PluginInfo> implicits = new ArrayList<>(requestHandlers.size());
+    for (Map.Entry<String, Map<String, Object>> entry : 
requestHandlers.entrySet()) {
+      Map<String, Object> info = entry.getValue();
+      info.put(CommonParams.NAME, entry.getKey());
+      implicits.add(new PluginInfo(SolrRequestHandler.TYPE, info));
+    }
+    return Collections.unmodifiableList(implicits);
+  }
+
   private static final class ImplicitHolder {
     private ImplicitHolder() {}
 
-    private static final List<PluginInfo> INSTANCE;
+    private static volatile List<PluginInfo> INSTANCE = null;
 
-    static {
+    static List<PluginInfo> getInstance(SolrCore core) {
+      if (INSTANCE == null) {
+        synchronized (ImplicitHolder.class) {
+          if (INSTANCE == null) {
+            INSTANCE = loadImplicitPlugins(core);
+          }
+        }
+      }
+      return INSTANCE;
+    }
+
+    private static List<PluginInfo> loadImplicitPlugins(SolrCore core) {
+      // Check for custom implicit plugins file from solr.xml (global 
configuration)
+      String customPluginsFile = 
core.getCoreContainer().getConfig().getImplicitPluginsFile();
+      if (customPluginsFile != null && !customPluginsFile.isEmpty()) {
+        try {
+          // Resolve path similar to solr.xml - support both absolute and 
relative paths
+          Path customPluginsPath = Path.of(customPluginsFile);
+          if (!customPluginsPath.isAbsolute()) {
+            // Resolve relative paths against SOLR_HOME
+            Path solrHome = core.getCoreContainer().getSolrHome();
+            customPluginsPath = solrHome.resolve(customPluginsFile);
+          }
+

Review Comment:
   Good find by copilot!



##########
solr/server/solr/solr.xml:
##########
@@ -35,6 +35,7 @@
   <str name="allowUrls">${solr.security.allow.urls:}</str>
   <str name="hideStackTrace">${solr.hideStackTrace:false}</str>
   <int name="indexSearcherExecutorThreads">${solr.searchThreads:0}</int>
+  <str name="implicitPluginsFile">${solr.implicitPluginsFile:}</str>

Review Comment:
   Did you consider a "modern" property name?



##########
solr/core/src/java/org/apache/solr/core/SolrCore.java:
##########
@@ -3614,32 +3614,112 @@ public void cleanupOldIndexDirectories(boolean reload) 
{
     }
   }
 
+  /**
+   * Parses implicit plugin definitions from a JSON map and converts them to 
PluginInfo objects.
+   *
+   * @param implicitPluginsInfo the parsed JSON map containing plugin 
definitions
+   * @return an unmodifiable list of PluginInfo objects for request handlers
+   * @throws NullPointerException if requestHandlers section is missing
+   */
+  static List<PluginInfo> parseImplicitPlugins(Map<String, ?> 
implicitPluginsInfo) {
+    @SuppressWarnings("unchecked")
+    Map<String, Map<String, Object>> requestHandlers =
+        (Map<String, Map<String, Object>>) 
implicitPluginsInfo.get(SolrRequestHandler.TYPE);
+
+    if (requestHandlers == null) {
+      throw new NullPointerException("No requestHandler section found in 
implicit plugins");
+    }
+
+    List<PluginInfo> implicits = new ArrayList<>(requestHandlers.size());
+    for (Map.Entry<String, Map<String, Object>> entry : 
requestHandlers.entrySet()) {
+      Map<String, Object> info = entry.getValue();
+      info.put(CommonParams.NAME, entry.getKey());
+      implicits.add(new PluginInfo(SolrRequestHandler.TYPE, info));
+    }
+    return Collections.unmodifiableList(implicits);
+  }
+
   private static final class ImplicitHolder {
     private ImplicitHolder() {}
 
-    private static final List<PluginInfo> INSTANCE;
+    private static volatile List<PluginInfo> INSTANCE = null;
 
-    static {
+    static List<PluginInfo> getInstance(SolrCore core) {
+      if (INSTANCE == null) {
+        synchronized (ImplicitHolder.class) {
+          if (INSTANCE == null) {
+            INSTANCE = loadImplicitPlugins(core);
+          }
+        }
+      }
+      return INSTANCE;
+    }
+
+    private static List<PluginInfo> loadImplicitPlugins(SolrCore core) {
+      // Check for custom implicit plugins file from solr.xml (global 
configuration)
+      String customPluginsFile = 
core.getCoreContainer().getConfig().getImplicitPluginsFile();
+      if (customPluginsFile != null && !customPluginsFile.isEmpty()) {
+        try {
+          // Resolve path similar to solr.xml - support both absolute and 
relative paths
+          Path customPluginsPath = Path.of(customPluginsFile);
+          if (!customPluginsPath.isAbsolute()) {
+            // Resolve relative paths against SOLR_HOME
+            Path solrHome = core.getCoreContainer().getSolrHome();
+            customPluginsPath = solrHome.resolve(customPluginsFile);

Review Comment:
   Wasn't it suggested to disallow path.resolve due to how it will resolve 
`../../..` patterns perhaps unexpectedly? However, if calling 
`assertPathAllowed` before use, we should be safe anyway



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to