Repository: incubator-tamaya-extensions Updated Branches: refs/heads/master 4a70f5309 -> b9299af45
TAMAYA-198: Analyzed and applied patch to prevent reread of streams. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/b6be1178 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/b6be1178 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/b6be1178 Branch: refs/heads/master Commit: b6be11784398e4a0ac2f9118e2851e6ca472114a Parents: 4a70f53 Author: anatole <anat...@apache.org> Authored: Mon Dec 19 23:23:45 2016 +0100 Committer: anatole <anat...@apache.org> Committed: Mon Dec 19 23:23:45 2016 +0100 ---------------------------------------------------------------------- .../BaseFormatPropertySourceProvider.java | 14 +++--- .../FormatPropertySourceProviderTest.java | 50 ++++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/b6be1178/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java b/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java index 84d6cfa..90e1143 100644 --- a/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java +++ b/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java @@ -139,13 +139,15 @@ public abstract class BaseFormatPropertySourceProvider implements PropertySource public Collection<PropertySource> getPropertySources() { List<PropertySource> propertySources = new ArrayList<>(); for (URL res : this.paths) { - try(InputStream is = res.openStream()) { - for (ConfigurationFormat format : configFormats) { - ConfigurationData data = format.readConfiguration(res.toString(), is); - propertySources.addAll(getPropertySources(data)); + for (ConfigurationFormat format : configFormats) { + try(InputStream is = res.openStream()) { + if (format.accepts(res)) { + ConfigurationData data = format.readConfiguration(res.toString(), is); + propertySources.addAll(getPropertySources(data)); + } + } catch (Exception e) { + LOG.log(Level.WARNING, "Failed to put resource based config: " + res, e); } - } catch (Exception e) { - LOG.log(Level.WARNING, "Failed to put resource based config: " + res, e); } } return propertySources; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/b6be1178/modules/formats/base/src/test/java/org/apache/tamaya/format/FormatPropertySourceProviderTest.java ---------------------------------------------------------------------- diff --git a/modules/formats/base/src/test/java/org/apache/tamaya/format/FormatPropertySourceProviderTest.java b/modules/formats/base/src/test/java/org/apache/tamaya/format/FormatPropertySourceProviderTest.java new file mode 100644 index 0000000..3a4ec16 --- /dev/null +++ b/modules/formats/base/src/test/java/org/apache/tamaya/format/FormatPropertySourceProviderTest.java @@ -0,0 +1,50 @@ +/* + * 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.format; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertySourceProvider; +import org.junit.Test; +import static org.junit.Assert.*; + +public class FormatPropertySourceProviderTest + extends BaseFormatPropertySourceProvider { + public FormatPropertySourceProviderTest() { + super(ConfigurationFormats.getFormats(), "Test.ini", "Test.properties"); + } + + @Test + public void getPropertySourcesTest() { + PropertySourceProvider provider = new FormatPropertySourceProviderTest(); + Collection<PropertySource> sources = provider.getPropertySources(); + + assertEquals(2, sources.size()); + } + + @Override + protected Collection<PropertySource> getPropertySources(ConfigurationData data) { + PropertySource ps = new MappedConfigurationDataPropertySource(data); + ArrayList<PropertySource> result = new ArrayList<PropertySource>(); + result.add(ps); + return result; + } +}