janhoy commented on a change in pull request #560: URL: https://github.com/apache/solr/pull/560#discussion_r793487654
########## 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: Well, that is a happy-path integration test. I more thought of a unit test that simply creates a tmpDirectory folder with several different (and erraneous) sub folders inside to validate that you get exactley the expected packages back, and that failure cases are handled correctly. -- 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org