diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index 0d15fb9..3cbab5a 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -4,7 +4,7 @@ on: pull_request jobs: - build: + check_pr: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -15,6 +15,6 @@ jobs: distribution: 'temurin' # overrides the file ~/.m2/settings.xml with data to publish to maven pkg server with id github overwrite-settings: true - - name: Build + - name: Verify run: | mvn -B verify diff --git a/.github/workflows/deploy-snapshot.yml b/.github/workflows/deploy-release.yml similarity index 65% rename from .github/workflows/deploy-snapshot.yml rename to .github/workflows/deploy-release.yml index d33d76a..9cf71f1 100644 --- a/.github/workflows/deploy-snapshot.yml +++ b/.github/workflows/deploy-release.yml @@ -1,12 +1,11 @@ -name: 'Build and Deploy' +name: 'Build and Deploy new releases' on: push: - branches: master - tags: '*' + tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] jobs: - build: + BuildThenDeployRelease: runs-on: ubuntu-latest permissions: contents: write @@ -17,10 +16,19 @@ jobs: with: java-version: '17' distribution: 'temurin' + cache: 'maven' + server-id: central + server-username: MAVEN_USERNAME + server-password: MAVEN_CENTRAL_TOKEN # overrides the file ~/.m2/settings.xml with data to publish to maven pkg server with id github overwrite-settings: true - - name: Build - run: mvn install --no-transfer-progress + - name: Build and Sign* + env: + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + MAVEN_GPG_KEY: ${{ secrets.MAVEN_GPG_KEY }} + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} + run: mvn install gpg:sign --no-transfer-progress - name: Get current version id: version run: echo "::set-output name=prop::$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" diff --git a/README.md b/README.md index baf0531..2df80de 100644 --- a/README.md +++ b/README.md @@ -23,26 +23,15 @@ Usage is simple : just add this dependency inside your pom.xml : io.github.fbibonne boot-properties-logger-starter - 1.1.0 + 1.4.0 ``` NB : -1. the lib is not deployed on maven central for the moment so you must install - it locally before using it : - -```shell -$ git clone https://github.com/FBibonne/Properties-Logger.git --depth=1 --branch=master -$ mvn install -f Properties-Logger/pom.xml -``` - -Now ou can also download it -from [the github project packages](https://github.com/FBibonne/Properties-Logger/packages/2229078) - -2. The module module _Properties Logger_ logs its message with properties and their values - at the info level : so its **log level must be at least INFO**. DEBUG (or TRACE) give (much) more - informations. + The module module _Properties Logger_ logs its message with properties and their values + at the info level : so its **log level must be at least INFO**. DEBUG (or TRACE) give (much) more + informations. ## Result diff --git a/pom.xml b/pom.xml index fa20695..78fff9d 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.github.fbibonne boot-properties-logger-starter - 1.3.0 + 1.4.0 jar @@ -21,12 +21,14 @@ UTF-8 - - + Spring Boot Properties Logger + + + Fabrice Bibonne https://github.com/Fbibonne - - + + https://github.com/FBibonne/Properties-Logger/issues @@ -37,10 +39,20 @@ and their values resolved by Spring Boot. - https://github.com/FBibonne/Properties-Logger?tab=readme-ov-file#readme + https://github.com/FBibonne/Properties-Logger + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + scm:git:https://github.com/FBibonne/Properties-Logger.git + scm:git:git://github.com/FBibonne/Properties-Logger.git + https://github.com/FBibonne/Properties-Logger/tree/master @@ -92,6 +104,50 @@ true + + org.apache.maven.plugins + maven-source-plugin + 3.3.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.10.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.2.8 + + bc + + + + org.sonatype.central + central-publishing-maven-plugin + 0.8.0 + true + + central + Properties-Logger + + diff --git a/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/EnvironmentPreparedEventForPropertiesLogging.java b/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/EnvironmentPreparedEventForPropertiesLogging.java index e2e9eea..e959aa0 100644 --- a/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/EnvironmentPreparedEventForPropertiesLogging.java +++ b/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/EnvironmentPreparedEventForPropertiesLogging.java @@ -10,6 +10,14 @@ import java.util.Optional; import java.util.Set; +/** + * Spring ApplicationListener which triggers on {@link ApplicationEnvironmentPreparedEvent} to start properties logging process. + * If the logging is enabled (with property {@code properties.logger.disabled} at {@code false} (which is default value) ) and the + * environment associated with the applicationEnvironmentPreparedEvent is an {@link ConfigurableEnvironment}, then the listener + * will log properties using provided configuration. The responsibility of this class is only to trigger the process and collect the + * configuration for logging properties (properties starting with {@code properties.logger}) in the environment. It delegates the + * logging process to an instance of {@link PropertiesLogger} + */ public record EnvironmentPreparedEventForPropertiesLogging() implements ApplicationListener { private static final LocalLogger log = new LocalLogger(EnvironmentPreparedEventForPropertiesLogging.class); diff --git a/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java b/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java index 3d44a5e..95fa324 100644 --- a/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java +++ b/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java @@ -14,6 +14,12 @@ import java.util.function.UnaryOperator; import java.util.stream.Stream; +/** + * Class doing the real stuff for logging properties. The collect of properties to log, their value and the logging is done + * inside the {@link this#doLogProperties(EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment)} method. + * The state of the class stores {@link PropertySource} found, and a reference to an operator providing the origin of a property + * which is found while scanning propertySources + */ class PropertiesLogger { public static final String SEPARATION_LINE = "================================================================================"; @@ -35,6 +41,22 @@ class PropertiesLogger { this.ignoredPropertySources = ignoredPropertySources; } + /** + * This method : + *
    + *
  1. lists all propertySources of the environment and exclude all those which cannot be processed (see method {@link this#isEnumerable(PropertySource)} + * or are listed to be ignored (see property {@code properties.logger.sources-ignored}
  2. + *
  3. for each propertySource not excluded, list all property keys then exclude {@code null} keys and non-allowed prefixed ones (see property {@code properties.logger.prefix-for-properties}
  4. + *
  5. order distinct keys with alphabetical order (natural order of {@link String}
  6. + *
  7. for each key, compute an expression {@code key = value ### FROM value_origin ###} where {@code value} is the value of the key resolved against + * the environment (or masked if key is listed in property {@code properties.logger.with-hidden-values}) and {@code value_origin} is the + * propertySource which contains the value to which the key is resolved (if field {@link this#originFinder} can resolve it)
  8. + *
  9. log the list of used propertySources to find keys, the ordered list of properties and their values and origin when available
  10. + *
+ * + * @param abstractEnvironment : the environment of the application wrapped as an {@link io.github.fbibonne.springaddons.boot.propertieslogger.EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment} + * to safely resolve properties with unknown placeholders + */ public void doLogProperties(final EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment abstractEnvironment) { log.debug(() -> "Start logging properties with prefix " + allowedPrefixForProperties + " for all properties sources except " + ignoredPropertySources + ". Values masked for properties whose keys contain " + propertiesWithHiddenValues); @@ -102,6 +124,16 @@ private Stream toPropertyNames(EnumerablePropertySource propertySourc return Arrays.stream(propertySource.getPropertyNames()); } + /** + * Method which filter propertySource which can be processed to find properties to log. + * propertySource which can be processed are a subtype of {@link EnumerablePropertySource} : if not method log a + * debug message or a warning message for cases not implemented yet (AnsiPropertySource and JndiPropertySource). If + * propertySource is of type {@link org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource}, + * it will be referenced to resolve origin of property values later (see {@link this#originFinder}. If propertySource + * has an unknown type, a warning is logged. + * @param propertySource : instance of {@link PropertySource} which is checked for being processed or not. + * @return true if the propertySource can be processed. + */ private boolean isEnumerable(PropertySource propertySource) { if (propertySource instanceof AnsiPropertySource ansiPropertySource) { log.warn(()->"Processing of AnsiPropertySource "+ ansiPropertySource+" not yet implemented : properties exclusively from this property source will be ignored");