├── .gitignore
├── components
└── org.wso2.carbon.config
│ ├── src
│ ├── main
│ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ └── services
│ │ │ │ └── javax.annotation.processing.Processor
│ │ └── java
│ │ │ └── org
│ │ │ └── wso2
│ │ │ └── carbon
│ │ │ └── config
│ │ │ ├── ConfigurationException.java
│ │ │ ├── annotation
│ │ │ ├── Ignore.java
│ │ │ ├── Element.java
│ │ │ └── Configuration.java
│ │ │ ├── ConfigurationRuntimeException.java
│ │ │ ├── reader
│ │ │ ├── YAMLBasedConfigFileReader.java
│ │ │ ├── ConfigFileReader.java
│ │ │ └── YmlMerger.java
│ │ │ ├── ConfigConstants.java
│ │ │ ├── provider
│ │ │ ├── ConfigProvider.java
│ │ │ └── ImmutablePair.java
│ │ │ ├── ConfigurationProcessor.java
│ │ │ ├── internal
│ │ │ └── ConfigProviderComponent.java
│ │ │ ├── ConfigProviderFactory.java
│ │ │ └── ConfigurationUtils.java
│ └── test
│ │ ├── resources
│ │ ├── conf
│ │ │ ├── wso2carbon.jks
│ │ │ ├── master-keys.yaml
│ │ │ ├── secrets.properties
│ │ │ ├── envconfigoverridecomplex.yaml
│ │ │ ├── deployment.yaml
│ │ │ ├── envconfigwithoutdefaults.yaml
│ │ │ ├── invalidconfiguration.yaml
│ │ │ ├── systemconfigwithoutdefaults.yaml
│ │ │ ├── Example2.yaml
│ │ │ ├── envconfigoverrideuniqueelement.yaml
│ │ │ ├── envconfigoverridepriority.yaml
│ │ │ ├── Example.txt
│ │ │ ├── Example.xml
│ │ │ ├── Example.yaml
│ │ │ ├── envconfigoverride.yaml
│ │ │ ├── complexnamespaceconfig.yaml
│ │ │ └── sampledatasource.yaml
│ │ └── testng.xml
│ │ └── java
│ │ └── org
│ │ └── wso2
│ │ └── carbon
│ │ └── config
│ │ ├── configprovider
│ │ ├── BaseConfiguration.java
│ │ ├── ComplexNameSpaceConfiguration.java
│ │ ├── TestUtils.java
│ │ ├── BasicTestConfiguration.java
│ │ ├── PriorityTestConfiguration.java
│ │ ├── UniqueElementTestConfiguration.java
│ │ ├── TestTransportConfiguration2.java
│ │ ├── TestConfiguration.java
│ │ └── ConfigProviderFactoryTest.java
│ │ ├── utils
│ │ └── EnvironmentUtils.java
│ │ └── UtilsTest.java
│ └── pom.xml
├── docs
├── images
│ └── ConfigurationsViaEnvironmentVariables
│ │ ├── VarStructure.png
│ │ └── SysVarPriority.png
├── InstallingConfigFeature.md
└── ConfigurationsViaEnvironmentVariables.md
├── samples
├── config-provider
│ ├── standalone
│ │ ├── src
│ │ │ └── main
│ │ │ │ ├── resources
│ │ │ │ ├── conf
│ │ │ │ │ ├── master-keys.yaml
│ │ │ │ │ ├── secrets.properties
│ │ │ │ │ └── deployment.yaml
│ │ │ │ ├── security
│ │ │ │ │ └── wso2carbon.jks
│ │ │ │ └── log4j.properties
│ │ │ │ └── java
│ │ │ │ └── org
│ │ │ │ └── wso2
│ │ │ │ └── carbon
│ │ │ │ └── config
│ │ │ │ └── samples
│ │ │ │ └── standalone
│ │ │ │ └── Application.java
│ │ ├── assembly.xml
│ │ ├── README.md
│ │ └── pom.xml
│ └── osgi-bundle
│ │ ├── README.md
│ │ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── org
│ │ │ └── wso2
│ │ │ └── carbon
│ │ │ └── config
│ │ │ └── samples
│ │ │ └── bundle
│ │ │ ├── ChildConfiguration.java
│ │ │ ├── ParentConfiguration.java
│ │ │ └── internal
│ │ │ └── ConfigurationServiceComponent.java
│ │ └── pom.xml
└── config-generator
│ ├── src
│ └── main
│ │ └── java
│ │ └── org
│ │ └── wso2
│ │ └── carbon
│ │ └── config
│ │ └── samples
│ │ ├── ChildConfiguration.java
│ │ └── ParentConfiguration.java
│ ├── pom.xml
│ └── README.md
├── extensions
└── org.wso2.carbon.config.maven.plugin
│ ├── src
│ └── main
│ │ ├── resources
│ │ └── LICENSE.txt
│ │ └── java
│ │ └── org
│ │ └── wso2
│ │ └── carbon
│ │ └── config
│ │ └── maven
│ │ └── plugin
│ │ └── exceptions
│ │ └── ConfigurationMavenRuntimeException.java
│ └── pom.xml
├── issue_template.md
├── findbugs-exclude.xml
├── tests
├── org.wso2.carbon.config.test
│ ├── src
│ │ └── test
│ │ │ ├── resources
│ │ │ └── testng.xml
│ │ │ └── java
│ │ │ └── org
│ │ │ └── wso2
│ │ │ └── carbon
│ │ │ └── config
│ │ │ └── test
│ │ │ └── annotationprocessor
│ │ │ ├── TestConfiguration.java
│ │ │ └── AnnotationProcessorTest.java
│ └── pom.xml
└── org.wso2.carbon.config.test.coverage
│ └── pom.xml
├── pull_request_template.md
├── features
└── org.wso2.carbon.config.feature
│ └── pom.xml
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | .classpath
3 | .settings
4 | .project
5 | *.iml
6 | *.iws
7 | *.ipr
8 | .idea
9 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | org.wso2.carbon.config.ConfigurationProcessor
--------------------------------------------------------------------------------
/docs/images/ConfigurationsViaEnvironmentVariables/VarStructure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wso2/carbon-config/master/docs/images/ConfigurationsViaEnvironmentVariables/VarStructure.png
--------------------------------------------------------------------------------
/docs/images/ConfigurationsViaEnvironmentVariables/SysVarPriority.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wso2/carbon-config/master/docs/images/ConfigurationsViaEnvironmentVariables/SysVarPriority.png
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/wso2carbon.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wso2/carbon-config/master/components/org.wso2.carbon.config/src/test/resources/conf/wso2carbon.jks
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/master-keys.yaml:
--------------------------------------------------------------------------------
1 | permanent: true
2 | masterKeys:
3 | keyStorePassword: !!binary d3NvMmNhcmJvbg==
4 | privateKeyPassword: !!binary d3NvMmNhcmJvbg==
--------------------------------------------------------------------------------
/samples/config-provider/standalone/src/main/resources/conf/master-keys.yaml:
--------------------------------------------------------------------------------
1 | permanent: true
2 | masterKeys:
3 | keyStorePassword: !!binary d3NvMmNhcmJvbg==
4 | privateKeyPassword: !!binary d3NvMmNhcmJvbg==
--------------------------------------------------------------------------------
/samples/config-provider/standalone/src/main/resources/security/wso2carbon.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wso2/carbon-config/master/samples/config-provider/standalone/src/main/resources/security/wso2carbon.jks
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/secrets.properties:
--------------------------------------------------------------------------------
1 | wso2.sample.password1=plainText ABC@123
2 | wso2.sample.password2=cipherText SnBSWKjtZZOo0UsmOpPRhP6ZMNYTb80+BZHRDC/kxNT9ExcTswAbFjb/aip2KgQNaVuIT27UtrBaIv77Mb5sNPGiwyPrfajLNhSOlke2p8YmMkegx/mG2ytJhJa5j9iMGtCsbMt+SAf85v6kGIiH0gZA20qDZ9jnveT7/Ifz7v0\=
3 |
--------------------------------------------------------------------------------
/samples/config-provider/standalone/src/main/resources/conf/secrets.properties:
--------------------------------------------------------------------------------
1 | wso2.sample.password1=plainText ABC@123
2 | wso2.sample.password2=cipherText SnBSWKjtZZOo0UsmOpPRhP6ZMNYTb80+BZHRDC/kxNT9ExcTswAbFjb/aip2KgQNaVuIT27UtrBaIv77Mb5sNPGiwyPrfajLNhSOlke2p8YmMkegx/mG2ytJhJa5j9iMGtCsbMt+SAf85v6kGIiH0gZA20qDZ9jnveT7/Ifz7v0\=
3 |
--------------------------------------------------------------------------------
/samples/config-provider/standalone/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=info, stdout
2 |
3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5 |
6 | # Pattern to output the caller's file name and line number.
7 | log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
8 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/envconfigoverridecomplex.yaml:
--------------------------------------------------------------------------------
1 | basictestconfiguration:
2 | testBean:
3 | name: default
4 | complexTestBean:
5 | name: default
6 | testBean:
7 | name: default
8 |
9 | # BASICTESTCONFIGURATION_TESTBEAN_NAME="default"
10 | # BASICTESTCONFIGURATION_COMPLEXTESTBEAN_NAME="default"
11 | # BASICTESTCONFIGURATION_COMPLEXTESTBEAN_TESTBEAN_NAME="default"
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/deployment.yaml:
--------------------------------------------------------------------------------
1 | wso2.securevault:
2 | secretRepository:
3 | type: org.wso2.carbon.secvault.repository.DefaultSecretRepository
4 | parameters:
5 | privateKeyAlias: wso2carbon
6 | keystoreLocation: ${sys:keystore.file}
7 | secretPropertiesFile: ${sys:sec.prop.file}
8 | masterKeyReader:
9 | type: org.wso2.carbon.secvault.reader.DefaultMasterKeyReader
10 | parameters:
11 | masterKeyReaderFile: ${sys:master.key.file}
12 |
13 | testconfiguration:
14 | tenant: tenant
15 | transports:
16 | transport: #Transport with direct values
17 | - name: abc
18 | port: 8000
19 | secure: false
--------------------------------------------------------------------------------
/extensions/org.wso2.carbon.config.maven.plugin/src/main/resources/LICENSE.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) %s, WSO2 Inc. (http://www.wso2.org) All Rights Reserved
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the \"License\");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an \"AS IS\" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/envconfigwithoutdefaults.yaml:
--------------------------------------------------------------------------------
1 | testconfiguration:
2 | tenant: tenant
3 | transports:
4 | transport: #Transport with direct values
5 | - name: abc
6 | port: 8000
7 | secure: false
8 | desc: This transport will use 8000 as its port
9 | password: ${sec:conn.auth.password}
10 | - name: pqr
11 | port: ${env:pqr.http.port}
12 | secure: ${sys:pqr.secure}
13 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
14 | - name: xyz
15 | port: ${env:xyz.http.port}
16 | secure: ${sys:xyz.secure,true}
17 | desc: This transport will use ${env:xyz.http.port} as its port
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/invalidconfiguration.yaml:
--------------------------------------------------------------------------------
1 | testconfiguration1:
2 | tenant: tenant
3 | transports:
4 | transport: #Transport with direct values
5 | - name: abc
6 | port: 8000
7 | secure: false
8 | desc: This transport will use 8000 as its port
9 | password: ${sec:conn.auth.password}
10 | - name: pqr
11 | port: ${env:pqr.http.port}
12 | secure: ${sys:pqr.secure}
13 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
14 | - name: xyz
15 | port: ${env:xyz.http.port,9000}
16 | secure: ${sys:xyz.secure,true}
17 | desc: This transport will use ${env:xyz.http.port,8888} as its port
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/systemconfigwithoutdefaults.yaml:
--------------------------------------------------------------------------------
1 | testconfiguration:
2 | tenant: tenant
3 | transports:
4 | transport: #Transport with direct values
5 | - name: abc
6 | port: 8000
7 | secure: false
8 | desc: This transport will use 8000 as its port
9 | password: ${sec:conn.auth.password}
10 | - name: pqr
11 | port: ${env:pqr.http.port}
12 | secure: ${sys:pqr.secure}
13 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
14 | - name: xyz
15 | port: ${env:xyz.http.port,9000}
16 | secure: ${sys:xyz.secure}
17 | desc: This transport will use ${env:xyz.http.port,8888} as its port
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/Example2.yaml:
--------------------------------------------------------------------------------
1 | testTransports:
2 | - testTransport:
3 | name: abc
4 | port: 9090
5 | secure: true
6 | desc: This transport will use 8000 as its port
7 | password: ${sec:conn.auth.password}
8 | - testTransport:
9 | name: pqrs
10 | port: ${env:pqr.http.port}
11 | secure: ${sys:pqr.secure}
12 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
13 | - testTransport:
14 | name: xyz
15 | port: ${env:xyz.http.port,9000}
16 | secure: ${sys:xyz.secure,true}
17 | desc: This transport will use ${env:xyz.http.port,8888} as its port
18 |
19 | nonamespace.configuration:
20 | name: transport
21 | testBean:
22 | id: 30
--------------------------------------------------------------------------------
/issue_template.md:
--------------------------------------------------------------------------------
1 | **Description:**
2 |
3 |
4 | **Suggested Labels:**
5 |
6 |
7 | **Suggested Assignees:**
8 |
9 |
10 | **Affected Product Version:**
11 |
12 | **OS, DB, other environment details and versions:**
13 |
14 | **Steps to reproduce:**
15 |
16 |
17 | **Related Issues:**
18 |
--------------------------------------------------------------------------------
/findbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/envconfigoverrideuniqueelement.yaml:
--------------------------------------------------------------------------------
1 | uniqueelementtestconfiguration:
2 | uniqueElementTestBeans:
3 | uniqueElementTestBeanList:
4 | - uniqueElement: abc
5 | port: 8000
6 | - uniqueElement: pqr
7 | port: 9000
8 | - uniqueElement: xyz
9 | port: 7000
10 |
11 | # UNIQUEELEMENTTESTCONFIGURATION_UNIQUEELEMENTTESTBEANS_UNIQUEELEMENTTESTBEANLIST_0_UNIQUEELEMENT="abc"
12 | # UNIQUEELEMENTTESTCONFIGURATION_UNIQUEELEMENTTESTBEANS_UNIQUEELEMENTTESTBEANLIST_0_PORT="8000"
13 |
14 | # UNIQUEELEMENTTESTCONFIGURATION_UNIQUEELEMENTTESTBEANS_UNIQUEELEMENTTESTBEANLIST_1_UNIQUEELEMENT="pqr"
15 | # UNIQUEELEMENTTESTCONFIGURATION_UNIQUEELEMENTTESTBEANS_UNIQUEELEMENTTESTBEANLIST_1_PORT="9000"
16 |
17 | # UNIQUEELEMENTTESTCONFIGURATION_UNIQUEELEMENTTESTBEANS_UNIQUEELEMENTTESTBEANLIST_2_UNIQUEELEMENT="xyz"
18 | # UNIQUEELEMENTTESTCONFIGURATION_UNIQUEELEMENTTESTBEANS_UNIQUEELEMENTTESTBEANLIST_2_PORT="7000"
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/envconfigoverridepriority.yaml:
--------------------------------------------------------------------------------
1 | prioritytestconfiguration:
2 | testBeans:
3 | testBeanList:
4 | - name: abc
5 | id: 1
6 | port: 8000
7 | - name: pqr
8 | id: 2
9 | port: ${env:pqr.http.port}
10 | - name: xyz
11 | id: 3
12 | port: ${env:xyz.http.port,9000}
13 |
14 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_0_NAME="abc"
15 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_0_ID="1"
16 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_0_PORT="8000"
17 |
18 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_1_NAME="pqr"
19 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_1_ID="2"
20 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_1_PORT="${env:pqr.http.port}"
21 |
22 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_2_NAME="xyz"
23 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_2_ID="3"
24 | # PRIORITYTESTCONFIGURATION_TESTBEANS_TESTBEANLIST_2_PORT="${env:xyz.http.port,9000}"
--------------------------------------------------------------------------------
/tests/org.wso2.carbon.config.test/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/samples/config-provider/standalone/assembly.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | jar-with-dependencies
19 |
20 | jar
21 |
22 | false
23 |
24 |
25 | /
26 | true
27 | runtime
28 |
29 |
30 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/Example.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | tenant
4 |
5 |
6 |
7 | abc
8 | 8000
9 | This transport will use 8000 as its port
10 | ${sec:conn.auth.password}
11 |
12 |
13 |
14 | pqr
15 | ${env:pqr.http.port}
16 | This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
17 |
18 |
19 |
20 | xyz
21 | ${sys:xyz.http.port,9000}
22 | This transport will use ${env:xyz.http.port,8888} as its port
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/Example.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | tenant
4 |
5 |
6 |
7 | abc
8 | 8000
9 | This transport will use 8000 as its port
10 | ${sec:conn.auth.password}
11 |
12 |
13 |
14 | pqr
15 | ${env:pqr.http.port}
16 | This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
17 |
18 |
19 |
20 | xyz
21 | ${sys:xyz.http.port,9000}
22 | This transport will use ${env:xyz.http.port,8888} as its port
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/ConfigurationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config;
17 |
18 | /**
19 | * ConfigurationException throws when server cannot provide the configuration.
20 | *
21 | * @since 1.0.0
22 | */
23 | public class ConfigurationException extends Exception {
24 |
25 | public ConfigurationException(String message) {
26 | super(message);
27 | }
28 |
29 | public ConfigurationException(String message, Throwable cause) {
30 | super(message, cause);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/extensions/org.wso2.carbon.config.maven.plugin/src/main/java/org/wso2/carbon/config/maven/plugin/exceptions/ConfigurationMavenRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.maven.plugin.exceptions;
19 |
20 | /**
21 | * Exception class to interpret runtime exceptions when preparing the configuration.
22 | *
23 | * @since 1.0.0
24 | */
25 | public class ConfigurationMavenRuntimeException extends RuntimeException {
26 |
27 | public ConfigurationMavenRuntimeException(String message, Throwable cause) {
28 | super(message, cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/annotation/Ignore.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.annotation;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Field level annotation for configuration tool.
25 | * annotated fields will not go to the configuration file.
26 | *
27 | * @since 1.0.0
28 | */
29 | @Retention(RetentionPolicy.RUNTIME)
30 | @Target(ElementType.FIELD)
31 | public @interface Ignore {
32 | }
33 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/ConfigurationRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config;
19 |
20 | /**
21 | * Configuration runtime exception when error on providing configuration during the runtime.
22 | *
23 | * @since 1.0.0
24 | */
25 | public class ConfigurationRuntimeException extends RuntimeException {
26 |
27 | public ConfigurationRuntimeException(String message) {
28 | super(message);
29 | }
30 |
31 | public ConfigurationRuntimeException(String message, Throwable cause) {
32 | super(message, cause);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/annotation/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.annotation;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Field level annotation for configuration tool.
25 | * description : required, field comment
26 | * required : optional, only for the required field
27 | *
28 | * @since 1.0.0
29 | */
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Target(ElementType.FIELD)
32 | public @interface Element {
33 | // field description, required
34 | String description();
35 |
36 | boolean required() default false;
37 | }
38 |
--------------------------------------------------------------------------------
/samples/config-provider/standalone/README.md:
--------------------------------------------------------------------------------
1 | # Carbon Configuration - OSGi Sample
2 |
3 | ### Building the configuration
4 |
5 | Navigate to [Config Generator Sample](../config-generator)
6 | and [Config Standalone Sample](/) locations respectively and execute the command
7 | below:
8 |
9 | ```bash
10 | mvn clean install
11 | ```
12 |
13 | ### Running the sample
14 |
15 | * Navigate to [Target folder](/target)
16 | * Execute `java -jar provider-standalone-{version}.jar
17 | `
18 |
19 | Now you will notice the `Parent configuration - name : WSO2, value : 10, childConfiguration - destination : destination-name, isEnabled : false`
20 | log message.
21 |
22 | You can override the parent configuration values using the deployment.yaml configuration.
23 | In order to do so add the configurations you want to change under the `"wso2.configuration"`
24 | namespace is deployment.yaml.
25 |
26 | **Example deployment.yaml**
27 |
28 | ```yaml
29 | # Carbon Configuration Parameters
30 | wso2.carbon:
31 | # value to uniquely identify a server
32 | id: carbon-kernel
33 | # server name
34 | name: WSO2 Carbon Kernel
35 | # ports used by this server
36 | ports:
37 | # port offset
38 | offset: 0
39 |
40 | wso2.configuration:
41 | name: "SomeName"
42 | ```
43 |
44 | The above configuration will give the below output:
45 | `Parent configuration - name : SomeName, value : 10, childConfiguration - destination : destination-name, isEnabled : false`
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/Example.yaml:
--------------------------------------------------------------------------------
1 | testconfiguration:
2 | tenant: tenant
3 | transports:
4 | transport: #Transport with direct values
5 | - name: abc
6 | port: 8000
7 | secure: false
8 | desc: This transport will use 8000 as its port
9 | password: ${sec:conn.auth.password}
10 | - name: pqr
11 | port: ${env:pqr.http.port}
12 | secure: ${sys:pqr.secure}
13 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
14 | - name: xyz
15 | port: ${env:xyz.http.port,9000}
16 | secure: ${sys:xyz.secure,true}
17 | desc: This transport will use ${env:xyz.http.port,8888} as its port
18 |
19 | testconfiguration.v2:
20 | tenant: tenant
21 | transports:
22 | transport: #Transport with direct values
23 | - name: abc
24 | port: 9090
25 | secure: true
26 | desc: This transport will use 8000 as its port
27 | password: ${sec:conn.auth.password}
28 | - name: pqrs
29 | port: ${env:pqr.http.port}
30 | secure: ${sys:pqr.secure}
31 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
32 | - name: xyz
33 | port: ${env:xyz.http.port,9000}
34 | secure: ${sys:xyz.secure,true}
35 | desc: This transport will use ${env:xyz.http.port,8888} as its port
36 |
37 | nonamespace.configuration:
38 | name: transport
39 | testBean:
40 | id: 30
41 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/BaseConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.configprovider;
17 |
18 | /**
19 | * Sample configuration class for testing purposes.
20 | *
21 | * This is to test generating configuration for beans without namespace.
22 | *
23 | * @since 2.1.3
24 | */
25 | public class BaseConfiguration {
26 | private String name = "test";
27 | private BaseTestBean testBean = new BaseTestBean();
28 |
29 | public String getName() {
30 | return name;
31 | }
32 |
33 | public BaseTestBean getTestBean() {
34 | return testBean;
35 | }
36 | }
37 |
38 | /**
39 | * Sample configuration class for testing purposes.
40 | */
41 | class BaseTestBean {
42 | private int id = 20;
43 |
44 | public int getId() {
45 | return id;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/config-provider/osgi-bundle/README.md:
--------------------------------------------------------------------------------
1 | # Carbon Configuration - OSGi Bundle Sample
2 |
3 | ### Building the configuration
4 |
5 | Navigate to [Config OSGi Sample](/) location and execute the command
6 | below:
7 |
8 | ```bash
9 | mvn clean install
10 | ```
11 |
12 | ### Running the sample
13 |
14 | * Download Carbon Kernel 5.2.0 from [http://wso2.com/products/carbon/](http://wso2.com/products/carbon/)
15 | * Copy provider-bundle-{version}.jar in [Config OSGi Sample](/target) to /lib location
16 | * Start the WSO2 Carbon Server by executing /bin/carbon.sh script
17 |
18 | Now you will notice the `Parent configuration - name : WSO2, value : 10, childConfiguration - destination : destination-name, isEnabled : false`
19 | log message.
20 |
21 | You can override the parent configuration values using the deployment.yaml configuration. In order to do so add the
22 | configurations you want to change under the `"wso2.configuration"` namespace is deployment.yaml.
23 |
24 | **Example deployment.yaml**
25 |
26 | ```yaml
27 | # Carbon Configuration Parameters
28 | wso2.carbon:
29 | # value to uniquely identify a server
30 | id: carbon-kernel
31 | # server name
32 | name: WSO2 Carbon Kernel
33 | # ports used by this server
34 | ports:
35 | # port offset
36 | offset: 0
37 |
38 | wso2.configuration:
39 | name: "SomeName"
40 | ```
41 |
42 | The above configuration will give the below output:
43 | `Parent configuration - name : SomeName, value : 10, childConfiguration - destination : destination-name, isEnabled : false`
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/annotation/Configuration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.annotation;
17 |
18 | import org.wso2.carbon.config.ConfigConstants;
19 |
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * Class level annotation for configuration tool.
27 | * namespace : optional, required only for root configuration classes
28 | * description : required, field comment
29 | *
30 | * @since 1.0.0
31 | */
32 | @Retention(RetentionPolicy.RUNTIME)
33 | @Target(ElementType.TYPE)
34 | public @interface Configuration {
35 |
36 | // needed only for root configuration bean
37 | String namespace() default ConfigConstants.NULL;
38 |
39 | // field description, required
40 | String description();
41 | }
42 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/reader/YAMLBasedConfigFileReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.reader;
17 |
18 | import org.wso2.carbon.config.ConfigurationException;
19 | import org.wso2.carbon.config.ConfigurationUtils;
20 |
21 | import java.nio.file.Path;
22 | import java.util.Map;
23 |
24 | /**
25 | * This class takes care of parsing the deployment.yaml file and creating the deployment configuration table.
26 | *
27 | * @since 1.0.0
28 | */
29 | public class YAMLBasedConfigFileReader extends ConfigFileReader {
30 |
31 | public YAMLBasedConfigFileReader(Path configurationFilePath) {
32 | super(configurationFilePath);
33 | }
34 |
35 | @Override
36 | public Map getDeploymentConfiguration() throws ConfigurationException {
37 | String yamlFileString = getFileContent();
38 | return ConfigurationUtils.getDeploymentConfigMap(yamlFileString);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/config-provider/standalone/src/main/resources/conf/deployment.yaml:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the \"License\");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an \"AS IS\" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | ################################################################################
16 |
17 | # Carbon Configuration Parameters
18 | wso2.carbon:
19 | # value to uniquely identify a server
20 | id: carbon-kernel
21 | # server name
22 | name: WSO2 Carbon Kernel
23 | # ports used by this server
24 | ports:
25 | # port offset
26 | offset: 0
27 |
28 | wso2.securevault:
29 | secretRepository:
30 | type: org.wso2.carbon.secvault.repository.DefaultSecretRepository
31 | parameters:
32 | privateKeyAlias: wso2carbon
33 | keystoreLocation: resources/security/wso2carbon.jks
34 | secretPropertiesFile: resources/conf/secrets.properties
35 | masterKeyReader:
36 | type: org.wso2.carbon.secvault.reader.DefaultMasterKeyReader
37 | parameters:
38 | masterKeyReaderFile: resources/conf/master-keys.yaml
39 |
--------------------------------------------------------------------------------
/docs/InstallingConfigFeature.md:
--------------------------------------------------------------------------------
1 | # Installing Configuration Provider Feature in OSGi
2 |
3 | Configuration Provider feature is depends on **carbon-secvault** feature and **carbon-utils** feature. If we need to install
4 | configuration provider feature, referred P2 repository needs to have both carbon-secvault feature and carbon-utils
5 | feature. So when we are generating P2 repository, we need to add features as below.
6 |
7 | ````xml
8 |
9 | org.wso2.carbon.maven
10 | carbon-feature-plugin
11 |
12 |
13 | p2-repo-generation
14 | package
15 |
16 | generate-repo
17 |
18 |
19 | file:${basedir}/target/p2-repo
20 |
21 |
22 | org.wso2.carbon.config.feature
23 | ${carbon.config.version}
24 |
25 |
26 | org.wso2.carbon.secvault.feature
27 | ${carbon.securevault.version}
28 |
29 |
30 | org.wso2.carbon.utils.feature
31 | ${carbon.utils.version}
32 |
33 |
34 |
35 |
36 | ...
37 |
38 |
39 | ````
40 |
41 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/envconfigoverride.yaml:
--------------------------------------------------------------------------------
1 | testconfiguration:
2 | tenant: tenant
3 | transports:
4 | transport: #Transport with direct values
5 | - name: abc
6 | port: 8000
7 | secure: false
8 | desc: This transport will use 8000 as its port
9 | password: ${sec:conn.auth.password}
10 | - name: pqr
11 | port: ${env:pqr.http.port}
12 | secure: ${sys:pqr.secure}
13 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
14 | - name: xyz
15 | port: ${env:xyz.http.port,9000}
16 | secure: ${sys:xyz.secure,true}
17 | desc: This transport will use ${env:xyz.http.port,8888} as its port
18 |
19 | # TESTCONFIGURATION_TENANT="tenant"
20 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_NAME="abc"
21 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_PORT="8000"
22 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_SECURE="false"
23 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_DESC="This transport will use 8000 as its port"
24 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_PASSWORD="${sec:conn.auth.password}"
25 |
26 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_NAME="pqr"
27 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_PORT="${env:pqr.http.port}"
28 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_SECURE="${sys:pqr.secure}"
29 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_DESC="This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}"
30 |
31 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_NAME="xyz"
32 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_PORT="${env:xyz.http.port,9000}"
33 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_SECURE="${sys:xyz.secure,true}"
34 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_DESC="This transport will use ${env:xyz.http.port,8888} as its port"
--------------------------------------------------------------------------------
/samples/config-provider/osgi-bundle/src/main/java/org/wso2/carbon/config/samples/bundle/ChildConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.samples.bundle;
19 |
20 | import org.wso2.carbon.config.annotation.Configuration;
21 | import org.wso2.carbon.config.annotation.Element;
22 |
23 | import java.util.Locale;
24 |
25 | /**
26 | * Child configuration of the {@link ParentConfiguration}.
27 | *
28 | * since 1.0.0
29 | */
30 | @Configuration(description = "Child configuration")
31 | public class ChildConfiguration {
32 |
33 | @Element(description = "A boolean field")
34 | private boolean isEnabled = false;
35 |
36 | @Element(description = "A string field")
37 | private String destination = "destination-name";
38 |
39 | public boolean isEnabled() {
40 | return isEnabled;
41 | }
42 |
43 | public String getDestination() {
44 | return destination;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return String.format(Locale.ENGLISH, "destination : %s, isEnabled : %s",
50 | destination, isEnabled);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/complexnamespaceconfig.yaml:
--------------------------------------------------------------------------------
1 | wso2.test.config:
2 | tenant: tenant
3 | transports:
4 | transport: #Transport with direct values
5 | - name: abc
6 | port: 8000
7 | secure: false
8 | desc: This transport will use 8000 as its port
9 | password: ${sec:conn.auth.password}
10 | - name: pqr
11 | port: ${env:pqr.http.port}
12 | secure: ${sys:pqr.secure}
13 | desc: This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}
14 | - name: xyz
15 | port: ${env:xyz.http.port,9000}
16 | secure: ${sys:xyz.secure,true}
17 | desc: This transport will use ${env:xyz.http.port,8888} as its port
18 |
19 | # TESTCONFIGURATION_TENANT="tenant"
20 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_NAME="abc"
21 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_PORT="8000"
22 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_SECURE="false"
23 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_DESC="This transport will use 8000 as its port"
24 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_0_PASSWORD="${sec:conn.auth.password}"
25 |
26 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_NAME="pqr"
27 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_PORT="${env:pqr.http.port}"
28 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_SECURE="${sys:pqr.secure}"
29 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_1_DESC="This transport will use ${env:pqr.http.port} as its port. Secure - ${sys:pqr.secure}"
30 |
31 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_NAME="xyz"
32 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_PORT="${env:xyz.http.port,9000}"
33 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_SECURE="${sys:xyz.secure,true}"
34 | # TESTCONFIGURATION_TRANSPORTS_TRANSPORT_2_DESC="This transport will use ${env:xyz.http.port,8888} as its port"
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/ComplexNameSpaceConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | *
18 | */
19 | package org.wso2.carbon.config.configprovider;
20 |
21 | import org.wso2.carbon.config.annotation.Configuration;
22 |
23 | import javax.xml.bind.annotation.XmlElement;
24 | import javax.xml.bind.annotation.XmlRootElement;
25 |
26 | /**
27 | * Sample configuration class for testing purposes.
28 | *
29 | * @since 1.0.0
30 | */
31 | @XmlRootElement(name = "testconfiguration")
32 | @Configuration(namespace = "wso2.test.config", description = "Test Configurations Bean")
33 | public class ComplexNameSpaceConfiguration {
34 |
35 | private String tenant = "default";
36 | private Transports transports = new Transports();
37 |
38 | @XmlElement
39 | public void setTenant(String tenant) {
40 | this.tenant = tenant;
41 | }
42 |
43 | public String getTenant() {
44 | return tenant;
45 | }
46 |
47 | @XmlElement
48 | public void setTransports(Transports transports) {
49 | this.transports = transports;
50 | }
51 |
52 | public Transports getTransports() {
53 | return transports;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tests/org.wso2.carbon.config.test/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | carbon-config
20 | org.wso2.carbon.config
21 | 2.1.18-SNAPSHOT
22 | ../../pom.xml
23 |
24 | 4.0.0
25 | org.wso2.carbon.config.test
26 | Carbon Configuration Tests
27 | jar
28 | http://wso2.com
29 |
30 |
31 | org.testng
32 | testng
33 |
34 |
35 | org.wso2.carbon.config
36 | org.wso2.carbon.config
37 |
38 |
39 | commons-io.wso2
40 | commons-io
41 | test
42 |
43 |
44 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/ConfigConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config;
17 |
18 | /**
19 | * Configuration Constants.
20 | *
21 | * @since 1.0.0
22 | */
23 | public final class ConfigConstants {
24 |
25 | public static final String NULL = "NULL";
26 | public static final String TEMP_CONFIG_FILE_NAME = "temp_config_classnames.txt";
27 | public static final String CONFIG_DIR = "config-docs";
28 | public static final String DEPLOYMENT_CONFIG_YAML = "deployment.yaml";
29 | public static final String SYSTEM_PROPERTY_DOC_GENERATION = "config.doc.generation";
30 | public static final String CURRENT_DIRECTORY = "currentDirectory";
31 |
32 | /**
33 | * Maven project properties.
34 | */
35 | public static final String PROJECT_DEFAULTS_PROPERTY_FILE = "project.defaults.properties";
36 |
37 | /**
38 | * Default value if it is not set in sys prop/env.
39 | */
40 | public static class PlaceHolders {
41 | public static final String SERVER_KEY = "carbon-kernel";
42 | public static final String SERVER_NAME = "WSO2 Carbon Kernel";
43 | public static final String SERVER_VERSION = "5";
44 |
45 | private PlaceHolders() {
46 | }
47 | }
48 |
49 | private ConfigConstants() {
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/samples/config-generator/src/main/java/org/wso2/carbon/config/samples/ChildConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.samples;
19 |
20 | import org.wso2.carbon.config.annotation.Configuration;
21 | import org.wso2.carbon.config.annotation.Element;
22 |
23 | import java.util.Locale;
24 |
25 | /**
26 | * Child configuration of the {@link ParentConfiguration}.
27 | * Don't need to specify the namespace in child configuration class, since the configuration is a part of the
28 | * ParentConfiguration.
29 | * Specifying the namespace will break this configuration to a separate configuration segment under specified namespace
30 | *
31 | * since 1.0.0
32 | */
33 | @Configuration(description = "Child configuration")
34 | public class ChildConfiguration {
35 |
36 | @Element(description = "A boolean field")
37 | private boolean isEnabled = false;
38 |
39 | @Element(description = "A string field")
40 | private String destination = "destination-name";
41 |
42 | public boolean isEnabled() {
43 | return isEnabled;
44 | }
45 |
46 | public String getDestination() {
47 | return destination;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return String.format(Locale.ENGLISH, "destination : %s, isEnabled : %s",
53 | destination, isEnabled);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/TestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.configprovider;
19 |
20 |
21 | import java.net.URL;
22 | import java.nio.file.Path;
23 | import java.nio.file.Paths;
24 | import java.util.Optional;
25 |
26 | /**
27 | * Class containing common methods required for testing.
28 | *
29 | * @since 2.0.0
30 | */
31 | public class TestUtils {
32 | private static final String OS_NAME_KEY = "os.name";
33 | private static final String WINDOWS_PARAM = "indow";
34 |
35 | /**
36 | * Get the path of a provided resource.
37 | *
38 | * @param resourcePaths path strings to the location of the resource
39 | * @return path of the resources
40 | */
41 | public static Optional getResourcePath(String... resourcePaths) {
42 | URL resourceURL = TestUtils.class.getClassLoader().getResource("");
43 | if (resourceURL != null) {
44 | String resourcePath = resourceURL.getPath();
45 | if (resourcePath != null) {
46 | resourcePath = System.getProperty(OS_NAME_KEY).contains(WINDOWS_PARAM) ?
47 | resourcePath.substring(1) : resourcePath;
48 | return Optional.ofNullable(Paths.get(resourcePath, resourcePaths));
49 | }
50 | }
51 | return Optional.empty(); // Resource do not exist
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/samples/config-provider/osgi-bundle/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | carbon-config
20 | org.wso2.carbon.config
21 | 2.1.18-SNAPSHOT
22 | ../../../pom.xml
23 |
24 | 4.0.0
25 | provider-bundle
26 | Carbon Configuration OSGi Sample
27 | bundle
28 | http://wso2.com
29 |
30 |
31 | org.wso2.carbon.config
32 | org.wso2.carbon.config
33 |
34 |
35 | org.slf4j
36 | slf4j-api
37 |
38 |
39 |
40 |
41 | org.wso2.carbon.config.samples.bundle.*;version="${carbon.config.version}"
42 |
43 |
44 | org.wso2.carbon.config.*;version="${carbon.config.package.import.version.range}",
45 | org.slf4j.*;version="${slf4j.logging.package.import.version.range}",
46 | org.osgi.framework.*;version="${osgi.framework.package.import.version.range}"
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/samples/config-generator/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | carbon-config
20 | org.wso2.carbon.config
21 | 2.1.18-SNAPSHOT
22 | ../../pom.xml
23 |
24 | 4.0.0
25 | config-generator
26 | Carbon Configuration Document Generation Sample
27 | jar
28 | http://wso2.com
29 |
30 |
31 | org.wso2.carbon.config
32 | org.wso2.carbon.config
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.wso2.carbon.config
41 | org.wso2.carbon.config.maven.plugin
42 | ${carbon.config.version}
43 |
44 |
45 |
46 | create-doc
47 |
48 | compile
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/samples/config-generator/src/main/java/org/wso2/carbon/config/samples/ParentConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.samples;
19 |
20 | import org.wso2.carbon.config.annotation.Configuration;
21 | import org.wso2.carbon.config.annotation.Element;
22 | import org.wso2.carbon.config.annotation.Ignore;
23 |
24 | import java.util.Locale;
25 |
26 | /**
27 | * Parent configuration class.
28 | *
29 | * @since 1.0.0
30 | */
31 | @Configuration(namespace = "wso2.configuration", description = "Parent configuration")
32 | public class ParentConfiguration {
33 |
34 | @Element(description = "An example element for this configuration")
35 | private String name = "WSO2";
36 |
37 | @Element(description = "Another example element in the config", required = true)
38 | private int value = 10;
39 |
40 | // This value will not be visible in the configuration
41 | @Ignore
42 | private String ignored = "Ignored String";
43 |
44 | @Element(description = "Second level configuration")
45 | private ChildConfiguration childConfiguration = new ChildConfiguration();
46 |
47 | public String getName() {
48 | return name;
49 | }
50 |
51 | public int getValue() {
52 | return value;
53 | }
54 |
55 | public String getIgnored() {
56 | return ignored;
57 | }
58 |
59 | public ChildConfiguration getChildConfiguration() {
60 | return childConfiguration;
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | return String.format(Locale.ENGLISH, "name : %s, value : %s, childConfiguration - %s",
66 | name, value, childConfiguration);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/samples/config-provider/osgi-bundle/src/main/java/org/wso2/carbon/config/samples/bundle/ParentConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.samples.bundle;
19 |
20 | import org.wso2.carbon.config.annotation.Configuration;
21 | import org.wso2.carbon.config.annotation.Element;
22 | import org.wso2.carbon.config.annotation.Ignore;
23 |
24 | import java.util.Locale;
25 |
26 | /**
27 | * Parent configuration class.
28 | *
29 | * @since 1.0.0
30 | */
31 | @Configuration(namespace = "wso2.configuration", description = "Parent configuration")
32 | public class ParentConfiguration {
33 |
34 | @Element(description = "An example element for this configuration")
35 | private String name = "WSO2";
36 |
37 | @Element(description = "Another example element in the config", required = true)
38 | private int value = 10;
39 |
40 | // This value will not be visible in the configuration
41 | @Ignore
42 | private String ignored = "Ignored String";
43 |
44 | @Element(description = "Second level configuration")
45 | private ChildConfiguration childConfiguration = new ChildConfiguration();
46 |
47 | public String getName() {
48 | return name;
49 | }
50 |
51 | public int getValue() {
52 | return value;
53 | }
54 |
55 | public String getIgnored() {
56 | return ignored;
57 | }
58 |
59 | public ChildConfiguration getChildConfiguration() {
60 | return childConfiguration;
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | return String.format(Locale.ENGLISH, "name : %s, value : %s, childConfiguration - %s",
66 | name, value, childConfiguration);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.
3 |
4 | ## Goals
5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above
6 |
7 | ## Approach
8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.
9 |
10 | ## User stories
11 | > Summary of user stories addressed by this change>
12 |
13 | ## Release note
14 | > Brief description of the new feature or bug fix as it will appear in the release notes
15 |
16 | ## Documentation
17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact
18 |
19 | ## Training
20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable
21 |
22 | ## Certification
23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.
24 |
25 | ## Marketing
26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable
27 |
28 | ## Automation tests
29 | - Unit tests
30 | > Code coverage information
31 | - Integration tests
32 | > Details about the test cases and coverage
33 |
34 | ## Security checks
35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no
36 | - Ran FindSecurityBugs plugin and verified report? yes/no
37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no
38 |
39 | ## Samples
40 | > Provide high-level details about the samples related to this feature
41 |
42 | ## Related PRs
43 | > List any other related PRs
44 |
45 | ## Migrations (if applicable)
46 | > Describe migration steps and platforms on which migration has been tested
47 |
48 | ## Test environment
49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested
50 |
51 | ## Learning
52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/resources/conf/sampledatasource.yaml:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the \"License\");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an \"AS IS\" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | ################################################################################
16 |
17 | # Data Sources Configuration
18 | wso2.datasources:
19 | - name: WSO2_CARBON_DB
20 | description: The datasource used for registry and user manager
21 | # JNDI mapping of a data source
22 | jndiConfig:
23 | # JNDI name
24 | # THIS IS A MANDATORY FIELD
25 | name: jdbc/WSO2CarbonDB/test
26 | # JNDI Reference Flag
27 | useJndiReference: true
28 | # data source definition
29 | definition:
30 | # data source type
31 | # THIS IS A MANDATORY FIELD
32 | type: RDBMS
33 | # data source configuration
34 | configuration:
35 | jdbcUrl: 'jdbc:h2:./target/database/TEST_DB1;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000'
36 | username: wso2carbon
37 | password: wso2carbon
38 | driverClassName: org.h2.Driver
39 | maxPoolSize: 50
40 | idleTimeout: 60000
41 | connectionTestQuery: SELECT 1
42 | validationTimeout: 30000
43 | isAutoCommit: false
44 | - name: WSO2_ANALYTICS_DB
45 | description: The datasource used for registry and user manager
46 | # JNDI mapping of a data source
47 | jndiConfig:
48 | # JNDI name
49 | # THIS IS A MANDATORY FIELD
50 | name: jdbc/WSO2CarbonDB/testDb2
51 | # JNDI Reference Flag
52 | useJndiReference: true
53 | definition:
54 | # data source type
55 | # THIS IS A MANDATORY FIELD
56 | type: RDBMS
57 | # data source configuration
58 | configuration:
59 | jdbcUrl: 'jdbc:h2:./target/database/ANALYTICS_DB1;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000'
60 | username: wso2carbon
61 | password: wso2carbon
62 | driverClassName: org.h2.Driver
63 | maxPoolSize: 50
64 | idleTimeout: 60000
65 | connectionTestQuery: SELECT 1
66 | validationTimeout: 30000
67 | isAutoCommit: false
68 |
69 |
--------------------------------------------------------------------------------
/samples/config-provider/osgi-bundle/src/main/java/org/wso2/carbon/config/samples/bundle/internal/ConfigurationServiceComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.samples.bundle.internal;
19 |
20 | import org.osgi.service.component.annotations.Activate;
21 | import org.osgi.service.component.annotations.Component;
22 | import org.osgi.service.component.annotations.Reference;
23 | import org.osgi.service.component.annotations.ReferenceCardinality;
24 | import org.osgi.service.component.annotations.ReferencePolicy;
25 | import org.slf4j.Logger;
26 | import org.slf4j.LoggerFactory;
27 | import org.wso2.carbon.config.ConfigurationException;
28 | import org.wso2.carbon.config.provider.ConfigProvider;
29 | import org.wso2.carbon.config.samples.bundle.ParentConfiguration;
30 |
31 | /**
32 | * Declarative service component used with the example configuration bundle.
33 | */
34 | @Component(
35 | name = "org.wso2.carbon.config.samples.bundle.internal.ConfigurationServiceComponent",
36 | immediate = true
37 | )
38 | public class ConfigurationServiceComponent {
39 |
40 | private static final Logger logger = LoggerFactory
41 | .getLogger(ConfigurationServiceComponent.class);
42 | private ConfigProvider configProvider;
43 |
44 | @Activate
45 | public void start() throws ConfigurationException {
46 | ParentConfiguration parentConfiguration = configProvider
47 | .getConfigurationObject(ParentConfiguration.class);
48 | logger.info("Parent configuration - {}", parentConfiguration);
49 | }
50 |
51 | @Reference(
52 | name = "carbon.config.provider",
53 | service = ConfigProvider.class,
54 | cardinality = ReferenceCardinality.MANDATORY,
55 | policy = ReferencePolicy.DYNAMIC,
56 | unbind = "unregisterConfigProvider"
57 | )
58 | protected void registerConfigProvider(ConfigProvider configProvider) {
59 | this.configProvider = configProvider;
60 | }
61 |
62 | protected void unregisterConfigProvider(ConfigProvider configProvider) {
63 | this.configProvider = null;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/BasicTestConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.config.configprovider;
20 |
21 | import org.wso2.carbon.config.annotation.Configuration;
22 |
23 | import javax.xml.bind.annotation.XmlElement;
24 | import javax.xml.bind.annotation.XmlRootElement;
25 |
26 | /**
27 | * Sample configuration class for testing purposes.
28 | *
29 | * @since 2.0.6
30 | */
31 | @XmlRootElement
32 | @Configuration(description = "Test Bean")
33 | class TestBean {
34 |
35 | private String name = "default";
36 |
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | @XmlElement
42 | public void setName(String name) {
43 | this.name = name;
44 | }
45 | }
46 |
47 | /**
48 | * Sample configuration class for testing purposes.
49 | *
50 | * @since 2.0.6
51 | */
52 | @XmlRootElement
53 | @Configuration(description = "Complex Test Bean")
54 | class ComplexTestBean {
55 |
56 | private String name = "default";
57 | private TestBean testBean = new TestBean();
58 |
59 | public String getName() {
60 | return name;
61 | }
62 |
63 | @XmlElement
64 | public void setName(String name) {
65 | this.name = name;
66 | }
67 |
68 | public TestBean getTestBean() {
69 | return testBean;
70 | }
71 |
72 | @XmlElement
73 | public void setTestBean(TestBean testBean) {
74 | this.testBean = testBean;
75 | }
76 | }
77 |
78 | /**
79 | * Sample configuration class for testing purposes.
80 | *
81 | * @since 2.0.6
82 | */
83 | @XmlRootElement(name = "basictestconfiguration")
84 | @Configuration(namespace = "basictestconfiguration", description = "Test Configurations Bean")
85 | public class BasicTestConfiguration {
86 |
87 | private TestBean testBean = new TestBean();
88 | private ComplexTestBean complexTestBean = new ComplexTestBean();
89 |
90 | public TestBean getTestBean() {
91 | return testBean;
92 | }
93 |
94 | @XmlElement
95 | public void setTestBean(TestBean testBean) {
96 | this.testBean = testBean;
97 | }
98 |
99 | public ComplexTestBean getComplexTestBean() {
100 | return complexTestBean;
101 | }
102 |
103 | @XmlElement
104 | public void setComplexTestBean(ComplexTestBean complexTestBean) {
105 | this.complexTestBean = complexTestBean;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/PriorityTestConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.configprovider;
17 |
18 | import org.wso2.carbon.config.annotation.Configuration;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import javax.xml.bind.annotation.XmlElement;
23 | import javax.xml.bind.annotation.XmlRootElement;
24 |
25 | /**
26 | * Sample configuration class for testing purposes.
27 | *
28 | * @since 2.0.6
29 | */
30 | @XmlRootElement
31 | @Configuration(description = "Priority Test Bean")
32 | class PriorityTestBean {
33 |
34 | private String name = "default";
35 | private int id = 0;
36 | private int port = 8000;
37 |
38 | public int getId() {
39 | return id;
40 | }
41 |
42 | @XmlElement
43 | public void setId(int id) {
44 | this.id = id;
45 | }
46 |
47 | public String getName() {
48 | return name;
49 | }
50 |
51 | @XmlElement
52 | public void setName(String name) {
53 | this.name = name;
54 | }
55 |
56 | public int getPort() {
57 | return port;
58 | }
59 |
60 | @XmlElement
61 | public void setPort(int port) {
62 | this.port = port;
63 | }
64 | }
65 |
66 | /**
67 | * Sample configuration class for testing purposes.
68 | *
69 | * @since 2.0.6
70 | */
71 | @XmlRootElement
72 | @Configuration(description = "Test Beans")
73 | class TestBeans {
74 |
75 | private List testBeanList;
76 |
77 | TestBeans() {
78 | testBeanList = new ArrayList<>();
79 | testBeanList.add(new PriorityTestBean());
80 | }
81 |
82 | public List getTestBeanList() {
83 | return testBeanList;
84 | }
85 |
86 | @XmlElement
87 | public void setTestBeanList(List testBeans) {
88 | this.testBeanList = testBeans;
89 | }
90 |
91 | }
92 |
93 | /**
94 | * Sample configuration class for testing purposes.
95 | *
96 | * @since 2.0.6
97 | */
98 | @XmlRootElement(name = "prioritytestconfiguration")
99 | @Configuration(namespace = "prioritytestconfiguration", description = "Priority Test Configurations Bean")
100 | public class PriorityTestConfiguration {
101 |
102 | private TestBeans testBeans = new TestBeans();
103 |
104 | public TestBeans getTestBeans() {
105 | return testBeans;
106 | }
107 |
108 | @XmlElement
109 | public void setTestBeans(TestBeans priorityTestBeans) {
110 | this.testBeans = priorityTestBeans;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/UniqueElementTestConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.configprovider;
17 |
18 | import org.wso2.carbon.config.annotation.Configuration;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import javax.xml.bind.annotation.XmlElement;
23 | import javax.xml.bind.annotation.XmlRootElement;
24 |
25 | /**
26 | * Sample configuration class for testing purposes.
27 | *
28 | * @since 2.0.6
29 | */
30 | @XmlRootElement
31 | @Configuration(description = "Unique Element Test Bean")
32 | class UniqueElementTestBean {
33 |
34 | private String uniqueElement = "default";
35 | private int port = 8000;
36 |
37 | public String getUniqueElement() {
38 | return uniqueElement;
39 | }
40 |
41 | @XmlElement
42 | public void setUniqueElement(String uniqueElement) {
43 | this.uniqueElement = uniqueElement;
44 | }
45 |
46 | public int getPort() {
47 | return port;
48 | }
49 |
50 | @XmlElement
51 | public void setPort(int port) {
52 | this.port = port;
53 | }
54 | }
55 |
56 | /**
57 | * Sample configuration class for testing purposes.
58 | *
59 | * @since 2.0.6
60 | */
61 | @XmlRootElement
62 | @Configuration(description = "Unique Element Test Beans")
63 | class UniqueElementTestBeans {
64 |
65 | private List uniqueElementTestBeanList;
66 |
67 | UniqueElementTestBeans() {
68 | uniqueElementTestBeanList = new ArrayList<>();
69 | uniqueElementTestBeanList.add(new UniqueElementTestBean());
70 | }
71 |
72 | public List getUniqueElementTestBeanList() {
73 | return uniqueElementTestBeanList;
74 | }
75 |
76 | @XmlElement
77 | public void setUniqueElementTestBeanList(List uniqueElementTestBeanList) {
78 | this.uniqueElementTestBeanList = uniqueElementTestBeanList;
79 | }
80 |
81 | }
82 |
83 | /**
84 | * Sample configuration class for testing purposes.
85 | *
86 | * @since 2.0.6
87 | */
88 | @XmlRootElement(name = "uniqueelementtestconfiguration")
89 | @Configuration(namespace = "uniqueelementtestconfiguration", description = "Unique Element Test Configurations Bean")
90 | public class UniqueElementTestConfiguration {
91 |
92 | private UniqueElementTestBeans uniqueElementTestBeans = new UniqueElementTestBeans();
93 |
94 | public UniqueElementTestBeans getUniqueElementTestBeans() {
95 | return uniqueElementTestBeans;
96 | }
97 |
98 | @XmlElement
99 | public void setUniqueElementTestBeans(UniqueElementTestBeans uniqueElementTestBeans) {
100 | this.uniqueElementTestBeans = uniqueElementTestBeans;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.config.feature/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | carbon-config
20 | org.wso2.carbon.config
21 | 2.1.18-SNAPSHOT
22 | ../../pom.xml
23 |
24 | 4.0.0
25 | carbon-feature
26 | org.wso2.carbon.config.feature
27 | Carbon Configuration Feature
28 | http://wso2.com
29 |
30 |
31 | org.wso2.carbon.config
32 | org.wso2.carbon.config
33 |
34 |
35 |
36 |
37 |
38 | org.wso2.carbon.maven
39 | carbon-feature-plugin
40 | true
41 |
42 |
43 | p2-feature-generation
44 | package
45 |
46 | generate
47 |
48 |
49 | ../etc/feature.properties
50 |
51 |
52 | org.eclipse.equinox.p2.type.group
53 | false
54 |
55 |
56 |
57 |
58 | org.wso2.carbon.config
59 | ${carbon.config.version}
60 |
61 |
62 |
63 |
64 | org.wso2.carbon.secvault.feature
65 | ${carbon.securevault.version}
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/extensions/org.wso2.carbon.config.maven.plugin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | org.wso2.carbon.config
20 | carbon-config
21 | 2.1.18-SNAPSHOT
22 | ../../pom.xml
23 |
24 | 4.0.0
25 | org.wso2.carbon.config.maven.plugin
26 | maven-plugin
27 | Carbon Configuration Maven Plugin
28 |
29 | This module has mojo class for carbon configuration plugin.
30 |
31 | http://wso2.com
32 |
33 |
34 | org.apache.maven
35 | maven-project
36 |
37 |
38 | org.apache.maven
39 | maven-plugin-api
40 |
41 |
42 | org.apache.maven.plugin-tools
43 | maven-plugin-annotations
44 |
45 |
46 | org.apache.maven
47 | maven-core
48 |
49 |
50 | org.slf4j
51 | slf4j-api
52 |
53 |
54 | org.yaml
55 | snakeyaml
56 |
57 |
58 | org.wso2.carbon.config
59 | org.wso2.carbon.config
60 |
61 |
62 |
63 |
64 |
65 | org.apache.maven.plugins
66 | maven-plugin-plugin
67 | ${maven.plugin.plugin.version}
68 |
69 | true
70 |
71 |
72 |
73 | mojo-descriptor
74 | process-classes
75 |
76 | descriptor
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/provider/ConfigProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.provider;
19 |
20 | import org.wso2.carbon.config.ConfigurationException;
21 |
22 | import java.util.ArrayList;
23 |
24 | /**
25 | * ConfigProvider provides the configuration mapping of the class namespace.
26 | * This will update the configuration values with
27 | * following placeholders ${env:alias}, ${sys:alias} and ${sec:alias}
28 | *
29 | * @since 1.0.0
30 | */
31 | public interface ConfigProvider {
32 |
33 | /**
34 | * Returns configuration object of the class.
35 | * if configuration doesn't exist in deployment.yaml, returns object with default values.
36 | *
37 | * @param configClass configuration bean class
38 | * @param object type
39 | * @return configuration bean object of given type
40 | * @throws ConfigurationException if there is a problem with config object instantiation.
41 | */
42 | T getConfigurationObject(Class configClass) throws ConfigurationException;
43 |
44 | /**
45 | * Returns configuration object of the namespace.
46 | * Configuration object can be either List or Map, it depends on configuration of the namespace.
47 | *
48 | * @param namespace config namespace
49 | * @return configuration object
50 | * @throws ConfigurationException if there is a problem while reading the configurations
51 | */
52 | Object getConfigurationObject(String namespace) throws ConfigurationException;
53 |
54 | /**
55 | * Returns configuration object of the class.
56 | *
57 | * If configuration namespace is given, reads the configuration of the namespace and create instance of the the
58 | * class from that configurations.
59 | *
60 | * If namespace is null or configuration doesn't exist for in configuration file, returns configurations based on
61 | * the bean class.
62 | *
63 | * @param namespace config namespace
64 | * @param configClass configuration bean class
65 | * @param object type
66 | * @return configuration object
67 | * @throws ConfigurationException if there is a problem while reading the configurations
68 | */
69 | T getConfigurationObject(String namespace, Class configClass) throws ConfigurationException;
70 |
71 | /**
72 | * Returns te configuration object list of the class under the namespace
73 | *
74 | * @param namespace config namespace
75 | * @param configClass configuration bean class
76 | * @param object type
77 | * @return list of configuration object
78 | * @throws ConfigurationException if there is a problem while reading the configurations
79 | */
80 | ArrayList getConfigurationObjectList(String namespace, Class configClass) throws ConfigurationException;
81 | }
82 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/ConfigurationProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config;
17 |
18 | import org.wso2.carbon.config.annotation.Configuration;
19 |
20 | import java.io.IOException;
21 | import java.io.Writer;
22 | import java.util.Set;
23 | import javax.annotation.processing.AbstractProcessor;
24 | import javax.annotation.processing.RoundEnvironment;
25 | import javax.annotation.processing.SupportedAnnotationTypes;
26 | import javax.annotation.processing.SupportedSourceVersion;
27 | import javax.lang.model.SourceVersion;
28 | import javax.lang.model.element.Element;
29 | import javax.lang.model.element.TypeElement;
30 | import javax.tools.Diagnostic;
31 | import javax.tools.FileObject;
32 | import javax.tools.StandardLocation;
33 |
34 | /**
35 | * Configuration annotation processor extending AbstractProcessor.
36 | * Reads all classes annotated Configuration
37 | *
38 | * @since 1.0.0
39 | */
40 | @SupportedAnnotationTypes("org.wso2.carbon.config.annotation.Configuration")
41 | @SupportedSourceVersion(SourceVersion.RELEASE_8)
42 | public class ConfigurationProcessor extends AbstractProcessor {
43 |
44 | public ConfigurationProcessor() {
45 | super();
46 | }
47 |
48 | /**
49 | * This method reads all Configuration classes in the project and create temp files with qualified names of classes.
50 | *
51 | * @param annotations set of annotations
52 | * @param roundEnv annotation object to process
53 | * @return return true if processing is completed, false otherwise
54 | */
55 | @Override
56 | public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
57 | Set extends Element> configSet = roundEnv.getElementsAnnotatedWith(Configuration.class);
58 | StringBuilder builder = new StringBuilder();
59 | for (Element element : configSet) {
60 | Configuration configuration = element.getAnnotation(Configuration.class);
61 | if (configuration != null && !ConfigConstants.NULL.equals(configuration.namespace())) {
62 | builder.append(((TypeElement) element).getQualifiedName()).append(",");
63 | }
64 | }
65 | if (builder.length() > 0) {
66 | try {
67 | FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
68 | ConfigConstants.TEMP_CONFIG_FILE_NAME);
69 | try (Writer writer = file.openWriter()) {
70 | writer.write(builder.toString());
71 | }
72 | } catch (IOException e) {
73 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
74 | }
75 | } else {
76 | processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Configuration classes doesn't exist in " +
77 | "the project");
78 | }
79 | return true;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/TestTransportConfiguration2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.configprovider;
17 |
18 | import org.wso2.carbon.config.annotation.Configuration;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import javax.xml.bind.annotation.XmlAttribute;
23 | import javax.xml.bind.annotation.XmlElement;
24 | import javax.xml.bind.annotation.XmlRootElement;
25 |
26 | /**
27 | * Sample configuration class for testing purposes.
28 | *
29 | * @since 1.0.0
30 | */
31 | @XmlRootElement
32 | @Configuration(namespace = "testTransports", description = "Test Transports Bean")
33 | class TestTransportRoot {
34 |
35 | public List testTransports;
36 |
37 | TestTransportRoot() {
38 | testTransports = new ArrayList<>();
39 | testTransports.add(new TestTransportElement());
40 | }
41 |
42 | @XmlElement
43 | public void setTestTransports(List transportsTest) {
44 | this.testTransports = transportsTest;
45 | }
46 |
47 | public List getTestTransports() {
48 | return testTransports;
49 | }
50 | }
51 |
52 | @XmlRootElement
53 | @Configuration(description = "Test Transport Bean")
54 | class TestTransportElement {
55 |
56 | public TestTransport testTransport = new TestTransport();
57 |
58 | public TestTransport getTestTransport() {
59 | return testTransport;
60 | }
61 |
62 | public void setTestTransport(TestTransport testTransport) {
63 | this.testTransport = testTransport;
64 | }
65 | }
66 |
67 | @XmlRootElement
68 | @Configuration(description = "Test Transport Bean")
69 | class TestTransport {
70 |
71 | public String name = "default transport";
72 | public int port = 8000;
73 | public boolean secure = false;
74 | public String desc = "Default Transport Configurations";
75 | public String password = "zzz";
76 |
77 | @XmlAttribute
78 | public void setSecure(boolean secure) {
79 | this.secure = secure;
80 | }
81 |
82 | public boolean isSecure() {
83 | return secure;
84 | }
85 |
86 | @XmlElement
87 | public void setName(String name) {
88 | this.name = name;
89 | }
90 |
91 | public String getName() {
92 | return name;
93 | }
94 |
95 | @XmlElement
96 | public void setPort(int port) {
97 | this.port = port;
98 | }
99 |
100 | public int getPort() {
101 | return port;
102 | }
103 |
104 | @XmlElement
105 | public void setDesc(String desc) {
106 | this.desc = desc;
107 | }
108 |
109 | public String getDesc() {
110 | return desc;
111 | }
112 |
113 | @XmlElement
114 | public void setPassword(String password) {
115 | this.password = password;
116 | }
117 |
118 | public String getPassword() {
119 | return password;
120 | }
121 | }
122 |
123 |
--------------------------------------------------------------------------------
/samples/config-provider/standalone/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | carbon-config
20 | org.wso2.carbon.config
21 | 2.1.18-SNAPSHOT
22 | ../../../pom.xml
23 |
24 | 4.0.0
25 | provider-standalone
26 | Carbon Configuration Standalone Sample
27 | jar
28 | http://wso2.com
29 |
30 |
31 | org.wso2.carbon.config
32 | org.wso2.carbon.config
33 |
34 |
35 | org.slf4j
36 | slf4j-api
37 |
38 |
39 | org.slf4j
40 | slf4j-log4j12
41 | ${slf4j.api.version}
42 |
43 |
44 | org.wso2.carbon.config
45 | config-generator
46 | ${project.version}
47 |
48 |
49 |
50 |
51 |
52 | org.apache.maven.plugins
53 | maven-assembly-plugin
54 |
55 |
56 | jar-with-dependencies
57 | package
58 |
59 | single
60 |
61 |
62 |
63 |
64 |
65 | org.wso2.carbon.config.samples.standalone.Application
66 |
67 |
68 |
69 | false
70 | false
71 |
72 | assembly.xml
73 |
74 |
75 | provider-standalone-${project.version}
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | 1.7.13
86 |
87 |
88 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/internal/ConfigProviderComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.internal;
19 |
20 | import org.osgi.framework.BundleContext;
21 | import org.osgi.service.component.annotations.Activate;
22 | import org.osgi.service.component.annotations.Component;
23 | import org.osgi.service.component.annotations.Deactivate;
24 | import org.osgi.service.component.annotations.Reference;
25 | import org.osgi.service.component.annotations.ReferenceCardinality;
26 | import org.osgi.service.component.annotations.ReferencePolicy;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 | import org.wso2.carbon.config.ConfigProviderFactory;
30 | import org.wso2.carbon.config.ConfigurationException;
31 | import org.wso2.carbon.config.provider.ConfigProvider;
32 | import org.wso2.carbon.secvault.SecureVault;
33 | import org.wso2.carbon.utils.Constants;
34 | import org.wso2.carbon.utils.Utils;
35 |
36 | import java.nio.file.Path;
37 | import java.nio.file.Paths;
38 |
39 | /**
40 | * This service component is responsible for registering ConfigProvider OSGi service.
41 | *
42 | * @since 1.0.0
43 | */
44 | @Component(
45 | name = "ConfigProviderComponent",
46 | immediate = true
47 | )
48 | public class ConfigProviderComponent {
49 | private static final Logger logger = LoggerFactory.getLogger(ConfigProviderComponent.class);
50 | private SecureVault secureVault = null;
51 |
52 | @Activate
53 | protected void activate(BundleContext bundleContext) {
54 | initializeConfigProvider(bundleContext);
55 | logger.debug("Carbon Configuration Component activated");
56 | }
57 |
58 | @Deactivate
59 | protected void deactivate(BundleContext bundleContext) {
60 | logger.debug("Stopping ConfigProviderComponent");
61 | }
62 |
63 | @Reference(
64 | name = "org.wso2.carbon.secvault.SecureVault",
65 | service = SecureVault.class,
66 | cardinality = ReferenceCardinality.MANDATORY,
67 | policy = ReferencePolicy.DYNAMIC,
68 | unbind = "unRegisterSecureVault"
69 | )
70 | protected void registerSecureVault(SecureVault secureVault) {
71 | this.secureVault = secureVault;
72 | }
73 |
74 | protected void unRegisterSecureVault(SecureVault secureVault) {
75 | this.secureVault = null;
76 | }
77 |
78 | /**
79 | * Initialise carbon config provider.
80 | *
81 | * @param bundleContext OSGi Bundle Context
82 | */
83 | private void initializeConfigProvider(BundleContext bundleContext) {
84 | try {
85 | Path deploymentConfigPath = Paths.get(Utils.getRuntimeConfigPath().toString(),
86 | Constants.DEPLOYMENT_CONFIG_YAML);
87 | ConfigProvider configProvider = ConfigProviderFactory.getConfigProvider(deploymentConfigPath, secureVault);
88 | bundleContext.registerService(ConfigProvider.class, configProvider, null);
89 | logger.debug("ConfigProvider OSGi service registered successfully");
90 | } catch (ConfigurationException e) {
91 | logger.error("Error occurred while initializing config provider" , e);
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/test/java/org/wso2/carbon/config/configprovider/TestConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.configprovider;
17 |
18 | import org.wso2.carbon.config.annotation.Configuration;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import javax.xml.bind.annotation.XmlAttribute;
23 | import javax.xml.bind.annotation.XmlElement;
24 | import javax.xml.bind.annotation.XmlRootElement;
25 |
26 | /**
27 | * Sample configuration class for testing purposes.
28 | *
29 | * @since 1.0.0
30 | */
31 | @XmlRootElement
32 | @Configuration(description = "Test Transport Bean")
33 | class Transport {
34 |
35 | private String name = "default transport";
36 | private int port = 8000;
37 | private String secure = "false";
38 | private String desc = "Default Transport Configurations";
39 | private String password = "zzz";
40 |
41 | @XmlAttribute
42 | public void setSecure(String secure) {
43 | this.secure = secure;
44 | }
45 |
46 | public String isSecure() {
47 | return secure;
48 | }
49 |
50 | @XmlElement
51 | public void setName(String name) {
52 | this.name = name;
53 | }
54 |
55 | public String getName() {
56 | return name;
57 | }
58 |
59 | @XmlElement
60 | public void setPort(int port) {
61 | this.port = port;
62 | }
63 |
64 | public int getPort() {
65 | return port;
66 | }
67 |
68 | @XmlElement
69 | public void setDesc(String desc) {
70 | this.desc = desc;
71 | }
72 |
73 | public String getDesc() {
74 | return desc;
75 | }
76 |
77 | @XmlElement
78 | public void setPassword(String password) {
79 | this.password = password;
80 | }
81 |
82 | public String getPassword() {
83 | return password;
84 | }
85 | }
86 |
87 | /**
88 | * Sample configuration class for testing purposes.
89 | *
90 | * @since 1.0.0
91 | */
92 | @XmlRootElement
93 | @Configuration(description = "Test Transports Bean")
94 | class Transports {
95 |
96 | private List transport;
97 |
98 | Transports() {
99 | transport = new ArrayList<>();
100 | transport.add(new Transport());
101 | }
102 |
103 | @XmlElement
104 | public void setTransport(List transport) {
105 | this.transport = transport;
106 | }
107 |
108 | public List getTransport() {
109 | return transport;
110 | }
111 |
112 | }
113 |
114 | /**
115 | * Sample configuration class for testing purposes.
116 | *
117 | * @since 1.0.0
118 | */
119 | @XmlRootElement(name = "testconfiguration")
120 | @Configuration(namespace = "testconfiguration", description = "Test Configurations Bean")
121 | public class TestConfiguration {
122 |
123 | private String tenant = "default";
124 | private Transports transports = new Transports();
125 |
126 | @XmlElement
127 | public void setTenant(String tenant) {
128 | this.tenant = tenant;
129 | }
130 |
131 | public String getTenant() {
132 | return tenant;
133 | }
134 |
135 | @XmlElement
136 | public void setTransports(Transports transports) {
137 | this.transports = transports;
138 | }
139 |
140 | public Transports getTransports() {
141 | return transports;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/tests/org.wso2.carbon.config.test/src/test/java/org/wso2/carbon/config/test/annotationprocessor/TestConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.wso2.carbon.config.test.annotationprocessor;
17 |
18 | import org.wso2.carbon.config.annotation.Configuration;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import javax.xml.bind.annotation.XmlAttribute;
23 | import javax.xml.bind.annotation.XmlElement;
24 | import javax.xml.bind.annotation.XmlRootElement;
25 |
26 | /**
27 | * Sample configuration class for testing purposes.
28 | *
29 | * @since 1.0.0
30 | */
31 | @XmlRootElement
32 | @Configuration(description = "Test Transport Bean")
33 | class Transport {
34 |
35 | private String name = "default transport";
36 | private int port = 8000;
37 | private String secure = "false";
38 | private String desc = "Default Transport Configurations";
39 | private String password = "zzz";
40 |
41 | @XmlAttribute
42 | public void setSecure(String secure) {
43 | this.secure = secure;
44 | }
45 |
46 | public String isSecure() {
47 | return secure;
48 | }
49 |
50 | @XmlElement
51 | public void setName(String name) {
52 | this.name = name;
53 | }
54 |
55 | public String getName() {
56 | return name;
57 | }
58 |
59 | @XmlElement
60 | public void setPort(int port) {
61 | this.port = port;
62 | }
63 |
64 | public int getPort() {
65 | return port;
66 | }
67 |
68 | @XmlElement
69 | public void setDesc(String desc) {
70 | this.desc = desc;
71 | }
72 |
73 | public String getDesc() {
74 | return desc;
75 | }
76 |
77 | @XmlElement
78 | public void setPassword(String password) {
79 | this.password = password;
80 | }
81 |
82 | public String getPassword() {
83 | return password;
84 | }
85 | }
86 |
87 | /**
88 | * Sample configuration class for testing purposes.
89 | *
90 | * @since 1.0.0
91 | */
92 | @XmlRootElement
93 | @Configuration(description = "Test Transports Bean")
94 | class Transports {
95 |
96 | private List transport;
97 |
98 | Transports() {
99 | transport = new ArrayList<>();
100 | transport.add(new Transport());
101 | }
102 |
103 | @XmlElement
104 | public void setTransport(List transport) {
105 | this.transport = transport;
106 | }
107 |
108 | public List getTransport() {
109 | return transport;
110 | }
111 |
112 | }
113 |
114 | /**
115 | * Sample configuration class for testing purposes.
116 | *
117 | * @since 1.0.0
118 | */
119 | @XmlRootElement(name = "testconfiguration")
120 | @Configuration(namespace = "testconfiguration", description = "Test Configurations Bean")
121 | public class TestConfiguration {
122 |
123 | private String tenant = "default";
124 | private Transports transports = new Transports();
125 |
126 | @XmlElement
127 | public void setTenant(String tenant) {
128 | this.tenant = tenant;
129 | }
130 |
131 | public String getTenant() {
132 | return tenant;
133 | }
134 |
135 | @XmlElement
136 | public void setTransports(Transports transports) {
137 | this.transports = transports;
138 | }
139 |
140 | public Transports getTransports() {
141 | return transports;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Carbon Configuration
2 |
3 | Carbon configuration provides a framework for managing server configurations. With global configuration model, server
4 | will have only one configuration file for all server configurations. So that,
5 |
6 | * Global configuration file (deployment.yaml) includes minimal sets of configurations which need to override very
7 | often by default (e.g: server ports etc).
8 | * All user settable configurations must have default values and they are burnt into compile codes.
9 | * Any default configuration can overridden by adding the particular configuration to the global configuration
10 | file(deployment.yaml).
11 | * Defining all configurations in the configuration file in not required. add only if we need to override the
12 | default value.
13 | * If configurations are not specified in the configuration file, values defined in the bean class will apply by
14 | default.
15 |
16 | In global configuration file (deployment.yaml),
17 |
18 | * Each component will have their own configurations with a unique namespace (e.g: wso2.carbon, wso2.transports.netty etc) and it will be a fragment of deployment.yaml file. Please find the sample file below.
19 | * At runtime, the relevant config bean will be generated by overriding the default values specified in bean class with values mentioned in deployment.yaml file.
20 |
21 | Sample file looks like:
22 |
23 | ```yaml
24 | # Carbon Configuration Parameters
25 | wso2.carbon:
26 | id: carbon-kernel
27 | version: 5.2.0-SNAPSHOT
28 | ports:
29 | offset: 0
30 | ...
31 |
32 | # Netty Transport Configurations
33 | wso2.transports.netty:
34 | listeners:
35 | - id: msf4j-http
36 | host: 127.0.0.1
37 | port: 8080
38 | bossThreadPoolSize: 2
39 | workerThreadPoolSize: 250
40 | parameters:
41 | - name: "executor.workerpool.size"
42 | value: 60
43 |
44 | ...
45 | ```
46 |
47 | Following annotations are introduced for configuration bean classes.
48 |
49 | * `org.wso2.carbon.config.annotations.Configuration`: This is a class-level annotation, which corresponds to a configuration bean to be used by a component.
50 | * `org.wso2.carbon.config.annotations.Element`: This is a field-level annotation, which corresponds to a field of the class.
51 | * `org.wso2.carbon.config.annotations.Ignore`: This is a field-level annotation, which specifies that the field needs to be ignored when the configuration is generated.
52 |
53 | Sample bean class with above annotations looks like:
54 |
55 | ```java
56 | @Configuration(namespace = "wso2.carbon", description = "Carbon Configuration Parameters")
57 | public class CarbonConfiguration {
58 |
59 | @Element(description = "value to uniquely identify a server", required = true)
60 | private String id = "carbon-kernel";
61 |
62 | @Element(description = "server name")
63 | private String name = "WSO2 Carbon Kernel";
64 |
65 | @Element(description = "server version")
66 | private String version = "5.2.0";
67 |
68 | @Ignore
69 | private String tenant = Constants.DEFAULT_TENANT;
70 |
71 | }
72 | ```
73 |
74 | The framework provides maven plugin to read all configuration bean classes in the component and create the relevant
75 | segment of the configuration file(for documentation purposes) automatically at compile time.
76 |
77 | The framework provides OSGI service(ConfigProvider) to read configuration from deployment.yaml file. Following apis
78 | are read configuration from the file.
79 |
80 | * `getConfigurationObject(Class configClass)`: Returns configuration object of the class with overriding the values of deployment.yaml. If configuration doesn't exist in deployment.yaml, returns object with default values.
81 | * `getConfigurationMap(String namespace)`: Returns configuration map of the namespace, if configuration exists for the given namespace in deployment.yaml.
82 |
83 | For more information, Please refer document link below.
84 |
85 | * [Using the Global Configuration Model](docs/UpdatingConfigurations.md)
86 | * [Installing Configuration Provider Feature](docs/InstallingConfigFeature.md)
87 | * [Configurations via Environment Variables](docs/ConfigurationsViaEnvironmentVariables.md)
--------------------------------------------------------------------------------
/components/org.wso2.carbon.config/src/main/java/org/wso2/carbon/config/provider/ImmutablePair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package org.wso2.carbon.config.provider;
19 |
20 | import java.util.Arrays;
21 | import java.util.Locale;
22 | import java.util.Objects;
23 |
24 | /**
25 | * An {@link ImmutablePair} consists of two elements within. The elements once set
26 | * in the ImmutablePair cannot be modified. The class itself is final, so that it
27 | * cannot be subclassed. This is general norm for creating Immutable classes.
28 | * Please note that the {@link ImmutablePair} cannot be modified once set, but the
29 | * objects within them can be, so in general it means that if there are mutable objects
30 | * within the pair then the pair itself is effectively mutable.
31 | *