http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java ---------------------------------------------------------------------- diff --git a/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java b/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java new file mode 100644 index 0000000..2f0fc09 --- /dev/null +++ b/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java @@ -0,0 +1,80 @@ +/* + * 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.consul; + +import com.google.common.net.HostAndPort; +import org.apache.tamaya.consul.ConsulPropertySource; +import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest; +import org.junit.BeforeClass; + +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.util.Map; +import java.util.UUID; + +import static org.junit.Assert.*; + +/** + * Tests for th consul backend integration for writing to the consul backend. + */ +public class ConsulWriteTest { + + private static HostAndPort accessor; + static boolean execute = false; + private static ConsulPropertySource propertySource; + + @BeforeClass + public static void setup() throws MalformedURLException, URISyntaxException { + System.setProperty("consul.urls", "http://127.0.0.1:8300"); + accessor = HostAndPort.fromString("127.0.0.1:8500"); + propertySource = new ConsulPropertySource(); + } + + @org.junit.Test + public void testSetNormal() throws Exception { + if (!execute) return; + String taID = UUID.randomUUID().toString(); + ConfigChangeRequest request = new ConfigChangeRequest("testSetNormal"); + request.put(taID, "testSetNormal"); + propertySource.applyChange(request); + } + + + @org.junit.Test + public void testDelete() throws Exception { + if(!execute)return; + String taID = UUID.randomUUID().toString(); + ConfigChangeRequest request = new ConfigChangeRequest("testDelete"); + request.put(taID, "testDelete"); + propertySource.applyChange(request); + assertEquals(propertySource.get("testDelete").getValue(), taID.toString()); + assertNotNull(propertySource.get("_testDelete.createdIndex")); + request = new ConfigChangeRequest("testDelete2"); + request.remove("testDelete"); + propertySource.applyChange(request); + assertNull(propertySource.get("testDelete")); + } + + @org.junit.Test + public void testGetProperties() throws Exception { + if(!execute)return; + Map<String,String> result = propertySource.getProperties(); + assertTrue(result.isEmpty()); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-simple/config/README.txt ---------------------------------------------------------------------- diff --git a/metamodel-simple/config/README.txt b/metamodel-simple/config/README.txt deleted file mode 100644 index 3dd71f5..0000000 --- a/metamodel-simple/config/README.txt +++ /dev/null @@ -1,20 +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 current 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. -# -This folder is for testing only. It contains some config files that are to be included by the -ConfigDirPropertySourceProvider config provider. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-simple/config/test3.properties ---------------------------------------------------------------------- diff --git a/metamodel-simple/config/test3.properties b/metamodel-simple/config/test3.properties deleted file mode 100644 index 9ddef76..0000000 --- a/metamodel-simple/config/test3.properties +++ /dev/null @@ -1,21 +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 current 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. -# -tamaya.ordinal=100000 -test3=3-overridden -test5=value5 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-simple/pom.xml ---------------------------------------------------------------------- diff --git a/metamodel-simple/pom.xml b/metamodel-simple/pom.xml deleted file mode 100644 index 9c96c28..0000000 --- a/metamodel-simple/pom.xml +++ /dev/null @@ -1,86 +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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext.metamodels</groupId> - <artifactId>tamaya-metamodels</artifactId> - <version>0.3-incubating-SNAPSHOT</version> - <relativePath>..</relativePath> - </parent> - <artifactId>tamaya-metamodels-simple</artifactId> - <name>Apache Tamaya Modules Metamodels - Simple</name> - <description>Simple Tamaya Metamodel, e.g. feasible for SE commandline tools and simple use cases.</description> - <packaging>bundle</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-core</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-resources</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-formats</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Import-Package> - org.apache.tamaya, - org.apache.tamaya.spi, - org.apache.tamaya.format, - javax.annotation, - * - </Import-Package> - <Export-Package> - org.apache.tamaya.metamodel.simple - </Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/ConfigDirPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/ConfigDirPropertySourceProvider.java b/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/ConfigDirPropertySourceProvider.java deleted file mode 100644 index e3c9cbf..0000000 --- a/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/ConfigDirPropertySourceProvider.java +++ /dev/null @@ -1,81 +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.metamodel.simple.internal; - - -import org.apache.tamaya.format.ConfigurationData; -import org.apache.tamaya.format.ConfigurationFormats; -import org.apache.tamaya.format.FlattenedDefaultPropertySource; -import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; -import org.apache.tamaya.spi.PropertySource; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Created by Anatole on 20.03.2015. - */ -public class ConfigDirPropertySourceProvider extends AbstractPathPropertySourceProvider { - - public ConfigDirPropertySourceProvider() { - super(getConfigLocation()); - } - - private static String getConfigLocation() { - String location = System.getProperty("configdir"); - if (location == null) { - location = "./config"; - } - if (!location.endsWith("/")) { - location += "/"; - } - if (!location.startsWith("file:")) { - location = "file:" + location; - } - return location + "**/*.*"; - } - - @Override - protected Collection<PropertySource> getPropertySources(URL url) { - try { - ConfigurationData config = ConfigurationFormats.readConfigurationData(url); - if (config == null) { - Logger.getLogger(getClass().getName()).log(Level.INFO, - "Failed to read configuration from " + url); - return Collections.emptySet(); - } - return asCollection(new FlattenedDefaultPropertySource(config)); - } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, - "Failed to read configuration from " + url, e); - return Collections.emptySet(); - } - } - - 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/041f5998/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/MetainfConfigPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/MetainfConfigPropertySourceProvider.java b/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/MetainfConfigPropertySourceProvider.java deleted file mode 100644 index 0edbbc7..0000000 --- a/metamodel-simple/src/main/java/org/apache/tamaya/metamodel/simple/internal/MetainfConfigPropertySourceProvider.java +++ /dev/null @@ -1,62 +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.metamodel.simple.internal; - - -import org.apache.tamaya.format.ConfigurationData; -import org.apache.tamaya.format.ConfigurationFormats; -import org.apache.tamaya.format.FlattenedDefaultPropertySource; -import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; -import org.apache.tamaya.spi.PropertySource; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Created by Anatole on 20.03.2015. - */ -public class MetainfConfigPropertySourceProvider extends AbstractPathPropertySourceProvider { - - public MetainfConfigPropertySourceProvider() { - super("classpath:META-INF/config/**/*.*"); - } - - @Override - protected Collection<PropertySource> getPropertySources(URL url) { - try { - ConfigurationData config = ConfigurationFormats.readConfigurationData(url); - return asCollection(new FlattenedDefaultPropertySource(config)); - } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, - "Failed to read configuration from " + url, e); - return Collections.emptySet(); - } - } - - 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/041f5998/metamodel-simple/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider ---------------------------------------------------------------------- diff --git a/metamodel-simple/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/metamodel-simple/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider deleted file mode 100644 index 2e963e2..0000000 --- a/metamodel-simple/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider +++ /dev/null @@ -1,20 +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 current 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. -# -org.apache.tamaya.metamodel.simple.internal.ConfigDirPropertySourceProvider -org.apache.tamaya.metamodel.simple.internal.MetainfConfigPropertySourceProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-simple/src/test/java/org/apache/tamaya/metamodel/simple/SimpleTest.java ---------------------------------------------------------------------- diff --git a/metamodel-simple/src/test/java/org/apache/tamaya/metamodel/simple/SimpleTest.java b/metamodel-simple/src/test/java/org/apache/tamaya/metamodel/simple/SimpleTest.java deleted file mode 100644 index 677d8fc..0000000 --- a/metamodel-simple/src/test/java/org/apache/tamaya/metamodel/simple/SimpleTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apache.tamaya.metamodel.simple; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Anatole on 26.07.2015. - */ -public class SimpleTest { - - @Test - public void testClasspathConfig() { - Configuration config = ConfigurationProvider.getConfiguration(); - assertEquals(config.get("test1"), "1"); - assertEquals(config.get("test2"), "2"); - // overridden by file config - assertEquals(config.get("test3"), "3-overridden"); - assertEquals(config.get("test4"), "4"); - // added by file config - assertEquals(config.get("test5"), "value5"); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-simple/src/test/resources/META-INF/config/test.properties ---------------------------------------------------------------------- diff --git a/metamodel-simple/src/test/resources/META-INF/config/test.properties b/metamodel-simple/src/test/resources/META-INF/config/test.properties deleted file mode 100644 index af16b23..0000000 --- a/metamodel-simple/src/test/resources/META-INF/config/test.properties +++ /dev/null @@ -1,20 +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 current 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. -# -test1=1 -test2=2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-simple/src/test/resources/META-INF/config/test2.properties ---------------------------------------------------------------------- diff --git a/metamodel-simple/src/test/resources/META-INF/config/test2.properties b/metamodel-simple/src/test/resources/META-INF/config/test2.properties deleted file mode 100644 index 58524b7..0000000 --- a/metamodel-simple/src/test/resources/META-INF/config/test2.properties +++ /dev/null @@ -1,20 +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 current 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. -# -test3=3 -test4=4 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/pom.xml ---------------------------------------------------------------------- diff --git a/metamodel-staged/pom.xml b/metamodel-staged/pom.xml deleted file mode 100644 index b5c96a2..0000000 --- a/metamodel-staged/pom.xml +++ /dev/null @@ -1,114 +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 current 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext.metamodels</groupId> - <artifactId>tamaya-metamodels</artifactId> - <version>0.3-incubating-SNAPSHOT</version> - <relativePath>..</relativePath> - </parent> - - <artifactId>tamaya-metamodel-staged</artifactId> - <name>Apache Tamaya Modules - Staged Configuration</name> - <packaging>bundle</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-core</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-functions</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-resolver</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-spisupport</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-resources</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-formats</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-yaml</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>java-hamcrest</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Import-Package> - org.apache.tamaya, - org.apache.tamaya.spi, - org.apache.tamaya.resources, - org.apache.tamaya.spisupport, - org.apache.tamaya.functions, - javax.annotation, - * - </Import-Package> - <Export-Package> - org.apache.tamaya.metamodel.simple - </Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/DSLFormatManager.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/DSLFormatManager.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/DSLFormatManager.java deleted file mode 100644 index 916fa49..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/DSLFormatManager.java +++ /dev/null @@ -1,115 +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.dsl; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.format.ConfigurationFormat; -import org.apache.tamaya.format.ConfigurationFormats; -import org.apache.tamaya.functions.ConfigurationFunctions; - -import java.util.*; - -/** - * Component that manages the current supported formats: - * <pre> - * TAMAYA: - * FORMAT-DEF: - * - formats: yaml, properties, xml-properties - * </pre> - * Hereby: - * <ul> - * <li><b>profiles</b> defines the available profiles, including implicit default profiles.</li> - * </ul> - */ -public final class DSLFormatManager { - - private static final DSLFormatManager INSTANCE = new DSLFormatManager(); - - /** The currently active formats, in order of precedence, the most significant are the last ones. */ - private List<ConfigurationFormat> formats = new ArrayList<>(); - /** The currently active suffixes, in order of precedence, the most significant are the last ones. */ - private List<String> suffixes = new ArrayList<>(); - - - /** - * Get the current instance. - * @return the current profile manager, never null. - */ - public static DSLFormatManager getInstance(){ - return INSTANCE; - } - - private DSLFormatManager(){ - Configuration metaConfig = MetaConfiguration.getConfiguration(); - Configuration formatsConfig = metaConfig.with( - ConfigurationFunctions.section("TAMAYA.FORMATS")); - String[] formats = formatsConfig.getOrDefault("formats","yamk,properties,ini").split(","); - this.formats.addAll(ConfigurationFormats.getFormats(formats)); - String[] suffixes = formatsConfig.getOrDefault("suffixes","yml,properties,ini").split(","); - for(String sfx:suffixes){ - sfx = sfx.trim(); - if(sfx.isEmpty()){ - continue; - } - this.suffixes.add(sfx); - } - } - - - /** - * Allows to check if a suffix is currently activated. - * @param suffix the suffix name, not null. - * @return true, if the profile is defined. - */ - public boolean isSuffixDefined(String suffix){ - return this.suffixes.contains(suffix); - } - - /** - * Allows to check if a format is selected. - * @param formatName the format name, not null. - * @return true, if the format is a selected. - */ - public boolean isFormatSelected(String formatName){ - for(ConfigurationFormat format:formats){ - if(format.getName().equals(formatName)){ - return true; - } - } - return false; - } - - /** - * Get the list of currently active suffixes. - * @return the list of currently active suffixes, never null. - */ - public List<String> getSuffixes(){ - return Collections.unmodifiableList(suffixes); - } - - /** - * Get the list of currently active formats. - * @return the list of currently active formats, never null. - */ - public List<ConfigurationFormat> getFormats(){ - return Collections.unmodifiableList(formats); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/MetaConfiguration.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/MetaConfiguration.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/MetaConfiguration.java deleted file mode 100644 index a16bfa8..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/MetaConfiguration.java +++ /dev/null @@ -1,144 +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.dsl; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.format.ConfigurationData; -import org.apache.tamaya.format.ConfigurationFormat; -import org.apache.tamaya.format.ConfigurationFormats; -import org.apache.tamaya.json.YAMLFormat; -import org.apache.tamaya.resource.ConfigResources; -import org.apache.tamaya.spi.ConfigurationContextBuilder; -import org.apache.tamaya.spisupport.DefaultConfiguration; -import org.apache.tamaya.spisupport.MapPropertySource; - -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Meta environment configuration builder and accessor. Normally this class shoulds never be accessed - * by client code. But it could be useful for extensions that extend the meta-configuration capabilities - * of tamaya having access to the meta-configuration, so they can read their own meta-entries to - * setup whatever features they implement. - */ -public final class MetaConfiguration { - - private static final Logger LOGGER = Logger.getLogger(MetaConfiguration.class.getName()); - private static MetaConfiguration INSTANCE = new MetaConfiguration(); - - private Configuration config; - private String resourceExpression; - private String[] formatNames; - - /** - * Initializes the metaconfiguration. - * @param resourceExpression the resource expression that defines the resources to load. - * @param formatNames the format names to be used. - */ - private void init(String resourceExpression, String... formatNames){ - if(this.config!=null){ - LOGGER.warning(">>> Reset of Meta-Configuration resource : " + resourceExpression); - LOGGER.warning(">>> Reset of Meta-Configuration formats : " + Arrays.toString(formatNames)); - } - if(resourceExpression==null){ - resourceExpression = "tamaya-config.*"; - } - LOGGER.info(">>> Meta-Configuration resource : " + resourceExpression); - ConfigurationFormat[] formats = loadFormats(formatNames); - ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder(); - for(URL url:ConfigResources.getResourceResolver().getResources(resourceExpression)) { - for(ConfigurationFormat format:formats) { - if(format.accepts(url)){ - try(InputStream is = url.openStream()){ - ConfigurationData data = format.readConfiguration(url.toString(), is); - builder.addPropertySources(new MapPropertySource( - url.toString(), data.getCombinedProperties())); - }catch(Exception e){ - LOGGER.log(Level.INFO, "Failed to read " + url + " with format " + format, e); - } - } - } - } - this.config = new DefaultConfiguration(builder.build()); - LOGGER.info("Meta-Configuration read: " + this.config.getProperties().size() + " entries."); - } - - private ConfigurationFormat[] loadFormats(String... formatNames) { - List<ConfigurationFormat> formats = new ArrayList<>(); - if(formatNames.length==0) { - String metaFormats = System.getProperty("tamaya.meta-formats"); - if (metaFormats != null) { - formatNames = metaFormats.split(","); - } - } - for (String formatName : formatNames) { - formats.addAll(ConfigurationFormats.getFormats(formatName)); - } - if(formats.isEmpty()){ - formats.addAll(ConfigurationFormats.getFormats("yaml")); - } - if(formats.isEmpty()){ - formats.add(new YAMLFormat()); - } - LOGGER.info(">>> Meta-Configuration formats : " + formats); - return formats.toArray(new ConfigurationFormat[formats.size()]); - } - - /** - * Access the system's meta-configuration, initialize if necessary. Normally this class shoulds never be accessed - * by client code. But it could be useful for extensions that extend the meta-configuration capabilities - * of tamaya having access to the meta-configuration, so they can read their own meta-entries to - * setup whatever features they implement. - * @return the meta-configuration instance used for setting up the Tamaya's application configuration - * model. - */ - public static Configuration getConfiguration(){ - if(INSTANCE.config==null) { - INSTANCE.init(null); - } - return INSTANCE.config; - } - - /** - * Access the system's meta-configuration, initialize if necessary. Normally this class shoulds never be accessed - * by client code. But it could be useful for extensions that extend the meta-configuration capabilities - * of tamaya having access to the meta-configuration, so they can read their own meta-entries to - * setup whatever features they implement. - * - * @param resourceExpression the resource expression that defines where the metaconfiguration - * files/resources are located. - * @param formatNames the formats supported, if null all formats found are tried for each resource(=URL). - * @return the meta-configuration instance used for setting up the Tamaya's application configuration - * model. - */ - public static Configuration getConfiguration(String resourceExpression, - String... formatNames){ - if(INSTANCE.config==null) { - INSTANCE.init(resourceExpression, formatNames); - } - return INSTANCE.config; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/ProfileManager.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/ProfileManager.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/ProfileManager.java deleted file mode 100644 index 70211ca..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/ProfileManager.java +++ /dev/null @@ -1,213 +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.dsl; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.functions.ConfigurationFunctions; -import org.apache.tamaya.resolver.Resolver; -import org.apache.tamaya.resolver.spi.ExpressionResolver; -import org.apache.tamaya.spi.ServiceContextManager; - -import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Component that manages the current setup profiles for this environment/runtime. The profile manager - * reads the profile meta configuration that looks as follows: - * <pre> - * TAMAYA: - * PROFILES-DEF: - * - profiles: DEFAULTS,DEV,TEST,PTA,PROD - * - defaults: DEFAULTS - * - default-active: DEV - * - evaluation: ${sys:ENV}, ${env:ENV} - * </pre> - * Hereby: - * <ul> - * <li><b>profiles</b> defines the available profiles, including implicit default profiles.</li> - * <li><b>defaults</b> defines the profiles that are loaded implicitly first as defaults.</li> - * <li><b>default-active</b> defines the profile(s) activated by default, when no profile setting could be evaluated. - * <li><b>evaluation</b> defines the resolution expressions to be used to evaluate the current profiles active. - * By default {@code ${sys:ENV}, ${env:ENV}} is used, which tries to evaluate {@code ENV} using system and - * environment properties. Refere to the {@code tamaya-resolver} module for further details on resolvers and - * expressions and see {@link Resolver#evaluateExpression(String, boolean)}. - * </ul> - */ -public final class ProfileManager { - - private static final Logger LOG = Logger.getLogger(ProfileManager.class.getName()); - private static final ProfileManager INSTANCE = new ProfileManager(); - - /** The currently active profiles, in order of precedence, the most significant are the last ones. */ - private List<String> activeProfiles = new ArrayList<>(); - /** A set of all defined profiles. */ - private Set<String> profiles = new HashSet<>(); - /** The current used default profiles, loaded initially, before all other profiles are loaded. */ - private List<String> defaultProfiles = new ArrayList<>(); - - - /** - * Get the current instance. - * @return the current profile manager, never null. - */ - public static ProfileManager getInstance(){ - return INSTANCE; - } - - private ProfileManager(){ - Configuration metaConfig = MetaConfiguration.getConfiguration(); - Configuration profileConfig = metaConfig.with( - ConfigurationFunctions.section("TAMAYA.PROFILES-DEF")); - String[] selectables = profileConfig.getOrDefault("profiles","DEFAULT,DEV,TEST,PROD").split(","); - for(String sel:selectables){ - sel = sel.trim(); - if(sel.isEmpty()){ - continue; - } - this.profiles.add(sel); - } - String[] defaults = profileConfig.getOrDefault("defaults","DEFAULT").split(","); - for(String def:defaults){ - def = def.trim(); - if(def.isEmpty()){ - continue; - } - if(!isProfileDefined(def)){ - throw new ConfigException("Invalid profile encountered: " +def + ", valid are: " + profiles); - } - this.defaultProfiles.add(def); - } - String[] expressions = profileConfig.getOrDefault("evaluation","${sys:ENV}, ${env:ENV}").split(","); - String currentEnvironment = null; - for(String exp:expressions){ - exp = exp.trim(); - if(exp.isEmpty()){ - continue; - } - currentEnvironment = evaluateExpression(exp); - if(currentEnvironment!=null){ - currentEnvironment = currentEnvironment.trim(); - if(!currentEnvironment.isEmpty()){ - break; - } - } - } - if(currentEnvironment==null|| currentEnvironment.isEmpty()){ - currentEnvironment = profileConfig.getOrDefault("default-active", "DEV"); - } - this.activeProfiles.addAll(defaultProfiles); - String[] profilesActive = currentEnvironment.split(","); - for(String prof:profilesActive){ - prof = prof.trim(); - if(prof.isEmpty()){ - continue; - } - if(!isProfileDefined(prof)){ - throw new ConfigException("Invalid profile encountered: " +prof + ", valid are: " + profiles); - } - this.activeProfiles.add(prof); - } - } - - /** - * Evaluates the expressions to evaluate the current profile. - * Currently the following expressions are supported - * <pre> - * sys-property:xxx - * env-property:xxx - * </pre> - * {@code xxx} is the corresponding key. - * @param currentProfileExpression the profile expression. - * @return the evaluated String, or null. - */ - private String evaluateExpression(String currentProfileExpression){ - currentProfileExpression = currentProfileExpression.trim(); - List<ExpressionResolver> resolvers = new ArrayList<>(); - for(ExpressionResolver res: ServiceContextManager.getServiceContext().getServices(ExpressionResolver.class)){ - resolvers.add(res); - } - for(ExpressionResolver res:resolvers){ - if(currentProfileExpression.startsWith(res.getResolverPrefix())){ - try{ - return res.evaluate(currentProfileExpression.substring(res.getResolverPrefix().length())); - }catch(Exception e){ - LOG.log(Level.FINEST, "Error evaluating resolver: " + res, e); - } - } - } - return null; - } - - /** - * Allows to check if a profile is currently active. - * @param profileName the profile name, not null. - * @return true, if the profile is active. - */ - public boolean isProfileActive(String profileName){ - return this.activeProfiles.contains(profileName); - } - - /** - * Allows to check if a profile is currently defined. - * @param profileName the profile name, not null. - * @return true, if the profile is defined. - */ - public boolean isProfileDefined(String profileName){ - return this.profiles.contains(profileName); - } - - /** - * Allows to check if a profile is a default profile. - * @param profileName the profile name, not null. - * @return true, if the profile is a default profile. - */ - public boolean isProfileDefault(String profileName){ - return this.defaultProfiles.contains(profileName); - } - - /** - * Get the list of currently active profiles. - * @return the list of currently active profiles, in order of precedence, the most significant - * are the last ones, never null. - */ - public List<String> getActiveProfiles(){ - return Collections.unmodifiableList(activeProfiles); - } - - /** - * Get the list of currently active profiles. - * @return the list of currently active profiles, in order of precedence, the most significant - * are the last ones, never null. - */ - public List<String> getDefaultProfiles(){ - return Collections.unmodifiableList(defaultProfiles); - } - - /** - * Get the list of currently active profiles. - * @return the list of currently active profiles, in order of precedence, the most significant - * are the last ones, never null. - */ - public Set<String> getAllProfiles(){ - return Collections.unmodifiableSet(profiles); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/TamayaConfigurator.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/TamayaConfigurator.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/TamayaConfigurator.java deleted file mode 100644 index c7c62b5..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/TamayaConfigurator.java +++ /dev/null @@ -1,234 +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.dsl; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.functions.ConfigurationFunctions; -import org.apache.tamaya.spi.*; -import org.apache.tamaya.staged.spi.DSLPropertySourceProvider; - -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.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Logger; - -/** - * Configuration class setting up the Tamaya runtime model. - */ -public final class TamayaConfigurator { - - private static final Logger LOGGER = Logger.getLogger(MetaConfiguration.class.getName()); - private static final Comparator<WrappedPropertySource> ORDINAL_COMPARATOR = - new Comparator<WrappedPropertySource>(){ - @Override - public int compare(WrappedPropertySource o1, WrappedPropertySource o2) { - return o1.getOrdinal() - o2.getOrdinal(); - } - }; - - private static final TamayaConfigurator INSTANCE = new TamayaConfigurator(); - - private ConfigurationContext configurationContext; - private Set<String> formats = new HashSet<>(); - private Set<String> suffixes = new HashSet<>(); - private Map<String,DSLPropertySourceProvider> dslResolvers = new HashMap<>(); - - - private TamayaConfigurator(){ - configure(null); - } - - /** - * Get the singleton instance. - * @return the instance, never null. - */ - public static TamayaConfigurator getInstance(){ - return INSTANCE; - } - - /** - * Configures the Tamaya runtime using the metamodel configuration found at the default - * location. - * @see MetaConfiguration - */ - public void configure(){ - configure(null); - } - - /** - * Configures the Tamaya runtime using the given resource location expression and (optionally) - * formats to be used for evaluating the metamodel configuration. - * @param resourceExpression resource expression for resolving the location of the - * meta configuration. - * @param formats the format names to be used, optional, but not null. - * @see MetaConfiguration - */ - public void configure(String resourceExpression, String... formats){ - loadDSLSourceResolvers(); - Configuration metaConfig = MetaConfiguration.getConfiguration(resourceExpression, formats); - Configuration profilesConfig = metaConfig.with( - ConfigurationFunctions.section("TAMAYA.PROFILES.", true)); - Configuration metaProfile = profilesConfig.with( - ConfigurationFunctions.section("<COMMON>.", true)); - System.out.println(metaProfile.getProperties().keySet()); - String[] values = metaProfile.getOrDefault("formats","yaml, properties, xml-properties").split(","); - for(String fmt:values){ - fmt = fmt.trim(); - if(fmt.isEmpty()){ - continue; - } - this.formats.add(fmt); - } - values = metaProfile.getOrDefault("suffixes", "yml, yaml, properties, xml").split(","); - for(String sfx:values){ - sfx = sfx.trim(); - if(sfx.isEmpty()){ - continue; - } - this.suffixes.add(sfx); - } - ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder(); - Map<String, PropertySource> loadedPropertySources = loadDefaultPropertySources(); - int defaultOrdinal = loadSources(builder, "<COMMON>", metaProfile, loadedPropertySources, 0) + 20; - // Load current profiles - for(String profile:ProfileManager.getInstance().getActiveProfiles()){ - metaProfile = profilesConfig.with( - ConfigurationFunctions.section(profile, true)); - defaultOrdinal = loadSources(builder, profile, metaProfile, loadedPropertySources, defaultOrdinal) + 20; - } - // formats: yaml, properties, xml-properties - // - SUFFIX: yaml, yml, properties, xml - // - sources: - // - "named:env-properties" # provider name, or class name - // - "named:main-args" - // - "named:sys-properties" - // - "resource:classpath:META-INF/config/**/*.SUFFIX" - - } - - /** - * Loads all default registered property sources and providers. - * @return the default property sources available on the system. - */ - private Map<String, PropertySource> loadDefaultPropertySources() { - Map<String, PropertySource> loadedPropertySources = new HashMap<>(); - for(PropertySource ps: ServiceContextManager.getServiceContext().getServices(PropertySource.class)){ - loadedPropertySources.put(ps.getName(), ps); - } - for(PropertySourceProvider prov: ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class)){ - for(PropertySource ps: prov.getPropertySources()){ - loadedPropertySources.put(ps.getName(), ps); - } - } - return loadedPropertySources; - } - - private int loadSources(ConfigurationContextBuilder builder, String profileId, Configuration metaProfile, Map<String, - PropertySource> defaultPropertySources, int nextOrdinal) { - String[] values; - List<PropertySource> propertySourcesLoaded = new ArrayList<>(); - values = metaProfile.getOrDefault("sources","<default>").split(","); - if(values.length==1 && "<default>".equals(values[0])){ - // load default property sources and providers from config as default. - // additional providers may be added depending on the active profile... - LOGGER.info("Using default configuration setup for "+profileId); - nextOrdinal = addAndGetNextOrdinal(builder, defaultPropertySources.values(), - propertySourcesLoaded, nextOrdinal); - }else { - LOGGER.info("Loading DSL based "+profileId+" configuration context..."); - int count = 0; - for (String source : values) { - source = source.trim(); - if (source.isEmpty()) { - continue; - } - String sourceKey = getSourceKey(source); - LOGGER.info("Loading "+profileId+" configuration source: " + source); - // evaluate DSLSourceResolver and resolve PropertySources, register thm into context - // apply newMaxOrdinal... - DSLPropertySourceProvider resolver = dslResolvers.get(sourceKey); - if(resolver==null){ - LOGGER.warning("DSL error: unresolvable source expression: "+ source); - continue; - } - List<PropertySource> sources = resolver.resolve(source.substring(sourceKey.length()), - defaultPropertySources); - nextOrdinal = addAndGetNextOrdinal(builder, sources, propertySourcesLoaded, nextOrdinal); - } - LOGGER.info("Loaded "+count+" DSL based "+profileId+" configuration contexts."); - } - return nextOrdinal; - } - - private int addAndGetNextOrdinal(ConfigurationContextBuilder builder, Collection<PropertySource> sourcesToAdd, - List<PropertySource> allPropertySources, int nextOrdinal) { - allPropertySources.addAll(wrapOrdinals(nextOrdinal, sourcesToAdd)); - nextOrdinal = Math.max(calculateHighestOrdinal(allPropertySources)+1, nextOrdinal+1); - builder.addPropertySources(allPropertySources); - return nextOrdinal; - } - - private List<WrappedPropertySource> wrapOrdinals(int nextOrdinal, Collection<PropertySource> propertySources) { - List<WrappedPropertySource> result = new ArrayList<>(); - for(PropertySource ps: propertySources){ - result.add(WrappedPropertySource.of(ps)); - } - Collections.sort(result, ORDINAL_COMPARATOR); - for(WrappedPropertySource ps: result){ - ps.setOrdinal(nextOrdinal++); - } - Collections.sort(result, ORDINAL_COMPARATOR); - return result; - } - - private int calculateHighestOrdinal(Collection<PropertySource> sources) { - int maxOrdinal = 0; - for (PropertySource ps : sources) { - if (ps.getOrdinal() > maxOrdinal) { - maxOrdinal = ps.getOrdinal(); - } - } - return maxOrdinal; - } - - private String getSourceKey(String source) { - int index = source.indexOf(':'); - if(index>0){ - return source.substring(0,index); - } - return source; - } - - private void loadDSLSourceResolvers() { - // Load the ConfigurationDSLSourceResolvers on the system - for(DSLPropertySourceProvider res: - ServiceContextManager.getServiceContext().getServices( - DSLPropertySourceProvider.class)){ - this.dslResolvers.put(res.getKey(), res); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/WrappedPropertySource.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/WrappedPropertySource.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/WrappedPropertySource.java deleted file mode 100644 index 15e6089..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/WrappedPropertySource.java +++ /dev/null @@ -1,100 +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.dsl; - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - -import java.util.Map; -import java.util.Objects; - -/** - * Wrapped property source that allows dynamically reassigning the property source's - * ordinal value. This is needed for reordering the property sources to - * match the DSL configured ordering. - */ -final class WrappedPropertySource implements PropertySource { - - private Integer ordinalAssigned; - private PropertySource wrapped; - - private WrappedPropertySource(PropertySource wrapped){ - this.wrapped = Objects.requireNonNull(wrapped); - } - - /** - * Wraps a given property source. - * @param propertySource the property source to be wrapped. - * @return a wrapped property source. - */ - public static WrappedPropertySource of(PropertySource propertySource){ - if(propertySource instanceof WrappedPropertySource){ - return (WrappedPropertySource)propertySource; - } - return new WrappedPropertySource(propertySource); - } - - @Override - public int getOrdinal() { - return ordinalAssigned!=null?ordinalAssigned.intValue():wrapped.getOrdinal(); - } - - /** - * Applies the given ordinal to the instance. - * @param ordinal the new ordinal. - */ - public void setOrdinal(int ordinal){ - this.ordinalAssigned = ordinal; - } - - /** - * Resetting the ordinal to the one of the wrapped property source. - */ - public void resetOrdinal(){ - this.ordinalAssigned = null; - } - - @Override - public String getName() { - return wrapped.getName(); - } - - @Override - public PropertyValue get(String key) { - return wrapped.get(key); - } - - @Override - public Map<String, String> getProperties() { - return wrapped.getProperties(); - } - - @Override - public boolean isScannable() { - return wrapped.isScannable(); - } - - @Override - public String toString() { - return "WrappedPropertySource{" + - "ordinalAssigned=" + ordinalAssigned + - ", wrapped=" + wrapped + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/DSLLoadingConfigurationProviderSpi.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/DSLLoadingConfigurationProviderSpi.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/DSLLoadingConfigurationProviderSpi.java deleted file mode 100644 index 8538609..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/DSLLoadingConfigurationProviderSpi.java +++ /dev/null @@ -1,82 +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.dsl.internal; - -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.dsl.TamayaConfigurator; -import org.apache.tamaya.spi.ConfigurationContextBuilder; -import org.apache.tamaya.spi.ConfigurationProviderSpi; -import org.apache.tamaya.spi.ServiceContextManager; -import org.apache.tamaya.spisupport.DefaultConfiguration; -import org.apache.tamaya.spisupport.DefaultConfigurationContext; - -import javax.annotation.Priority; - -/** - * ConfigurationContext that uses {@link TamayaConfigurator} to configure the - * Tamaya runtime context. - */ -@Priority(10) -public class DSLLoadingConfigurationProviderSpi implements ConfigurationProviderSpi{ - - private boolean configured; - - private ConfigurationContext context = new DefaultConfigurationContext(); - private Configuration config = new DefaultConfiguration(context); - - - @Override - public ConfigurationContextBuilder getConfigurationContextBuilder() { - return ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class); - } - - @Override - public void setConfigurationContext(ConfigurationContext context){ - // TODO think on a SPI or move event part into API... - this.config = new DefaultConfiguration(context); - this.context = context; - } - - @Override - public boolean isConfigurationContextSettable() { - return true; - } - - @Override - public Configuration getConfiguration() { - checkInitialized(); - return config; - } - - @Override - public ConfigurationContext getConfigurationContext() { - checkInitialized(); - return context; - } - - private void checkInitialized() { - if(!configured){ - synchronized (context) { - TamayaConfigurator.getInstance().configure(); - configured = true; - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/NamedDSLPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/NamedDSLPropertySourceProvider.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/NamedDSLPropertySourceProvider.java deleted file mode 100644 index 0bc71da..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/NamedDSLPropertySourceProvider.java +++ /dev/null @@ -1,53 +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.dsl.internal; - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.staged.spi.DSLPropertySourceProvider; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - -/** - * DSL provider implementation that allows to use registered {@link PropertySource} instances - * by matching {@link PropertySource#getName()} with the configured value and overriding the - * {@link PropertySource#getOrdinal()} method. - */ -public class NamedDSLPropertySourceProvider implements DSLPropertySourceProvider{ - - private static final Logger LOG = Logger.getLogger(NamedDSLPropertySourceProvider.class.getName()); - - @Override - public List<PropertySource> resolve(String sourceExpression, Map<String, PropertySource> defaultPropertySources) { - List<PropertySource> result = new ArrayList<>(); - PropertySource ps = defaultPropertySources.get(sourceExpression); - if(ps==null){ - LOG.warning("No such property source provider found: " + sourceExpression); - } - result.add(ps); - return result; - } - - @Override - public String getKey() { - return "named:"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/ResourceDSLPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/ResourceDSLPropertySourceProvider.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/ResourceDSLPropertySourceProvider.java deleted file mode 100644 index 394562d..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/internal/ResourceDSLPropertySourceProvider.java +++ /dev/null @@ -1,82 +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.dsl.internal; - -import org.apache.tamaya.dsl.DSLFormatManager; -import org.apache.tamaya.format.ConfigurationData; -import org.apache.tamaya.format.ConfigurationFormat; -import org.apache.tamaya.resource.ConfigResources; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spisupport.MapPropertySource; -import org.apache.tamaya.staged.spi.DSLPropertySourceProvider; - -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * DSL provider implementation that allows to use registered {@link PropertySource} instances - * by matching {@link PropertySource#getName()} with the configured value and overriding the - * {@link PropertySource#getOrdinal()} method. - */ -public class ResourceDSLPropertySourceProvider implements DSLPropertySourceProvider{ - - private static final Logger LOG = Logger.getLogger(ResourceDSLPropertySourceProvider.class.getName()); - - @Override - public List<PropertySource> resolve(String sourceExpression, Map<String, PropertySource> defaultPropertySources) { - List<PropertySource> result = new ArrayList<>(); - List<URL> resources = new ArrayList<>(); - if(sourceExpression.contains("SUFFIX")) { - for (String suffix : DSLFormatManager.getInstance().getSuffixes()) { - Collection<URL> locations = ConfigResources.getResourceResolver().getResources(getClass().getClassLoader(), - sourceExpression.replace("SUFFIX", suffix)); - loadPropertySources(locations, result); - } - }else { - Collection<URL> locations = ConfigResources.getResourceResolver().getResources(getClass().getClassLoader(), - sourceExpression); - loadPropertySources(locations, result); - } - return result; - } - - private void loadPropertySources(Collection<URL> locations, List<PropertySource> result) { - for(URL url:locations){ - for(ConfigurationFormat format: DSLFormatManager.getInstance().getFormats()) { - try(InputStream is = url.openStream()){ - ConfigurationData data = format.readConfiguration(url.toString(),is); - result.add(new MapPropertySource(url.toString(), data.getCombinedProperties())); - }catch(Exception e){ - LOG.log(Level.FINEST, "Format failed: " + format.getName() + " for " + url, e); - } - } - } - } - - @Override - public String getKey() { - return "resource:"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/dsl/package-info.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/package-info.java b/metamodel-staged/src/main/java/org/apache/tamaya/dsl/package-info.java deleted file mode 100644 index 0b89d0d..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/dsl/package-info.java +++ /dev/null @@ -1,23 +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. - */ -/** - * Main package of the DSL module. Normally client code does not need access this package. - * But extensions also relying on the meta-data configuration mechanism may use it. - */ -package org.apache.tamaya.dsl; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java b/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java deleted file mode 100644 index 04a7359..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java +++ /dev/null @@ -1,121 +0,0 @@ -///* -// * Licensed to the Apache Software Foundation (ASF) under one or more -// * contributor license agreements. See the NOTICE file distributed with -// * this work for additional information regarding copyright ownership. -// * The ASF licenses this file to You under the Apache License, Version 2.0 -// * (the "License"); you may not use this file except in compliance with -// * the License. You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//package org.apache.tamaya.staged.spi; -// -// -//import org.apache.tamaya.ConfigException; -//import org.apache.tamaya.spi.PropertySource; -//import org.apache.tamaya.spi.PropertySourceProvider; -// -//import java.util.ArrayList; -//import java.util.Arrays; -//import java.util.Collection; -//import java.util.List; -//import java.util.logging.Logger; -// -///** -// * Implements a base property source provider that defines a multilayered -// * stage setup. -// */ -//public abstract class BaseStagedPropertySourceProvider implements PropertySourceProvider { -// -// /** The logger used. */ -// private static final Logger LOGGER = Logger.getLogger(BaseStagedPropertySourceProvider.class.getName()); -// -// /** the current environment stages in order of precedence (weakest first). */ -// private List<String> contextIds = new ArrayList<>(); -// -// /** Optional root context of the environment in the config tree. All entries loaded will be mapped into -// * this root conztext. -// */ -// private String rootContext; -// -// /** List of PropertySources evaluated and returned to the current ConfigurationContext on load. */ -// private List<PropertySource> propertySources = new ArrayList<>(); -// -// -// /** -// * Creates a new Environment provider, hereby using 10 for basePriority and priorityIncrease. -// * @param rootContext the environment target root context, e.g. ENV. or null -// * for not remapping the environment properties. -// * @param contextIds the context ids, that build up the environment. -// */ -// public BaseStagedPropertySourceProvider(String rootContext, -// String... contextIds) { -// this(rootContext, 10,10, contextIds); -// } -// /** -// * Creates a new Environment provider. -// * @param rootContext the environment target root context, e.g. ENV. or null -// * for not remapping the environment properties. -// * @param basePriority the base priority used for the weakest environment properties set. -// * @param priorityIncrease the value the property source's priority should be increased with each -// * environment context level added. -// * @param contextIds the context ids, that build up the environment. -// */ -// public BaseStagedPropertySourceProvider(String rootContext, int basePriority, int priorityIncrease, -// String... contextIds) { -// if (contextIds.length == 0) { -// throw new ConfigException("At least one environment context id must be defined."); -// } -// if (rootContext == null) { -// LOGGER.finest("No environment mapping is applied."); -// } -// this.rootContext = rootContext; -// this.contextIds.addAll(Arrays.asList(contextIds)); -// int priority = basePriority; -// for (String contextId : contextIds) { -// propertySources.addAll(loadStageProperties(rootContext, contextId, priority)); -// priority += priorityIncrease; -// } -// } -// -// /** -// * Method that loads the environment properties for the given contextId. -// * @param rootContext the root context, where entries read should be mapped to. -// * @param contextId the contextId. -// * @param priority the target priority the created PropertySource should have. This priority is -// * important, since it reflects the order as defined -// * when configuring this class. Therefore it should not be overridden normally. -// * @return the corresponding PrioritySources to be added, never null. -// */ -// protected abstract Collection<PropertySource> loadStageProperties( -// String rootContext, String contextId, int priority); -// -// /** -// * Get the environment context ids that define how this environment configuration -// * is setup, in order of their increasing priority. -// * @return the ordered list of context ids. -// */ -// public List<String> getContextIds() { -// return contextIds; -// } -// -// @Override -// public String toString() { -// return "EnvironmentPropertySourceProvider{" + -// "contextIds=" + contextIds + -// ", rootContext='" + rootContext + '\'' + -// '}'; -// } -// -// @Override -// public Collection<PropertySource> getPropertySources() { -// return propertySources; -// } -// -//} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/DSLPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/DSLPropertySourceProvider.java b/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/DSLPropertySourceProvider.java deleted file mode 100644 index 4482a5e..0000000 --- a/metamodel-staged/src/main/java/org/apache/tamaya/staged/spi/DSLPropertySourceProvider.java +++ /dev/null @@ -1,51 +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.staged.spi; - -import org.apache.tamaya.spi.PropertySource; - -import java.util.List; -import java.util.Map; - -/** - * Resolver to resolve/map DSL related source expressions into PropertySources - * loadable by a ConfigurationContext. Hereby the ordering of loaded property sources must be - * honored if possible by implicitly adapting/Overriding the default ordinal for the sources - * added. - */ -public interface DSLPropertySourceProvider { - - /** - * Resolve the given expression (without the key part). - * @param sourceExpression the source expression, not null. - * @param defaultPropertySources the default property sources that can be used as defined by the functionality by - * a resolver. - * @return the list of loaded Property sources, never null. - */ - List<PropertySource> resolve(String sourceExpression, - Map<String, PropertySource> defaultPropertySources); - - /** - * Get the resolver key, which identifiesan expression to be resolved by a resolver instance. - * As an example {@code "named:"} is the key for an expression {@code "named:sys-properties"}. - * The method {@link #resolve(String, Map)} will onyl receive the secoind part of the expression. - * @return identifying key. - */ - String getKey(); -}
