novoda / gradle-build-properties-plugin

Keep your secrets secret. External build properties support for your Gradle scripts.
Other
110 stars 13 forks source link

Improve error rendering #32

Closed mr-archano closed 7 years ago

mr-archano commented 7 years ago

Scope of the PR

This PR adds a description property to each build properties set. Such information is then printed below the message of an evaluation failure to give the user more context about the properties set involved in the evaluation (as Additional info:). Example:

...
Build file '/Users/toto/novoda/gradle-build-properties-plugin/sample/app/build.gradle' line: 53

> Build properties evaluation failed:
  - Unable to find value for key 'googleMapsKey2' in properties set 'buildProperties.secrets'.
  - Unable to create properties set 'buildProperties.notThere': file:///Users/toto/novoda/gradle-build-properties-plugin/sample/whatever does not exist.

  Additional info:
  * buildProperties.notThere: This file actually doesn't exists. This properties set is used to show how
                              properties files are lazy-loaded.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

The new description property makes incidentally obsolete the old API to create a build properties set from a properties file:

BeforeAfter
file (File file, String errorMessage)
from (File file)
setDescription(String description)
buildProperties {
 foo {
  file project.file('foo.properties'),
   'This properties set ...'
 }
}
buildProperties {
 foo {
  from project.file('foo.properties')
  description='This properties set ...'
 }
}

Considerations/Implementation Details

Each properties set (instance of BuildProperties) now holds an ExceptionFactory that can be used to create exceptions thrown as part of the evaluation of their entries. The BuildPropertiesException instances assembled via the factory are then including also the additional info of the properties sets involved in the evaluation.

mr-archano commented 7 years ago

Addresses #33 and #34