diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContext.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContext.java index c5355a312..107a4e07d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContext.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContext.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.jsr.configuration.support; +import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -99,11 +100,18 @@ public class BatchPropertyContext { for(Map.Entry propertiesEntry : properties.entrySet()) { String stepName = propertiesEntry.getKey(); + Properties stepProperties = propertiesEntry.getValue(); - if (!propertiesEntry.getValue().isEmpty()) { + if (!stepProperties.isEmpty()) { if (this.stepProperties.containsKey(stepName)) { Properties existingStepProperties = this.stepProperties.get(stepName); - existingStepProperties.putAll(propertiesEntry.getValue()); + + Enumeration stepPropertyNames = stepProperties.propertyNames(); + + while(stepPropertyNames.hasMoreElements()) { + String propertyEntryName = (String) stepPropertyNames.nextElement(); + existingStepProperties.put(propertyEntryName, stepProperties.getProperty(propertyEntryName)); + } this.stepProperties.put(stepName, existingStepProperties); } else { @@ -134,9 +142,7 @@ public class BatchPropertyContext { /** *

- * Obtains the batch {@link Properties} for the provided artifact name. The returned {@link Properties} - * will also contain any job level properties that have been set. Job level properties will not override - * existing lower level artifact properties. + * Obtains the batch {@link Properties} for the provided artifact name. *

* * @param artifactName the batch artifact to obtain properties for @@ -144,7 +150,6 @@ public class BatchPropertyContext { */ public Properties getArtifactProperties(String artifactName) { Properties properties = new Properties(); - properties.putAll(getJobProperties()); if (artifactProperties.containsKey(artifactName)) { properties.putAll(artifactProperties.get(artifactName)); @@ -184,7 +189,6 @@ public class BatchPropertyContext { */ public Properties getStepArtifactProperties(String stepName, String artifactName) { Properties properties = new Properties(); - properties.putAll(getJobProperties()); properties.putAll(getStepProperties(stepName)); Map artifactProperties = stepArtifactProperties.get(stepName); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/PropertyParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/PropertyParser.java index 28b373916..3555a9acb 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/PropertyParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/PropertyParser.java @@ -36,18 +36,18 @@ import org.w3c.dom.Element; * @since 3.0 */ public class PropertyParser { - private static final String PROPERTY_ELEMENT = "property"; - private static final String PROPERTIES_ELEMENT = "properties"; - private static final String PROPERTY_NAME_ATTRIBUTE = "name"; - private static final String PROPERTY_VALUE_ATTRIBUTE = "value"; - private static final String JOB_PROPERTIES_BEAN_NAME = "jobProperties"; - private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext"; - private static final String JOB_PROPERTIES_PROPERTY_NAME = "jobProperties"; - private static final String STEP_PROPERTIES_PROPERTY_NAME = "stepProperties"; - private static final String ARTIFACT_PROPERTIES_PROPERTY_NAME = "artifactProperties"; - private static final String STEP_ARTIFACT_PROPERTIES_PROPERTY_NAME = "stepArtifactProperties"; + private static final String PROPERTY_ELEMENT = "property"; + private static final String PROPERTIES_ELEMENT = "properties"; + private static final String PROPERTY_NAME_ATTRIBUTE = "name"; + private static final String PROPERTY_VALUE_ATTRIBUTE = "value"; + private static final String JOB_PROPERTIES_BEAN_NAME = "jobProperties"; + private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext"; + private static final String JOB_PROPERTIES_PROPERTY_NAME = "jobProperties"; + private static final String STEP_PROPERTIES_PROPERTY_NAME = "stepProperties"; + private static final String ARTIFACT_PROPERTIES_PROPERTY_NAME = "artifactProperties"; + private static final String STEP_ARTIFACT_PROPERTIES_PROPERTY_NAME = "stepArtifactProperties"; - private String beanName; + private String beanName; private String stepName; private ParserContext parserContext; private BatchArtifact.BatchArtifactType batchArtifactType; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContextTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContextTests.java index d8d555089..2ab952715 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContextTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/support/BatchPropertyContextTests.java @@ -144,11 +144,9 @@ public class BatchPropertyContextTests { batchPropertyContext.setStepProperties(stepProperties); Properties artifactProperties = batchPropertyContext.getArtifactProperties("decider1"); - assertEquals(4, artifactProperties.size()); + assertEquals(2, artifactProperties.size()); assertEquals("deciderProperty1value", artifactProperties.getProperty("deciderProperty1")); assertEquals("deciderProperty2value", artifactProperties.getProperty("deciderProperty2")); - assertEquals("jobProperty1value", artifactProperties.getProperty("jobProperty1")); - assertEquals("jobProperty2value", artifactProperties.getProperty("jobProperty2")); } @Test @@ -160,13 +158,11 @@ public class BatchPropertyContextTests { batchPropertyContext.setStepArtifactProperties(stepArtifactProperties); Properties artifactProperties = batchPropertyContext.getStepArtifactProperties("step1", "reader"); - assertEquals(6, artifactProperties.size()); + assertEquals(4, artifactProperties.size()); assertEquals("readerProperty1value", artifactProperties.getProperty("readerProperty1")); assertEquals("readerProperty2value", artifactProperties.getProperty("readerProperty2")); assertEquals("step1PropertyValue1", artifactProperties.getProperty("step1PropertyName1")); assertEquals("step1PropertyValue2", artifactProperties.getProperty("step1PropertyName2")); - assertEquals("jobProperty1value", artifactProperties.getProperty("jobProperty1")); - assertEquals("jobProperty2value", artifactProperties.getProperty("jobProperty2")); } @Test @@ -181,11 +177,9 @@ public class BatchPropertyContextTests { batchPropertyContext.setJobProperties(jobProperties); Properties step1 = batchPropertyContext.getArtifactProperties("decider1"); - assertEquals(4, step1.size()); + assertEquals(2, step1.size()); assertEquals("deciderProperty1value", step1.getProperty("deciderProperty1")); assertEquals("deciderProperty2value", step1.getProperty("deciderProperty2")); - assertEquals("jobProperty1value", step1.getProperty("jobProperty1")); - assertEquals("jobProperty2value", step1.getProperty("jobProperty2")); Properties job = batchPropertyContext.getJobProperties(); assertEquals(3, job.size()); @@ -204,14 +198,12 @@ public class BatchPropertyContextTests { batchPropertyContext.setStepArtifactProperties(partitionProperties); Properties artifactProperties = batchPropertyContext.getStepArtifactProperties("step2:partition0", "writer"); - assertEquals(8, artifactProperties.size()); + assertEquals(6, artifactProperties.size()); assertEquals("writerProperty1", artifactProperties.getProperty("writerProperty1Step")); assertEquals("writerProperty2", artifactProperties.getProperty("writerProperty2Step")); assertEquals("writerProperty1valuePartition0", artifactProperties.getProperty("writerProperty1")); assertEquals("writerProperty2valuePartition0", artifactProperties.getProperty("writerProperty2")); assertEquals("step2PropertyValue1", artifactProperties.getProperty("step2PropertyName1")); assertEquals("step2PropertyValue2", artifactProperties.getProperty("step2PropertyName2")); - assertEquals("jobProperty1value", artifactProperties.getProperty("jobProperty1")); - assertEquals("jobProperty2value", artifactProperties.getProperty("jobProperty2")); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java index 8ff2c4d4e..a9b114281 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java @@ -81,8 +81,6 @@ public class JobPropertyTests { org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName2").equals("step1PropertyValue2")); org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null); org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null); - org.springframework.util.Assert.isTrue("jobPropertyValue1".equals(jobPropertyName1)); - org.springframework.util.Assert.isTrue("jobPropertyValue2".equals(jobPropertyName2)); org.springframework.util.Assert.isTrue("readerPropertyValue1".equals(readerPropertyName1)); org.springframework.util.Assert.isTrue("readerPropertyValue2".equals(readerPropertyName2)); org.springframework.util.Assert.isTrue("annotationNamedReaderPropertyValue".equals(annotationNamedProperty)); @@ -92,6 +90,14 @@ public class JobPropertyTests { org.springframework.util.Assert.notNull(injectAnnotatedOnlyField); org.springframework.util.Assert.isTrue("job1".equals(injectAnnotatedOnlyField.getJobName())); org.springframework.util.Assert.isNull(readerPropertyName3); + + Properties jobProperties = injectAnnotatedOnlyField.getProperties(); + org.springframework.util.Assert.isTrue(jobProperties.size() == 5); + org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName1").equals("jobPropertyValue1")); + org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName2").equals("jobPropertyValue2")); + org.springframework.util.Assert.isTrue(jobProperties.get("step2name").equals("step2")); + org.springframework.util.Assert.isTrue(jobProperties.get("filestem").equals("postings")); + org.springframework.util.Assert.isTrue(jobProperties.get("x").equals("xVal")); } @Override @@ -242,6 +248,9 @@ public class JobPropertyTests { @Inject @BatchProperty String notDefinedProperty; @Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty; @Inject javax.batch.runtime.context.StepContext stepContext; + @Inject @BatchProperty(name = "infile.name") String infile; + @Inject @BatchProperty(name = "y") String y; + @Inject @BatchProperty(name = "x") String x; @Override public String process() throws Exception { @@ -256,8 +265,11 @@ public class JobPropertyTests { org.springframework.util.Assert.isTrue("batchletPropertyValue1".equals(batchletPropertyName1)); org.springframework.util.Assert.isTrue("batchletPropertyValue2".equals(batchletPropertyName2)); org.springframework.util.Assert.isTrue("annotationNamedBatchletPropertyValue".equals(annotationNamedProperty)); + org.springframework.util.Assert.isTrue("postings.txt".equals(infile)); + org.springframework.util.Assert.isTrue("xVal".equals(y)); org.springframework.util.Assert.isNull(notDefinedProperty); org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty); + org.springframework.util.Assert.isNull(x); return null; } diff --git a/spring-batch-core/src/test/resources/META-INF/batch-jobs/jsrJobPropertyTests.xml b/spring-batch-core/src/test/resources/META-INF/batch-jobs/jsrJobPropertyTests.xml index 5791bf1b3..9e99606f3 100644 --- a/spring-batch-core/src/test/resources/META-INF/batch-jobs/jsrJobPropertyTests.xml +++ b/spring-batch-core/src/test/resources/META-INF/batch-jobs/jsrJobPropertyTests.xml @@ -6,6 +6,8 @@ + + @@ -92,6 +94,8 @@ + +