You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ja...@apache.org on 2022/05/12 10:19:03 UTC

[solr] branch branch_9x updated: SOLR-15921 Look for jars in SOLR_TIP/lib/ (#525)

This is an automated email from the ASF dual-hosted git repository.

janhoy pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 9a2a737873b SOLR-15921 Look for jars in SOLR_TIP/lib/ (#525)
9a2a737873b is described below

commit 9a2a737873b9cde62a709c18971d110c877688eb
Author: Jan Høydahl <ja...@users.noreply.github.com>
AuthorDate: Thu May 12 12:13:46 2022 +0200

    SOLR-15921 Look for jars in SOLR_TIP/lib/ (#525)
    
    (cherry picked from commit 16657ccab0929ab6440b4b1b09a4b4983616c7d9)
---
 solr/CHANGES.txt                                   |  2 ++
 solr/build.gradle                                  |  2 --
 .../src/java/org/apache/solr/core/NodeConfig.java  |  3 +++
 .../org/apache/solr/core/TestCoreContainer.java    | 30 ++++++++++++++++++++++
 solr/packaging/build.gradle                        |  4 +++
 solr/packaging/static/lib/README.md                | 24 +++++++++++++++++
 .../modules/configuration-guide/pages/libs.adoc    |  4 +++
 .../deployment-guide/pages/installing-solr.adoc    |  6 +++++
 .../src/java/org/apache/solr/SolrTestCase.java     |  5 ++++
 .../src/java/org/apache/solr/SolrTestCaseJ4.java   |  5 ----
 10 files changed, 78 insertions(+), 7 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 11216b583c9..8798cda9ace 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -11,6 +11,8 @@ New Features
 * SOLR-16111: Add hl.queryFieldPattern support, an advanced alternative to the hl.requireFieldMatch boolean flag.
   (Christine Poerschke, David Smiley)
 
+* SOLR-15921: Load jars in <solr-install-dir>/lib/ by default (janhoy)
+
 Improvements
 ---------------------
 * SOLR-15986: CommitUpdateCommand and SplitIndexCommand can write user commit metadata. (Bruno Roustant)
diff --git a/solr/build.gradle b/solr/build.gradle
index 60961744285..0493eae7a7f 100644
--- a/solr/build.gradle
+++ b/solr/build.gradle
@@ -20,5 +20,3 @@ description = 'Parent project for Apache Solr'
 subprojects {
   group "org.apache.solr"
 }
-
-
diff --git a/solr/core/src/java/org/apache/solr/core/NodeConfig.java b/solr/core/src/java/org/apache/solr/core/NodeConfig.java
index 757e8b3bf4a..114ac3b8fef 100644
--- a/solr/core/src/java/org/apache/solr/core/NodeConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/NodeConfig.java
@@ -427,6 +427,9 @@ public class NodeConfig {
     Set<String> libDirs = new LinkedHashSet<>();
     libDirs.add("lib");
 
+    // Always add $SOLR_TIP/lib to the shared resource loader
+    libDirs.add(getSolrInstallDir().resolve("lib").toAbsolutePath().normalize().toString());
+
     if (!StringUtils.isBlank(getSharedLibDirectory())) {
       List<String> sharedLibs = Arrays.asList(getSharedLibDirectory().split("\\s*,\\s*"));
       libDirs.addAll(sharedLibs);
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index bbe302fb4fa..363da957814 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -16,6 +16,7 @@
  */
 package org.apache.solr.core;
 
+import static org.apache.solr.servlet.SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE;
 import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.core.Is.is;
@@ -477,6 +478,35 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
     System.clearProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
   }
 
+  @Test
+  public void testSolrInstallDir() throws Exception {
+    Path installDirPath = createTempDir("solrInstallDirTest").toAbsolutePath().normalize();
+    Files.createDirectories(installDirPath.resolve("lib"));
+    try (JarOutputStream jar1 =
+        new JarOutputStream(
+            new FileOutputStream(installDirPath.resolve("lib").resolve("jar1.jar").toFile()))) {
+      jar1.putNextEntry(new JarEntry("solrInstallDirLibResource"));
+      jar1.closeEntry();
+    }
+
+    System.setProperty(SOLR_INSTALL_DIR_ATTRIBUTE, installDirPath.toString());
+
+    final CoreContainer cores = init(CONFIGSETS_SOLR_XML);
+    try {
+      Path solrInstallDir = cores.getConfig().getSolrInstallDir();
+      assertTrue(
+          "solrInstallDir was " + solrInstallDir,
+          solrInstallDir != null
+              && installDirPath
+                  .toString()
+                  .equals(cores.getConfig().getSolrInstallDir().toString()));
+      // Proves that <solr-install-dir>/lib/jar1.jar is found, and the resource inside available
+      assertNotNull(cores.getResourceLoader().openResource("solrInstallDirLibResource"));
+    } finally {
+      cores.shutdown();
+    }
+  }
+
   private static final String CONFIGSETS_SOLR_XML =
       "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
           + "<solr>\n"
diff --git a/solr/packaging/build.gradle b/solr/packaging/build.gradle
index 9a98ae436b9..91ce0b60c30 100644
--- a/solr/packaging/build.gradle
+++ b/solr/packaging/build.gradle
@@ -85,6 +85,10 @@ distributions {
         include "README.md"
       })
 
+      from ('static/lib', {
+        into 'lib'
+      })
+
       from(configurations.modules, {
         into "modules"
       })
diff --git a/solr/packaging/static/lib/README.md b/solr/packaging/static/lib/README.md
new file mode 100644
index 00000000000..38447c46342
--- /dev/null
+++ b/solr/packaging/static/lib/README.md
@@ -0,0 +1,24 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+Lib directories
+===============
+
+There are several special places you can place Solr plugin .jar files. This is one of them.
+Jar files placed in this folder will be globally available.
+
+See https://solr.apache.org/guide/libs.html for more information.
\ No newline at end of file
diff --git a/solr/solr-ref-guide/modules/configuration-guide/pages/libs.adoc b/solr/solr-ref-guide/modules/configuration-guide/pages/libs.adoc
index db651e2403d..6843686cd24 100644
--- a/solr/solr-ref-guide/modules/configuration-guide/pages/libs.adoc
+++ b/solr/solr-ref-guide/modules/configuration-guide/pages/libs.adoc
@@ -35,6 +35,10 @@ See xref:deployment-guide:taking-solr-to-production.adoc[].
 * `<core_instance>/lib/`: In a user-managed cluster or a single-node installation, you may want to add plugins just for a specific Solr core.
 Create this adjacent to the `conf/` directory; it's not present by default.
 
+* `<solr_install>/lib/`: The `.jar` files placed here are available to all Solr cores running on the node, and to node level plugins referenced in `solr.xml` -- so basically everything.
+Contrary to `<solr_home>/lib/`, this directory is always located in the install dir, so it can be used e.g. for custom
+Dockerfile to place custom plugin jars.
+
 * `<solr_install>/server/solr-webapp/webapp/WEB-INF/lib/`: The `.jar` files for Solr itself and it's dependencies live here.
 Certain plugins or add-ons to plugins require placement here.
 They will document themselves to say so.
diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/installing-solr.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/installing-solr.adoc
index 26e7a29c8f5..920e9a3d103 100644
--- a/solr/solr-ref-guide/modules/deployment-guide/pages/installing-solr.adoc
+++ b/solr/solr-ref-guide/modules/deployment-guide/pages/installing-solr.adoc
@@ -104,6 +104,12 @@ This directory also contains the scripts needed when using Solr inside the Docke
 The `README.md` in this directory describes how custom Solr Docker images can be built using this binary distribution.
 Refer to the section xref:deployment-guide:solr-in-docker.adoc[] page for information on using a Solr Docker image.
 
+lib/::
+Folder where Solr will look for additional plugin jar files.
+
+dist/::
+The `dist` directory contains the main Solr .jar files.
+
 docs/::
 The `docs` directory includes a link to online Javadocs for Solr.
 
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
index 14d05a97c29..ea72ebe2fae 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
@@ -119,6 +119,11 @@ public class SolrTestCase extends LuceneTestCase {
           ExternalPaths.DEFAULT_CONFIGSET);
     }
 
+    // set solr.install.dir needed by some test configs outside of the test sandbox (!)
+    if (ExternalPaths.SOURCE_HOME != null) {
+      System.setProperty("solr.install.dir", ExternalPaths.SOURCE_HOME);
+    }
+
     if (!TEST_NIGHTLY) {
       System.setProperty("zookeeper.nio.numSelectorThreads", "2");
       System.setProperty("zookeeper.nio.numWorkerThreads", "3");
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index bdd127356a7..09ced75588b 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -149,7 +149,6 @@ import org.apache.solr.update.processor.DistributedZkUpdateProcessor;
 import org.apache.solr.update.processor.UpdateRequestProcessor;
 import org.apache.solr.util.BaseTestHarness;
 import org.apache.solr.util.ErrorLogMuter;
-import org.apache.solr.util.ExternalPaths;
 import org.apache.solr.util.LogLevel;
 import org.apache.solr.util.RandomizeSSL;
 import org.apache.solr.util.RandomizeSSL.SSLRandomizer;
@@ -284,10 +283,6 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
             new SolrNamedThreadFactory("testExecutor"),
             true);
 
-    // set solr.install.dir needed by some test configs outside of the test sandbox (!)
-    if (ExternalPaths.SOURCE_HOME != null) {
-      System.setProperty("solr.install.dir", ExternalPaths.SOURCE_HOME);
-    }
     // not strictly needed by this class at this point in the control lifecycle, but for
     // backcompat create it now in case any third party tests expect initCoreDataDir to be
     // non-null after calling setupTestCases()