Skip to content

Commit

Permalink
Merge pull request #111 from struberg/i70
Browse files Browse the repository at this point in the history
I70 fix for #70
  • Loading branch information
struberg authored Mar 20, 2019
2 parents ff1e6e2 + 8ce678c commit ac47a50
Show file tree
Hide file tree
Showing 60 changed files with 92 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/javax/config/inject/ConfigProperty.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/javax/config/inject/package-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/javax/config/package-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/javax/config/spi/ConfigBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/javax/config/spi/package-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion site.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#######################################################################
## Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
## Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
##
## See the NOTICE file(s) distributed with this work for additional
## information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion spec/src/main/asciidoc/architecture.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Eclipse ConfigJSR Contributors:
// Copyright (c) 2016-2019 Eclipse ConfigJSR Contributors:
// Mark Struberg
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
21 changes: 10 additions & 11 deletions spec/src/main/asciidoc/configaccessor.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand Down Expand Up @@ -32,17 +32,15 @@ This can also be handled via `ConfigAccessor` as shown in the following example:
.Simple example of ConfigAccessor
[source,java]
-----------------------------------------------------------------
String userName = config.access("user.name").getValue();
String userName = config.access("user.name", String.class).build().getValue();
-----------------------------------------------------------------

Additional to this the `ConfigAccessor` also allows for far more complex control over the access to configured values.

The call to `config.access(..)` returns a `ConfigAccessor`.
The call to `config.access(..)` returns a `ConfigAccessor.Builder`.
This is basically a builder which has methods to refine the resolution, including the following:

* `as(Class<N> clazz)` -- defines the return type of the property
* `asList()` -- Declare the ConfigAccessor to return a List of the given Type.
* `evaluateVariables(boolean evaluateVariables)`
* `evaluateVariables(boolean evaluateVariables)` -- Allows variable parts in configured values.
* `useConverter(Converter<T> converter)` -- Defines a specific {@link Converter} to be used instead of applying the default Converter resolving logic.
* `addLookupSuffix(String postfixName)` -- sets a parameter for the resolution of a 'postfix' for the resolution
* `addLookupSuffix(ConfigAccessor)` -- you can also use a `ConfigAccessor` to determine the 'postfix' for the resolution
Expand All @@ -55,11 +53,12 @@ This is basically a builder which has methods to refine the resolution, includin
Config config = ConfigProvider.getConfig();
ConfigAccessor<Integer> dbPortCfg
= config.access("db.port")
.as(Integer.class)
.withProjectStage(true)
.withLookupChain("§{database.vendor}")
.withDefault(3306);
= config.access("db.port", Integer.class)
.addLookupSuffix(config.access("project.projectStage")
.cacheFor(Duration.ofHours(12L))
.addLookupSuffix("database.vendor")
.withDefault(3306)
.build();
...
Integer port = dbPortCfg.getValue();
-----------------------------------------------------------------
15 changes: 14 additions & 1 deletion spec/src/main/asciidoc/configexamples.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand Down Expand Up @@ -54,6 +54,14 @@ $> java -Dacme.myprj.some.url=http://other.server/other/endpoint -jar some.jar
Note that this is only one example how to possibly configure your application.
Another example is to register <<custom_configsources, Custom ConfigSources>> to e.g. pick up values from a database table, etc.

If a config value is a comma(`,`) separated string, this value can be automatically converted to a multiple element array with `\` as the escape character.
When specifying the property `myPets=dog,cat,dog\\,cat` in a config source, the following code snippet can be used to obtain an array.
----
String[] myPets = config.getValue("myPets", String[].class);
//myPets = {"dog", "cat", "dog,cat"}
----


=== Simple Dependency Injection Example

JavaConfig also provides ways to inject configured values into your beans using the `@Inject` and the `@ConfigProperty` qualifier.
Expand Down Expand Up @@ -87,6 +95,11 @@ public class InjectedConfigUsageSample {
@Inject
@ConfigProperty(name="myprj.some.dynamic.timeout", defaultValue="100")
private javax.inject.Provider<Long> timeout;
//The following code injects an Array, List or Set for the `myPets` property,
//where its value is a comma separated value ( myPets=dog,cat,dog\\,cat)
@Inject @ConfigProperty(name="myPets") private String[] myArrayPets;
@Inject @ConfigProperty(name="myPets") private List<String> myListPets;
@Inject @ConfigProperty(name="myPets") private Set<String> mySetPets;
}
----

2 changes: 1 addition & 1 deletion spec/src/main/asciidoc/configprovider.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion spec/src/main/asciidoc/configsources.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand Down
10 changes: 7 additions & 3 deletions spec/src/main/asciidoc/converters.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand Down Expand Up @@ -36,7 +36,7 @@ The following `Converter` s are provided by JavaConfig by default:
* `long` and `Long`
* `float` and `Float` , a dot '.' is used to separate the fractional digits
* `double` and `Double` , a dot '.' is used to separate the fractional digits
* `URL`
* `URL` as defined by `java.net.URL#URL(java.lang.String)`

All built-in `Converter` have the `@Priority` of `1`.

Expand All @@ -52,6 +52,9 @@ The `Config` will use the `Converter` with the highest `Priority` for each targe

A custom `Converter` for a target type of any of the built-in Converters will overwrite the default Converter.

Converters can be added to the `ConfigBuilder` programmatically via `ConfigBuilder#withConverters(Converter<?>... converters)`
where the type of the converters can be obtained via reflection. However, this is not possible for a lambda converter.
In this case, use the method `ConfigBuilder#withConverter(Class<T> type, int priority, Converter<T> converter)`.

=== Implicit Converters

Expand Down Expand Up @@ -84,7 +87,8 @@ Array as a class type is supported in the programmatic lookup.

[source, java]
----
String[] myPets = ConfigProvider.getConfig().getValue("myPet", String[].class);
Config = ConfigProvider.getConfig();
String[] myPets = config.getValue("myPets", String[].class);
----

myPets will be "dog", "cat", "dog,cat" as an array
Expand Down
6 changes: 3 additions & 3 deletions spec/src/main/asciidoc/javaconfig-spec.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Eclipse ConfigJSR Contributors:
// Copyright (c) 2016-2019 Eclipse ConfigJSR Contributors:
// Mark Struberg
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,10 +16,10 @@
//

= Configuration API for Java, v1.0
:authors: Mark Struberg, Emily Jiang, John D. Ament
:authors: Mark Struberg, Emily Jiang, John D. Ament, et al
:email: [email protected], [email protected], [email protected]
:revnumber: 1.0-Draft
:revdate: 2018-07-05
:revdate: 2019-03-13
:revremark: Draft
:version-label!:
:sectanchors:
Expand Down
4 changes: 2 additions & 2 deletions spec/src/main/asciidoc/license-alv2.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Eclipse ConfigJSR Contributors:
// Copyright (c) 2016-2019 Eclipse ConfigJSR Contributors:
// Mark Struberg
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -26,7 +26,7 @@ Status: {revremark}
Release: {revdate}
Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tck/running_the_tck.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
2 changes: 1 addition & 1 deletion tck/src/main/java/org/eclipse/configjsr/ConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Loading

0 comments on commit ac47a50

Please sign in to comment.