This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/1.22 by this push:
new 6187cdd398 OAK-10103: oak-store-document: remove deprecated
SystemPropertySupplier
6187cdd398 is described below
commit 6187cdd398883d91f9ff7656161c7d4bc7b5ce40
Author: Julian Reschke <[email protected]>
AuthorDate: Tue Feb 11 17:08:49 2025 +0100
OAK-10103: oak-store-document: remove deprecated SystemPropertySupplier
---
.../oak/plugins/document/ClusterNodeInfo.java | 2 +-
.../plugins/document/DocumentNodeStoreService.java | 2 +-
.../plugins/document/rdb/RDBConnectionHandler.java | 2 +-
.../plugins/document/rdb/RDBDataSourceFactory.java | 2 +-
.../oak/plugins/document/rdb/RDBDocumentStore.java | 2 +-
.../plugins/document/rdb/RDBDocumentStoreDB.java | 2 +-
.../document/rdb/RDBMissingLastRevSeeker.java | 2 +-
.../plugins/document/rdb/RDBVersionGCSupport.java | 2 +-
.../document/util/SystemPropertySupplier.java | 184 ---------------------
.../document/util/SystemPropertySupplierTest.java | 121 --------------
10 files changed, 8 insertions(+), 313 deletions(-)
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
index eca976cc78..c73382492e 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
@@ -43,7 +43,7 @@ import java.util.concurrent.TimeUnit;
import com.google.common.base.Stopwatch;
import org.apache.jackrabbit.oak.commons.StringUtils;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.stats.Clock;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
index 1afbe72f95..2bc2e277f6 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
@@ -62,6 +62,7 @@ import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
import org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean;
import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import
org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
import
org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
@@ -80,7 +81,6 @@ import
org.apache.jackrabbit.oak.plugins.blob.datastore.BlobIdTracker;
import org.apache.jackrabbit.oak.plugins.blob.datastore.SharedDataStoreUtils;
import
org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
import org.apache.jackrabbit.oak.spi.cluster.ClusterRepositoryInfo;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.blob.BlobStoreWrapper;
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java
index 4f26a23417..837f68b755 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java
@@ -26,8 +26,8 @@ import java.util.concurrent.ConcurrentMap;
import javax.sql.DataSource;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.LoggerFactory;
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
index abee07ad21..fe9ca370fe 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
@@ -30,8 +30,8 @@ import java.util.logging.Logger;
import javax.sql.DataSource;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
import org.slf4j.LoggerFactory;
/**
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
index 15676af7a7..db1588ff1d 100755
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
@@ -63,6 +63,7 @@ import javax.sql.DataSource;
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.cache.CacheValue;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder;
@@ -82,7 +83,6 @@ import
org.apache.jackrabbit.oak.plugins.document.locks.NodeDocumentLocks;
import
org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.util.CloseableIterator;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreDB.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreDB.java
index 27e31a93b1..fdfd9116ed 100755
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreDB.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreDB.java
@@ -31,8 +31,8 @@ import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import
org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.PreparedStatementComponent;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBMissingLastRevSeeker.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBMissingLastRevSeeker.java
index 8e99645595..aa9d42a672 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBMissingLastRevSeeker.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBMissingLastRevSeeker.java
@@ -22,11 +22,11 @@ package org.apache.jackrabbit.oak.plugins.document.rdb;
import java.util.Collections;
import java.util.List;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
import
org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
import org.apache.jackrabbit.oak.stats.Clock;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java
index ab47041a68..783afbab0b 100644
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java
+++
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
@@ -37,7 +38,6 @@ import
org.apache.jackrabbit.oak.plugins.document.VersionGCSupport;
import
org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition;
import
org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.UnsupportedIndexedPropertyException;
import org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable;
-import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.stats.Clock;
import org.slf4j.Logger;
diff --git
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SystemPropertySupplier.java
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SystemPropertySupplier.java
deleted file mode 100755
index 2a483a377c..0000000000
---
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SystemPropertySupplier.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * 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.jackrabbit.oak.plugins.document.util;
-
-import java.util.Objects;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-
-import org.jetbrains.annotations.NotNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.event.Level;
-
-/**
- * Utility class for consistent handling of system properties.
- * <p>
- * It provides for:
- * <ul>
- * <li>TRACE level logging of getting the system property
- * <li>ERROR level logging when value does not parse or is invalid (where
- * validity can be checked by a {@link Predicate})
- * <li>(default) INFO level logging when value differs from default (log level
- * and message format can be overridden)
- * </ul>
- * <p>
- * The supported types are: {@link Boolean}, {@link Integer}, {@link Long},
{@link String}
- */
-public class SystemPropertySupplier<T> implements Supplier<T> {
-
- private static final Logger LOG =
LoggerFactory.getLogger(SystemPropertySupplier.class);
-
- private final String propName;
- private final T defaultValue;
- private final Function<String, T> parser;
-
- private Logger log = LOG;
- private Level successLogLevel = Level.INFO;
- private Predicate<T> validator = (a) -> true;
- private Function<String, String> sysPropReader = System::getProperty;
- private BiFunction<String, T, String> setMessageFormatter = (a, b) -> {
- return String.format("System property %s found to be '%s'", a, b);
- };
-
- private SystemPropertySupplier(@NotNull String propName, @NotNull T
defaultValue) throws IllegalArgumentException {
- this.propName = Objects.requireNonNull(propName, "propertyName must be
non-null");
- this.defaultValue = Objects.requireNonNull(defaultValue, "defaultValue
must be non-null");
- this.parser = getValueParser(defaultValue);
- }
-
- /**
- * Create it for a given property name and default value.
- */
- public static <U> SystemPropertySupplier<U> create(@NotNull String
propName, @NotNull U defaultValue)
- throws IllegalArgumentException {
- return new SystemPropertySupplier<U>(propName, defaultValue);
- }
-
- /**
- * Specify the {@link Logger} to log to (defaults to this classes logger
otherwise).
- */
- public SystemPropertySupplier<T> loggingTo(@NotNull Logger log) {
- this.log = Objects.requireNonNull(log);
- return this;
- }
-
- /**
- * Specify a validation expression.
- */
- public SystemPropertySupplier<T> validateWith(@NotNull Predicate<T>
validator) {
- this.validator = Objects.requireNonNull(validator);
- return this;
- }
-
- /**
- * Specify a formatter for the "success" log message to be used when the
- * returned property value differs from the default.
- */
- public SystemPropertySupplier<T> formatSetMessage(@NotNull
BiFunction<String, T, String> setMessageFormatter) {
- this.setMessageFormatter = Objects.requireNonNull(setMessageFormatter);
- return this;
- }
-
- /**
- * Specify {@link Level} to use for "success" message.
- */
- public SystemPropertySupplier<T> logSuccessAs(Level successLogLevel) {
- this.successLogLevel = Objects.requireNonNull(successLogLevel);
- return this;
- }
-
- /**
- * <em>For unit testing</em>: specify a function to read system properties
- * (overriding default of {@code System.getProperty(String}).
- */
- protected SystemPropertySupplier<T> usingSystemPropertyReader(@NotNull
Function<String, String> sysPropReader) {
- this.sysPropReader = Objects.requireNonNull(sysPropReader);
- return this;
- }
-
- /**
- * Obtains the value of a system property, optionally generating
- * diagnostics.
- *
- * @return value of system property
- */
- public T get() {
-
- T ret = defaultValue;
-
- String value = sysPropReader.apply(propName);
- if (value == null) {
- log.trace("System property {} not set", propName);
- } else {
- log.trace("System property {} set to '{}'", propName, value);
- try {
- T v = parser.apply(value);
- if (!validator.test(v)) {
- log.error("Ignoring invalid value '{}' for system property
{}", value, propName);
- } else {
- ret = v;
- }
- } catch (NumberFormatException ex) {
- log.error("Ignoring malformed value '{}' for system property
{}", value, propName);
- }
-
- if (!ret.equals(defaultValue)) {
- String msg = setMessageFormatter.apply(propName, ret);
- switch (successLogLevel) {
- case INFO:
- log.info(msg);
- break;
- case DEBUG:
- log.debug(msg);
- break;
- case ERROR:
- log.error(msg);
- break;
- case TRACE:
- log.trace(msg);
- break;
- case WARN:
- log.warn(msg);
- break;
- default:
- break;
- }
- }
- }
-
- return ret;
- }
-
- @SuppressWarnings("unchecked")
- private static <T> Function<String, T> getValueParser(T defaultValue) {
- if (defaultValue instanceof Boolean) {
- return v -> (T) Boolean.valueOf(v);
- } else if (defaultValue instanceof Integer) {
- return v -> (T) Integer.valueOf(v);
- } else if (defaultValue instanceof Long) {
- return v -> (T) Long.valueOf(v);
- } else if (defaultValue instanceof String) {
- return v -> (T) v;
- } else {
- throw new IllegalArgumentException(
- String.format("expects a defaultValue of Boolean, Integer,
Long, or String, but got: %s", defaultValue.getClass()));
- }
- }
-}
diff --git
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/SystemPropertySupplierTest.java
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/SystemPropertySupplierTest.java
deleted file mode 100755
index d8093b0996..0000000000
---
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/SystemPropertySupplierTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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.jackrabbit.oak.plugins.document.util;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.event.Level;
-
-public class SystemPropertySupplierTest {
-
- private static final Logger LOG =
LoggerFactory.getLogger(SystemPropertySupplierTest.class);
-
- @Test
- public void testBoolean() {
- assertEquals(Boolean.TRUE, SystemPropertySupplier.create("foo",
Boolean.TRUE).usingSystemPropertyReader((n) -> null).get());
- assertEquals(Boolean.FALSE,
- SystemPropertySupplier.create("foo",
Boolean.FALSE).usingSystemPropertyReader((n) -> null).get());
- assertEquals(Boolean.TRUE,
- SystemPropertySupplier.create("foo",
Boolean.FALSE).usingSystemPropertyReader((n) -> "true").get());
- assertEquals(Boolean.FALSE,
- SystemPropertySupplier.create("foo",
Boolean.FALSE).usingSystemPropertyReader((n) -> "false").get());
- }
-
- @Test
- public void testInteger() {
- assertEquals(Integer.valueOf(123),
- SystemPropertySupplier.create("foo",
Integer.valueOf(123)).usingSystemPropertyReader((n) -> null).get());
- assertEquals(Integer.valueOf(1742),
- SystemPropertySupplier.create("foo",
Integer.valueOf(123)).usingSystemPropertyReader((n) -> "1742").get());
- }
-
- @Test
- public void testLong() {
- long big = Long.MAX_VALUE;
- assertEquals(Long.valueOf(big),
- SystemPropertySupplier.create("foo",
Long.valueOf(big)).usingSystemPropertyReader((n) -> null).get());
- assertEquals(Long.valueOf(1742),
- SystemPropertySupplier.create("foo",
Long.valueOf(big)).usingSystemPropertyReader((n) -> "1742").get());
- }
-
- @Test
- public void testString() {
- assertEquals("bar", SystemPropertySupplier.create("foo",
"bar").usingSystemPropertyReader((n) -> null).get());
- assertEquals("", SystemPropertySupplier.create("foo",
"bar").usingSystemPropertyReader((n) -> "").get());
- }
-
- @Test
- public void testFilter() {
- LogCustomizer logCustomizer =
LogCustomizer.forLogger(SystemPropertySupplierTest.class.getName()).enable(Level.ERROR)
- .contains("Ignoring invalid value").create();
- logCustomizer.starting();
-
- try {
- int positive = SystemPropertySupplier.create("foo",
Integer.valueOf(123)).loggingTo(LOG)
- .usingSystemPropertyReader((n) -> "-1").validateWith(n ->
n >= 0).get();
- assertEquals(123, positive);
- assertEquals(1, logCustomizer.getLogs().size());
- } finally {
- logCustomizer.finished();
- }
- }
-
- @Test
- public void testNonParseable() {
- LogCustomizer logCustomizer =
LogCustomizer.forLogger(SystemPropertySupplierTest.class.getName()).enable(Level.ERROR)
- .contains("Ignoring malformed value").create();
- logCustomizer.starting();
-
- try {
- int positive = SystemPropertySupplier.create("foo",
Integer.valueOf(123)).loggingTo(LOG)
- .usingSystemPropertyReader((n) -> "abc").validateWith(n ->
n >= 0).get();
- assertEquals(123, positive);
- assertEquals(1, logCustomizer.getLogs().size());
- } finally {
- logCustomizer.finished();
- }
- }
-
- @Test
- public void testRedirectSuccess() {
- Logger local =
LoggerFactory.getLogger(SystemPropertySupplierTest.class.getName() + "-FOO");
- LogCustomizer logCustomizer =
LogCustomizer.forLogger(SystemPropertySupplierTest.class.getName() + "-FOO")
- .enable(Level.TRACE).create();
- logCustomizer.starting();
-
- try {
- int positive = SystemPropertySupplier.create("foo",
Integer.valueOf(123)).loggingTo(local)
- .usingSystemPropertyReader((n) -> "4217").get();
- assertEquals(4217, positive);
- assertEquals(2, logCustomizer.getLogs().size());
- } finally {
- logCustomizer.finished();
- }
- }
-
- @Test
- public void testUnsupportedType() {
- try {
- SystemPropertySupplier.create("foo", new Object());
- } catch (IllegalArgumentException expected) {
- }
- }
-}