Commit Graph

232 Commits

Author SHA1 Message Date
Phillip Webb
67402405db Reformat code 2015-09-08 14:56:40 -07:00
Phillip Webb
0335053139 Merge branch '1.2.x' 2015-09-08 14:37:16 -07:00
Phillip Webb
15686ed4fd Reformat code 2015-09-08 14:07:06 -07:00
Phillip Webb
0f6b60d8c8 Organize imports 2015-09-08 14:05:00 -07:00
Stephane Nicoll
35875c7f08 Merge manual item meta-data
Previously, manual meta-data were added to the existing set of entries
which could lead to duplicates if a manual entry is meant to complement
a property that is detected via the processor.

We now match the name and type of the item against the auto-detected
entries. If no match is found, we add the extra entry as we did before.
If a match is found we override the description, default value and
deprecation information.

Closes gh-3562
2015-08-20 17:08:54 +02:00
Stephane Nicoll
3763eda64e Merge branch '1.2.x' 2015-08-10 16:36:11 +02:00
Stephane Nicoll
1ee31e73d3 Avoid NPE if @ConfigurationProperties is not present
The annotation processor detects `@ConfigurationProperties` bean or
method definition and merges manual meta-data. The former step will fail
with a NPE if the annotation is not present on the classpath. This could
happen if the annotation processor is added to a module that is not
actually using Spring Boot.

We now have a defensive check that skips that steps but still attempts to
merge manual meta-data if present.

Closes gh-3720
2015-08-10 16:34:30 +02:00
arghya88
64c6e5b403 Fix typo
Closes gh-3610
2015-07-28 10:39:10 +02:00
Stephane Nicoll
42e230192f Polish 2015-07-24 07:19:53 +02:00
Stephane Nicoll
e9a6245a44 Remove unnecessary System.out 2015-07-22 16:59:53 +02:00
Stephane Nicoll
178c690d37 Fix meta-data root attributes ordering 2015-07-22 16:59:25 +02:00
Phillip Webb
e9d252e05c Add @DeprecatedConfigurationProperties annotation
Add a new @DeprecatedConfigurationProperties annotation which can be
used by the `ConfigurationMetadataAnnotationProcessor` to generating
meta-data deprecated blocks.

Fixes gh-3543
2015-07-17 14:14:37 -07:00
Phillip Webb
728e64b929 Polish 2015-07-16 12:56:49 -07:00
izeye
f4589e7cc3 Fix typos
Closes gh-3504
2015-07-15 15:45:02 +02:00
Stephane Nicoll
f2d32d3e98 Add support for property deprecation
Previously, an item could only have a 'deprecated' boolean flag to
indicate that the property is deprecated. It is desirable to provide an
additional description for the deprecation as well as the name of the
property to use instead.

The `deprecated` boolean flag is now supported. Instead, a `deprecated`
object can be specified with two optional attributes: `reason` to provide
an explanation for the deprecation and `replacement` to refer to the
property that should be used instead. If none of them is present, an
empty deprecation object should be set.

For backward compatibility, the `deprecated` field is still set.

Deprecation information can only set via manual meta-data.

Closes gh-3449
2015-07-15 15:41:52 +02:00
izeye
019140c901 Remove redundant check
Closes gh-3497
2015-07-15 09:58:15 +02:00
Phillip Webb
f0f5f78e25 Polish 2015-07-14 22:17:52 -07:00
Stephane Nicoll
c4c24b1f44 Detect default value from factory method
If a field is initialized via a factory method taking a single argument,
we can relatively safely consider that said argument is a good
representation of its default value. This is typically the case for
Charset or MimeType instances.

We now make sure to detect such use case (i.e. method argument with a
single argument).

Closes gh-3482
2015-07-14 15:08:43 +02:00
Phillip Webb
9ebe15232e Polish 2015-07-13 11:05:46 -07:00
Stephane Nicoll
cb5eccb5c1 Add missing handle-as meta-data
Liquibase has a `changeLog` property that is definitely used as a
`Resource` but cannot be defined as such as the original String value
should be kept against an API we don't control.

Update the tests also to make it more clear that if hints are added
against a property that is detected automatically, said property still
keeps all its auto-discovered capabilities.

Closes gh-3457
2015-07-13 13:45:23 +02:00
izeye
f85f316873 Polish toString()
Closes gh-3465
2015-07-13 09:52:29 +02:00
Stephane Nicoll
3664895f04 Polish 2015-07-12 09:20:12 +02:00
Stephane Nicoll
97634e85ac Remove unnecessary keyword 2015-07-09 14:33:01 +02:00
Phillip Webb
0cf6efca4f Polish 2015-07-06 13:05:09 -07:00
Stephane Nicoll
162cbdd5cb Fail the build if the meta-data are invalid
Make sure to fail the build with a proper compilation error message if
the user-defined meta-data are invalid. For now, this takes care of the
JSON format but other checks may be added in the future.

Closes gh-3329
2015-07-06 11:35:57 +02:00
Spring Buildmaster
7ce391db4f Next development version 2015-07-01 22:48:01 -07:00
Phillip Webb
7879743b9f Polish 2015-06-25 12:00:48 -07:00
Stephane Nicoll
0ec9de9137 Add support for value provider
Improve the "hints" section of the metadata so that each hint can provide
the reference to a value provider.

A value provider defines how a tool can discover the potential values of
a property based on the context. The provider is identifed by a name and
may have an arbitrary number of parameters.

Closes gh-3303
2015-06-25 14:58:10 +02:00
Phillip Webb
778e3eb091 Polish 2015-06-24 16:15:12 -07:00
Stephane Nicoll
bc9321734f Add support for property hint
Create a new section in the meta-data called "hints" where users can
provide hints about a given property. The most basic use case for now
is to provide a list of values that a property can have. Each value may
have a description.

This sample JSON provides a basic example for a property called `foo.mode`
that exposes 3 values: "auto", "basic" and "advanced".

```
 "hints": [
    {
      "id": "foo.mode",
      "values": [
        {
          "value": "auto",
          "description": "Some smart description."
        },
        {
          "name": "basic"
        },
        {
          "name": "advanced"
        }
      ]
    }
]
```

This information can be read by tools (such as IDE) and offer an
auto-completion with the list of values.

Closes gh-2054
2015-06-24 18:53:11 +02:00
Spring Buildmaster
5d81c87b43 Next Development Version 2015-06-04 00:49:11 -07:00
Spring Buildmaster
e03c11dda8 Next development version 2015-03-30 22:56:20 -07:00
Phillip Webb
a57a88f5cf Move master to 1.3.0.BUILD-SNAPSHOT 2015-02-26 17:01:02 -08:00
Spring Buildmaster
8f0ad02237 Next development version 2015-02-26 15:26:53 -08:00
Phillip Webb
56e31a8c6b Polish 2015-02-23 19:21:37 -08:00
Phillip Webb
1f0d45d795 Protect against NPE and improve error message
Update ConfigurationMetadataAnnotationProcessor so that `prefix` is
only obtained when the annotation is not null. Also improve exception
message by including the element.
2015-02-23 18:28:23 -08:00
Stephane Nicoll
e8e39e4bcf polish 2015-02-13 14:56:13 +01:00
Phillip Webb
8e398dc6a7 Polish Javadoc
Update Javadoc to add missing @return and @param elements.
2015-02-03 11:35:06 -08:00
Phillip Webb
072f873f34 Polish 2015-02-01 21:37:17 -08:00
Andy Wilkinson
23c175f674 Polish metadata annotation processor’s incremental build support
The main change in this commit is to introduce a new BuildHandler
abstraction. A BuildHandler is responsible for producing the metadata
for a build. Two implementations are provided; one for standard builds
and one for incremental builds. This change means that the annotation
processor is no longer concerned with the two different build types
and can use the same logic in each case.

The code for reading and writing metadata files has also been moved
out into a separate class, MetadataStore, to allow it to be easily
utilised from multiple places.

Closes gh-2313
2015-01-28 15:27:45 +00:00
Kris De Volder
8df43a8a79 Update the metadata annotation processor to support incremental builds
This commit udpdates the metadata annotation processor so that change
data from an incremental build is merged with the metadata from the
previous build.

Closes gh-2321
2015-01-28 15:26:02 +00:00
Andy Wilkinson
528a632fd1 Allow XA DataSource and ConnFactory pools to be configured via the env
This commit adds support for configuring the XA DataSource and
ConnectionFactory pools created by Atomikos and Bitronix via the
environment. The property prefixes vary depending on the transaction
manager that’s in use. They are:

Bitronix:
 - spring.jta.bitronix.datasource
 - spring.jta.bitronix.connectionfactory

Atomikos:
 - spring.jta.atomikos.datasource
 - spring.jta.atomikos.connectionfactory

The configuration processor has been updated to ignore
javax.jms.XAConnectionFactory and javax.sql.XADataSource as neither of
these types can be created via property binding.

Closes gh-2027
2015-01-27 10:55:56 +00:00
Andy Wilkinson
606ea4979a Add a test to cover the merging of an additional metadata file
This test covers the code path that caused gh-2361 and also checks that,
when an additional metadata file is found, it’s correctly merged with
the other metadata.

Closes gh-2361
2015-01-21 11:18:32 +00:00
Kris De Volder
65acaf885b Remove incorrect assumption that output will be in folder named classes
When running in Eclipse, by default Gradle builds its output into a
folder named bin. This commit update the annotation processor to remove
the failure assumption that the output will always be located beneath
a folder named classes.

Closes gh-2369
See gh-2361
2015-01-21 11:16:56 +00:00
Spring Buildmaster
60725cd8bd Next development version 2015-01-07 23:37:07 -08:00
Phillip Webb
3cd40e2488 Update getSupportedSourceVersion() logic
Use SourceVersion.latestSupported() rather than @SupportedSourceVersion
since we might build with an earlier JDK.

Fixes gh-2302
2015-01-07 15:04:09 -08:00
Phillip Webb
358ad0df37 Log stacktrace on additional metadata merge fail
See gh-2288
2015-01-07 14:07:28 -08:00
Phillip Webb
10177fb754 Update @SupportedSourceVersion to RELEASE_8
Update the @SupportedSourceVersion annotation to RELEASE_8 since it
should indicate "the latest source version an annotation processor
supports".

Fixes gh-2302
2015-01-07 14:07:28 -08:00
Phillip Webb
64b9066661 Refine additional metadata detection logic
Update the additional metadata detection logic to deal with Gradle
folder layouts.

Fixes gh-2271
2015-01-07 14:07:28 -08:00
Kris De Volder
2dfa424246 Don't fail build on merge failure
Be more lenient when processing additional metadata json files.

Fixes gh-2287
Closes gh-2288
2015-01-06 15:02:05 -08:00
Phillip Webb
7c29c96da6 Change additional metadata file lookup logic
Update ConfigurationMetadataAnnotationProcessor to find the additional
metadata json file using createResource rather than getResource. Prior
to this commit the file could be skipped when multiple files were
contained on the classpath.

Fixes gh-2271
2015-01-06 14:50:56 -08:00
Phillip Webb
f2af8b30b0 Code formatting 2014-12-16 09:30:45 -08:00
Stephane Nicoll
77427f53cc Support of Lombok annotated ConfigurationProperties
Previously, no configuration properties were discovered on a class using
lombok instead of regular getters/setters.

This commit adds a support for some of the lombok annotations,
specifically that is @Data, @Getter and @Setter. Provides the same
semantic as what lombok is generating.

Closes gh-2114
2014-12-16 10:41:07 +01:00
Phillip Webb
5dd40e6999 Polish 2014-12-12 16:33:44 -08:00
Stephane Nicoll
8f6f25f88e Improve property target name
Previously, non camel case properties were wrongly resolved, i.e.
getFOO() leading to a 'f-o-o'. While unusual, underscores can also be
added to a property name. In that case, the hyphen should not be added
as the binder consider this to be a single "word". Typically setFoo_Bar
on the "something" prefix is mapped using "something.foo_bar".

All these cases are now handled properly, generating the target name that
the binder expects.

Fixes gh-2118
2014-12-12 14:17:15 +01:00
Spring Buildmaster
1a788c1741 Next development version 2014-12-10 16:35:50 -08:00
Stephane Nicoll
16164b30a9 Do not exclude Flyway's MigrationVersion
flyway.init and flyway.target are two options that are missing from the
meta-data following the change in f0bc3c0. It turns out that both these
properties have an additional setter taking a String so they shouldn't be
excluded after all

Closes gh-2088
2014-12-09 18:17:09 +01:00
Phillip Webb
4b7c6f61b4 Polish 2014-12-08 13:37:39 -08:00
Phillip Webb
f0bc3c08e1 Add additional ElementExcludeFilter items
Fixes gh-2088
2014-12-08 13:35:13 -08:00
Stephane Nicoll
f4fb9ddfe6 Fix wrong file name 2014-12-04 09:35:31 +01:00
Phillip Webb
ba67e16258 Formatting 2014-12-03 09:12:28 -08:00
Stephane Nicoll
509201907c Polish default value for arrays
See gh-1996
2014-12-03 17:32:00 +01:00
Stephane Nicoll
7d57cb7081 Add default value for arrays
Previously, a property holding an array did not have a proper default
value in the meta-data even though the related field was initialized
properly.

An explicit support for arrays has been added. The "defaultValue" now
holds the default value for singular properties or an array of values for
array-based properties. If the value is initalized with an empty array,
the default value is an empty array as well.

Closes gh-1996
2014-12-03 16:18:54 +01:00
Stephane Nicoll
3922808de0 Add exclusion for well-known property types
Previously, any valid property was added to the meta-data of the current
group. This can be annoying for types that are not meant to be bound from
a simple string value. ClassLoader is one example.

A list of well-known types has been added: if the property type matches
an element of this list, it is ignored.

Fixes gh-2012
2014-12-02 19:00:25 -08:00
Stephane Nicoll
20bb9c0305 Remove warnings for expected deprecation usage 2014-11-28 15:54:31 +01:00
Stephane Nicoll
e507c61481 polish 2014-11-27 15:30:04 +01:00
Stephane Nicoll
5b231e600b Also flag deprecated properties in a @Deprecated class
Previously, any property defined in a @Deprecated class were not marked
as deprecated as only the getter or field was inspected for the
annotation.

An additional check on the class has been added to handle this case.

Fixes gh-2014
2014-11-27 15:27:12 +01:00
Phillip Webb
e56a1ba561 Refine inner class detection algorithm
Update the ConfigurationMetadataAnnotationProcessor nested class
algorithm to prevent inner classes being added as both groups and
properties.

Fixes gh-1975
2014-11-21 14:16:37 -08:00
Phillip Webb
2a9a749329 Polish 2014-11-21 13:27:19 -08:00
Stephane Nicoll
2b19955cee Remove useless System.out.println 2014-11-21 17:39:42 +01:00
Stephane Nicoll
32efff3f30 Avoid creating a nested group for an Enum
Previously, an Enum that is defined as an inner class of a
@ConfigurationProperties pojo was wrongly detected as an nested group.

This case is now handled explicitly and covered by a test.

Fixes gh-1971
2014-11-21 17:20:35 +01:00
Phillip Webb
f75b266d64 Add 'deprecated' field to configuration meta-data
Update the ConfigurationMetadataAnnotationProcessor to detect the
@Deprecated annotation on getters or setters.

Fixes gh-1846
2014-11-19 14:15:35 -08:00
Phillip Webb
e902f6b91d Fix annotation processor builder setter detection
Update TypeElementMembers to correctly detect builder style setters.
The previous logic could fail because of the crazy way that TypeMirror
implements its equals() method.

Fixes gh-1859
See gh-1854
2014-11-10 23:03:32 -08:00
Phillip Webb
7b09cbee35 Don't generate empty configuration meta-data
Update ConfigurationMetadataAnnotationProcessor to only write non-empty
meta-data files.

Fixes gh-1858
2014-11-10 22:06:24 -08:00
Phillip Webb
3c9476fbe6 Polish 2014-11-10 19:13:34 -08:00
Stephane Nicoll
2786234eb4 Detect builder-style setter
Previously, a setter method that was returning the current instance was
not identified as a "setter" by the configuration processor. As a result,
builder-style APIs were not covered by the configuration metadata.

If a setter returns either void or the current class, it is now
recognized as a valid setter.

Fixes gh-1854
2014-11-08 17:53:06 +00:00
Stephane Nicoll
5946a44b7b Fix typo 2014-11-08 17:53:06 +00:00
Phillip Webb
2696d37097 Protect against transitive additional meta-data
Update ConfigurationMetadataAnnotationProcessor to ensure that only
local `additional-spring-configuration-metadata.json` files are merged
with the final output.

See gh-1830
2014-11-05 21:03:10 -08:00
Phillip Webb
7e5bb9697c Call meta-data processor regardless of annotations
Update ConfigurationMetadataAnnotationProcessor so that it gets called
even if the source code doesn't include any @ConfigurationProperties
items.

See gh-1830
2014-11-05 21:01:25 -08:00
Stephane Nicoll
a46396f691 Add @NestedConfigurationProperty meta-data support
Add a @NestedConfigurationProperty annotation which can be used to
customize how configuration mete-data is generated.

Prior to this commit only inner-classes where considered nested
(see Tomcat in ServerProperties). Using this new annotation, the Ssl
property in ServerProperties can be detected as well.

See gh-1001
2014-11-02 21:46:36 -08:00
Phillip Webb
c73adcd198 Add a defaultValue attribute to config meta-data
Update `ConfigurationMetadataAnnotationProcessor` to include the
'defaultValue' of a property when possible. For example the
'defaultValue' or 'server.port' is '8080'.

Default values are detected by inspecting the field assignments of
@ConfigurationProperties items. In order to detect field values some
internals of the Java compiler are used. To save a dependency on
'tools.jar' internal javac classes are accessed using reflection.

See gh-1001
2014-11-02 21:46:35 -08:00
Stephane Nicoll
884c058e57 Add processor to generate configuration meta-data
Adds an annotation processor to generates a JSON meta-data file at
compile time from @ConfigurationProperties items. Each meta-data file
can include an array or 'properties' and 'groups'.

A 'property' is a single item that may appear in a Spring Boot
'application.properties' file with a given value. For example,
'server.port' and 'server.context-path' are properties. Each property
may optionally include 'type' and 'description' attributes to provide
the data type (e.g. `java.lang.Integer`, `java.lang.String`) and
some short documentation (taken from the field javadoc) about what the
property is for. For consistency, the type of a primitive is translated
to its wrapper counterpart, i.e. `boolean` becomes `java.lang.Boolean`.

A 'group' provides a higher level grouping of properties. For example
the 'server.port' and 'server.context-path' properties are in the
'server' group.

Both 'property' and 'group' items may additional have 'sourceType' and
'sourceMethod' attributes to indicate the source that contributed them.

Users may use `META-INF/additional-spring-configuration-metadata.json`
to manually provide additionally meta-data that is not covered by
@ConfigurationProperties objects. The contents of this file will be
read and merged with harvested items. The complete meta-data file is
finally written to `META-INF/spring-configuration-metadata.json`.

See gh-1001
2014-11-02 21:46:28 -08:00