<commit_before>//
// Copyright (c) 2016-2017 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Contributors:
// <NAME>
// <NAME>
// <NAME>

[[configsource]]
== ConfigSources

A `ConfigSource` is exactly what its name says: a source for configured values.
The `Config` uses all configured implementations of `ConfigSource` to look up the property in question.

=== ConfigSource Ordering

Each `ConfigSource` has a specified `ordinal`, which is used to determine the importance of the values taken from the associated `ConfigSource`.
A higher `ordinal` means that the values taken from this `ConfigSource` will override values from lower-priority <<ConfigSource,ConfigSources>>.
This allows a configuration to be customized from outside a binary, assuming that external `ConfigSource` s have higher `ordinal` values than the ones whose values originate within the release binaries.

It can also be used to implement a drop-in configuration approach.
Simply create a jar containing a `ConfigSource` with a higher ordinal and override configuration values in it.
If the jar is present on the classpath then it will override configuration values from <<ConfigSource,ConfigSources>> with lower `ordinal` values.

[source, text]
----
config_ordinal = 120
com.acme.myproject.someserver.url = http://more_important.server/some/endpoint
----


Note that `config_ordinal` can be set within any `ConfigSource` implementation.  The default implementation of `getOrdinal()` will attempt to read this value, if found and a valid integer, the value will be used, otherwise the default of `100` will be returned.

[[default_configsources]]
=== Default ConfigSources

A Microprofile-Config implementation must provide <<ConfigSource,ConfigSources>> for the following data out of the box:

* System properties (default ordinal=400).
* Environment variables (default ordinal=300).
+
[[default_configsources.env.mapping]]

Some operating systems allow only alphabetic characters or an underscore, `_`, in environment variables. Other characters such as `., /`, etc may be disallowed. In order to set a value for a config property that has a name containing such disallowed characters from an environment variable, the following rules are used.

This `ConfigSource` searches 3 environment variables for a given property name (e.g. `com.ACME.size`):
This `ConfigSource` searches 3 environment variables for a given property name (e.g. `com.ACME.size`):

  1. Exact match (i.e. `com.ACME.size`)
  2. Replace the character that is neither alphanumeric nor `\_` with `_` (i.e. `com_ACME_size`)
  3. Replace the character that is neither alphanumeric nor `\_` with `_` and convert to upper case (i.e. `COM_ACME_SIZE`)

+
The first environment variable that is found is returned by this `ConfigSource`.

* A `ConfigSource` for each property file `META-INF/microprofile-config.properties` found on the classpath. (default ordinal = 100).

[[custom_configsources]]<commit_msg>Remove duplicate sentance<commit_after>//
// Copyright (c) 2016-2017 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Contributors:
// <NAME>
// <NAME>
// <NAME>

[[configsource]]
== ConfigSources

A `ConfigSource` is exactly what its name says: a source for configured values.
The `Config` uses all configured implementations of `ConfigSource` to look up the property in question.

=== ConfigSource Ordering

Each `ConfigSource` has a specified `ordinal`, which is used to determine the importance of the values taken from the associated `ConfigSource`.
A higher `ordinal` means that the values taken from this `ConfigSource` will override values from lower-priority <<ConfigSource,ConfigSources>>.
This allows a configuration to be customized from outside a binary, assuming that external `ConfigSource` s have higher `ordinal` values than the ones whose values originate within the release binaries.

It can also be used to implement a drop-in configuration approach.
Simply create a jar containing a `ConfigSource` with a higher ordinal and override configuration values in it.
If the jar is present on the classpath then it will override configuration values from <<ConfigSource,ConfigSources>> with lower `ordinal` values.

[source, text]
----
config_ordinal = 120
com.acme.myproject.someserver.url = http://more_important.server/some/endpoint
----


Note that `config_ordinal` can be set within any `ConfigSource` implementation.  The default implementation of `getOrdinal()` will attempt to read this value, if found and a valid integer, the value will be used, otherwise the default of `100` will be returned.

[[default_configsources]]
=== Default ConfigSources

A Microprofile-Config implementation must provide <<ConfigSource,ConfigSources>> for the following data out of the box:

* System properties (default ordinal=400).
* Environment variables (default ordinal=300).
+
[[default_configsources.env.mapping]]

Some operating systems allow only alphabetic characters or an underscore, `_`, in environment variables. Other characters such as `., /`, etc may be disallowed. In order to set a value for a config property that has a name containing such disallowed characters from an environment variable, the following rules are used.

This `ConfigSource` searches 3 environment variables for a given property name (e.g. `com.ACME.size`):

  1. Exact match (i.e. `com.ACME.size`)
  2. Replace the character that is neither alphanumeric nor `\_` with `_` (i.e. `com_ACME_size`)
  3. Replace the character that is neither alphanumeric nor `\_` with `_` and convert to upper case (i.e. `COM_ACME_SIZE`)

+
The first environment variable that is found is returned by this `ConfigSource`.

* A `ConfigSource` for each property file `META-INF/microprofile-config.properties` found on the classpath. (default ordinal = 100).

[[custom_configsources]]
{'fraction_non_alphanumeric': 0.08201317818589654, 'fraction_numerical': 0.008832188420019628, 'mean_word_length': 4.55607476635514, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5098809', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1768, 'n_words': 908}