From f32c7922dd4bd2517fb0a1b167801bc065de9337 Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Tue, 12 Aug 2025 16:51:00 +0200 Subject: [PATCH 1/7] pom(prepare publish to central) --- pom.xml | 56 +++++++++++++++++-- ...mentPreparedEventForPropertiesLogging.java | 8 +++ .../propertieslogger/PropertiesLogger.java | 32 +++++++++++ 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index fa20695..8e4d5e2 100644 --- a/pom.xml +++ b/pom.xml @@ -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,40 @@ 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 + + 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"); From a59dc08cd3ee4f516b6a5b2d68fe9aa6dad24b9c Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 13 Aug 2025 12:12:10 +0200 Subject: [PATCH 2/7] ci(test mvn requirements) --- .github/workflows/check-mvn.yml | 22 ++++++++++++++++++++++ .github/workflows/check-pr.yml | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/check-mvn.yml diff --git a/.github/workflows/check-mvn.yml b/.github/workflows/check-mvn.yml new file mode 100644 index 0000000..2056689 --- /dev/null +++ b/.github/workflows/check-mvn.yml @@ -0,0 +1,22 @@ +name: 'try gpg sign' + +on: + push: + branches: prepare-central-publish + +jobs: + check_pr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + # overrides the file ~/.m2/settings.xml with data to publish to maven pkg server with id github + overwrite-settings: true + - name: Test gpg + run: | + mvn -B clean package gpg:sign + ls target 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 From f71ebac78d399c6c02bd00299ed7c8349fdedce1 Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 13 Aug 2025 12:16:19 +0200 Subject: [PATCH 3/7] ci(test mvn requirements) --- .github/workflows/check-mvn.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check-mvn.yml b/.github/workflows/check-mvn.yml index 2056689..a27dab1 100644 --- a/.github/workflows/check-mvn.yml +++ b/.github/workflows/check-mvn.yml @@ -18,5 +18,8 @@ jobs: overwrite-settings: true - name: Test gpg run: | + echo $MAVEN_GPG_TEST + echo ${#MAVEN_GPG_PASSPHRASE} + echo ${#MAVEN_GPG_KEY} mvn -B clean package gpg:sign ls target From 56d4886303b20acaea1a98aaf21726a6919afcdc Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 13 Aug 2025 12:22:45 +0200 Subject: [PATCH 4/7] ci(test mvn requirements) --- .github/workflows/check-mvn.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check-mvn.yml b/.github/workflows/check-mvn.yml index a27dab1..6b632c4 100644 --- a/.github/workflows/check-mvn.yml +++ b/.github/workflows/check-mvn.yml @@ -17,6 +17,9 @@ jobs: # overrides the file ~/.m2/settings.xml with data to publish to maven pkg server with id github overwrite-settings: true - name: Test gpg + env: + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + MAVEN_GPG_KEY: ${{ secrets.MAVEN_GPG_KEY }} run: | echo $MAVEN_GPG_TEST echo ${#MAVEN_GPG_PASSPHRASE} From 0d5b2820b86d5b9c4631b1eab8a210ec6e5ba8b4 Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 13 Aug 2025 15:14:39 +0200 Subject: [PATCH 5/7] ci(add maven central deployment instruction) --- .github/workflows/check-mvn.yml | 28 ------------------- ...deploy-snapshot.yml => deploy-release.yml} | 17 ++++++++--- pom.xml | 10 +++++++ 3 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/check-mvn.yml rename .github/workflows/{deploy-snapshot.yml => deploy-release.yml} (67%) diff --git a/.github/workflows/check-mvn.yml b/.github/workflows/check-mvn.yml deleted file mode 100644 index 6b632c4..0000000 --- a/.github/workflows/check-mvn.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: 'try gpg sign' - -on: - push: - branches: prepare-central-publish - -jobs: - check_pr: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - # overrides the file ~/.m2/settings.xml with data to publish to maven pkg server with id github - overwrite-settings: true - - name: Test gpg - env: - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} - MAVEN_GPG_KEY: ${{ secrets.MAVEN_GPG_KEY }} - run: | - echo $MAVEN_GPG_TEST - echo ${#MAVEN_GPG_PASSPHRASE} - echo ${#MAVEN_GPG_KEY} - mvn -B clean package gpg:sign - ls target diff --git a/.github/workflows/deploy-snapshot.yml b/.github/workflows/deploy-release.yml similarity index 67% rename from .github/workflows/deploy-snapshot.yml rename to .github/workflows/deploy-release.yml index d33d76a..ca55666 100644 --- a/.github/workflows/deploy-snapshot.yml +++ b/.github/workflows/deploy-release.yml @@ -1,4 +1,4 @@ -name: 'Build and Deploy' +name: 'Build and Deploy new releases' on: push: @@ -6,7 +6,7 @@ on: tags: '*' jobs: - build: + BuildThenDeployRelease: runs-on: ubuntu-latest permissions: contents: write @@ -17,10 +17,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/pom.xml b/pom.xml index 8e4d5e2..0169315 100644 --- a/pom.xml +++ b/pom.xml @@ -138,6 +138,16 @@ bc + + org.sonatype.central + central-publishing-maven-plugin + 0.8.0 + true + + central + Properties-Logger + + From c0b87ea5de9bf872a2d409dc48728cf37e482c68 Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 13 Aug 2025 15:15:00 +0200 Subject: [PATCH 6/7] ci(deploy only for release tags) --- .github/workflows/deploy-release.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index ca55666..9cf71f1 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -2,8 +2,7 @@ name: 'Build and Deploy new releases' on: push: - branches: master - tags: '*' + tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] jobs: BuildThenDeployRelease: From d4ee707faf2cfc80e2ae247e09a893853afe1c2d Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 13 Aug 2025 18:48:27 +0200 Subject: [PATCH 7/7] pom (upgrade to new version for maven central) --- README.md | 19 ++++--------------- pom.xml | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) 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 0169315..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