Apache Solr open-source search software
SOLR-18167: Fix the original PR #4507 to cover more use cases in mapping old to new system property names (#4535)
Eric Pugh28ac2a574470
diff --git a/solr/packaging/test/test_start_solr.bats b/solr/packaging/test/test_start_solr.batsindex f85c0e5918d..be365e7a65b 100644--- a/solr/packaging/test/test_start_solr.bats+++ b/solr/packaging/test/test_start_solr.bats@@ -85,7 +85,7 @@ teardown() {@test "deprecated system properties converted to modern properties" {solr start -Ddisable.config.edit=true- assert_file_contains "${SOLR_LOGS_DIR}/solr.log" 'You are passing in deprecated system property disable.config.edit and should upgrade to using solr.api.config.edit.enabled instead.'+ assert_file_contains "${SOLR_LOGS_DIR}/solr.log" 'Deprecated system property disable.config.edit has been replaced by solr.api.config.edit.enabled'}@test "start with custom jetty options" {diff --git a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.javaindex d0b24ca0f31..031116ba23e 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java@@ -75,7 +75,7 @@ public class EnvUtils {CUSTOM_MAPPINGS.put(key, props.getProperty(key));}for (String key : deprecatedProps.stringPropertyNames()) {- DEPRECATED_MAPPINGS.put(deprecatedProps.getProperty(key), key);+ DEPRECATED_MAPPINGS.put(camelCaseToDotSeparated(deprecatedProps.getProperty(key)), key);}init(false, System.getenv(), System.getProperties());}@@ -217,24 +217,14 @@ public class EnvUtils {}for (String deprecatedKey : sysProperties.stringPropertyNames()) {- String lookupKey = findDeprecatedMappingKey(deprecatedKey);- if (lookupKey != null) {- applyDeprecatedPropertyMapping(deprecatedKey, lookupKey, sysProperties);+ var dotKey = camelCaseToDotSeparated(deprecatedKey);+ if (DEPRECATED_MAPPINGS.containsKey(dotKey)+ || DEPRECATED_MAPPINGS.containsKey("!" + dotKey)) {+ applyDeprecatedPropertyMapping(deprecatedKey, dotKey, sysProperties);}}}- // "-D" flags land in system properties as typed - often camelCase - but our mapping file uses- // dot-separated keys, so normalise before looking up.- private static String findDeprecatedMappingKey(String sysPropKey) {- var dotKey = camelCaseToDotSeparated(sysPropKey);- return isInDeprecatedMappings(dotKey) ? dotKey : null;- }-- private static boolean isInDeprecatedMappings(String key) {- return DEPRECATED_MAPPINGS.containsKey(key) || DEPRECATED_MAPPINGS.containsKey("!" + key);- }-private static void applyDeprecatedPropertyMapping(String deprecatedKey, String lookupKey, Properties sysProperties) {var newPropName =@@ -242,7 +232,7 @@ public class EnvUtils {var newValue =DEPRECATED_MAPPINGS.containsKey(lookupKey)? sysProperties.getProperty(deprecatedKey)- : String.valueOf(!Boolean.getBoolean(deprecatedKey));+ : String.valueOf(!Boolean.parseBoolean(sysProperties.getProperty(deprecatedKey)));log.warn("Deprecated system property {} has been replaced by {}. Support for the old property will be removed in a future version of Solr.",deprecatedKey,diff --git a/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.java b/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.javaindex cce0a483bcb..346aee08b42 100644--- a/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.java+++ b/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.java@@ -103,7 +103,6 @@ public class EnvUtilsTest extends SolrTestCase {public void testDeprecated() {var env = Map.of("SOLR_OVERWRITE", "overwritten");Properties defaultProps = new Properties();- // Use the already converted version, not the original camelCase.defaultProps.setProperty("solr.config.set.forbidden.file.types", "xml,json,jar");EnvUtils.init(false, env, defaultProps);@@ -111,13 +110,29 @@ public class EnvUtilsTest extends SolrTestCase {}@Test- public void deprecatedCamelCaseDFlagIsTranslatedToCurrentPropertyName() {+ public void deprecatedCamelCaseSystemPropertyIsMigratedToCurrentName() {Properties sysprops = new Properties();sysprops.setProperty("solr.auth.jwt.allowOutboundHttp", "true");EnvUtils.init(false, Map.of(), sysprops);assertTrue(EnvUtils.getPropertyAsBool("solr.auth.jwt.outbound.http.enabled"));}+ @Test+ public void deprecatedCamelCaseOldNameInMappingsFileIsTranslated() {+ Properties sysprops = new Properties();+ sysprops.setProperty("collection.configName", "techproducts");+ EnvUtils.init(false, Map.of(), sysprops);+ assertEquals("techproducts", EnvUtils.getProperty("solr.configset.bootstrap.config.name"));+ }++ @Test+ public void deprecatedCamelCaseInvertedPropertyIsTranslatedAndValueIsFlipped() {+ Properties sysprops = new Properties();+ sysprops.setProperty("solr.disableFingerprint", "true");+ EnvUtils.init(true, Map.of(), sysprops);+ assertFalse(EnvUtils.getPropertyAsBool("solr.index.replication.fingerprint.enabled"));+ }+@Testpublic void testFlippingDisabledToEnabledPropertyName() {