/scalate-jrebel/src/main/scala/org/fusesource/scalate/jrebel/ScalateReloader.scala

http://github.com/scalate/scalate · Scala · 32 lines · 18 code · 6 blank · 8 comment · 0 complexity · 7b98b3873dabda9a5965a675211b1c9b MD5 · raw file

  1. package org.fusesource.scalate
  2. package jrebel
  3. import org.zeroturnaround.javarebel.ClassEventListener
  4. import org.zeroturnaround.javarebel.ReloaderFactory
  5. import util.Logging
  6. /**
  7. * A JRebel plugin to reload templates in a Scalate TemplateEngine if dependent classes are modified
  8. */
  9. object ScalateReloader extends TemplateEngineAddOn with Logging {
  10. /**
  11. * Reloads templates in a template engine if the classes are modified
  12. */
  13. @deprecated("Scalate-jrebel is deprecated", "1.9.6")
  14. def apply(engine: TemplateEngine): Unit = {
  15. info("Installing JRebel Scalate plugin on instance: " + engine + " " + System.identityHashCode(engine))
  16. ReloaderFactory.getInstance.addClassReloadListener(new ClassEventListener {
  17. def priority = ClassEventListener.PRIORITY_DEFAULT
  18. def onClassEvent(i: Int, clazz: Class[_]) = {
  19. // TODO we could be a bit more clever to figure out which templates need to be reloaded
  20. // for now lets just flush all templates!
  21. info("Flushing Scalate templates on instance: " + engine)
  22. engine.invalidateCachedTemplates()
  23. }
  24. })
  25. }
  26. }