noblepaul commented on a change in pull request #560:
URL: https://github.com/apache/solr/pull/560#discussion_r794187077
##########
File path: solr/core/src/java/org/apache/solr/pkg/PackageLoader.java
##########
@@ -70,17 +77,85 @@
public PackageLoader(CoreContainer coreContainer) {
this.coreContainer = coreContainer;
+
+ List<String> enabledPackages = StrUtils.splitSmart(localPkgsWhiteList,
',');
packageAPI = new PackageAPI(coreContainer, this);
- refreshPackageConf();
+ if (localPkgsDir != null && !enabledPackages.isEmpty()) {
+ loadLocalPackages(enabledPackages);
+ }
+ if (enablePackages) refreshPackageConf();
+ }
+
+ private void loadLocalPackages(List<String> enabledPackages) {
+ final Path packagesPath = new File(localPkgsDir.charAt(0)==
File.separatorChar?
+ localPkgsDir :
+ coreContainer.getSolrHome()+ File.separator+
localPkgsDir).toPath();
+ log.info("Packages to be loaded from directory: {}", packagesPath);
+
+ if (!packagesPath.toFile().exists()) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "No such
directory: " + packagesPath);
+ }
+ File file = new File(packagesPath.toFile(), LOCAL_PACKAGES_JSON);
+ if(file.exists()) {
+ try {
+
+ try (InputStream in = new FileInputStream(file)) {
+ localPackages = PackageAPI.mapper.readValue(in,
PackageAPI.Packages.class);
+ }
+ } catch (IOException e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error
reading local_packages.json", e);
+ }
+ } else {
+ //the no local_packages.json
+ //we will look for each subdirectory and consider them as a package
+ localPackages = readDirAsPackages(packagesPath);
+ }
+
+ for (Map.Entry<String, List<PackageAPI.PkgVersion>> e :
localPackages.packages.entrySet()) {
+ if(!enabledPackages.contains(e.getKey())) continue;
+ Package p = new Package(e.getKey());
+ p.updateVersions(e.getValue(), packagesPath);
+ packageClassLoaders.put(e.getKey(), p);
+ }
+ }
+
+ /**If a directory with no local_packages.json is provided,
+ * each sub directory that contains one or more jar files
+ * will be treated as a package and each jar file in that
+ * directory is added to the package classpath
+ */
+ private PackageAPI.Packages readDirAsPackages(Path packagesPath) {
Review comment:
I shall add one. but the code is written to handle directories with jars
only
--
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]