http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java index c3d646b..e931f47 100644 --- a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java @@ -19,12 +19,8 @@ package org.apache.tamaya.metamodel.internal.resolver; import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.metamodel.MetaContext; import org.apache.tamaya.metamodel.spi.MetaConfigurationReader; import org.apache.tamaya.spi.ConfigurationBuilder; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.ConfigurationContextBuilder; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -50,8 +46,8 @@ public class LoggingReader implements MetaConfigurationReader{ @Override public void run() { Map<String, Object> meta = new HashMap<>(); - meta.put("context", ConfigurationProvider.getConfiguration().getContext()); - meta.put("config", ConfigurationProvider.getConfiguration()); + meta.put("context", Configuration.current().getContext()); + meta.put("config", Configuration.current()); NodeList nodeList = document.getDocumentElement().getElementsByTagName("context"); for(int i=0;i<nodeList.getLength();i++){ Node node = nodeList.item(i);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java index 19a7dfb..faf2b21 100644 --- a/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java @@ -66,7 +66,7 @@ public class ConfigDirPropertySourceProvider extends AbstractPathPropertySourceP "Failed to read configuration from " + url); return Collections.emptySet(); } - return asCollection(new MappedConfigurationDataPropertySource(config)); + return Collections.singleton(new MappedConfigurationDataPropertySource(config)); } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to read configuration from " + url, e); @@ -74,9 +74,4 @@ public class ConfigDirPropertySourceProvider extends AbstractPathPropertySourceP } } - private Collection<PropertySource> asCollection(PropertySource propertySource) { - List<PropertySource> result = new ArrayList<>(1); - result.add(propertySource); - return result; - } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java index fe5759f..d450842 100644 --- a/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java @@ -47,7 +47,7 @@ public class MetainfConfigPropertySourceProvider extends AbstractPathPropertySou protected Collection<PropertySource> getPropertySources(URL url) { try { ConfigurationData config = ConfigurationFormats.readConfigurationData(url); - return asCollection(new MappedConfigurationDataPropertySource(config)); + return Collections.singleton(new MappedConfigurationDataPropertySource(config)); } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to read configuration from " + url, e); @@ -55,9 +55,4 @@ public class MetainfConfigPropertySourceProvider extends AbstractPathPropertySou } } - private Collection<PropertySource> asCollection(PropertySource propertySource) { - List<PropertySource> result = new ArrayList<>(1); - result.add(propertySource); - return result; - } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java deleted file mode 100644 index 2b1f96b..0000000 --- a/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java +++ /dev/null @@ -1,122 +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.tamaya.propertysources; - -import org.apache.tamaya.spisupport.propertysource.SimplePropertySource; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -/** - * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}. - */ -public final class PropertySourceBuilder { - /** The ordinal to be used. */ - private int ordinal; - /** The name to be used. */ - private final String name; - /** The properties. */ - private final Map<String,String> properties = new HashMap<>(); - - /** private constructor. */ - private PropertySourceBuilder(String name){ - this.name = Objects.requireNonNull(name); - } - - /** - * Gets a new instance of a builder. - * @param name The name of the property source, not null. - * @return a new instance. - */ - public static PropertySourceBuilder of(String name){ - return new PropertySourceBuilder(name); - } - - /** - * Gets a new instance of a builder. - * @param name The name of the property source, not null. - * @return a new instance. - */ - public static PropertySourceBuilder from(String name){ - return new PropertySourceBuilder(name); - } - - /** - * Sets a new property key/value. - * @param key the property key, not null. - * @param value the property value, not null. - * @return the bulder for chaining. - */ - public PropertySourceBuilder put(String key, String value){ - this.properties.put(key, value); - return this; - } - - /** - * Put all the given key, values. - * @param values the new key/values, not null. - * @return the bulder for chaining. - */ - public PropertySourceBuilder putAll(Map<String, String> values){ - this.properties.putAll(values); - return this; - } - - /** - * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}. - * @param ordinal the explicit ordinal to be used. - * @return the bulder for chaining. - */ - public PropertySourceBuilder withOrdinal(int ordinal){ - this.ordinal = ordinal; - return this; - } - - /** - * Puts all values from the given property source. - * @param propertySource the property source, not null. - * @return the bulder for chaining. - */ - public PropertySourceBuilder putAll(PropertySource propertySource){ - for(PropertyValue val:propertySource.getProperties().values()) { - this.properties.put(val.getKey(), val.getValue()); - } - return this; - } - - /** - * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance. - * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null. - */ - public PropertySource build(){ - return new SimplePropertySource(name, properties); - } - - @Override - public String toString() { - return "PropertySourceBuilder{" + - "ordinal=" + ordinal + - ", name='" + name + '\'' + - ", properties=" + properties + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/propertysources/src/main/java/org/apache/tamaya/propertysources/SimplePropertySourceBuilder.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/SimplePropertySourceBuilder.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/SimplePropertySourceBuilder.java new file mode 100644 index 0000000..884ca61 --- /dev/null +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/SimplePropertySourceBuilder.java @@ -0,0 +1,122 @@ +/* + * 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.tamaya.propertysources; + +import org.apache.tamaya.spisupport.propertysource.SimplePropertySource; +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}. + */ +public final class SimplePropertySourceBuilder { + /** The ordinal to be used. */ + private int ordinal; + /** The name to be used. */ + private final String name; + /** The properties. */ + private final Map<String,String> properties = new HashMap<>(); + + /** private constructor. */ + private SimplePropertySourceBuilder(String name){ + this.name = Objects.requireNonNull(name); + } + + /** + * Gets a new instance of a builder. + * @param name The name of the property source, not null. + * @return a new instance. + */ + public static SimplePropertySourceBuilder of(String name){ + return new SimplePropertySourceBuilder(name); + } + + /** + * Gets a new instance of a builder. + * @param name The name of the property source, not null. + * @return a new instance. + */ + public static SimplePropertySourceBuilder from(String name){ + return new SimplePropertySourceBuilder(name); + } + + /** + * Sets a new property key/value. + * @param key the property key, not null. + * @param value the property value, not null. + * @return the bulder for chaining. + */ + public SimplePropertySourceBuilder put(String key, String value){ + this.properties.put(key, value); + return this; + } + + /** + * Put all the given key, values. + * @param values the new key/values, not null. + * @return the bulder for chaining. + */ + public SimplePropertySourceBuilder putAll(Map<String, String> values){ + this.properties.putAll(values); + return this; + } + + /** + * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}. + * @param ordinal the explicit ordinal to be used. + * @return the bulder for chaining. + */ + public SimplePropertySourceBuilder withOrdinal(int ordinal){ + this.ordinal = ordinal; + return this; + } + + /** + * Puts all values from the given property source. + * @param propertySource the property source, not null. + * @return the bulder for chaining. + */ + public SimplePropertySourceBuilder putAll(PropertySource propertySource){ + for(PropertyValue val:propertySource.getProperties().values()) { + this.properties.put(val.getKey(), val.getValue()); + } + return this; + } + + /** + * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance. + * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null. + */ + public PropertySource build(){ + return new SimplePropertySource(name, properties); + } + + @Override + public String toString() { + return "PropertySourceBuilder{" + + "ordinal=" + ordinal + + ", name='" + name + '\'' + + ", properties=" + properties + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/propertysources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java ---------------------------------------------------------------------- diff --git a/propertysources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java b/propertysources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java index 0250ff6..fecfff7 100644 --- a/propertysources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java +++ b/propertysources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java @@ -31,7 +31,7 @@ public class MetainfConfigPropertySourceProviderTest { public void getPropertySources_Default() throws Exception { MetainfConfigPropertySourceProvider provider = new MetainfConfigPropertySourceProvider(); assertNotNull(provider.getPropertySources()); - // TODO add test for containing property sources. + // TODO addNode test for containing property sources. } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java ---------------------------------------------------------------------- diff --git a/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java b/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java index de65fb7..f1b600a 100644 --- a/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java +++ b/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java @@ -90,26 +90,26 @@ public abstract class BaseRemotePropertySource implements PropertySource{ } protected Map<String,String> mapConfigurationData(ConfigurationData data){ - Map<String,String> readProperties; + Map<String,String> readProperties = new HashMap<>(); if(data!=null){ - readProperties = data.getCombinedProperties(); - if(readProperties!=null){ - Map<String,String> newProperties = new HashMap<>(); - for(Map.Entry<String,String> en:readProperties.entrySet()){ - // filter data entries - newProperties.put(en.getKey(), en.getValue()); - } - // the configs served by the tamaya server module has a 'data' root section containing the - // config entries. if not present, we assume an alternate format, which is sued as is... - if(newProperties.isEmpty()){ - Logger.getLogger(getClass().getName()).info( - "Loaded remote config from: " + data.getResource() + ", does not have a data section, using as is..."); - newProperties = readProperties; - } + for(PropertyValue val:data.getData()) { + readProperties.putAll(val.asMap()); + } + Map<String,String> newProperties = new HashMap<>(); + for(Map.Entry<String,String> en:readProperties.entrySet()){ + // filter data entries + newProperties.put(en.getKey(), en.getValue()); + } + // the configs served by the tamaya server module has a 'data' root section containing the + // config entries. if not present, we assume an alternate format, which is sued as is... + if(newProperties.isEmpty()){ Logger.getLogger(getClass().getName()).info( - "Reloaded remote config from: " + data.getResource() + ", entriea read: " + this.properties.size()); - return newProperties; + "Loaded remote config from: " + data.getResource() + ", does not have a data section, using as is..."); + newProperties = readProperties; } + Logger.getLogger(getClass().getName()).info( + "Reloaded remote config from: " + data.getResource() + ", entriea read: " + this.properties.size()); + return newProperties; } return Collections.emptyMap(); } @@ -138,7 +138,7 @@ public abstract class BaseRemotePropertySource implements PropertySource{ } /** - * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value. + * Returns the default ordinal used, when no ordinal is setCurrent, or the ordinal was not parseable to an int value. * @return the default ordinal used, by default 0. */ public int getDefaultOrdinal(){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java b/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java index f13446a..3370fac 100644 --- a/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java +++ b/server/src/main/java/org/apache/tamaya/server/ConfigurationServices.java @@ -82,7 +82,7 @@ public class ConfigurationResource { @Path("/keys") public String readConfig(@QueryParam("recursive") Boolean recursive) { readCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); + final Configuration config = Configuration.current(); final Map<String, String> children = config.getProperties(); final JsonArrayBuilder ab = Json.createArrayBuilder(); for (final Map.Entry<String, String> en : children.entrySet()) { @@ -122,7 +122,7 @@ public class ConfigurationResource { @Path("/keys/{key}") public String readConfig(@PathParam("key") String key, @QueryParam("recursive") Boolean recursive) { readCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); + final Configuration config = Configuration.current(); if (key != null) { if (key.startsWith("/")) { key = key.substring(1); @@ -194,7 +194,7 @@ public class ConfigurationResource { public String writeConfig(@PathParam("key") String key, @javax.ws.rs.FormParam("value") String value, @FormParam("ttl") Integer ttl) { writeCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); + final Configuration config = Configuration.current(); if (key.startsWith("/")) { key = key.substring(1); } @@ -220,7 +220,7 @@ public class ConfigurationResource { @Path("/keys/{key}") public String deleteConfig(@PathParam("key") String key) { deleteCounter.incrementAndGet(); - final Configuration config = ConfigurationProvider.getConfiguration(); + final Configuration config = Configuration.current(); if (key.startsWith("/")) { key = key.substring(1); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/server/src/main/java/org/apache/tamaya/server/Server.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/tamaya/server/Server.java b/server/src/main/java/org/apache/tamaya/server/Server.java index 3a5a7cf..dd16192 100644 --- a/server/src/main/java/org/apache/tamaya/server/Server.java +++ b/server/src/main/java/org/apache/tamaya/server/Server.java @@ -69,7 +69,7 @@ public class Server { public static void main(String... args) throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); + Configuration config = Configuration.current(); String contextPath = config.getOrDefault("tamaya.server.contextPath", "/"); int port = config.getOrDefault("tamaya.server.port", Integer.class, 8085); start(contextPath, port); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java ---------------------------------------------------------------------- diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java b/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java index 515dcd7..137705e 100644 --- a/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java +++ b/ui/base/src/main/java/org/apache/tamaya/ui/TamayaUI.java @@ -106,7 +106,7 @@ public class TamayaUI extends UI { * @throws Exception if startup fails. */ public static void main(String[] args) throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); + Configuration config = Configuration.current(); String contextPath = config.getOrDefault("tamaya.server.contextPath", "/tamaya"); String appBase = "."; Tomcat tomcat = new Tomcat(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java ---------------------------------------------------------------------- diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java index b83fcbd..9ab6153 100644 --- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java +++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfigurationBasedMessageProvider.java @@ -167,7 +167,7 @@ public final class ConfigurationBasedMessageProvider implements MessageProvider{ baseName = System.getenv("tamaya.ui.baseName"); } if(baseName==null || baseName.isEmpty()){ - baseName = ConfigurationProvider.getConfiguration().get("tamaya.ui.baseName"); + baseName = Configuration.current().get("tamaya.ui.baseName"); } if(baseName==null || baseName.isEmpty()){ baseName = "ui/lang/tamaya"; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java ---------------------------------------------------------------------- diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java index ee687e9..4b1607e 100644 --- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java +++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ConfiguredUserService.java @@ -47,7 +47,7 @@ public class ConfiguredUserService implements UserService{ */ public ConfiguredUserService(){ // read from config - Map<String,String> config = ConfigurationProvider.getConfiguration().with( + Map<String,String> config = Configuration.current().with( ConfigurationFunctions.section("tamaya.users.", true)).getProperties(); for(Map.Entry<String,String> en:config.entrySet()){ if(en.getKey().endsWith(".pwd")){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java ---------------------------------------------------------------------- diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java index 6772085..3a3195d 100644 --- a/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java +++ b/ui/base/src/main/java/org/apache/tamaya/ui/internal/ResourceBundleMessageProvider.java @@ -50,7 +50,7 @@ public class ResourceBundleMessageProvider implements MessageProvider{ baseName = System.getenv("tamaya.ui.baseName"); } if(baseName==null || baseName.isEmpty()){ - baseName = ConfigurationProvider.getConfiguration().get("tamaya.ui.baseName"); + baseName = Configuration.current().get("tamaya.ui.baseName"); } if(baseName==null || baseName.isEmpty()){ baseName = "ui/ui.lang/tamaya"; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java ---------------------------------------------------------------------- diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java index e4c6de1..3de6a8f 100644 --- a/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java +++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/ConfigView.java @@ -151,7 +151,7 @@ public class ConfigView extends VerticalSpacedLayout implements View { private void fillTree() { final String keyFilterExp = this.keyFilter.getValue(); final String valueFilterExp = this.valueFilter.getValue(); - Configuration config = ConfigurationProvider.getConfiguration() + Configuration config = Configuration.current() .with(ConfigurationFunctions.filter(new PropertyMatcher() { @Override public boolean test(String key, String value) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java ---------------------------------------------------------------------- diff --git a/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java b/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java index 0896c3c..602652d 100644 --- a/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java +++ b/ui/base/src/main/java/org/apache/tamaya/ui/views/TamayaGeneralSystemInfoProvider.java @@ -43,7 +43,7 @@ public class TamayaGeneralSystemInfoProvider extends AbstractTextInfoProvider { @Override protected String getInfo() { - Configuration config = ConfigurationProvider.getConfiguration(); + Configuration config = Configuration.current(); return new StringBuilder() .append("Configuration: ").append(config.getClass().getName()).append('\n') .append("ConfigurationContext: ").append(config.getContext().getClass().getName()).append('\n') http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/uom/src/main/java/org/apache/tamaya/uom/UnitConverter.java ---------------------------------------------------------------------- diff --git a/uom/src/main/java/org/apache/tamaya/uom/UnitConverter.java b/uom/src/main/java/org/apache/tamaya/uom/UnitConverter.java index d1baa43..0fb69f4 100644 --- a/uom/src/main/java/org/apache/tamaya/uom/UnitConverter.java +++ b/uom/src/main/java/org/apache/tamaya/uom/UnitConverter.java @@ -40,9 +40,9 @@ public class UnitConverter implements PropertyConverter<Unit> { private static final Pattern IS_INTEGER_VALUE = Pattern.compile(PATTERN_REGEX); @Override - public Unit convert(String value, ConversionContext context) { + public Unit convert(String value) { String trimmed = requireNonNull(value).trim(); - addSupportedFormats(context); + addSupportedFormats(); UnitFormat format = ServiceProvider.current().getUnitFormatService().getUnitFormat(); Unit result = null; @@ -58,7 +58,9 @@ public class UnitConverter implements PropertyConverter<Unit> { return result; } - private void addSupportedFormats(ConversionContext context) { - context.addSupportedFormats(UnitConverter.class, "All Units supported by JSR 363"); + private void addSupportedFormats() { + ConversionContext.doOptional(context -> { + context.addSupportedFormats(UnitConverter.class, "All Units supported by JSR 363"); + }); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/uom/src/test/java/org/apache/tamaya/uom/UnitConverterTest.java ---------------------------------------------------------------------- diff --git a/uom/src/test/java/org/apache/tamaya/uom/UnitConverterTest.java b/uom/src/test/java/org/apache/tamaya/uom/UnitConverterTest.java index 6e64fb1..c809272 100644 --- a/uom/src/test/java/org/apache/tamaya/uom/UnitConverterTest.java +++ b/uom/src/test/java/org/apache/tamaya/uom/UnitConverterTest.java @@ -18,9 +18,7 @@ */ package org.apache.tamaya.uom; -import org.apache.tamaya.spi.ConversionContext; import org.junit.Test; -import org.mockito.Mockito; import tec.units.ri.unit.Units; @@ -36,9 +34,7 @@ public class UnitConverterTest { @Test public void canConvertUnitInformation() { - ConversionContext context = Mockito.mock(ConversionContext.class); - - Unit<?> unit = converter.convert("m", context); + Unit<?> unit = converter.convert("m"); assertThat("Converter failed to convert input value " + unit, notNullValue()); assertEquals(unit, Units.METRE); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java index 5cae8d2..ccb27cf 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java @@ -53,7 +53,7 @@ public final class ConfigUsage { } /** - * Returns a set of package names that are to be ignored when collecting usage data. + * Returns a setCurrent of package names that are to be ignored when collecting usage data. * @return the ignored package names, not null. */ public static Set<String> getIgnoredPackages(){ @@ -70,7 +70,7 @@ public final class ConfigUsage { /** * Enables/disables usage tracking. - * @param enabled set to true to enable usage tracking. + * @param enabled setCurrent to true to enable usage tracking. */ public static void enableUsageTracking(boolean enabled){ spi().enableUsageTracking(enabled); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java index 8cd0236..4239050 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java @@ -117,7 +117,7 @@ public final class UsageStat { /** * Access access details for a given class. - * @param type class to get usage access stats for, not null. + * @param type class to getChild usage access stats for, not null. * @return the usage ref, if present, or null. */ public Collection<AccessStats> getAccessDetails(Class type){ @@ -126,7 +126,7 @@ public final class UsageStat { /** * Access access details for a given package. - * @param pack package to get usage access stats for, not null. + * @param pack package to getChild usage access stats for, not null. * @return the usage ref, if present, or null. */ public Collection<AccessStats> getAccessDetails(Package pack){ @@ -168,7 +168,7 @@ public final class UsageStat { /** * Evaluates the current access point from the current stacktrace and adds an according * usage reference object (or updates any existing one) for the given key. The - * stacktrace is shortened to a maximal size of 20 items. + * stacktrace is shortened to a maximal getNumChilds of 20 items. * @param value the value returned, not null. */ public void trackUsage(PropertyValue value){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java index 34e1fa4..759082a 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java @@ -49,7 +49,7 @@ public class DefaultConfigUsage implements ConfigUsageSpi { /** * Method that checks the 'tamaya.usage-report' system property for * enabling tamaya usage reporting initially. - * @return {@code true} iff property is set to {@code true} + * @return {@code true} iff property is setCurrent to {@code true} */ private boolean initEnabled() { String val = System.getProperty("tamaya.usage-report"); @@ -113,12 +113,12 @@ public class DefaultConfigUsage implements ConfigUsageSpi { @Override public void recordAllPropertiesAccess(ConfigurationContext context){ - recordSingleKeyAccess(PropertyValue.of("<<all>>","<not stored>","-"), context); + recordSingleKeyAccess(PropertyValue.create("<<all>>","<not stored>"), context); } @Override public void recordSingleKeyAccess(PropertyValue value, ConfigurationContext context){ - // Ignore meta-entries + // Ignore getMeta-entries if(!isTrackingEnabled()){ return; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java index c9839ac..11644c7 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java @@ -25,6 +25,7 @@ import org.apache.tamaya.spi.ServiceContextManager; import org.apache.tamaya.usagetracker.spi.ConfigUsageSpi; import javax.annotation.Priority; +import java.util.logging.Filter; /** * Configuration filter to be applied at the end of the filter chain. This filter @@ -35,12 +36,13 @@ import javax.annotation.Priority; public class UsageTrackerFilter implements PropertyFilter{ @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - ConfigUsageSpi tracker = ServiceContextManager.getServiceContext().getService(ConfigUsageSpi.class); - if (context.isSinglePropertyScoped()) { - tracker.recordSingleKeyAccess(value, context.getContext()); + public PropertyValue filterProperty(PropertyValue value) { + ConfigUsageSpi tracker = ServiceContextManager.getServiceContext().getService(ConfigUsageSpi.class); + FilterContext context = FilterContext.get(); + if (context == null || context.isSinglePropertyScoped()) { + tracker.recordSingleKeyAccess(value, context.current()); } else { - tracker.recordAllPropertiesAccess(context.getContext()); + tracker.recordAllPropertiesAccess(context.current()); } return value; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java index 46fd767..e3d3d7e 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java @@ -33,7 +33,7 @@ public interface ConfigUsageSpi { /** * Enables/disables usage tracking. - * @param enable set to true to enable usage tracking. + * @param enable setCurrent to true to enable usage tracking. */ void enableUsageTracking(boolean enable); @@ -45,7 +45,7 @@ public interface ConfigUsageSpi { /** * Get the list of packages, which are not evaluated for tracking configuration access and usage statistics. - * @return the set of ignored package names. + * @return the setCurrent of ignored package names. */ Set<String> getIgnoredPackages(); @@ -84,7 +84,7 @@ public interface ConfigUsageSpi { void recordAllPropertiesAccess(ConfigurationContext context); /** - * Track the access of {@code Configuration#get(String)} for + * Track the access of {@code Configuration#getChild(String)} for * usage statistics. * @param context the corresponding context. * @param value value to track for http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java b/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java index 1fcdee9..04a3cbf 100644 --- a/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java +++ b/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java @@ -19,7 +19,6 @@ package org.apache.tamaya.model; import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.usagetracker.ConfigUsage; import org.junit.Test; import test.model.TestConfigAccessor; @@ -35,7 +34,7 @@ public class ConfigUsageStatsTest { public void testUsageWhenEnabled(){ ConfigUsage.enableUsageTracking(true); TestConfigAccessor.readConfiguration(); - Configuration config = ConfigurationProvider.getConfiguration(); + Configuration config = Configuration.current(); String info = ConfigUsage.getInfo(); assertFalse(info.contains("java.version")); assertNotNull(info); @@ -57,7 +56,7 @@ public class ConfigUsageStatsTest { ConfigUsage.enableUsageTracking(false); ConfigUsage.clearStats(); TestConfigAccessor.readConfiguration(); - Configuration config = ConfigurationProvider.getConfiguration(); + Configuration config = Configuration.current(); String info = ConfigUsage.getInfo(); assertNotNull(info); assertFalse(info.contains("java.version")); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/usagetracker/src/test/java/test/model/TestConfigAccessor.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/test/java/test/model/TestConfigAccessor.java b/usagetracker/src/test/java/test/model/TestConfigAccessor.java index 498d2b6..c9012df 100644 --- a/usagetracker/src/test/java/test/model/TestConfigAccessor.java +++ b/usagetracker/src/test/java/test/model/TestConfigAccessor.java @@ -19,7 +19,6 @@ package test.model; import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import java.util.Map; @@ -31,12 +30,12 @@ public final class TestConfigAccessor { private TestConfigAccessor(){} public static Map<String,String> readAllProperties(){ - return ConfigurationProvider.getConfiguration() + return Configuration.current() .getProperties(); } public static Configuration readConfiguration(){ - return ConfigurationProvider.getConfiguration(); + return Configuration.current(); } public static String readProperty(Configuration config, String key){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/pom.xml ---------------------------------------------------------------------- diff --git a/validation/pom.xml b/validation/pom.xml index 870bcaa..7252316 100644 --- a/validation/pom.xml +++ b/validation/pom.xml @@ -5,7 +5,7 @@ ~ 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 + ~ with the License. You may obtain a copy create the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java b/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java index a9c58f0..b6da54b 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java +++ b/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -29,12 +29,12 @@ public interface ConfigModel { /** * Access the owner. - * @return the owner of this model, never null. + * @return the owner create this model, never null. */ String getOwner(); /** - * Get the type of item that is modelled. + * Get the type create item that is modelled. * @return the modelled type, never null. */ ModelTarget getType(); @@ -59,7 +59,7 @@ public interface ConfigModel { boolean isRequired(); /** - * Get an description of the item, using the default locale. The description is basically optional + * Get an description create the item, using the default locale. The description is basically optional * though it is higly recommended to provide a description, so the validation issues is well * resolvable. * @@ -68,7 +68,7 @@ public interface ConfigModel { String getDescription(); /** - * Validates the item and all its children against the given configuration. + * Validates the item and all its getChildren against the given configuration. * * @param config the configuration to be validated against, not null. * @return the validation result, or null, if not applicable. http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java b/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java index 0f3cce5..b4a89ad 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java +++ b/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -19,7 +19,6 @@ package org.apache.tamaya.validation; import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.validation.spi.ConfigDocumentationMBean; import org.apache.tamaya.validation.spi.ModelProviderSpi; import org.apache.tamaya.spi.ServiceContextManager; @@ -31,7 +30,6 @@ import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -56,18 +54,16 @@ public final class ConfigModelManager { } /** - * Access the usage statistics for the recorded uses of configuration. + * Access the usage statistics for the recorded uses create configuration. + * @param inModels the target models, not null. * @return usage statistics */ - public static String getConfigInfoText(){ + public static String getConfigModelDescription(Collection<ConfigModel> inModels){ StringBuilder b = new StringBuilder(); - List<ConfigModel> models = new ArrayList<>(getModels()); - Collections.sort(models, new Comparator<ConfigModel>() { - @Override - public int compare(ConfigModel k1, ConfigModel k2) { + List<ConfigModel> models = new ArrayList<>(inModels); + Collections.sort(models, (k1, k2) -> { return k2.getName().compareTo(k2.getName()); - } - }); + }); b.append("TYPE OWNER NAME MANDATORY DESCRIPTION\n"); b.append("-----------------------------------------------------------------------------------------------------\n"); for(ConfigModel model:models){ @@ -99,28 +95,25 @@ public final class ConfigModelManager { return b.toString(); } - private static String formatWithFixedLength(String name, int targetLength) { - targetLength = targetLength-1; - StringBuilder b = new StringBuilder(); - if(name.length() > targetLength){ - name = name.substring(0, targetLength); - } - b.append(name); - for(int i=0;i<(targetLength-name.length());i++){ - b.append(' '); - } - b.append(' '); - return b.toString(); + /** + * Get the validations defined, using the default classloader. + * + * @return the sections defined, never null. + * @see ServiceContextManager#getDefaultClassLoader() + */ + public static Collection<ConfigModel> getModels() { + return getModels(ServiceContextManager.getDefaultClassLoader()); } /** * Get the validations defined. * + * @param classLoader the target classloader, not null. * @return the sections defined, never null. */ - public static Collection<ConfigModel> getModels() { + public static Collection<ConfigModel> getModels(ClassLoader classLoader) { List<ConfigModel> result = new ArrayList<>(); - for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) { + for (ModelProviderSpi model : ServiceContextManager.getServiceContext(classLoader).getServices(ModelProviderSpi.class)) { result.addAll(model.getConfigModels()); } return result; @@ -128,33 +121,29 @@ public final class ConfigModelManager { /** - * Find the validations by matching the validation's name against the given model type. - * - * @param name the name to use, not null. - * @param modelType classname of the target model type. - * @param <T> type of the model to filter for. + * Find the validations by checking the validation's name using the given regular expression and + * the default classloader. + * + * @param namePattern the regular expression to use, not null. + * @param targets the target types only to be returned (optional). * @return the sections defined, never null. + * @see ServiceContextManager#getDefaultClassLoader() */ - public static <T extends ConfigModel> T getModel(String name, Class<T> modelType) { - for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) { - for(ConfigModel configModel : model.getConfigModels()) { - if(configModel.getName().equals(name) && configModel.getClass().equals(modelType)) { - return modelType.cast(configModel); - } - } - } - return null; + public static Collection<ConfigModel> findModels(String namePattern, ModelTarget... targets) { + return findModels(namePattern, ServiceContextManager.getDefaultClassLoader(), targets); } /** * Find the validations by checking the validation's name using the given regular expression. + * + * @param classLoader the target classloader, not null. * @param namePattern the regular expression to use, not null. * @param targets the target types only to be returned (optional). * @return the sections defined, never null. */ - public static Collection<ConfigModel> findModels(String namePattern, ModelTarget... targets) { + public static Collection<ConfigModel> findModels(String namePattern, ClassLoader classLoader, ModelTarget... targets) { List<ConfigModel> result = new ArrayList<>(); - for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) { + for (ModelProviderSpi model : ServiceContextManager.getServiceContext(classLoader).getServices(ModelProviderSpi.class)) { for(ConfigModel configModel : model.getConfigModels()) { if(configModel.getName().matches(namePattern)) { if(targets.length>0){ @@ -174,24 +163,6 @@ public final class ConfigModelManager { } /** - * Validates the current configuration. - * - * @return the validation results, never null. - */ - public static Collection<Validation> validate() { - return validate(false); - } - - /** - * Validates the current configuration. - * @param showUndefined show any unknown parameters. - * @return the validation results, never null. - */ - public static Collection<Validation> validate(boolean showUndefined) { - return validate(ConfigurationProvider.getConfiguration(), showUndefined); - } - - /** * Validates the given configuration. * * @param config the configuration to be validated against, not null. @@ -210,7 +181,7 @@ public final class ConfigModelManager { */ public static Collection<Validation> validate(Configuration config, boolean showUndefined) { List<Validation> result = new ArrayList<>(); - for (ConfigModel defConf : getModels()) { + for (ConfigModel defConf : getModels(config.getContext().getServiceContext().getClassLoader())) { result.addAll(defConf.validate(config)); } if(showUndefined){ @@ -233,34 +204,20 @@ public final class ConfigModelManager { for (ConfigModel defConf : getModels()) { if(ModelTarget.Section.equals(defConf.getType())){ if(defConf.getName().endsWith(".*") && entry.getKey().matches(defConf.getName())){ - // Ignore parameters that are part of transitive section. + // Ignore parameters that are part create transitive section. continue outer; } } } - result.add(Validation.ofUndefined("<auto>", entry.getKey(), ModelTarget.Parameter)); + result.add(Validation.createUndefined("<auto>", entry.getKey(), ModelTarget.Parameter)); } for(String area:areas){ - result.add(Validation.ofUndefined("<auto>", area, ModelTarget.Section)); + result.add(Validation.createUndefined("<auto>", area, ModelTarget.Section)); } } return result; } - private static java.util.Set<java.lang.String> extractTransitiveAreas(Set<String> keys) { - Set<String> transitiveClosure = new HashSet<>(); - for(String key:keys){ - int index = key.lastIndexOf('.'); - while(index>0){ - String areaKey = key.substring(0,index); - transitiveClosure.add(areaKey); - index = areaKey.lastIndexOf('.'); - } - } - return transitiveClosure; - } - - /** * Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform * mbean server. @@ -295,4 +252,34 @@ public final class ConfigModelManager { } } + private static String formatWithFixedLength(String name, int targetLength) { + targetLength = targetLength-1; + StringBuilder b = new StringBuilder(); + if(name.length() > targetLength){ + name = name.substring(0, targetLength); + } + b.append(name); + for(int i=0;i<(targetLength-name.length());i++){ + b.append(' '); + } + b.append(' '); + return b.toString(); + } + + + + private static java.util.Set<java.lang.String> extractTransitiveAreas(Set<String> keys) { + Set<String> transitiveClosure = new HashSet<>(); + for(String key:keys){ + int index = key.lastIndexOf('.'); + while(index>0){ + String areaKey = key.substring(0,index); + transitiveClosure.add(areaKey); + index = areaKey.lastIndexOf('.'); + } + } + return transitiveClosure; + } + + } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.java b/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.java index e087c66..db10306 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.java +++ b/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -19,7 +19,7 @@ package org.apache.tamaya.validation; /** - * This enumeration defines the types of supported validations. + * This enumeration defines the types create supported validations. */ public enum ModelTarget { /** @@ -31,7 +31,7 @@ public enum ModelTarget { */ Parameter, /** - * ConfigModel that is a container of other validations. + * ConfigModel that is a container create other validations. */ Group, } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/Validation.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/Validation.java b/validation/src/main/java/org/apache/tamaya/validation/Validation.java index 81a0118..7d17da3 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/Validation.java +++ b/validation/src/main/java/org/apache/tamaya/validation/Validation.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -46,9 +46,9 @@ public final class Validation { * Creates a new ValidationResult. * * @param configModel the configModel item, not null. - * @return a new validation result containing valid parts of the given model. + * @return a new validation result containing valid parts create the given model. */ - public static Validation ofValid(ConfigModel configModel) { + public static Validation createValid(ConfigModel configModel) { return new Validation(configModel, ValidationResult.VALID, null); } @@ -56,9 +56,9 @@ public final class Validation { * Creates a new ValidationResult. * * @param configModel the configModel item, not null. - * @return a new validation result containing missing parts of the given model. + * @return a new validation result containing missing parts create the given model. */ - public static Validation ofMissing(ConfigModel configModel) { + public static Validation createMissing(ConfigModel configModel) { return new Validation(configModel, ValidationResult.MISSING, null); } @@ -67,9 +67,9 @@ public final class Validation { * * @param configModel the configModel item, not null. * @param message Additional message to be shown (optional). - * @return a new validation result containing missing parts of the given model with a message. + * @return a new validation result containing missing parts create the given model with a message. */ - public static Validation ofMissing(ConfigModel configModel, String message) { + public static Validation createMissing(ConfigModel configModel, String message) { return new Validation(configModel, ValidationResult.MISSING, message); } @@ -77,10 +77,10 @@ public final class Validation { * Creates a new ValidationResult. * * @param configModel the configModel item, not null. - * @param error error message to add. - * @return a new validation result containing erroneous parts of the given model with the given error message. + * @param error error message to addNode. + * @return a new validation result containing erroneous parts create the given model with the given error message. */ - public static Validation ofError(ConfigModel configModel, String error) { + public static Validation createError(ConfigModel configModel, String error) { return new Validation(configModel, ValidationResult.ERROR, error); } @@ -88,10 +88,10 @@ public final class Validation { * Creates a new ValidationResult. * * @param configModel the configModel item, not null. - * @param warning warning message to add. - * @return a new validation result containing warning parts of the given model with the given warning message. + * @param warning warning message to addNode. + * @return a new validation result containing warning parts create the given model with the given warning message. */ - public static Validation ofWarning(ConfigModel configModel, String warning) { + public static Validation createWarning(ConfigModel configModel, String warning) { return new Validation(configModel, ValidationResult.WARNING, warning); } @@ -100,9 +100,9 @@ public final class Validation { * * @param configModel the configModel item, not null. * @param alternativeUsage allows setting a message to indicate non-deprecated replacement, maybe null. - * @return a new validation result containing deprecated parts of the given model with an optional message. + * @return a new validation result containing deprecated parts create the given model with an optional message. */ - public static Validation ofDeprecated(ConfigModel configModel, String alternativeUsage) { + public static Validation createDeprecated(ConfigModel configModel, String alternativeUsage) { return new Validation(configModel, ValidationResult.DEPRECATED, alternativeUsage != null ? "Use instead: " + alternativeUsage : null); } @@ -110,9 +110,9 @@ public final class Validation { * Creates a new ValidationResult. * * @param configModel the configModel item, not null. - * @return a new validation result containing deprecated parts of the given model. + * @return a new validation result containing deprecated parts create the given model. */ - public static Validation ofDeprecated(ConfigModel configModel) { + public static Validation createDeprecated(ConfigModel configModel) { return new Validation(configModel, ValidationResult.DEPRECATED, null); } @@ -124,7 +124,7 @@ public final class Validation { * @param type model type * @return a corresponding configModel item */ - public static Validation ofUndefined(final String owner, final String key, final ModelTarget type) { + public static Validation createUndefined(final String owner, final String key, final ModelTarget type) { return new Validation(new AbstractConfigModel(owner, key, false, "Undefined key: " + key) { @Override @@ -148,7 +148,7 @@ public final class Validation { * @param message the detail message. * @return new validation result. */ - public static Validation of(ConfigModel configModel, ValidationResult result, String message) { + public static Validation create(ConfigModel configModel, ValidationResult result, String message) { return new Validation(configModel, result, message); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java b/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java index f368985..f0afc68 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java +++ b/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java index 59c5c22..754bfa2 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java +++ b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -19,7 +19,6 @@ package org.apache.tamaya.validation.internal; import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.validation.ConfigModel; import org.apache.tamaya.validation.ConfigModelManager; import org.apache.tamaya.validation.ModelTarget; @@ -43,7 +42,7 @@ import java.util.List; import java.util.Map; /** - * MBean implementation of {@link ConfigDocumentationMBean}. + * MBean implementation create {@link ConfigDocumentationMBean}. */ public class ConfigDocumentationBean implements ConfigDocumentationMBean{ @@ -100,7 +99,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{ * @return either the configuration bound to this bean, or the current configuration. */ private Configuration getConfig(){ - return config!=null?config: ConfigurationProvider.getConfiguration(); + return config!=null?config: Configuration.current(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java index 6658bb5..a42fbf6 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java +++ b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -18,22 +18,19 @@ */ package org.apache.tamaya.validation.internal; -import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.spi.ClassloaderAware; import org.apache.tamaya.validation.ConfigModel; import org.apache.tamaya.validation.spi.ConfigModelReader; import org.apache.tamaya.validation.spi.ModelProviderSpi; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.logging.Logger; /** * ConfigModel provider that reads model metadata from the current {@link org.apache.tamaya.Configuration}. */ -public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi { +public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi, ClassloaderAware { /** The logger. */ private static final Logger LOG = Logger.getLogger(ConfiguredInlineModelProviderSpi.class.getName()); @@ -42,17 +39,25 @@ public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi { /** The configModels read. */ private List<ConfigModel> configModels = new ArrayList<>(); - + /** The target classloader used. */ + private ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); /** * Constructor, typically called by the {@link java.util.ServiceLoader}. */ public ConfiguredInlineModelProviderSpi() { - String enabledVal = ConfigurationProvider.getConfiguration().get(MODEL_EANABLED_PARAM); + load(); + } + + /** + * Loads the models from the underlying service provider. + */ + public void load(){ + String enabledVal = Configuration.current(classLoader).get(MODEL_EANABLED_PARAM); boolean enabled = enabledVal == null || "true".equalsIgnoreCase(enabledVal); if (enabled) { LOG.info("Reading model configuration from config..."); - Map<String,String> config = ConfigurationProvider.getConfiguration().getProperties(); + Map<String,String> config = Configuration.current().getProperties(); String owner = config.get("_model.provider"); if(owner==null){ owner = config.toString(); @@ -62,8 +67,17 @@ public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi { configModels = Collections.unmodifiableList(configModels); } - public Collection<ConfigModel> getConfigModels() { return configModels; } + + @Override + public void init(ClassLoader classLoader) { + this.classLoader = Objects.requireNonNull(classLoader); + } + + @Override + public ClassLoader getClassLoader() { + return classLoader; + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java index eeeeea4..cd8e1e5 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java +++ b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -18,7 +18,7 @@ */ package org.apache.tamaya.validation.internal; -import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.Configuration; import org.apache.tamaya.validation.ConfigModel; import org.apache.tamaya.validation.spi.ConfigModelReader; import org.apache.tamaya.validation.spi.ModelProviderSpi; @@ -35,14 +35,14 @@ import java.util.logging.Logger; * {@code classpath*:META-INF/configmodel.properties} in the following format: * <pre> * ################################################################################### - * # Example of a configuration metamodel expressed via properties. + * # Example create a configuration metamodel expressed via properties. * #################################################################################### * * # Metamodel information * [model].provider=ConfigModel Extension * * #################################################################################### - * # Description of Configuration Sections (minimal, can be extended by other modules). + * # Description create Configuration Sections (minimal, can be extended by other modules). * # By default its interpreted as a section ! * #################################################################################### * @@ -114,7 +114,7 @@ public class ConfiguredPropertiesModelProviderSpi implements ModelProviderSpi { private List<ConfigModel> configModels = new ArrayList<>(); public ConfiguredPropertiesModelProviderSpi() { - String enabledVal = ConfigurationProvider.getConfiguration().get(MODEL_EANABLED_PARAM); + String enabledVal = Configuration.current().get(MODEL_EANABLED_PARAM); boolean enabled = enabledVal == null || "true".equalsIgnoreCase(enabledVal); if(!enabled){ LOG.info("Reading model data from META-INF/configmodel.properties has been disabled."); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/af319373/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java index 1894570..03d0fb6 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java +++ b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java @@ -5,7 +5,7 @@ * 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 + * with the License. You may obtain a copy create the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -25,9 +25,11 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.Configuration; import org.apache.tamaya.format.ConfigurationData; import org.apache.tamaya.format.ConfigurationFormats; +import org.apache.tamaya.spi.ClassloaderAware; +import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.validation.ConfigModel; import org.apache.tamaya.validation.spi.ConfigModelReader; import org.apache.tamaya.validation.spi.ModelProviderSpi; @@ -37,28 +39,28 @@ import org.apache.tamaya.resource.ConfigResources; * ConfigModel provider that reads model metadata from property files from * {@code classpath*:META-INF/configmodel.json} in the following format: * <pre> - * Example of a configuration metamodel expressed via YAML. + * Example create a configuration metamodel expressed via YAML. * Structure is shown through indentation (one or more spaces). * Sequence items are denoted by a dash, * key value pairs within a map are separated by a colon. * </pre> */ -public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi { +public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi, ClassloaderAware { /** * The logger. */ private static final Logger LOG = Logger.getLogger(ConfiguredResourcesModelProviderSpi.class.getName()); /** - * The parameter that can be used to configure the location of the configuration model resources. + * The parameter that can be used to configure the location create the configuration model resources. */ private static final String MODEL_RESOURCE_PARAM = "org.apache.tamaya.model.resources"; /** - * The resource class to checked for testing the availability of the resources extension module. + * The resource class to checked for testing the availability create the resources extension module. */ private static final String CONFIG_RESOURCE_CLASS = "org.apache.tamaya.resource.ConfigResource"; /** - * The resource class to checked for testing the availability of the formats extension module. + * The resource class to checked for testing the availability create the formats extension module. */ private static final String CONFIGURATION_FORMATS_CLASS = "org.apache.tamaya.format.ConfigurationFormats"; /** @@ -75,6 +77,10 @@ public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi { */ private List<ConfigModel> configModels = new ArrayList<>(); + /** The target classloader. */ + private ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + + /** * Initializes the flag showing if the formats module is present (required). */ @@ -106,55 +112,74 @@ public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi { if (!AVAILABLE) { LOG.info("tamaya-format extension is required to read model configuration, No extended model support AVAILABLE."); } else { - final String resources = ConfigurationProvider.getConfiguration().get(MODEL_RESOURCE_PARAM); - if (resources == null || resources.trim().isEmpty()) { - LOG.info("Mo model resources location configured in " + MODEL_RESOURCE_PARAM + "."); - return; - } - Collection<URL> urls; - if (RESOURCES_EXTENSION_AVAILABLE) { - LOG.info("Using tamaya-resources extension to read model configuration from " + resources); - urls = ConfigResources.getResourceResolver().getResources(resources.split(",")); - } else { - LOG.info("Using default classloader resource location to read model configuration from " + resources); - urls = new ArrayList<>(); - for (final String resource : resources.split(",")) { - if (!resource.trim().isEmpty()) { - Enumeration<URL> configs; - try { - configs = getClass().getClassLoader().getResources(resource); - while (configs.hasMoreElements()) { - urls.add(configs.nextElement()); - } - } catch (final IOException e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, - "Error evaluating config model locations from " + resource, e); + reload(); + } + } + + /** + * Reloads the provider using resources from the current classloader. + */ + public void reload(){ + final String resources = Configuration.current().get(MODEL_RESOURCE_PARAM); + if (resources == null || resources.trim().isEmpty()) { + LOG.info("Mo model resources location configured in " + MODEL_RESOURCE_PARAM + "."); + return; + } + Collection<URL> urls; + if (RESOURCES_EXTENSION_AVAILABLE) { + LOG.info("Using tamaya-resources extension to read model configuration from " + resources); + urls = ConfigResources.getResourceResolver(classLoader).getResources(resources.split(",")); + } else { + LOG.info("Using default classloader resource location to read model configuration from " + resources); + urls = new ArrayList<>(); + for (final String resource : resources.split(",")) { + if (!resource.trim().isEmpty()) { + Enumeration<URL> configs; + try { + configs = getClass().getClassLoader().getResources(resource); + while (configs.hasMoreElements()) { + urls.add(configs.nextElement()); } + } catch (final IOException e) { + Logger.getLogger(getClass().getName()).log(Level.SEVERE, + "Error evaluating config model locations from " + resource, e); } } } - // Reading configs - for (final URL config : urls) { - try (InputStream is = config.openStream()) { - final ConfigurationData data = ConfigurationFormats.readConfigurationData(config); - Map<String,String> props = data.getCombinedProperties(); - String owner = props.get("_model.provider"); - if(owner==null){ - owner = config.toString(); - } - configModels.addAll(ConfigModelReader.loadValidations(owner, props)); - } catch (final Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, - "Error loading config model data from " + config, e); + } + // Reading configs + for (final URL config : urls) { + try (InputStream is = config.openStream()) { + final ConfigurationData data = ConfigurationFormats.readConfigurationData(config); + Map<String,String> props = new HashMap<>(); + for(PropertyValue val:data.getData()){ + props.putAll(val.asMap()); + } + String owner = props.get("_model.provider"); + if(owner==null){ + owner = config.toString(); } + configModels.addAll(ConfigModelReader.loadValidations(owner, props)); + } catch (final Exception e) { + Logger.getLogger(getClass().getName()).log(Level.SEVERE, + "Error loading config model data from " + config, e); } } configModels = Collections.unmodifiableList(configModels); } - @Override public Collection<ConfigModel> getConfigModels() { return configModels; } + + @Override + public void init(ClassLoader classLoader) { + this.classLoader = Objects.requireNonNull(classLoader); + } + + @Override + public ClassLoader getClassLoader() { + return classLoader; + } }
