You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2020/07/17 14:41:50 UTC

[maven-filtering] branch master updated: [SHARED-934] Allow using a different encoding when filtering properties files. - Add logging to inform the users if the encoding for properties files have not been set, and what consequences that might have.

This is an automated email from the ASF dual-hosted git repository.

dennisl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-filtering.git


The following commit(s) were added to refs/heads/master by this push:
     new 1bc58b3  [SHARED-934] Allow using a different encoding when filtering properties files. - Add logging to inform the users if the encoding for properties files have not been set, and what consequences that might have.
1bc58b3 is described below

commit 1bc58b3b2fa7f9155d9cc9b32395ccb72076b4ff
Author: Dennis Lundberg <de...@apache.org>
AuthorDate: Fri Jul 17 16:41:39 2020 +0200

    [SHARED-934] Allow using a different encoding when filtering properties files.
    - Add logging to inform the users if the encoding for properties files have not been set, and what consequences that might have.
---
 .../filtering/DefaultMavenResourcesFiltering.java  | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index a3d8a81..5108e0f 100644
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -144,6 +144,22 @@ public class DefaultMavenResourcesFiltering
                 + "' encoding to copy filtered resources." );
         }
 
+        if ( mavenResourcesExecution.getPropertiesEncoding() == null
+            || mavenResourcesExecution.getPropertiesEncoding().length() < 1 )
+        {
+            getLogger().info( "Using '" + mavenResourcesExecution.getEncoding()
+                + "' encoding to copy filtered properties files." );
+        }
+        else
+        {
+            getLogger().info( "Using '" + mavenResourcesExecution.getPropertiesEncoding()
+                + "' encoding to copy filtered properties files." );
+        }
+
+        // Keep track of filtering being used and the properties files being filtered
+        boolean isFilteringUsed = false;
+        List<File> propertiesFiles = new ArrayList<>();
+
         for ( Resource resource : mavenResourcesExecution.getResources() )
         {
 
@@ -190,6 +206,10 @@ public class DefaultMavenResourcesFiltering
                 throw new MavenFilteringException( "Cannot create resource output directory: " + outputDirectory );
             }
 
+            if ( resource.isFiltering() )
+            {
+                isFilteringUsed = true;
+            }
             boolean ignoreDelta = !outputExists || buildContext.hasDelta( mavenResourcesExecution.getFileFilters() )
                 || buildContext.hasDelta( getRelativeOutputDirectory( mavenResourcesExecution ) );
             getLogger().debug( "ignoreDelta " + ignoreDelta );
@@ -229,6 +249,10 @@ public class DefaultMavenResourcesFiltering
 
                 boolean filteredExt =
                     filteredFileExtension( source.getName(), mavenResourcesExecution.getNonFilteredFileExtensions() );
+                if ( resource.isFiltering() && isPropertiesFile( source ) )
+                {
+                    propertiesFiles.add( source );
+                }
 
                 // Determine which encoding to use when filtering this file
                 String encoding = getEncoding( source, mavenResourcesExecution.getEncoding(),
@@ -262,6 +286,37 @@ public class DefaultMavenResourcesFiltering
 
         }
 
+        // Warn the user if all of the following requirements are met, to avoid those that are not affected
+        // - the propertiesEncoding parameter has not been set
+        // - properties is a filtered extension
+        // - filtering is enabled for at least one resource
+        // - there is at least one properties file in one of the resources that has filtering enabled
+        if ( ( mavenResourcesExecution.getPropertiesEncoding() == null
+            || mavenResourcesExecution.getPropertiesEncoding().length() < 1 )
+            && !mavenResourcesExecution.getNonFilteredFileExtensions().contains( "properties" )
+            && isFilteringUsed
+            && propertiesFiles.size() > 0 )
+        {
+            // @todo Sometime in the future we should change this to be a warning
+            getLogger().info( "The encoding used to copy filtered properties files have not been set."
+                                  + " This means that the same encoding will be used to copy filtered properties files"
+                                  + " as when copying other filtered resources. This might not be what you want!"
+                                  + " Run your build with --debug to see which files might be affected."
+                                  + " Read more at "
+                                  + "https://maven.apache.org/plugins/maven-resources-plugin/"
+                                  + "examples/filtering-properties-files.html" );
+
+            StringBuilder affectedFiles = new StringBuilder();
+            affectedFiles.append( "Here is a list of the filtered properties files in you project that might be"
+                                      + " affected by encoding problems: " );
+            for ( File propertiesFile : propertiesFiles )
+            {
+                affectedFiles.append( System.lineSeparator() ).append( " - " ).append( propertiesFile.getPath() );
+            }
+            getLogger().debug( affectedFiles.toString() );
+
+        }
+
     }
 
     /**