From 132e29f37b265b97fc6f586aafa095837c630463 Mon Sep 17 00:00:00 2001 From: dsyer Date: Wed, 3 Jun 2009 15:07:40 +0000 Subject: [PATCH] RESOLVED - issue BATCH-1268: Remove dependency on commons lang Up to a point - made it optional for Spring Core. --- spring-batch-core/pom.xml | 6 +- .../batch/core/JobParameter.java | 71 +++++++++---------- .../batch/core/JobParameters.java | 4 +- .../xml/JobParserJobFactoryBean.java | 4 +- .../step/tasklet/SystemCommandTasklet.java | 5 +- spring-batch-integration/pom.xml | 5 ++ spring-batch-samples/pom.xml | 4 ++ 7 files changed, 51 insertions(+), 48 deletions(-) diff --git a/spring-batch-core/pom.xml b/spring-batch-core/pom.xml index 2c14b672e..a8f27f613 100644 --- a/spring-batch-core/pom.xml +++ b/spring-batch-core/pom.xml @@ -43,6 +43,7 @@ commons-lang commons-lang + true org.easymock @@ -117,11 +118,6 @@ javax.annotation jsr250-api - - log4j - log4j - false - log4j log4j diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java index 0c7af27c1..7a4744e67 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java @@ -19,39 +19,38 @@ package org.springframework.batch.core; import java.io.Serializable; import java.util.Date; -import org.apache.commons.lang.builder.HashCodeBuilder; - /** - * Domain representation of a parameter to a batch job. Only the following types can be - * parameters: String, Long, Date, and Double. + * Domain representation of a parameter to a batch job. Only the following types + * can be parameters: String, Long, Date, and Double. * * @author Lucas Ward * @since 2.0 - * + * */ -public class JobParameter implements Serializable{ - +public class JobParameter implements Serializable { + private final Object parameter; + private final ParameterType parameterType; - + /** * Construct a new JobParameter as a String. */ - public JobParameter(String parameter){ + public JobParameter(String parameter) { this.parameter = parameter; parameterType = ParameterType.STRING; } - + /** * Construct a new JobParameter as a Long. * * @param parameter */ - public JobParameter(Long parameter){ + public JobParameter(Long parameter) { this.parameter = parameter; parameterType = ParameterType.LONG; } - + /** * Construct a new JobParameter as a Date. * @@ -61,65 +60,65 @@ public class JobParameter implements Serializable{ this.parameter = new Date(parameter.getTime()); parameterType = ParameterType.DATE; } - + /** * Construct a new JobParameter as a Double. * * @param parameter */ - public JobParameter(Double parameter){ + public JobParameter(Double parameter) { this.parameter = parameter; parameterType = ParameterType.DOUBLE; } - + /** * @return the value contained within this JobParameter. */ - public Object getValue(){ - - if(parameter.getClass().isInstance(Date.class)){ - return new Date(((Date)parameter).getTime()); + public Object getValue() { + + if (parameter.getClass().isInstance(Date.class)) { + return new Date(((Date) parameter).getTime()); } - else{ + else { return parameter; } } - + /** * @return a ParameterType representing the type of this parameter. */ - public ParameterType getType(){ + public ParameterType getType() { return parameterType; } - + @Override public boolean equals(Object obj) { - if(obj instanceof JobParameter == false){ + if (obj instanceof JobParameter == false) { return false; } - - if(this == obj){ + + if (this == obj) { return true; } - - JobParameter rhs = (JobParameter)obj; + + JobParameter rhs = (JobParameter) obj; return this.parameter.equals(rhs.parameter); } - + @Override public String toString() { - return parameterType==ParameterType.DATE ? ""+((Date)parameter).getTime() : parameter.toString(); + return parameterType == ParameterType.DATE ? "" + ((Date) parameter).getTime() : parameter.toString(); } - + public int hashCode() { - return new HashCodeBuilder(7, 21).append(parameter).toHashCode(); + return 7 + 21 * parameter.hashCode(); } - + /** - * Enumeration representing the type of a JobParameter. + * Enumeration representing the type of a JobParameter. */ - public enum ParameterType{ - + public enum ParameterType { + STRING, DATE, LONG, DOUBLE; } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java index 14c1a1879..487383f45 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java @@ -21,8 +21,6 @@ import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; -import org.apache.commons.lang.builder.HashCodeBuilder; - /** * Value object representing runtime parameters to a batch job. Because the * parameters have no individual meaning outside of the JobParameters they are @@ -193,7 +191,7 @@ public class JobParameters implements Serializable { @Override public int hashCode() { - return new HashCodeBuilder(7, 21).append(parameters).toHashCode(); + return 17 + 23 * parameters.hashCode(); } @Override diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBean.java index cac420889..ef3248453 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParserJobFactoryBean.java @@ -15,7 +15,6 @@ */ package org.springframework.batch.core.configuration.xml; -import org.apache.commons.lang.StringUtils; import org.springframework.batch.core.JobExecutionListener; import org.springframework.batch.core.JobParametersIncrementer; import org.springframework.batch.core.job.flow.Flow; @@ -23,6 +22,7 @@ import org.springframework.batch.core.job.flow.FlowJob; import org.springframework.batch.core.repository.JobRepository; import org.springframework.beans.factory.FactoryBean; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * This {@link FactoryBean} is used by the batch namespace parser to create @@ -51,7 +51,7 @@ class JobParserJobFactoryBean implements FactoryBean { } public final Object getObject() throws Exception { - Assert.isTrue(!StringUtils.isBlank(name), "The job must have an 'id'."); + Assert.isTrue(StringUtils.hasText(name), "The job must have an id."); FlowJob flowJob = new FlowJob(name); if (restartable != null) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java index 8bf954bec..141cce6d3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java @@ -20,7 +20,6 @@ import java.io.File; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; -import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.ExitStatus; @@ -34,6 +33,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.util.Assert; +import org.springframework.util.StopWatch; /** * {@link Tasklet} that executes a system command. @@ -105,7 +105,7 @@ public class SystemCommandTasklet extends StepExecutionListenerSupport implement contribution.setExitStatus(systemProcessExitCodeMapper.getExitStatus(systemCommandTask.get())); return RepeatStatus.FINISHED; } - else if (stopWatch.getTime() > timeout) { + else if (stopWatch.getTotalTimeMillis() > timeout) { systemCommandTask.cancel(interruptOnCancel); throw new SystemCommandException("Execution of system command did not finish within the timeout"); } @@ -169,6 +169,7 @@ public class SystemCommandTasklet extends StepExecutionListenerSupport implement } /** + * Timeout in milliseconds. * @param timeout upper limit for how long the execution of the external * program is allowed to last. */ diff --git a/spring-batch-integration/pom.xml b/spring-batch-integration/pom.xml index 22d77b063..5e720aa73 100644 --- a/spring-batch-integration/pom.xml +++ b/spring-batch-integration/pom.xml @@ -78,6 +78,11 @@ aspectjweaver test + + commons-lang + commons-lang + test + cglib cglib-nodep diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index 8be9bc00d..fbbe8a09d 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -116,6 +116,10 @@ commons-dbcp commons-dbcp + + commons-lang + commons-lang + com.thoughtworks.xstream xstream