package liquibase.configuration.core;

import liquibase.configuration.AbstractMapConfigurationValueProvider;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.servicelocator.LiquibaseService;
import liquibase.util.StringUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;

@LiquibaseService(skip = true)
public class DefaultsFileValueProvider extends AbstractMapConfigurationValueProvider {

    private final Properties properties;
    private final String sourceDescription;

    public DefaultsFileValueProvider(File path) {
        this.sourceDescription = "File " + path.getAbsolutePath();

        try (InputStream stream = new FileInputStream(path)) {
            this.properties = new Properties();
            this.properties.load(stream);
        } catch (Exception e) {
            throw new UnexpectedLiquibaseException(e);
        }

    }

    protected DefaultsFileValueProvider(Properties properties) {
        this.properties = properties;
        sourceDescription = "Passed default properties";
    }

    @Override
    public int getPrecedence() {
        return 50;
    }

    @Override
    protected Map<?, ?> getMap() {
        return properties;
    }

    @Override
    protected boolean keyMatches(String wantedKey, String storedKey) {
        if (super.keyMatches(wantedKey, storedKey)) {
            return true;
        }

        if (wantedKey.replaceFirst(".*\\.", "").equalsIgnoreCase(StringUtil.toCamelCase(storedKey))) {
            //Stored the argument name without a prefix
            return true;
        }

        return false;
    }

    @Override
    protected String getSourceDescription() {
        return sourceDescription;
    }
}

@@ -853,16 +853,49 @@
 tream);%0A
+            trimAllProperties();%0A
         
@@ -987,24 +987,425 @@
   %7D%0A%0A    %7D%0A%0A
+    //%0A    // Remove trailing spaces on the property file values%0A    //%0A    private void trimAllProperties() %7B%0A        properties.forEach((k, v)  -%3E %7B%0A            if (! (v instanceof String)) %7B%0A                return;%0A            %7D%0A            String value = (String)v;%0A            String newString = (value != null ? value.trim() : null);%0A            properties.put(k, newString);%0A        %7D);%0A    %7D%0A%0A
     protecte

Handle trailing spaces in property values