/src/main/resources/com/onresolve/jira/groovy/canned/admin/ClearCaches.groovy
Groovy | 75 lines | 60 code | 15 blank | 0 comment | 5 complexity | 7f83e6ebdf3a74330b80615f557a6c18 MD5 | raw file
- package com.onresolve.jira.groovy.canned.admin
-
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.util.ErrorCollection
- import com.onresolve.jira.groovy.canned.CannedScript
- import org.apache.log4j.Category
- import com.atlassian.event.api.EventPublisher
- import com.atlassian.jira.event.ClearCacheEvent
- import com.atlassian.jira.util.SimpleErrorCollection
-
- class ClearCaches implements CannedScript {
-
- Category log = Category.getInstance(ClearCaches.class)
- public static final String FIELD__WHICH__CACHE = 'FIELD_WHICH_CACHE'
- public static final String FIELD__WHICH__CACHE_JIRA = 'jira'
- public static final String FIELD__WHICH__CACHE_GCL = 'gcl'
-
- String getName() {
- return "Clear classloader or jira internal caches"
- }
-
- String getDescription() {
- 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."
- }
-
- public String getHelpUrl() {
- "https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-ClearJIRAorGroovyCaches"
- }
-
- List getCategories() {
- ["ADMIN"]
- }
-
- List getParameters(Map params) {
- [
- [
- Name: FIELD__WHICH__CACHE,
- Label: 'Which cache?',
- Type: 'radio',
- Description: "Which cache do you want to clear?",
- Values: [(FIELD__WHICH__CACHE_GCL): "Groovy class loader", (FIELD__WHICH__CACHE_JIRA): "Jira internal caches"],
- ]
- ]
- }
-
- ErrorCollection doValidate(Map params, boolean forPreview) {
- def errorCollection = new SimpleErrorCollection()
- if (!params) {
- errorCollection.addError(FIELD__WHICH__CACHE, "Choose a cache to clear.")
- }
- return errorCollection
- }
-
- Map doScript(Map params) {
-
- if (params[FIELD__WHICH__CACHE] == FIELD__WHICH__CACHE_GCL) {
- this.class.classLoader.parent.clearCache()
- }
-
- if (params[FIELD__WHICH__CACHE] == FIELD__WHICH__CACHE_JIRA) {
- ComponentManager.getComponentInstanceOfType(EventPublisher.class).publish(ClearCacheEvent.INSTANCE);
- }
-
- params['output'] = "Cache cleared."
- params
- }
-
- String getDescription(Map params, boolean forPreview) {
- "Please press the Run button to clear the cache."
- }
-
- Boolean isFinalParamsPage(Map params) {
- return true
- }
- }