diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java index 7e48bdad..84d60f8d 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java @@ -690,7 +690,7 @@ public List getJbakeProperties() { @Override public void addConfiguration(Properties properties) { - compositeConfiguration.addConfiguration(new MapConfiguration(properties)); + compositeConfiguration.addConfigurationFirst(new MapConfiguration(properties)); } @Override diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java index cdd11e6b..42260e2c 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java @@ -339,7 +339,7 @@ public interface JBakeConfiguration { String getVersion(); /** - * Set a property value for the given key + * Set a property value for the given key. * * @param key the key for the property * @param value the value of the property @@ -371,6 +371,10 @@ public interface JBakeConfiguration { List getJbakeProperties(); + /** + * Adds another configuration whose properties take precedence over the ones already set. + * @param properties + */ void addConfiguration(Properties properties); } diff --git a/jbake-core/src/test/java/org/jbake/app/configuration/DefaultJBakeConfigurationTest.java b/jbake-core/src/test/java/org/jbake/app/configuration/DefaultJBakeConfigurationTest.java new file mode 100644 index 00000000..7241d017 --- /dev/null +++ b/jbake-core/src/test/java/org/jbake/app/configuration/DefaultJBakeConfigurationTest.java @@ -0,0 +1,41 @@ +package org.jbake.app.configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.File; +import java.util.Properties; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class DefaultJBakeConfigurationTest { + + @TempDir + File root; + + private JBakeConfiguration jBakeConfig; + + @BeforeEach + public void setup() { + jBakeConfig = new ConfigUtil().loadConfig(root, null); + } + + @Test + public void testAddConfiguration() { + Properties props = new Properties(); + props.setProperty("version", "overwritten"); // overwrite property from default.properties + props.setProperty("foo", "bar"); + jBakeConfig.addConfiguration(props); + assertEquals("overwritten", jBakeConfig.get("version")); + assertEquals("bar", jBakeConfig.get("foo")); + } + + @Test + public void testSetProperty() { + jBakeConfig.setProperty("version", "overwritten"); // overwrite property from default.properties + jBakeConfig.setProperty("foo", "bar"); + assertEquals("overwritten", jBakeConfig.get("version")); + assertEquals("bar", jBakeConfig.get("foo")); + } +}