diff --git a/execution/src/main/java/org/springframework/batch/execution/facade/BatchResourceFactoryBean.java b/execution/src/main/java/org/springframework/batch/execution/facade/BatchResourceFactoryBean.java index 8625c270a..da05a71f7 100644 --- a/execution/src/main/java/org/springframework/batch/execution/facade/BatchResourceFactoryBean.java +++ b/execution/src/main/java/org/springframework/batch/execution/facade/BatchResourceFactoryBean.java @@ -16,6 +16,8 @@ package org.springframework.batch.execution.facade; +import java.io.File; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.context.ResourceLoaderAware; @@ -151,6 +153,9 @@ public class BatchResourceFactoryBean extends AbstractFactoryBean implements Res public void setRootDirectory(String rootDirectory) { this.rootDirectory = rootDirectory; + if (rootDirectory!=null && rootDirectory.endsWith(File.separator)) { + this.rootDirectory = rootDirectory.substring(0, rootDirectory.lastIndexOf(File.separator)); + } } public void setStepName(String stepName) { diff --git a/execution/src/test/java/org/springframework/batch/execution/facade/BatchResourceFactoryBeanTests.java b/execution/src/test/java/org/springframework/batch/execution/facade/BatchResourceFactoryBeanTests.java index fc50f4f9b..387c06f7b 100644 --- a/execution/src/test/java/org/springframework/batch/execution/facade/BatchResourceFactoryBeanTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/facade/BatchResourceFactoryBeanTests.java @@ -39,24 +39,21 @@ public class BatchResourceFactoryBeanTests extends TestCase { */ private BatchResourceFactoryBean resourceFactory = new BatchResourceFactoryBean(); - private String rootDir = System.getProperty("java.io.tmpdir"); + private String rootDir = getRootDir(); private char pathsep = File.separatorChar; private String PATTERN_STRING = "%BATCH_ROOT%"+pathsep+"%JOB_NAME%-%SCHEDULE_DATE%-%JOB_RUN%-%STREAM_NAME%"; - private String EXPECTED_ABSOLUTE_PATH = rootDir+"testJob-20070730-0-testStream"; + private String EXPECTED_ABSOLUTE_PATH = rootDir+pathsep+"testJob-20070730-0-testStream"; - private String NULL_JOB_NAME_PATH = rootDir+"%JOB_NAME%-20070730-0-testStream"; + private String NULL_JOB_NAME_PATH = rootDir+pathsep+"%JOB_NAME%-20070730-0-testStream"; /** * mock step context */ protected void setUp() throws Exception { - System.err.println("***for Ben, System.getProperty(\"java.io.tmpdir\"): "+rootDir); - System.err.println("***for Ben, File.createTempFile(\"foo\", \".bar\"): "+File.createTempFile("foo", ".bar")); - assertNotNull(rootDir); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2007); calendar.set(Calendar.MONTH, Calendar.JULY); @@ -74,6 +71,15 @@ public class BatchResourceFactoryBeanTests extends TestCase { resourceFactory.afterPropertiesSet(); } + private String getRootDir() { + String rootDir = System.getProperty("java.io.tmpdir"); + assertNotNull(rootDir); + if (rootDir!=null && rootDir.endsWith(File.separator)) { + rootDir = rootDir.substring(0, rootDir.lastIndexOf(File.separator)); + } + return rootDir; + } + /** * regular use with valid context and pattern provided */ @@ -83,6 +89,8 @@ public class BatchResourceFactoryBeanTests extends TestCase { String returnedPath = resource.getFile().getAbsolutePath(); + System.err.println(EXPECTED_ABSOLUTE_PATH); + System.err.println(returnedPath); assertEquals(EXPECTED_ABSOLUTE_PATH, returnedPath); }