From d2d75f9458a394fd60d05c64a7b14ff873a94cbb Mon Sep 17 00:00:00 2001 From: "James R. Perkins" Date: Fri, 19 Jan 2018 14:08:40 -0800 Subject: [PATCH] =?UTF-8?q?Revert=20"[LOGMGR-188]=20Add=20option=20for=20g?= =?UTF-8?q?eneric=20properties=20and=20child=20handler=20name=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logmanager/PropertyConfigurator.java | 85 +++++------ .../config/AbstractPropertyConfiguration.java | 60 ++------ .../config/ConfigurationProperty.java | 69 --------- .../config/ConfigurationPropertyImpl.java | 51 ------- .../config/HandlerConfiguration.java | 17 --- .../config/HandlerConfigurationImpl.java | 11 -- .../config/LogContextConfiguration.java | 81 ----------- .../config/LogContextConfigurationImpl.java | 35 ----- .../config/PropertyConfigurable.java | 71 --------- .../logmanager/PropertyConfiguratorTests.java | 135 ------------------ 10 files changed, 47 insertions(+), 568 deletions(-) delete mode 100644 src/main/java/org/jboss/logmanager/config/ConfigurationProperty.java delete mode 100644 src/main/java/org/jboss/logmanager/config/ConfigurationPropertyImpl.java diff --git a/src/main/java/org/jboss/logmanager/PropertyConfigurator.java b/src/main/java/org/jboss/logmanager/PropertyConfigurator.java index 9b47ba20..9042ff9f 100644 --- a/src/main/java/org/jboss/logmanager/PropertyConfigurator.java +++ b/src/main/java/org/jboss/logmanager/PropertyConfigurator.java @@ -37,7 +37,6 @@ import java.util.Set; import java.util.regex.Pattern; -import org.jboss.logmanager.config.ConfigurationProperty; import org.jboss.logmanager.config.ErrorManagerConfiguration; import org.jboss.logmanager.config.FilterConfiguration; import org.jboss.logmanager.config.FormatterConfiguration; @@ -138,7 +137,7 @@ public void writeConfiguration(final OutputStream outputStream, final boolean wr for (String loggerName : loggerNames) { writeLoggerConfiguration(out, config.getLoggerConfiguration(loggerName), implicitHandlers, implicitFilters, writeExpressions); } - final List allHandlerNames = config.getPersistableHandlerNames(); + final List allHandlerNames = config.getHandlerNames(); final List explicitHandlerNames = new ArrayList(allHandlerNames); explicitHandlerNames.removeAll(implicitHandlers); if (!explicitHandlerNames.isEmpty()) { @@ -150,7 +149,7 @@ public void writeConfiguration(final OutputStream outputStream, final boolean wr writeHandlerConfiguration(out, config.getHandlerConfiguration(handlerName), implicitHandlers, implicitFilters, implicitFormatters, implicitErrorManagers, writeExpressions); } - final List allFilterNames = config.getPersistableFilterNames(); + final List allFilterNames = config.getFilterNames(); final List explicitFilterNames = new ArrayList(allFilterNames); explicitFilterNames.removeAll(implicitFilters); if (!explicitFilterNames.isEmpty()) { @@ -161,7 +160,7 @@ public void writeConfiguration(final OutputStream outputStream, final boolean wr for (String filterName : allFilterNames) { writeFilterConfiguration(out, config.getFilterConfiguration(filterName), writeExpressions); } - final List allFormatterNames = config.getPersistableFormatterNames(); + final List allFormatterNames = config.getFormatterNames(); final ArrayList explicitFormatterNames = new ArrayList(allFormatterNames); explicitFormatterNames.removeAll(implicitFormatters); if (!explicitFormatterNames.isEmpty()) { @@ -172,7 +171,7 @@ public void writeConfiguration(final OutputStream outputStream, final boolean wr for (String formatterName : allFormatterNames) { writeFormatterConfiguration(out, config.getFormatterConfiguration(formatterName), writeExpressions); } - final List allErrorManagerNames = config.getPersistableErrorManagerNames(); + final List allErrorManagerNames = config.getErrorManagerNames(); final ArrayList explicitErrorManagerNames = new ArrayList(allErrorManagerNames); explicitErrorManagerNames.removeAll(implicitErrorManagers); if (!explicitErrorManagerNames.isEmpty()) { @@ -185,7 +184,7 @@ public void writeConfiguration(final OutputStream outputStream, final boolean wr } // Write POJO configurations - final List pojoNames = config.getPersistablePojoNames(); + final List pojoNames = config.getPojoNames(); if (!pojoNames.isEmpty()) { writePropertyComment(out, "POJOs to configure"); writeProperty(out, "pojos", toCsvString(pojoNames)); @@ -246,7 +245,7 @@ private void writeHandlerConfiguration(final Writer out, final HandlerConfigurat final Set implicitHandlers, final Set implicitFilters, final Set implicitFormatters, final Set implicitErrorManagers, final boolean writeExpressions) throws IOException { - if (handler != null && handler.isPersistable()) { + if (handler != null) { out.write(NEW_LINE); final String name = handler.getName(); final String prefix = "handler." + name + "."; @@ -298,7 +297,7 @@ private void writeHandlerConfiguration(final Writer out, final HandlerConfigurat printError("Handler %s is not defined and will not be written to the configuration for handler %s%n", handlerName, name); } } - if (!handlerNames.isEmpty() && handler.isHandlerNamesPersistable()) { + if (!handlerNames.isEmpty()) { writeProperty(out, prefix, "handlers", toCsvString(handlerNames)); } final List postConfigurationMethods = handler.getPostConfigurationMethods(); @@ -310,7 +309,7 @@ private void writeHandlerConfiguration(final Writer out, final HandlerConfigurat } private static void writeFilterConfiguration(final Writer out, final FilterConfiguration filter, final boolean writeExpressions) throws IOException { - if (filter != null && filter.isPersistable()) { + if (filter != null) { out.write(NEW_LINE); final String name = filter.getName(); final String prefix = "filter." + name + "."; @@ -329,7 +328,7 @@ private static void writeFilterConfiguration(final Writer out, final FilterConfi } private static void writeFormatterConfiguration(final Writer out, final FormatterConfiguration formatter, final boolean writeExpressions) throws IOException { - if (formatter != null && formatter.isPersistable()) { + if (formatter != null) { out.write(NEW_LINE); final String name = formatter.getName(); final String prefix = "formatter." + name + "."; @@ -348,7 +347,7 @@ private static void writeFormatterConfiguration(final Writer out, final Formatte } private static void writeErrorManagerConfiguration(final Writer out, final ErrorManagerConfiguration errorManager, final boolean writeExpressions) throws IOException { - if (errorManager != null && errorManager.isPersistable()) { + if (errorManager != null) { out.write(NEW_LINE); final String name = errorManager.getName(); final String prefix = "errorManager." + name + "."; @@ -367,7 +366,7 @@ private static void writeErrorManagerConfiguration(final Writer out, final Error } private static void writePojoConfiguration(final Writer out, final PojoConfiguration pojo, final boolean writeExpressions) throws IOException { - if (pojo != null && pojo.isPersistable()) { + if (pojo != null) { out.write(NEW_LINE); final String name = pojo.getName(); final String prefix = "pojo." + name + "."; @@ -427,30 +426,6 @@ private static void writeProperty(final Writer out, final String prefix, final S out.write(NEW_LINE); } - /** - * Writes a property to the print stream. - * - * @param out the print stream to write to. - * @param prefix the prefix for the name or {@code null} to use no prefix. - * @param property the property that may be or may not be written to the configuration - * @param writeExpression {@code true} if expressions should be written, {@code false} if the resolved value - * should be written - */ - private static void writeProperty(final Writer out, final String prefix, final ConfigurationProperty property, final boolean writeExpression) throws IOException { - if (property.isPersistable()) { - final String value = property.getValue(writeExpression); - if (!value.isEmpty()) { - if (prefix == null) { - writeKey(out, property.getKey()); - } else { - writeKey(out, String.format("%s%s", prefix, property.getKey())); - } - writeValue(out, value); - out.write(NEW_LINE); - } - } - } - /** * Writes a collection of properties to the print stream. Uses the {@link org.jboss.logmanager.config.PropertyConfigurable#getPropertyValueString(String)} * to extract the value. @@ -462,23 +437,33 @@ private static void writeProperty(final Writer out, final String prefix, final C * should be written */ private static void writeProperties(final Writer out, final String prefix, final PropertyConfigurable propertyConfigurable, final boolean writeExpression) throws IOException { - final List props = propertyConfigurable.getProperties(); - if (!props.isEmpty()) { + final List names = propertyConfigurable.getPropertyNames(); + if (!names.isEmpty()) { final List ctorProps = propertyConfigurable.getConstructorProperties(); - final List names = new ArrayList<>(); - for (ConfigurationProperty property : props) { - if (property.isPersistable()) { - names.add(property.getKey()); + if (prefix == null) { + writeProperty(out, "properties", toCsvString(names)); + if (!ctorProps.isEmpty()) { + writeProperty(out, "constructorProperties", toCsvString(ctorProps)); } - } - if (!names.isEmpty()) { + for (String name : names) { + if (writeExpression) { + writeProperty(out, name, propertyConfigurable.getPropertyValueExpression(name).getValue()); + } else { + writeProperty(out, name, propertyConfigurable.getPropertyValueString(name)); + } + } + } else { writeProperty(out, prefix, "properties", toCsvString(names)); - } - if (!ctorProps.isEmpty()) { - writeProperty(out, prefix, "constructorProperties", toCsvString(ctorProps)); - } - for (ConfigurationProperty property : props) { - writeProperty(out, prefix, property, writeExpression); + if (!ctorProps.isEmpty()) { + writeProperty(out, prefix, "constructorProperties", toCsvString(ctorProps)); + } + for (String name : names) { + if (writeExpression) { + writeProperty(out, prefix, name, propertyConfigurable.getPropertyValueExpression(name).getValue()); + } else { + writeProperty(out, prefix, name, propertyConfigurable.getPropertyValueString(name)); + } + } } } } diff --git a/src/main/java/org/jboss/logmanager/config/AbstractPropertyConfiguration.java b/src/main/java/org/jboss/logmanager/config/AbstractPropertyConfiguration.java index e8d30c09..fb96218f 100644 --- a/src/main/java/org/jboss/logmanager/config/AbstractPropertyConfiguration.java +++ b/src/main/java/org/jboss/logmanager/config/AbstractPropertyConfiguration.java @@ -47,11 +47,9 @@ abstract class AbstractPropertyConfiguration properties = new LinkedHashMap<>(0); + private final Map> properties = new LinkedHashMap>(0); private final Map postConfigurationMethods = new LinkedHashMap(); - private boolean persistable; - protected AbstractPropertyConfiguration(final Class baseClass, final LogContextConfigurationImpl configuration, final Map refs, final Map configs, final String name, final String moduleName, final String className, final String[] constructorProperties) { super(name, configuration, refs, configs); this.moduleName = moduleName; @@ -76,7 +74,6 @@ protected AbstractPropertyConfiguration(final Class baseClass, final LogConte throw new IllegalArgumentException(String.format("Failed to load class \"%s\" for %s \"%s\"", className, getDescription(), name), e); } this.actualClass = actualClass; - persistable = true; } ConfigAction getConstructAction() { @@ -110,8 +107,7 @@ public T validate() throws IllegalArgumentException { if (! properties.containsKey(property)) { throw new IllegalArgumentException(String.format("No property named \"%s\" is configured on %s \"%s\"", property, getDescription(), getName())); } - final ConfigurationProperty configurationProperty = properties.get(property); - final ValueExpression valueExpression = configurationProperty == null ? null : configurationProperty.getValue(); + final ValueExpression valueExpression = properties.get(property); final Object value = getConfiguration().getValue(actualClass, property, paramTypes[i], valueExpression, true).getObject(); params[i] = value; } @@ -150,18 +146,13 @@ static boolean contains(Object[] array, Object val) { } public void setPropertyValueString(final String propertyName, final String value) throws IllegalArgumentException { - setPropertyValueExpression(propertyName, value, true); - } - - @Override - public void setPropertyValueString(final String propertyName, final String value, final boolean persist) throws IllegalArgumentException { if (isRemoved()) { throw new IllegalArgumentException(String.format("Cannot set property \"%s\" on %s \"%s\" (removed)", propertyName, getDescription(), getName())); } if (propertyName == null) { throw new IllegalArgumentException("propertyName is null"); } - setPropertyValueExpression(propertyName, new ConfigurationPropertyImpl(propertyName, ValueExpression.STRING_RESOLVER.resolve(value), persist)); + setPropertyValueExpression(propertyName, ValueExpression.STRING_RESOLVER.resolve(value)); } public String getPropertyValueString(final String propertyName) { @@ -170,55 +161,39 @@ public String getPropertyValueString(final String propertyName) { @Override public ValueExpression getPropertyValueExpression(final String propertyName) { - return properties.containsKey(propertyName) ? properties.get(propertyName).getValue() : ValueExpression.NULL_STRING_EXPRESSION; + return properties.containsKey(propertyName) ? properties.get(propertyName) : ValueExpression.NULL_STRING_EXPRESSION; } @Override public void setPropertyValueExpression(final String propertyName, final String expression) { - setPropertyValueExpression(propertyName, expression, true); - } - - @Override - public void setPropertyValueExpression(final String propertyName, final String expression, final boolean persist) { if (isRemoved()) { throw new IllegalArgumentException(String.format("Cannot set property \"%s\" on %s \"%s\" (removed)", propertyName, getDescription(), getName())); } if (propertyName == null) { throw new IllegalArgumentException("propertyName is null"); } - setPropertyValueExpression(propertyName, new ConfigurationPropertyImpl(propertyName, ValueExpression.STRING_RESOLVER.resolve(expression), persist)); + setPropertyValueExpression(propertyName, ValueExpression.STRING_RESOLVER.resolve(expression)); } @Override public void setPropertyValueExpression(final String propertyName, final String expression, final String value) { - setPropertyValueExpression(propertyName, expression, value, true); - } - - @Override - public void setPropertyValueExpression(final String propertyName, final String expression, final String value, final boolean persist) { if (isRemoved()) { throw new IllegalArgumentException(String.format("Cannot set property \"%s\" on %s \"%s\" (removed)", propertyName, getDescription(), getName())); } if (propertyName == null) { throw new IllegalArgumentException("propertyName is null"); } - setPropertyValueExpression(propertyName, new ConfigurationPropertyImpl(propertyName, new ValueExpressionImpl<>(expression, value), persist)); + setPropertyValueExpression(propertyName, new ValueExpressionImpl(expression, value)); } - @Override - public List getProperties() { - return new ArrayList<>(properties.values()); - } - - private void setPropertyValueExpression(final String propertyName, final ConfigurationProperty configurationProperty) { + private void setPropertyValueExpression(final String propertyName, final ValueExpression expression) { final boolean replacement = properties.containsKey(propertyName); final boolean constructorProp = contains(constructorProperties, propertyName); final Method setter = getPropertySetter(actualClass, propertyName); if (setter == null && ! constructorProp) { throw new IllegalArgumentException(String.format("No property \"%s\" setter found for %s \"%s\"", propertyName, getDescription(), getName())); } - final ConfigurationProperty oldProperty = properties.put(propertyName, configurationProperty); - final ValueExpression oldValue = oldProperty == null ? null : oldProperty.getValue(); + final ValueExpression oldValue = properties.put(propertyName, expression); getConfiguration().addAction(new ConfigAction() { public ObjectProducer validate() throws IllegalArgumentException { if (setter == null) { @@ -228,7 +203,7 @@ public ObjectProducer validate() throws IllegalArgumentException { if (propertyType == null) { throw new IllegalArgumentException(String.format("No property \"%s\" type could be determined for %s \"%s\"", propertyName, getDescription(), getName())); } - return getConfiguration().getValue(actualClass, propertyName, propertyType, configurationProperty.getValue(), false); + return getConfiguration().getValue(actualClass, propertyName, propertyType, expression, false); } public void applyPreCreate(final ObjectProducer param) { @@ -255,7 +230,7 @@ public void rollback() { } final ObjectProducer producer; if (replacement) { - properties.put(propertyName, oldProperty); + properties.put(propertyName, oldValue); producer = getConfiguration().getValue(actualClass, propertyName, propertyType, oldValue, true); } else { properties.remove(propertyName); @@ -291,9 +266,8 @@ public boolean removeProperty(final String propertyName) { if (setter == null) { throw new IllegalArgumentException(String.format("No property \"%s\" setter found for %s \"%s\"", propertyName, getDescription(), getName())); } - final ConfigurationProperty oldProperty = properties.remove(propertyName); - if (oldProperty != null) { - final ValueExpression oldValue = oldProperty.getValue(); + final ValueExpression oldValue = properties.remove(propertyName); + if (oldValue != null) { getConfiguration().addAction(new ConfigAction() { public ObjectProducer validate() throws IllegalArgumentException { final Class propertyType = getPropertyType(actualClass, propertyName); @@ -466,16 +440,6 @@ public void rollback() { return true; } - @Override - public boolean isPersistable() { - return persistable; - } - - @Override - public void setPersistable(final boolean persistable) { - this.persistable = persistable; - } - protected final void addPostConfigurationActions() { addPostConfigurationActions(false); } diff --git a/src/main/java/org/jboss/logmanager/config/ConfigurationProperty.java b/src/main/java/org/jboss/logmanager/config/ConfigurationProperty.java deleted file mode 100644 index 39593dd1..00000000 --- a/src/main/java/org/jboss/logmanager/config/ConfigurationProperty.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * - * Copyright 2018 Red Hat, Inc., and individual contributors - * as indicated by the @author tags. - * - * Licensed 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.jboss.logmanager.config; - -/** - * Represents a configuration property. - * - * @author James R. Perkins - */ -public interface ConfigurationProperty { - - /** - * Indicates whether or not the property should be perisisted to the configuration. - * - * @return {@code true} if the property should be persisted, otherwise {@code false} - */ - boolean isPersistable(); - - /** - * The key for the property. - * - * @return the key - */ - String getKey(); - - /** - * The properties value. - * - * @return the value - */ - ValueExpression getValue(); - - /** - * The properties value which may or may not be an expression. If {@code allowExpression} is {@code false} a - * string representation of the {@linkplain ValueExpression#getResolvedValue() resolved value} will be returned. - * Otherwise a string which may be an expression will be returned. - * - * @param allowExpression {@code true} if a possible expression is allowed to be returned {@code false} if any - * possible expressions should be resovled - * - * @return a string representation of the value - * - * @see ValueExpression#getValue() - */ - default String getValue(final boolean allowExpression) { - final ValueExpression value = getValue(); - if (value == null) { - return ""; - } - return allowExpression ? value.getValue() : value.getResolvedValue(); - } -} diff --git a/src/main/java/org/jboss/logmanager/config/ConfigurationPropertyImpl.java b/src/main/java/org/jboss/logmanager/config/ConfigurationPropertyImpl.java deleted file mode 100644 index ed52e90d..00000000 --- a/src/main/java/org/jboss/logmanager/config/ConfigurationPropertyImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * - * Copyright 2018 Red Hat, Inc., and individual contributors - * as indicated by the @author tags. - * - * Licensed 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.jboss.logmanager.config; - -/** - * @author James R. Perkins - */ -class ConfigurationPropertyImpl implements ConfigurationProperty { - - private final String key; - private final ValueExpression value; - private final boolean writable; - - ConfigurationPropertyImpl(final String key, final ValueExpression value, final boolean writable) { - this.key = key; - this.value = value == null ? ValueExpression.NULL_STRING_EXPRESSION : value; - this.writable = writable; - } - - @Override - public boolean isPersistable() { - return writable; - } - - @Override - public String getKey() { - return key; - } - - @Override - public ValueExpression getValue() { - return value; - } -} diff --git a/src/main/java/org/jboss/logmanager/config/HandlerConfiguration.java b/src/main/java/org/jboss/logmanager/config/HandlerConfiguration.java index 6cbee570..77de632d 100644 --- a/src/main/java/org/jboss/logmanager/config/HandlerConfiguration.java +++ b/src/main/java/org/jboss/logmanager/config/HandlerConfiguration.java @@ -172,21 +172,4 @@ public interface HandlerConfiguration extends HandlerContainingConfigurable, Nam * @see ValueExpression */ void setErrorManagerName(String expression, String value); - - /** - * Indicates whether or not the handler names should be persisted to the configuration. - * - * @return {@code true} if the handler names should be persisted, otherwise {@code false} - */ - default boolean isHandlerNamesPersistable() { - return true; - } - - /** - * Sets whether or not the handler names should be persisted to the configuration. - * - * @param persistable {@code true} if the handler names should be persisted, otherwise {@code false} - */ - default void setHandlerNamesPersistable(final boolean persistable) { - } } diff --git a/src/main/java/org/jboss/logmanager/config/HandlerConfigurationImpl.java b/src/main/java/org/jboss/logmanager/config/HandlerConfigurationImpl.java index d0a3ccee..8ce39d1f 100644 --- a/src/main/java/org/jboss/logmanager/config/HandlerConfigurationImpl.java +++ b/src/main/java/org/jboss/logmanager/config/HandlerConfigurationImpl.java @@ -46,7 +46,6 @@ final class HandlerConfigurationImpl extends AbstractPropertyConfiguration filter; private ValueExpression encoding; private ValueExpression errorManagerName; - private boolean handlerNamesPersistable = true; HandlerConfigurationImpl(final LogContextConfigurationImpl configuration, final String name, final String moduleName, final String className, final String[] constructorProperties) { super(Handler.class, configuration, configuration.getHandlerRefs(), configuration.getHandlerConfigurations(), name, moduleName, className, constructorProperties); @@ -398,16 +397,6 @@ public void rollback() { return true; } - @Override - public boolean isHandlerNamesPersistable() { - return handlerNamesPersistable; - } - - @Override - public void setHandlerNamesPersistable(final boolean persistable) { - this.handlerNamesPersistable = persistable; - } - String getDescription() { return "handler"; } diff --git a/src/main/java/org/jboss/logmanager/config/LogContextConfiguration.java b/src/main/java/org/jboss/logmanager/config/LogContextConfiguration.java index a92b1edd..91085cdc 100644 --- a/src/main/java/org/jboss/logmanager/config/LogContextConfiguration.java +++ b/src/main/java/org/jboss/logmanager/config/LogContextConfiguration.java @@ -19,7 +19,6 @@ package org.jboss.logmanager.config; -import java.util.ArrayList; import java.util.List; import org.jboss.logmanager.LogContext; @@ -69,22 +68,6 @@ public interface LogContextConfiguration { List getHandlerNames(); - /** - * Returns a list of handler names that can be persisted to a configuration. - * - * @return the persistable handler names - */ - default List getPersistableHandlerNames() { - final List handlerNames = new ArrayList<>(); - for (String name : getHandlerNames()) { - final HandlerConfiguration config = getHandlerConfiguration(name); - if (config != null && config.isPersistable()) { - handlerNames.add(name); - } - } - return handlerNames; - } - FormatterConfiguration addFormatterConfiguration(String moduleName, String className, String formatterName, String... constructorProperties); boolean removeFormatterConfiguration(String formatterName); @@ -93,22 +76,6 @@ default List getPersistableHandlerNames() { List getFormatterNames(); - /** - * Returns a list of formatter names that can be persisted to a configuration. - * - * @return the persistable formatter names - */ - default List getPersistableFormatterNames() { - final List formatterNames = new ArrayList<>(); - for (String name : getFilterNames()) { - final FormatterConfiguration config = getFormatterConfiguration(name); - if (config != null && config.isPersistable()) { - formatterNames.add(name); - } - } - return formatterNames; - } - FilterConfiguration addFilterConfiguration(String moduleName, String className, String filterName, String... constructorProperties); boolean removeFilterConfiguration(String filterName); @@ -117,22 +84,6 @@ default List getPersistableFormatterNames() { List getFilterNames(); - /** - * Returns a list of filter names that can be persisted to a configuration. - * - * @return the persistable filter names - */ - default List getPersistableFilterNames() { - final List filterNames = new ArrayList<>(); - for (String name : getFilterNames()) { - final FilterConfiguration config = getFilterConfiguration(name); - if (config != null && config.isPersistable()) { - filterNames.add(name); - } - } - return filterNames; - } - ErrorManagerConfiguration addErrorManagerConfiguration(String moduleName, String className, String errorManagerName, String... constructorProperties); boolean removeErrorManagerConfiguration(String errorManagerName); @@ -141,22 +92,6 @@ default List getPersistableFilterNames() { List getErrorManagerNames(); - /** - * Returns a list of error manager names that can be persisted to a configuration. - * - * @return the persistable error manager names - */ - default List getPersistableErrorManagerNames() { - final List errorManagerNames = new ArrayList<>(); - for (String name : getErrorManagerNames()) { - final ErrorManagerConfiguration config = getErrorManagerConfiguration(name); - if (config != null && config.isPersistable()) { - errorManagerNames.add(name); - } - } - return errorManagerNames; - } - /** * Prepares the current changes. The changes are applied into the running logging configuration, but can be rolled * back using the {@link #forget()} method if {@link #commit()} has not been invoked. @@ -202,22 +137,6 @@ default List getPersistableErrorManagerNames() { */ List getPojoNames(); - /** - * Returns a list of POJO names that can be persisted to a configuration. - * - * @return the persistable POJO names - */ - default List getPersistablePojoNames() { - final List pojoNames = new ArrayList<>(); - for (String name : getPojoNames()) { - final PojoConfiguration config = getPojoConfiguration(name); - if (config != null && config.isPersistable()) { - pojoNames.add(name); - } - } - return pojoNames; - } - /** * Commit the current changes into the running logging configuration. */ diff --git a/src/main/java/org/jboss/logmanager/config/LogContextConfigurationImpl.java b/src/main/java/org/jboss/logmanager/config/LogContextConfigurationImpl.java index 46434c54..92640321 100644 --- a/src/main/java/org/jboss/logmanager/config/LogContextConfigurationImpl.java +++ b/src/main/java/org/jboss/logmanager/config/LogContextConfigurationImpl.java @@ -164,11 +164,6 @@ public List getHandlerNames() { return new ArrayList(handlers.keySet()); } - @Override - public List getPersistableHandlerNames() { - return filterPersistableNames(handlers); - } - public FormatterConfiguration addFormatterConfiguration(final String moduleName, final String className, final String formatterName, final String... constructorProperties) { if (formatters.containsKey(formatterName)) { throw new IllegalArgumentException(String.format("Formatter \"%s\" already exists", formatterName)); @@ -198,11 +193,6 @@ public List getFormatterNames() { return new ArrayList(formatters.keySet()); } - @Override - public List getPersistableFormatterNames() { - return filterPersistableNames(formatters); - } - public FilterConfiguration addFilterConfiguration(final String moduleName, final String className, final String filterName, final String... constructorProperties) { if (filters.containsKey(filterName)) { throw new IllegalArgumentException(String.format("Filter \"%s\" already exists", filterName)); @@ -232,11 +222,6 @@ public List getFilterNames() { return new ArrayList(filters.keySet()); } - @Override - public List getPersistableFilterNames() { - return filterPersistableNames(filters); - } - public ErrorManagerConfiguration addErrorManagerConfiguration(final String moduleName, final String className, final String errorManagerName, final String... constructorProperties) { if (errorManagers.containsKey(errorManagerName)) { throw new IllegalArgumentException(String.format("ErrorManager \"%s\" already exists", errorManagerName)); @@ -266,11 +251,6 @@ public List getErrorManagerNames() { return new ArrayList(errorManagers.keySet()); } - @Override - public List getPersistableErrorManagerNames() { - return filterPersistableNames(errorManagers); - } - @Override public PojoConfiguration addPojoConfiguration(final String moduleName, final String className, final String pojoName, final String... constructorProperties) { if (pojos.containsKey(pojoName)) { @@ -303,11 +283,6 @@ public List getPojoNames() { return new ArrayList(pojos.keySet()); } - @Override - public List getPersistablePojoNames() { - return filterPersistableNames(pojos); - } - @Override public void prepare() { doPrepare(transactionState); @@ -760,16 +735,6 @@ private ObjectProducer resolveFilter(String expression, final boolean immediate) return result; } - private static List filterPersistableNames(final Map map) { - final List names = new ArrayList<>(); - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue().isPersistable()) { - names.add(entry.getKey()); - } - } - return names; - } - ObjectProducer resolveFilter(String expression) { return resolveFilter(expression, false); } diff --git a/src/main/java/org/jboss/logmanager/config/PropertyConfigurable.java b/src/main/java/org/jboss/logmanager/config/PropertyConfigurable.java index a44f75f3..91ce034e 100644 --- a/src/main/java/org/jboss/logmanager/config/PropertyConfigurable.java +++ b/src/main/java/org/jboss/logmanager/config/PropertyConfigurable.java @@ -19,7 +19,6 @@ package org.jboss.logmanager.config; -import java.util.ArrayList; import java.util.List; /** @@ -39,19 +38,6 @@ public interface PropertyConfigurable { */ void setPropertyValueString(String propertyName, String value) throws IllegalArgumentException; - /** - * Set a property value from a string. - * - * @param propertyName the property name - * @param value the property value - * @param persist indicates whether or not the property should be persisted to the configuration - * - * @throws IllegalArgumentException if the given value is not acceptable for this property - */ - default void setPropertyValueString(final String propertyName, final String value, final boolean persist) throws IllegalArgumentException { - setPropertyValueString(propertyName, value); - } - /** * Get the string property value with the given name. * @@ -78,17 +64,6 @@ default void setPropertyValueString(final String propertyName, final String valu */ void setPropertyValueExpression(String propertyName, String expression); - /** - * Sets the expression value for the property. - * - * @param propertyName the name of the property - * @param expression the expression used to resolve the value - * @param persist indicates whether or not the property should be persisted to the configuration - */ - default void setPropertyValueExpression(final String propertyName, final String expression, final boolean persist) { - setPropertyValueExpression(propertyName, expression); - } - /** * Sets the expression value for the property. *

@@ -101,22 +76,6 @@ default void setPropertyValueExpression(final String propertyName, final String */ void setPropertyValueExpression(String propertyName, String expression, String value); - /** - * Sets the expression value for the property. - *

- * This method will not parse the expression for the value and instead use the {@code value} parameter for the - * value. - *

- * - * @param propertyName the name of the property - * @param expression the expression used to resolve the value - * @param value the value to use - * @param persist indicates whether or not the property should be persisted to the configuration - */ - default void setPropertyValueExpression(final String propertyName, final String expression, final String value, final boolean persist) { - setPropertyValueExpression(propertyName, expression, value); - } - /** * Determine whether the given property name is configured. * @@ -197,34 +156,4 @@ default void setPropertyValueExpression(final String propertyName, final String * @return {@code true} if the method was removed, otherwise {@code false} */ boolean removePostConfigurationMethod(String methodName); - - /** - * Gets the configuration properties that have been set. - * - * @return the configuration properties - */ - default List getProperties() { - final List result = new ArrayList<>(); - for (String key : getPropertyNames()) { - result.add(new ConfigurationPropertyImpl(key, getPropertyValueExpression(key), true)); - } - return result; - } - - /** - * Indicates whether or not this configuration is persistable as a whole. - * - * @return {@code true} if this configuration should be persisted, owtherwise {@code false} - */ - default boolean isPersistable() { - return true; - } - - /** - * Sets whether or not this configuration should be persisted. - * - * @param persistable {@code false} if this configuration should not be persisted as a whole, otherwise {@code true} - */ - default void setPersistable(final boolean persistable) { - } } diff --git a/src/test/java/org/jboss/logmanager/PropertyConfiguratorTests.java b/src/test/java/org/jboss/logmanager/PropertyConfiguratorTests.java index 5e6882b8..975ac9c8 100644 --- a/src/test/java/org/jboss/logmanager/PropertyConfiguratorTests.java +++ b/src/test/java/org/jboss/logmanager/PropertyConfiguratorTests.java @@ -35,7 +35,6 @@ import java.util.Set; import java.util.TreeSet; import java.util.logging.Formatter; -import java.util.logging.Handler; import org.jboss.logmanager.config.HandlerConfiguration; import org.jboss.logmanager.config.LogContextConfiguration; @@ -320,115 +319,6 @@ public void testWriteInvalidConfig() throws Exception { } - @Test - public void testNonPersistableProperty() throws Exception { - final String typeName = TestQueueHandler.class.getName(); - final String handlerName = "testQueue"; - final String childHandlerName = "testChild"; - - final LogContext logContext = LogContext.create(); - final PropertyConfigurator configurator = new PropertyConfigurator(logContext); - - final LogContextConfiguration logContextConfiguration = configurator.getLogContextConfiguration(); - - // Add a handler that will not persist the handler names - final HandlerConfiguration handlerConfiguration = logContextConfiguration. - addHandlerConfiguration(null, typeName, handlerName); - handlerConfiguration.setLevel("INFO"); - handlerConfiguration.setHandlerNamesPersistable(false); - handlerConfiguration.setPropertyValueString("value", "testParentValue", true); - - // Add a root logger - final LoggerConfiguration loggerConfiguration = logContextConfiguration.addLoggerConfiguration(""); - loggerConfiguration.addHandlerName(handlerName); - loggerConfiguration.setLevel("INFO"); - - final HandlerConfiguration childHandlerConfiguration = logContextConfiguration - .addHandlerConfiguration(null, typeName, childHandlerName); - // Add a property that should not be persisted - childHandlerConfiguration.setPropertyValueString("value", "testValue", false); - // Add the handler which should not be persisted - handlerConfiguration.addHandlerName(childHandlerConfiguration.getName()); - - logContextConfiguration.commit(); - - // Since the VALUE is static it should always be set to the second configured value, however that value should - // not be persisted to via the PropertyConfigurator. The later will be tested below. - assertEquals("testValue", TestQueueHandler.VALUE); - - // Reload output streams into properties - final Properties configProps = new Properties(); - final ByteArrayOutputStream configOut = new ByteArrayOutputStream(); - configurator.writeConfiguration(configOut); - final ByteArrayInputStream configIn = new ByteArrayInputStream(configOut.toByteArray()); - configProps.load(new InputStreamReader(configIn, ENCODING)); - - // Manually create the expected properties and compare the written results - final Properties expectedProperties = new Properties(); - expectedProperties.setProperty("loggers", ""); - expectedProperties.setProperty("logger.level", "INFO"); - expectedProperties.setProperty("logger.handlers", handlerName); - expectedProperties.setProperty("handlers", childHandlerName); - expectedProperties.setProperty("handler." + handlerName, typeName); - expectedProperties.setProperty("handler." + handlerName + ".level", "INFO"); - expectedProperties.setProperty("handler." + handlerName + ".properties", "value"); - expectedProperties.setProperty("handler." + handlerName + ".value", "testParentValue"); - expectedProperties.setProperty("handler." + childHandlerName, typeName); - compare(expectedProperties, configProps); - } - - @Test - public void testNonPersistableHandler() throws Exception { - final String typeName = TestQueueHandler.class.getName(); - final String handlerName = "testQueue"; - final String childHandlerName = "testChild"; - - final LogContext logContext = LogContext.create(); - final PropertyConfigurator configurator = new PropertyConfigurator(logContext); - - final LogContextConfiguration logContextConfiguration = configurator.getLogContextConfiguration(); - - // Add a handler that will not persist the handler names - final HandlerConfiguration handlerConfiguration = logContextConfiguration. - addHandlerConfiguration(null, typeName, handlerName); - handlerConfiguration.setLevel("INFO"); - handlerConfiguration.setHandlerNamesPersistable(false); - handlerConfiguration.setPropertyValueString("value", "testParentValue", true); - - // Add a root logger - final LoggerConfiguration loggerConfiguration = logContextConfiguration.addLoggerConfiguration(""); - loggerConfiguration.addHandlerName(handlerName); - loggerConfiguration.setLevel("INFO"); - - final HandlerConfiguration childHandlerConfiguration = logContextConfiguration - .addHandlerConfiguration(null, typeName, childHandlerName); - // Add a property that should not be persisted - childHandlerConfiguration.setPropertyValueString("value", "testValue"); - childHandlerConfiguration.setPersistable(false); - // Add the handler which should not be persisted - handlerConfiguration.addHandlerName(childHandlerConfiguration.getName()); - - logContextConfiguration.commit(); - - // Reload output streams into properties - final Properties configProps = new Properties(); - final ByteArrayOutputStream configOut = new ByteArrayOutputStream(); - configurator.writeConfiguration(configOut); - final ByteArrayInputStream configIn = new ByteArrayInputStream(configOut.toByteArray()); - configProps.load(new InputStreamReader(configIn, ENCODING)); - - // Manually create the expected properties and compare the written results - final Properties expectedProperties = new Properties(); - expectedProperties.setProperty("loggers", ""); - expectedProperties.setProperty("logger.level", "INFO"); - expectedProperties.setProperty("logger.handlers", handlerName); - expectedProperties.setProperty("handler." + handlerName, typeName); - expectedProperties.setProperty("handler." + handlerName + ".level", "INFO"); - expectedProperties.setProperty("handler." + handlerName + ".properties", "value"); - expectedProperties.setProperty("handler." + handlerName + ".value", "testParentValue"); - compare(expectedProperties, configProps); - } - private void compare(final Properties defaultProps, final Properties configProps) { final Set dftNames = defaultProps.stringPropertyNames(); final Set configNames = configProps.stringPropertyNames(); @@ -584,29 +474,4 @@ static void safeFlush(final Flushable flushable) { } } } - - @SuppressWarnings("unused") - public static class TestQueueHandler extends ExtHandler { - - private static String VALUE; - - public String getValue() { - return VALUE; - } - - public void setValue(final String value) { - VALUE = value; - } - - @Override - protected void doPublish(final ExtLogRecord record) { - final Handler[] children = getHandlers(); - if (children != null) { - for (Handler child : children) { - child.publish(record); - } - } - super.doPublish(record); - } - } }