PageRenderTime 33ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/resources/com/onresolve/jira/groovy/canned/admin/ClearCaches.groovy

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 75 lines | 60 code | 15 blank | 0 comment | 5 complexity | 7f83e6ebdf3a74330b80615f557a6c18 MD5 | raw file
  1. package com.onresolve.jira.groovy.canned.admin
  2. import com.atlassian.jira.ComponentManager
  3. import com.atlassian.jira.util.ErrorCollection
  4. import com.onresolve.jira.groovy.canned.CannedScript
  5. import org.apache.log4j.Category
  6. import com.atlassian.event.api.EventPublisher
  7. import com.atlassian.jira.event.ClearCacheEvent
  8. import com.atlassian.jira.util.SimpleErrorCollection
  9. class ClearCaches implements CannedScript {
  10. Category log = Category.getInstance(ClearCaches.class)
  11. public static final String FIELD__WHICH__CACHE = 'FIELD_WHICH_CACHE'
  12. public static final String FIELD__WHICH__CACHE_JIRA = 'jira'
  13. public static final String FIELD__WHICH__CACHE_GCL = 'gcl'
  14. String getName() {
  15. return "Clear classloader or jira internal caches"
  16. }
  17. String getDescription() {
  18. return "Clear the groovy internal caches if this is not working automatically, or the jira caches if you have changed something in the database.<br>Expect a delay after executing this."
  19. }
  20. public String getHelpUrl() {
  21. "https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-ClearJIRAorGroovyCaches"
  22. }
  23. List getCategories() {
  24. ["ADMIN"]
  25. }
  26. List getParameters(Map params) {
  27. [
  28. [
  29. Name: FIELD__WHICH__CACHE,
  30. Label: 'Which cache?',
  31. Type: 'radio',
  32. Description: "Which cache do you want to clear?",
  33. Values: [(FIELD__WHICH__CACHE_GCL): "Groovy class loader", (FIELD__WHICH__CACHE_JIRA): "Jira internal caches"],
  34. ]
  35. ]
  36. }
  37. ErrorCollection doValidate(Map params, boolean forPreview) {
  38. def errorCollection = new SimpleErrorCollection()
  39. if (!params) {
  40. errorCollection.addError(FIELD__WHICH__CACHE, "Choose a cache to clear.")
  41. }
  42. return errorCollection
  43. }
  44. Map doScript(Map params) {
  45. if (params[FIELD__WHICH__CACHE] == FIELD__WHICH__CACHE_GCL) {
  46. this.class.classLoader.parent.clearCache()
  47. }
  48. if (params[FIELD__WHICH__CACHE] == FIELD__WHICH__CACHE_JIRA) {
  49. ComponentManager.getComponentInstanceOfType(EventPublisher.class).publish(ClearCacheEvent.INSTANCE);
  50. }
  51. params['output'] = "Cache cleared."
  52. params
  53. }
  54. String getDescription(Map params, boolean forPreview) {
  55. "Please press the Run button to clear the cache."
  56. }
  57. Boolean isFinalParamsPage(Map params) {
  58. return true
  59. }
  60. }