From e3fe9b11716f7e650ef8bc5ad18c832fbbf11525 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 19 Mar 2013 23:02:57 +0100 Subject: [PATCH] Upgraded to Quartz 1.8 and Velocity 1.7 --- build.gradle | 14 ++--- .../quartz/AdaptableJobFactory.java | 4 +- .../MethodInvokingJobDetailFactoryBean.java | 4 +- .../scheduling/quartz/QuartzJobBean.java | 5 +- .../scheduling/quartz/SchedulerAccessor.java | 33 +++------- .../quartz/SchedulerAccessorBean.java | 4 +- .../quartz/SchedulerFactoryBean.java | 4 +- .../quartz/SpringBeanJobFactory.java | 4 +- .../ui/velocity/CommonsLoggingLogSystem.java | 63 ------------------- .../ui/velocity/VelocityEngineFactory.java | 27 ++------ .../ui/velocity/VelocityEngineUtils.java | 39 ++---------- .../scheduling/quartz/QuartzSupportTests.java | 20 ++++++ 12 files changed, 58 insertions(+), 163 deletions(-) delete mode 100644 spring-context-support/src/main/java/org/springframework/ui/velocity/CommonsLoggingLogSystem.java diff --git a/build.gradle b/build.gradle index 8efb97baa3..c7dc8b05bd 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,6 @@ configure(allprojects) { project -> "http://fasterxml.github.com/jackson-core/javadoc/2.0.0", "http://jackson.codehaus.org/1.4.2/javadoc", "http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.javadoc.doc/web/apidocs", - "http://ibatis.apache.org/docs/java/dev", "http://tiles.apache.org/framework/apidocs", "http://commons.apache.org/dbcp/api-1.2.2", ] as String[] @@ -301,7 +300,6 @@ project("spring-context") { compile(project(":spring-expression")) compile(project(":spring-core")) compile(files(project(":spring-core").cglibRepackJar)) - optional("backport-util-concurrent:backport-util-concurrent:3.0") optional("javax.ejb:ejb-api:3.0") optional("javax.inject:javax.inject:1") optional("org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1") @@ -415,10 +413,12 @@ project("spring-context-support") { optional(project(":spring-tx")) // for Quartz support optional("javax.mail:mail:1.4") optional("javax.cache:cache-api:0.5") - optional("net.sf.ehcache:ehcache-core:2.0.0") - optional("opensymphony:quartz:1.6.2") + optional("net.sf.ehcache:ehcache-core:2.6.3") + optional("org.quartz-scheduler:quartz:1.8.3") { + exclude group: "org.slf4j", module: "slf4j-log4j12" + } optional("org.codehaus.fabric3.api:commonj:1.1.0") - optional("velocity:velocity:1.5") + optional("org.apache.velocity:velocity:1.7") optional("org.freemarker:freemarker:2.3.15") optional("com.lowagie:itext:2.1.7") optional("jasperreports:jasperreports:2.0.5") @@ -527,7 +527,6 @@ project("spring-webmvc") { optional("org.apache.tiles:tiles-core:2.1.2") optional("org.apache.tiles:tiles-jsp:2.1.2") optional("org.apache.tiles:tiles-servlet:2.1.2") - optional("velocity-tools:velocity-tools-view:1.4") optional("net.sourceforge.jexcelapi:jxl:2.6.3") optional("org.apache.poi:poi:3.0.2-FINAL") optional("com.lowagie:itext:2.1.7") @@ -535,7 +534,8 @@ project("spring-webmvc") { exclude group: "xml-apis", module: "xml-apis" } optional("rome:rome:1.0") - optional("velocity:velocity:1.5") + optional("org.apache.velocity:velocity:1.7") + optional("velocity-tools:velocity-tools-view:1.4") optional("org.freemarker:freemarker:2.3.15") optional("org.codehaus.jackson:jackson-mapper-asl:1.4.2") optional("com.fasterxml.jackson.core:jackson-databind:2.0.1") diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java index 0a2d63c48b..c84641f502 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -30,7 +30,7 @@ import org.springframework.util.ReflectionUtils; * JobFactory implementation that supports {@link java.lang.Runnable} * objects as well as standard Quartz {@link org.quartz.Job} instances. * - *

Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1. + *

Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0. * * @author Juergen Hoeller * @since 2.0 diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java index 80ce225457..47c1e95a33 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -67,7 +67,7 @@ import org.springframework.util.ReflectionUtils; * You need to implement your own Quartz Job as a thin wrapper for each case * where you want a persistent job to delegate to a specific service method. * - *

Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1. + *

Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0. * * @author Juergen Hoeller * @author Alef Arendsen diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/QuartzJobBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/QuartzJobBean.java index b2d61536da..57095247df 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/QuartzJobBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/QuartzJobBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -48,9 +48,6 @@ import org.springframework.util.ReflectionUtils; * implement the Quartz {@link org.quartz.StatefulJob} interface to * mark your concrete job bean as stateful. * - *

This version of QuartzJobBean requires Quartz 1.5 or higher, - * due to the support for trigger-specific job data. - * *

Note that as of Spring 2.0 and Quartz 1.5, the preferred way * to apply dependency injection to Job instances is via a JobFactory: * that is, to specify {@link SpringBeanJobFactory} as Quartz JobFactory diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java index 9c65590231..0912399c82 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -35,6 +35,7 @@ import org.quartz.SchedulerListener; import org.quartz.Trigger; import org.quartz.TriggerListener; import org.quartz.spi.ClassLoadHelper; +import org.quartz.xml.XMLSchedulingDataProcessor; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; @@ -51,7 +52,7 @@ import org.springframework.util.ReflectionUtils; *

For concrete usage, check out the {@link SchedulerFactoryBean} and * {@link SchedulerAccessorBean} classes. * - *

Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1. + *

Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0. * * @author Juergen Hoeller * @since 2.5.6 @@ -115,7 +116,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { * "job_scheduling_data_1_5" XSD or better. Can be specified to automatically * register jobs that are defined in such a file, possibly in addition * to jobs defined directly on this SchedulerFactoryBean. - * @see org.quartz.xml.XmlSchedulingDataProcessor + * @see org.quartz.xml.XMLSchedulingDataProcessor */ public void setJobSchedulingDataLocation(String jobSchedulingDataLocation) { this.jobSchedulingDataLocations = new String[] {jobSchedulingDataLocation}; @@ -126,7 +127,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { * "job_scheduling_data_1_5" XSD or better. Can be specified to automatically * register jobs that are defined in such files, possibly in addition * to jobs defined directly on this SchedulerFactoryBean. - * @see org.quartz.xml.XmlSchedulingDataProcessor + * @see org.quartz.xml.XMLSchedulingDataProcessor */ public void setJobSchedulingDataLocations(String[] jobSchedulingDataLocations) { this.jobSchedulingDataLocations = jobSchedulingDataLocations; @@ -251,30 +252,14 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { if (this.transactionManager != null) { transactionStatus = this.transactionManager.getTransaction(new DefaultTransactionDefinition()); } - try { + try { if (this.jobSchedulingDataLocations != null) { ClassLoadHelper clh = new ResourceLoaderClassLoadHelper(this.resourceLoader); clh.initialize(); - try { - // Quartz 1.8 or higher? - Class dataProcessorClass = getClass().getClassLoader().loadClass("org.quartz.xml.XMLSchedulingDataProcessor"); - logger.debug("Using Quartz 1.8 XMLSchedulingDataProcessor"); - Object dataProcessor = dataProcessorClass.getConstructor(ClassLoadHelper.class).newInstance(clh); - Method processFileAndScheduleJobs = dataProcessorClass.getMethod("processFileAndScheduleJobs", String.class, Scheduler.class); - for (String location : this.jobSchedulingDataLocations) { - processFileAndScheduleJobs.invoke(dataProcessor, location, getScheduler()); - } - } - catch (ClassNotFoundException ex) { - // Quartz 1.6 - Class dataProcessorClass = getClass().getClassLoader().loadClass("org.quartz.xml.JobSchedulingDataProcessor"); - logger.debug("Using Quartz 1.6 JobSchedulingDataProcessor"); - Object dataProcessor = dataProcessorClass.getConstructor(ClassLoadHelper.class, boolean.class, boolean.class).newInstance(clh, true, true); - Method processFileAndScheduleJobs = dataProcessorClass.getMethod("processFileAndScheduleJobs", String.class, Scheduler.class, boolean.class); - for (String location : this.jobSchedulingDataLocations) { - processFileAndScheduleJobs.invoke(dataProcessor, location, getScheduler(), this.overwriteExistingJobs); - } + XMLSchedulingDataProcessor dataProcessor = new XMLSchedulingDataProcessor(clh); + for (String location : this.jobSchedulingDataLocations) { + dataProcessor.processFileAndScheduleJobs(location, getScheduler()); } } diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java index 9c69a47c00..c5adb0a68a 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -29,7 +29,7 @@ import org.springframework.beans.factory.ListableBeanFactory; * Spring bean-style class for accessing a Quartz Scheduler, i.e. for registering jobs, * triggers and listeners on a given {@link org.quartz.Scheduler} instance. * - *

Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1. + *

Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0. * * @author Juergen Hoeller * @since 2.5.6 diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java index ed8baa41df..cde54d6554 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -74,7 +74,7 @@ import org.springframework.util.CollectionUtils; * automatically apply to Scheduler operations performed within those scopes. * Alternatively, you may add transactional advice for the Scheduler itself. * - *

Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1. + *

Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0. * * @author Juergen Hoeller * @since 18.02.2004 diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java index a9d837e7da..8a67bb5d49 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -37,7 +37,7 @@ import org.springframework.util.ReflectionUtils; * as bean property values. If no matching bean property is found, the entry * is by default simply ignored. This is analogous to QuartzJobBean's behavior. * - *

Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1. + *

Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0. * * @author Juergen Hoeller * @since 2.0 diff --git a/spring-context-support/src/main/java/org/springframework/ui/velocity/CommonsLoggingLogSystem.java b/spring-context-support/src/main/java/org/springframework/ui/velocity/CommonsLoggingLogSystem.java deleted file mode 100644 index 160516db63..0000000000 --- a/spring-context-support/src/main/java/org/springframework/ui/velocity/CommonsLoggingLogSystem.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2002-2012 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.ui.velocity; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.runtime.RuntimeServices; -import org.apache.velocity.runtime.log.LogSystem; - -/** - * Velocity LogSystem implementation for Jakarta Commons Logging. - * Used by VelocityConfigurer to redirect log output. - * - *

NOTE: To be replaced by Velocity 1.5's {@code LogChute} mechanism - * and Velocity 1.6's {@code CommonsLogLogChute} implementation once we - * upgrade to Velocity 1.6+ (likely Velocity 1.7+) in a future version of Spring. - * - * @author Juergen Hoeller - * @since 07.08.2003 - * @see VelocityEngineFactoryBean - * @deprecated as of Spring 3.2, in favor of Velocity 1.6's {@code CommonsLogLogChute} - */ -@Deprecated -public class CommonsLoggingLogSystem implements LogSystem { - - private static final Log logger = LogFactory.getLog(VelocityEngine.class); - - public void init(RuntimeServices runtimeServices) { - } - - public void logVelocityMessage(int type, String msg) { - switch (type) { - case ERROR_ID: - logger.error(msg); - break; - case WARN_ID: - logger.warn(msg); - break; - case INFO_ID: - logger.info(msg); - break; - case DEBUG_ID: - logger.debug(msg); - break; - } - } - -} diff --git a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java b/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java index 2e81188968..31dd8ef513 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java +++ b/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.VelocityException; import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.log.CommonsLogLogChute; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; @@ -198,8 +199,7 @@ public class VelocityEngineFactory { /** * Set whether Velocity should log via Commons Logging, i.e. whether Velocity's - * log system should be set to CommonsLoggingLogSystem. Default value is true. - * @see CommonsLoggingLogSystem + * log system should be set to {@link CommonsLogLogChute}. Default is "true". */ public void setOverrideLogging(boolean overrideLogging) { this.overrideLogging = overrideLogging; @@ -236,7 +236,7 @@ public class VelocityEngineFactory { // Log via Commons Logging? if (this.overrideLogging) { - velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLoggingLogSystem()); + velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute()); } // Apply properties to VelocityEngine. @@ -246,23 +246,8 @@ public class VelocityEngineFactory { postProcessVelocityEngine(velocityEngine); - try { - // Perform actual initialization. - velocityEngine.init(); - } - catch (IOException ex) { - throw ex; - } - catch (VelocityException ex) { - throw ex; - } - catch (RuntimeException ex) { - throw ex; - } - catch (Exception ex) { - logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex); - throw new VelocityException(ex.toString()); - } + // Perform actual initialization. + velocityEngine.init(); return velocityEngine; } diff --git a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineUtils.java b/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineUtils.java index edee342be2..bfc1e135a6 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineUtils.java +++ b/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -20,8 +20,6 @@ import java.io.StringWriter; import java.io.Writer; import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.VelocityException; @@ -35,9 +33,6 @@ import org.apache.velocity.exception.VelocityException; */ public abstract class VelocityEngineUtils { - private static final Log logger = LogFactory.getLog(VelocityEngineUtils.class); - - /** * Merge the specified Velocity template with the given model and write * the result to the given Writer. @@ -54,20 +49,8 @@ public abstract class VelocityEngineUtils { VelocityEngine velocityEngine, String templateLocation, Map model, Writer writer) throws VelocityException { - try { - VelocityContext velocityContext = new VelocityContext(model); - velocityEngine.mergeTemplate(templateLocation, velocityContext, writer); - } - catch (VelocityException ex) { - throw ex; - } - catch (RuntimeException ex) { - throw ex; - } - catch (Exception ex) { - logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex); - throw new VelocityException(ex.toString()); - } + VelocityContext velocityContext = new VelocityContext(model); + velocityEngine.mergeTemplate(templateLocation, velocityContext, writer); } /** @@ -84,20 +67,8 @@ public abstract class VelocityEngineUtils { VelocityEngine velocityEngine, String templateLocation, String encoding, Map model, Writer writer) throws VelocityException { - try { - VelocityContext velocityContext = new VelocityContext(model); - velocityEngine.mergeTemplate(templateLocation, encoding, velocityContext, writer); - } - catch (VelocityException ex) { - throw ex; - } - catch (RuntimeException ex) { - throw ex; - } - catch (Exception ex) { - logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex); - throw new VelocityException(ex.toString()); - } + VelocityContext velocityContext = new VelocityContext(model); + velocityEngine.mergeTemplate(templateLocation, encoding, velocityContext, writer); } /** diff --git a/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java b/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java index 04d7bda02f..f5f55ce540 100644 --- a/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java +++ b/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java @@ -1035,6 +1035,26 @@ public class QuartzSupportTests { @Override public void schedulerShutdown() { } + + @Override + public void jobAdded(JobDetail jobDetail) { + } + + @Override + public void jobDeleted(String s, String s1) { + } + + @Override + public void schedulerInStandbyMode() { + } + + @Override + public void schedulerStarted() { + } + + @Override + public void schedulerShuttingdown() { + } }