diff --git a/archetypes/simple-cli/.settings/org.maven.ide.eclipse.prefs b/archetypes/simple-cli/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..1c96ca81c --- /dev/null +++ b/archetypes/simple-cli/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Wed Sep 09 07:53:29 BST 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractGroupAwareJobFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractGroupAwareJobFactory.java deleted file mode 100644 index ace036880..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractGroupAwareJobFactory.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.configuration.support; - -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParametersIncrementer; -import org.springframework.batch.core.configuration.JobFactory; - -/** - * A {@link JobFactory} that can optionally prepend a group name to a job's - * name, to make it fit a naming convention for type or origin. E.g. the source - * job might be overnightJob and the group - * financeDepartment, which would result in a {@link Job} with - * identical functionality but named financeDepartment$overnightJob - * . The use of a "." separator for elements is deliberate, since it is a "safe" - * character in a URL. - * - * - * @author Dave Syer - * - */ -public abstract class AbstractGroupAwareJobFactory implements JobFactory { - - /** - * - */ - private static final String SEPARATOR = "."; - - private final String groupName; - - private final String jobName; - - /** - * Create a job factory for a job in no particular group. - * - * @param jobName the name of the job - */ - public AbstractGroupAwareJobFactory(String jobName) { - this(null, jobName); - } - - /** - * Create a job factory for a job in the group provided. The {@link Job} - * eventually returned from {@link #createJob()} will have a name composed - * of the group and job names together. - * - * @param groupName the name of the group - * @param jobName the name of the job - */ - public AbstractGroupAwareJobFactory(String groupName, String jobName) { - this.groupName = groupName; - this.jobName = jobName; - } - - /** - * The main factory method. Delegates to {@link #doCreateJob(String)} to - * create a delegate, which is then wrapped to give a job with the same - * functionality but a composite name (if the group is specified). - * - * @see org.springframework.batch.core.configuration.JobFactory#createJob() - */ - public final Job createJob() { - Job job = doCreateJob(jobName); - return groupName == null ? job : new GroupAwareJob(groupName, job); - } - - /** - * Extension point for concrete subclasses. - * - * @return a Job from the provided name - */ - protected abstract Job doCreateJob(String jobName); - - /** - * Return the bean name of the job in the application context. N.B. this is - * usually the name of the job as well, but it needn't be. The important - * thing is that the job can be located by this name. - * - * @see org.springframework.batch.core.configuration.JobFactory#getJobName() - */ - public final String getJobName() { - return groupName == null ? jobName : groupName + SEPARATOR + jobName; - } - - /** - * @author Dave Syer - * - */ - private static class GroupAwareJob implements Job { - - private final Job delegate; - - private final String groupName; - - /** - * @param groupName - * @param delegate - */ - public GroupAwareJob(String groupName, Job delegate) { - super(); - this.groupName = groupName; - this.delegate = delegate; - } - - public void execute(JobExecution execution) { - delegate.execute(execution); - } - - /** - * Concatenates the group name and the delegate job name (joining with a - * "$"). - * - * @see org.springframework.batch.core.Job#getName() - */ - public String getName() { - return groupName + SEPARATOR + delegate.getName(); - } - - public boolean isRestartable() { - return delegate.isRestartable(); - } - - public JobParametersIncrementer getJobParametersIncrementer() { - return delegate.getJobParametersIncrementer(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (obj instanceof GroupAwareJob) { - return ((GroupAwareJob) obj).delegate.equals(delegate); - } - return false; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - } - -} \ No newline at end of file diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactory.java index 1618e8962..b68b3cb94 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactory.java @@ -27,22 +27,9 @@ import org.springframework.context.ConfigurableApplicationContext; * @author Dave Syer * */ -public class ApplicationContextJobFactory extends AbstractGroupAwareJobFactory { +public class ApplicationContextJobFactory implements JobFactory { - final ApplicationContextFactory applicationContextFactory; - - /** - * @param groupName the name of the group that the job belongs to - * @param jobName the id of the {@link Job} in the application context to be - * created - * @param applicationContextFactory a factory for an application context - * containing a job with the job name provided - */ - public ApplicationContextJobFactory(String groupName, String jobName, - ApplicationContextFactory applicationContextFactory) { - super(groupName, jobName); - this.applicationContextFactory = applicationContextFactory; - } + private final Job job; /** * @param jobName the id of the {@link Job} in the application context to be @@ -51,7 +38,8 @@ public class ApplicationContextJobFactory extends AbstractGroupAwareJobFactory { * containing a job with the job name provided */ public ApplicationContextJobFactory(String jobName, ApplicationContextFactory applicationContextFactory) { - this(null, jobName, applicationContextFactory); + ConfigurableApplicationContext context = applicationContextFactory.createApplicationContext(); + this.job = (Job) context.getBean(jobName, Job.class); } /** @@ -60,11 +48,17 @@ public class ApplicationContextJobFactory extends AbstractGroupAwareJobFactory { * * @see org.springframework.batch.core.configuration.JobFactory#createJob() */ - @Override - protected Job doCreateJob(String jobName) { - ConfigurableApplicationContext context = applicationContextFactory.createApplicationContext(); - Job job = (Job) context.getBean(jobName, Job.class); + public final Job createJob() { return job; } + + /** + * Just return the name of instance passed in on initialization. + * + * @see JobFactory#getJobName() + */ + public String getJobName() { + return job.getName(); + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistry.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistry.java index 6b56014c2..0bb101fec 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistry.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistry.java @@ -24,6 +24,8 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.Job; +import org.springframework.batch.core.configuration.DuplicateJobException; +import org.springframework.batch.core.configuration.JobLocator; import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.ListableJobLocator; import org.springframework.batch.core.launch.NoSuchJobException; @@ -32,7 +34,10 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.core.io.Resource; /** @@ -49,8 +54,8 @@ import org.springframework.core.io.Resource; * @since 2.1 this class does not implement {@link JobRegistry}: it is a * {@link ListableJobLocator} */ -public class ClassPathXmlJobRegistry implements ListableJobLocator, ApplicationContextAware, InitializingBean, - DisposableBean { +public class ClassPathXmlJobRegistry implements ListableJobLocator, ApplicationContextAware, DisposableBean, + ApplicationListener { private static Log logger = LogFactory.getLog(ClassPathXmlJobRegistry.class); @@ -97,13 +102,41 @@ public class ClassPathXmlJobRegistry implements ListableJobLocator, ApplicationC return jobRegistry.getJob(name); } + public Collection getJobNames() { + return jobRegistry.getJobNames(); + } + /** * Create all the application contexts required and set up job registry * entries with all the instances of {@link Job} found therein. * * @see InitializingBean#afterPropertiesSet() */ - public void afterPropertiesSet() throws Exception { + public void onApplicationEvent(ApplicationEvent event) { + if (event instanceof ContextRefreshedEvent && event.getSource() == parent) { + try { + initialize(); + } + catch (DuplicateJobException e) { + throw new IllegalStateException(e); + } + catch (NoSuchJobException e) { + throw new IllegalStateException(e); + } + } + } + + /** + * Create jobs as instructed and register them so they can be accessed via + * the {@link JobLocator} interface. Normally called from + * {@link #onApplicationEvent(ApplicationEvent)} when the parent context is + * refreshed. + * + * @throws DuplicateJobException if the job registry detects a duplicate job + * @throws NoSuchJobException if no jobs are registered, since this is + * usually an error + */ + protected void initialize() throws DuplicateJobException, NoSuchJobException { for (Resource resource : jobPaths) { ClassPathXmlApplicationContextFactory applicationContextFactory = new ClassPathXmlApplicationContextFactory(); @@ -117,8 +150,7 @@ public class ClassPathXmlJobRegistry implements ListableJobLocator, ApplicationC for (String name : names) { logger.debug("Registering job: " + name + " from context: " + resource); - String groupName = getGroupName(context, resource, name); - ApplicationContextJobFactory jobFactory = new ApplicationContextJobFactory(groupName, name, + ApplicationContextJobFactory jobFactory = new ApplicationContextJobFactory(name, applicationContextFactory); jobRegistry.register(jobFactory); } @@ -130,20 +162,6 @@ public class ClassPathXmlJobRegistry implements ListableJobLocator, ApplicationC } - /** - * Determine a group name for the job to be registered. Default - * implementation does nothing, but provides an extension point for - * specialised subclasses. - * - * @param context the application context containing the job - * @param resource the resource that was used to create the context - * @param jobName the jobName - * @return a group name for the job (or null if not needed) - */ - protected String getGroupName(ApplicationContext context, Resource resource, String jobName) { - return null; - } - /** * Close the contexts that were created in {@link #afterPropertiesSet()}. * @@ -152,7 +170,9 @@ public class ClassPathXmlJobRegistry implements ListableJobLocator, ApplicationC public void destroy() throws Exception { for (ConfigurableApplicationContext context : contexts) { - context.close(); + if (context.isActive()) { + context.close(); + } } for (String jobName : jobRegistry.getJobNames()) { jobRegistry.unregister(jobName); @@ -161,8 +181,4 @@ public class ClassPathXmlJobRegistry implements ListableJobLocator, ApplicationC } - public Collection getJobNames() { - return jobRegistry.getJobNames(); - } - } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GroupAwareJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GroupAwareJob.java new file mode 100644 index 000000000..e664247fd --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GroupAwareJob.java @@ -0,0 +1,113 @@ +/* + * Copyright 2006-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.configuration.support; + +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobParametersIncrementer; + +/** + * A {@link Job} that can optionally prepend a group name to another job's name, + * to make it fit a naming convention for type or origin. E.g. the source job + * might be overnightJob and the group + * financeDepartment, which would result in a {@link Job} with + * identical functionality but named financeDepartment$overnightJob + * . The use of a "." separator for elements is deliberate, since it is a "safe" + * character in a URL. + * + * + * @author Dave Syer + * + */ +public class GroupAwareJob implements Job { + + /** + * The separator between group and delegate job names in the final name + * given to this job. + */ + private static final String SEPARATOR = "."; + + private final Job delegate; + + private final String groupName; + + /** + * Create a new {@link Job} with the delegate and no group name. + * + * @param delegate a delegate for the features of a regular Job + */ + public GroupAwareJob(Job delegate) { + this(null, delegate); + } + + /** + * Create a new {@link Job} with the given group name and delegate. + * + * @param groupName the group name to prepend + * @param delegate a delegate for the features of a regular Job + */ + public GroupAwareJob(String groupName, Job delegate) { + super(); + this.groupName = groupName; + this.delegate = delegate; + } + + public void execute(JobExecution execution) { + delegate.execute(execution); + } + + /** + * Concatenates the group name and the delegate job name (joining with a + * "."). + * + * @see org.springframework.batch.core.Job#getName() + */ + public String getName() { + return groupName==null ? delegate.getName() : groupName + SEPARATOR + delegate.getName(); + } + + public boolean isRestartable() { + return delegate.isRestartable(); + } + + public JobParametersIncrementer getJobParametersIncrementer() { + return delegate.getJobParametersIncrementer(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof GroupAwareJob) { + return ((GroupAwareJob) obj).delegate.equals(delegate); + } + return false; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return delegate.hashCode(); + } + +} \ No newline at end of file diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java index 533338011..633e71e73 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java @@ -126,13 +126,15 @@ public class JobRegistryBeanPostProcessor implements BeanPostProcessor, BeanFact if (beanFactory != null) { groupName = getGroupName(beanFactory.getBeanDefinition(beanName), job); } - ReferenceJobFactory jobFactory = new ReferenceJobFactory(groupName, job); + job = groupName==null ? job : new GroupAwareJob(groupName, job); + ReferenceJobFactory jobFactory = new ReferenceJobFactory(job); jobRegistry.register(jobFactory); jobNames.add(jobFactory.getJobName()); } catch (DuplicateJobException e) { throw new FatalBeanException("Cannot register job configuration", e); } + return job; } return bean; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ReferenceJobFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ReferenceJobFactory.java index faa7b7a3f..e4f60fef0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ReferenceJobFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ReferenceJobFactory.java @@ -25,32 +25,33 @@ import org.springframework.batch.core.configuration.JobFactory; * @author Dave Syer * */ -public class ReferenceJobFactory extends AbstractGroupAwareJobFactory { +public class ReferenceJobFactory implements JobFactory { private Job job; - /** - * @param groupName the name of the group that this job belongs to - * @param job the {@link Job} to return from {@link #createJob()}. - */ - public ReferenceJobFactory(String groupName, Job job) { - super(groupName, job.getName()); - this.job = job; - } - /** * @param job the {@link Job} to return from {@link #createJob()}. */ public ReferenceJobFactory(Job job) { - this(null, job); + this.job = job; } /** * Just return the instance passed in on initialization. + * + * @see JobFactory#createJob() */ - @Override - protected Job doCreateJob(String jobName) { + public final Job createJob() { return job; } + + /** + * Just return the name of instance passed in on initialization. + * + * @see JobFactory#getJobName() + */ + public String getJobName() { + return job.getName(); + } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java index 45ced5ab0..e6e0e1f8a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ApplicationContextJobFactoryTests.java @@ -5,6 +5,8 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.springframework.batch.core.job.JobSupport; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.StaticApplicationContext; @@ -18,10 +20,10 @@ public class ApplicationContextJobFactoryTests { } @Test - public void testGroupName() throws Exception { - ApplicationContextJobFactory factory = new ApplicationContextJobFactory("jobs", "job", - new StubApplicationContextFactory()); - assertEquals("jobs.job", factory.getJobName()); + public void testPostProcessing() throws Exception { + ApplicationContextJobFactory factory = new ApplicationContextJobFactory("job", + new PostProcessingApplicationContextFactory()); + assertEquals("bar", factory.getJobName()); } private static class StubApplicationContextFactory implements ApplicationContextFactory { @@ -33,4 +35,30 @@ public class ApplicationContextJobFactoryTests { } + private static class PostProcessingApplicationContextFactory implements ApplicationContextFactory { + public ConfigurableApplicationContext createApplicationContext() { + StaticApplicationContext context = new StaticApplicationContext(); + context.registerSingleton("job", JobSupport.class); + context.registerSingleton("postProcessor", TestBeanPostProcessor.class); + context.refresh(); + return context; + } + + } + + private static class TestBeanPostProcessor implements BeanPostProcessor { + + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + if (bean instanceof JobSupport) { + ((JobSupport) bean).setName("bar"); + } + return bean; + } + + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + } + } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistryTests.java index e0914ecbe..00e13a622 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlJobRegistryTests.java @@ -2,12 +2,14 @@ package org.springframework.batch.core.configuration.support; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Collection; import org.junit.Test; import org.springframework.batch.core.Job; import org.springframework.batch.core.launch.NoSuchJobException; +import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -33,7 +35,7 @@ public class ClassPathXmlJobRegistryTests { GenericApplicationContext applicationContext = new GenericApplicationContext(); applicationContext.refresh(); registry.setApplicationContext(applicationContext); - registry.afterPropertiesSet(); + registry.initialize(); Collection names = registry.getJobNames(); assertEquals(2, names.size()); @@ -55,7 +57,7 @@ public class ClassPathXmlJobRegistryTests { GenericApplicationContext applicationContext = new GenericApplicationContext(); applicationContext.refresh(); registry.setApplicationContext(applicationContext); - registry.afterPropertiesSet(); + registry.initialize(); } @Test @@ -67,17 +69,33 @@ public class ClassPathXmlJobRegistryTests { GenericApplicationContext applicationContext = new GenericApplicationContext(); applicationContext.refresh(); registry.setApplicationContext(applicationContext); - registry.afterPropertiesSet(); + registry.initialize(); assertEquals(2, registry.getJobNames().size()); } + @Test + public void testErrorInContext() throws Exception { + + Resource[] jobPaths = new Resource[] { + new ClassPathResource("org/springframework/batch/core/launch/support/2jobs.xml"), + new ClassPathResource("org/springframework/batch/core/launch/support/error.xml") }; + registry.setJobPaths(jobPaths); + try { + registry.initialize(); + fail("Expected BeanCreationException"); + } + catch (BeanCreationException e) { + } + + } + @Test public void testDestroy() throws Exception { Resource[] jobPaths = new Resource[] { new ClassPathResource( "org/springframework/batch/core/launch/support/2jobs.xml") }; registry.setJobPaths(jobPaths); - registry.afterPropertiesSet(); + registry.initialize(); assertEquals(2, registry.getJobNames().size()); registry.destroy(); assertEquals(0, registry.getJobNames().size()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobFactoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobTests.java similarity index 58% rename from spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobFactoryTests.java rename to spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobTests.java index 9b877cf41..d9e411eb0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobFactoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/GroupAwareJobTests.java @@ -15,7 +15,7 @@ */ package org.springframework.batch.core.configuration.support; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.springframework.batch.core.Job; @@ -23,34 +23,22 @@ import org.springframework.batch.core.job.JobSupport; /** * @author Dave Syer - * + * */ -public class GroupAwareJobFactoryTests { - +public class GroupAwareJobTests { + private Job job = new JobSupport("foo"); @Test public void testCreateJob() { - AbstractGroupAwareJobFactory factory = new AbstractGroupAwareJobFactory(job.getName()) { - @Override - protected Job doCreateJob(String jobName) { - return job; - } - }; - assertEquals(factory.getJobName(), factory.createJob().getName()); - assertEquals(job, factory.createJob()); + GroupAwareJob result = new GroupAwareJob(job); + assertEquals("foo", result.getName()); } @Test public void testGetJobName() { - AbstractGroupAwareJobFactory factory = new AbstractGroupAwareJobFactory("jobs", job.getName()) { - @Override - protected Job doCreateJob(String jobName) { - return job; - } - }; - assertEquals(factory.getJobName(), factory.createJob().getName()); - assertEquals("jobs.foo", factory.getJobName()); + GroupAwareJob result = new GroupAwareJob("jobs", job); + assertEquals("jobs.foo", result.getName()); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java index 8e8ccd599..9e9d9d934 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java @@ -25,7 +25,6 @@ import java.util.Collection; import org.junit.Test; import org.springframework.batch.core.configuration.DuplicateJobException; import org.springframework.batch.core.job.JobSupport; -import org.springframework.batch.core.launch.NoSuchJobException; import org.springframework.beans.FatalBeanException; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -67,8 +66,8 @@ public class JobRegistryBeanPostProcessorTests { processor.setJobRegistry(registry); JobSupport job = new JobSupport(); job.setBeanName("foo"); - assertEquals(job, processor.postProcessAfterInitialization(job, "bar")); - assertEquals(job.getName(), registry.getJob("foo").getName()); + assertNotNull(processor.postProcessAfterInitialization(job, "bar")); + assertEquals("[foo]", registry.getJobNames().toString()); } @Test @@ -78,7 +77,7 @@ public class JobRegistryBeanPostProcessorTests { processor.setGroupName("jobs"); JobSupport job = new JobSupport(); job.setBeanName("foo"); - assertEquals(job, processor.postProcessAfterInitialization(job, "bar")); + assertNotNull(processor.postProcessAfterInitialization(job, "bar")); assertEquals("[jobs.foo]", registry.getJobNames().toString()); } @@ -105,15 +104,9 @@ public class JobRegistryBeanPostProcessorTests { processor.setJobRegistry(registry); JobSupport job = new JobSupport(); job.setBeanName("foo"); - assertEquals(job, processor.postProcessAfterInitialization(job, "bar")); + assertNotNull(processor.postProcessAfterInitialization(job, "bar")); processor.destroy(); - try { - assertEquals(null, registry.getJob("foo")); - fail("Expected NoSuchJobConfigurationException"); - } - catch (NoSuchJobException e) { - // expected - } + assertEquals("[]", registry.getJobNames().toString()); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.java index 4d9b67f17..9739ec753 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ReferenceJobFactoryTests.java @@ -15,7 +15,7 @@ */ package org.springframework.batch.core.configuration.support; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.springframework.batch.core.job.JobSupport; @@ -28,8 +28,8 @@ public class ReferenceJobFactoryTests { @Test public void testGroupName() throws Exception { - ReferenceJobFactory factory = new ReferenceJobFactory("jobs", new JobSupport("foo")); - assertEquals("jobs.foo", factory.getJobName()); + ReferenceJobFactory factory = new ReferenceJobFactory(new JobSupport("foo")); + assertEquals("foo", factory.getJobName()); } } diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/launch/support/error.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/launch/support/error.xml new file mode 100644 index 000000000..90d2b3053 --- /dev/null +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/launch/support/error.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs b/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs index fba517e3a..2506d00a3 100644 --- a/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs +++ b/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,7 @@ -#Tue Aug 19 17:57:24 BST 2008 +#Wed Sep 09 08:10:50 BST 2009 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error @@ -80,4 +75,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/spring-batch-infrastructure/.settings/org.eclipse.jst.common.project.facet.core.prefs b/spring-batch-infrastructure/.settings/org.eclipse.jst.common.project.facet.core.prefs new file mode 100644 index 000000000..2d9c6c249 --- /dev/null +++ b/spring-batch-infrastructure/.settings/org.eclipse.jst.common.project.facet.core.prefs @@ -0,0 +1,3 @@ +#Wed Sep 09 08:10:50 BST 2009 +classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER\:\:org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType\:\:java-6-sun-1.6.0.14/owners=jst.java\:6.0 +eclipse.preferences.version=1 diff --git a/spring-batch-infrastructure/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-batch-infrastructure/.settings/org.eclipse.wst.common.project.facet.core.xml index 8de16aa85..66c5706f5 100644 --- a/spring-batch-infrastructure/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/spring-batch-infrastructure/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,7 +1,7 @@ - - - - - - - + + + + + + + diff --git a/spring-batch-parent/pom.xml b/spring-batch-parent/pom.xml index a2c69d4ef..128e2e0d2 100644 --- a/spring-batch-parent/pom.xml +++ b/spring-batch-parent/pom.xml @@ -112,6 +112,13 @@ + + + org.springframework.build.aws + org.springframework.build.aws.maven + 2.0.0.RELEASE + +