// Path: src/main/java/minhhai2209/jirapluginconverter/plugin/setting/PluginSetting.java
// public class PluginSetting {
// 
// //  public static final String ARTIFACT_ID = "generated_artifact_id";
// 
// //  public static final String PLUGIN_KEY = ARTIFACT_ID;
// 
//   private static Descriptor descriptor;
// 
//   private static com.atlassian.plugin.Plugin jiraPlugin;
// 
//   private static PluginSettingsFactory pluginSettingsFactory;
// 
//   private static TransactionTemplate transactionTemplate;
// 
//   public static void load(
//       PluginSettingsFactory pluginSettingsFactory,
//       TransactionTemplate transactionTemplate,
//       PluginLicenseManager pluginLicenseManager,
//       ConsumerService consumerService) throws Exception {
// 
//     PluginSetting.pluginSettingsFactory = pluginSettingsFactory;
//     PluginSetting.transactionTemplate = transactionTemplate;
// 
//     LicenseUtils.setPluginLicenseManager(pluginLicenseManager);
//     KeyUtils.loadJiraConsumer(consumerService);
//     KeyUtils.loadSharedSecret(pluginSettingsFactory);
//   }
// 
//   public static void readDescriptor() {
//     InputStream is = null;
//     try {
//       is = PluginSetting.class.getResourceAsStream("/imported_atlas_connect_descriptor.json");
//       String descriptorString = IOUtils.toString(is);
//       descriptor = JsonUtils.fromJson(descriptorString, Descriptor.class);
//       WebItemUtils.buildWebItemLookup();
//       WebPanelUtils.buildWebPanelLookup();
//       PageUtils.buildGeneralPageLookup();
//       PageUtils.buildAdminPageLookup();
//       PageUtils.buildConfigurePageLookup();
//       IssueTabPanelUtils.buildJiraIssueTabPanelLookup();
//       ProjectTabPanelUtils.buildProjectTabPanelLookup();
//       WorkflowPostFunctionUtils.buildWorkflowPostFunctionLookup();
//     } catch (Exception e1) {
//       if (is != null) {
//         try {
//           is.close();
//         } catch (Exception e2) {
//           ExceptionUtils.throwUnchecked(e2);
//         }
//       }
//       ExceptionUtils.throwUnchecked(e1);
//     }
//   }
// 
//   public static Descriptor getDescriptor() {
//     return descriptor;
//   }
// 
//   public static String getPluginBaseUrl() {
//     String baseUrl = transactionTemplate.execute(new TransactionCallback<String>() {
// 
//       @Override
//       public String doInTransaction() {
//         PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
//         String url = (String) settings.get(ConfigurePluginServlet.DB_URL);
//         return url;
//       }
// 
//     });
//     if (baseUrl == null) {
//       baseUrl = descriptor.getBaseUrl();
//     }
//     String jiraUrl = JiraUtils.getBaseUrl();
//     if (jiraUrl.startsWith("http:") && baseUrl.startsWith("https:")) {
//       baseUrl = baseUrl.replace("https:", "http:");
//     } else if (jiraUrl.startsWith("https:")) {
//       baseUrl = baseUrl.replace("http:", "https:");
//     }
//     return baseUrl;
//   }
// 
//   public static Modules getModules() {
//     return descriptor.getModules();
//   }
// 
//   public static Plugin getPlugin() {
//     Plugin plugin = new Plugin();
//     plugin.setName(descriptor.getName());
//     plugin.setBaseUrl(getPluginBaseUrl());
//     return plugin;
//   }
// 
//   public static com.atlassian.plugin.Plugin getJiraPlugin() {
//     return jiraPlugin;
//   }
// 
//   public static void setJiraPlugin(com.atlassian.plugin.Plugin jiraPlugin) {
//     PluginSetting.jiraPlugin = jiraPlugin;
//   }
// 
//   public static ApplicationUser getPluginUser() {
//     String userKey = transactionTemplate.execute(new TransactionCallback<String>() {
//       @Override
//       public String doInTransaction() {
// 
//         PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
//         String userKey = (String) settings.get(ConfigurePluginServlet.DB_USER);
//         return userKey;
//       }
//     });
//     ApplicationUser user;
//     UserUtil userUtil = ComponentAccessor.getUserUtil();
//     if (userKey != null) {
//       user = userUtil.getUserByKey(userKey);
//     } else {
//       Collection<User> admins = userUtil.getJiraAdministrators();
//       User admin = Iterables.get(admins, 0);
//       String adminName = admin.getName();
//       user = userUtil.getUserByName(adminName);
//     }
//     return user;
//   }
// }
// 
// Path: src/main/java/minhhai2209/jirapluginconverter/utils/ExceptionUtils.java
// public class ExceptionUtils {
// 
//   public static void throwUnchecked(Exception e) {
//     throw new IllegalStateException(e);
//   }
// 
//   public static String getStackTrace(Exception e) {
//     return Throwables.getStackTraceAsString(e);
//   }
// }


import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.plugin.Plugin;
import com.atlassian.plugin.event.PluginEventListener;
import com.atlassian.plugin.event.PluginEventManager;
import com.atlassian.plugin.event.events.PluginDisabledEvent;
import com.atlassian.plugin.event.events.PluginEnabledEvent;
import com.atlassian.plugin.event.events.PluginFrameworkShutdownEvent;
import com.atlassian.plugin.event.events.PluginUninstalledEvent;
import minhhai2209.jirapluginconverter.plugin.setting.PluginSetting;
import minhhai2209.jirapluginconverter.utils.ExceptionUtils;
import org.springframework.beans.factory.DisposableBean;
import java.util.UUID;
        pluginEventManager.register(this);
        registered = true;
      }
    } catch (Exception e) {
    }
  }

  private void setPluginStatus(EventType nextPluginStatus, Plugin plugin) {
    log("status " + currentPluginStatus + " to " + nextPluginStatus);
    try {
      newlyInstalled = false;
      currentPluginStatus = nextPluginStatus;
      switch (currentPluginStatus) {
        case installed:
          pluginLifeCycleEventHandler.onInstalled(null);
          break;
        case uninstalled:
          pluginLifeCycleEventHandler.onUninstalled();
          break;
        case enabled:
          pluginLifeCycleEventHandler.onEnabled();
          break;
        case disabled:
          pluginLifeCycleEventHandler.onDisabled();
          break;
        default:
          throw new IllegalArgumentException();
      }
    } catch (Exception e) {
      log(e.getMessage());
// Path: src/main/java/minhhai2209/jirapluginconverter/plugin/setting/PluginSetting.java
// public class PluginSetting {
// 
// //  public static final String ARTIFACT_ID = "generated_artifact_id";
// 
// //  public static final String PLUGIN_KEY = ARTIFACT_ID;
// 
//   private static Descriptor descriptor;
// 
//   private static com.atlassian.plugin.Plugin jiraPlugin;
// 
//   private static PluginSettingsFactory pluginSettingsFactory;
// 
//   private static TransactionTemplate transactionTemplate;
// 
//   public static void load(
//       PluginSettingsFactory pluginSettingsFactory,
//       TransactionTemplate transactionTemplate,
//       PluginLicenseManager pluginLicenseManager,
//       ConsumerService consumerService) throws Exception {
// 
//     PluginSetting.pluginSettingsFactory = pluginSettingsFactory;
//     PluginSetting.transactionTemplate = transactionTemplate;
// 
//     LicenseUtils.setPluginLicenseManager(pluginLicenseManager);
//     KeyUtils.loadJiraConsumer(consumerService);
//     KeyUtils.loadSharedSecret(pluginSettingsFactory);
//   }
// 
//   public static void readDescriptor() {
//     InputStream is = null;
//     try {
//       is = PluginSetting.class.getResourceAsStream("/imported_atlas_connect_descriptor.json");
//       String descriptorString = IOUtils.toString(is);
//       descriptor = JsonUtils.fromJson(descriptorString, Descriptor.class);
//       WebItemUtils.buildWebItemLookup();
//       WebPanelUtils.buildWebPanelLookup();
//       PageUtils.buildGeneralPageLookup();
//       PageUtils.buildAdminPageLookup();
//       PageUtils.buildConfigurePageLookup();
//       IssueTabPanelUtils.buildJiraIssueTabPanelLookup();
//       ProjectTabPanelUtils.buildProjectTabPanelLookup();
//       WorkflowPostFunctionUtils.buildWorkflowPostFunctionLookup();
//     } catch (Exception e1) {
//       if (is != null) {
//         try {
//           is.close();
//         } catch (Exception e2) {
//           ExceptionUtils.throwUnchecked(e2);
//         }
//       }
//       ExceptionUtils.throwUnchecked(e1);
//     }
//   }
// 
//   public static Descriptor getDescriptor() {
//     return descriptor;
//   }
// 
//   public static String getPluginBaseUrl() {
//     String baseUrl = transactionTemplate.execute(new TransactionCallback<String>() {
// 
//       @Override
//       public String doInTransaction() {
//         PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
//         String url = (String) settings.get(ConfigurePluginServlet.DB_URL);
//         return url;
//       }
// 
//     });
//     if (baseUrl == null) {
//       baseUrl = descriptor.getBaseUrl();
//     }
//     String jiraUrl = JiraUtils.getBaseUrl();
//     if (jiraUrl.startsWith("http:") && baseUrl.startsWith("https:")) {
//       baseUrl = baseUrl.replace("https:", "http:");
//     } else if (jiraUrl.startsWith("https:")) {
//       baseUrl = baseUrl.replace("http:", "https:");
//     }
//     return baseUrl;
//   }
// 
//   public static Modules getModules() {
//     return descriptor.getModules();
//   }
// 
//   public static Plugin getPlugin() {
//     Plugin plugin = new Plugin();
//     plugin.setName(descriptor.getName());
//     plugin.setBaseUrl(getPluginBaseUrl());
//     return plugin;
//   }
// 
//   public static com.atlassian.plugin.Plugin getJiraPlugin() {
//     return jiraPlugin;
//   }
// 
//   public static void setJiraPlugin(com.atlassian.plugin.Plugin jiraPlugin) {
//     PluginSetting.jiraPlugin = jiraPlugin;
//   }
// 
//   public static ApplicationUser getPluginUser() {
//     String userKey = transactionTemplate.execute(new TransactionCallback<String>() {
//       @Override
//       public String doInTransaction() {
// 
//         PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
//         String userKey = (String) settings.get(ConfigurePluginServlet.DB_USER);
//         return userKey;
//       }
//     });
//     ApplicationUser user;
//     UserUtil userUtil = ComponentAccessor.getUserUtil();
//     if (userKey != null) {
//       user = userUtil.getUserByKey(userKey);
//     } else {
//       Collection<User> admins = userUtil.getJiraAdministrators();
//       User admin = Iterables.get(admins, 0);
//       String adminName = admin.getName();
//       user = userUtil.getUserByName(adminName);
//     }
//     return user;
//   }
// }
// 
// Path: src/main/java/minhhai2209/jirapluginconverter/utils/ExceptionUtils.java
// public class ExceptionUtils {
// 
//   public static void throwUnchecked(Exception e) {
//     throw new IllegalStateException(e);
//   }
// 
//   public static String getStackTrace(Exception e) {
//     return Throwables.getStackTraceAsString(e);
//   }
// }


// Path: src/main/java/minhhai2209/jirapluginconverter/plugin/lifecycle/PluginLifeCycleEventListener.java
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.plugin.Plugin;
import com.atlassian.plugin.event.PluginEventListener;
import com.atlassian.plugin.event.PluginEventManager;
import com.atlassian.plugin.event.events.PluginDisabledEvent;
import com.atlassian.plugin.event.events.PluginEnabledEvent;
import com.atlassian.plugin.event.events.PluginFrameworkShutdownEvent;
import com.atlassian.plugin.event.events.PluginUninstalledEvent;
import minhhai2209.jirapluginconverter.plugin.setting.PluginSetting;
import minhhai2209.jirapluginconverter.utils.ExceptionUtils;
import org.springframework.beans.factory.DisposableBean;
import java.util.UUID;

        pluginEventManager.register(this);
        registered = true;
      }
    } catch (Exception e) {
    }
  }

  private void setPluginStatus(EventType nextPluginStatus, Plugin plugin) {
    log("status " + currentPluginStatus + " to " + nextPluginStatus);
    try {
      newlyInstalled = false;
      currentPluginStatus = nextPluginStatus;
      switch (currentPluginStatus) {
        case installed:
          pluginLifeCycleEventHandler.onInstalled(null);
          break;
        case uninstalled:
          pluginLifeCycleEventHandler.onUninstalled();
          break;
        case enabled:
          pluginLifeCycleEventHandler.onEnabled();
          break;
        case disabled:
          pluginLifeCycleEventHandler.onDisabled();
          break;
        default:
          throw new IllegalArgumentException();
      }
    } catch (Exception e) {
      log(e.getMessage());
      ExceptionUtils.throwUnchecked(e);