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


##########
solr/core/src/java/org/apache/solr/util/EnvUtils.java:
##########
@@ -0,0 +1,235 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.common.util.Utils;
+
+/**
+ * This class is a unified provider of environment variables and system 
properties. It exposes a
+ * mutable copy of the environment variables. It also converts 'SOLR_FOO' 
variables to system
+ * properties 'solr.foo' and provide various convenience accessors for them.
+ */
+public class EnvUtils {
+  private static final SortedMap<String, String> ENV = new 
TreeMap<>(System.getenv());
+  private static final Map<String, String> CUSTOM_MAPPINGS = new HashMap<>();
+
+  static {
+    try {
+      Properties props = new Properties();
+      try (InputStream stream =
+          
EnvUtils.class.getClassLoader().getResourceAsStream("EnvToSyspropMappings.properties"))
 {
+        props.load(new InputStreamReader(Objects.requireNonNull(stream), 
StandardCharsets.UTF_8));
+        for (String key : props.stringPropertyNames()) {
+          CUSTOM_MAPPINGS.put(key, props.getProperty(key));
+        }
+        init(false);

Review Comment:
   One question I have is whether there may be any race condition here, between 
`EnvUtils` static init and potential `System.getProperty()` access in static 
context in other Solr classes, such as populating static final strings. Not 
sure how/whether we can control ordering.
   
   Of course, if we ban `System.getProperty()` we could have `getProp()` and 
friends block until init is done.



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