janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r793368513



##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ */
+package org.apache.solr.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property 
solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change 
to "modules"
+  private static final Pattern validModNamesPattern = 
Pattern.compile("[\\w\\d-_]+");
+
+  /**
+   * Returns a path to a module's lib folder
+   * @param moduleName name of module
+   * @return the path to the module's lib folder
+   */
+  public static Path getModuleLibPath(Path solrInstallDirPath, String 
moduleName) {
+    return 
getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+  }
+
+  /**
+   * Finds list of module names requested by system property or environment 
variable
+   * @return set of raw volume names from sysprop and/or env.var
+   */
+  static Set<String> resolveFromSyspropOrEnv() {
+    // Fall back to sysprop and env.var if nothing configured through solr.xml
+    Set<String> mods = new HashSet<>();
+    String modulesFromProps = System.getProperty("solr.modules");
+    if (!StringUtils.isEmpty(modulesFromProps)) {
+      mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+    }
+    String modulesFromEnv = System.getenv("SOLR_MODULES");

Review comment:
       Glad to see some support. In the future I want to slim down `bin/solr`, 
`bin/solr.cmd` and also `SolrCLI` to remove all kinds of boiler-plate code to 
map between env.var and sys.prop, and introduce a new `ConfigResolver` to Solr, 
so some piece of code could say `ConfigResolver.getInt("solr.number")` and it 
would return and convert the value from either sys.prop `solr.number` or 
env.var `SOLR_NUMBER`. We could also add stuff like 
`ConfigResolver.getListOfStrings("solr.modules")` and it would return a 
`List<String>` for you. It could even support comma-separated, 
semicolon-separated or why not also props of format `["foo","bar"]`? 
   
   If we can somehow tie it in with loading values from solr.xml and our other 
config files, then we could have a DSL that would be really pleasant to use for 
falling back from explicit xml-config value to any of sys.prop or env.var.
   
   Of course we still need to parse and set JVM-level props like memory in 
bin/solr.




-- 
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

Reply via email to