View Javadoc
1   package com.atlassian.plugin;
2   
3   import com.google.common.base.Strings;
4   import org.slf4j.Logger;
5   import org.slf4j.LoggerFactory;
6   
7   import java.util.Optional;
8   
9   /**
10   * The mode of installation of a plugin
11   *
12   * @since 3.0
13   */
14  public enum InstallationMode {
15      /**
16       * Denotes a plugin installed from a remote plugin. This is the _proxy_ plugin created to represent and make the link
17       * with the remote plugin.
18       */
19      REMOTE("remote"),
20  
21      /**
22       * Denotes a plugin installed locally to the host application. This is the standard mode for plugins up to version 2.
23       */
24      LOCAL("local");
25  
26      private static final Logger LOGGER = LoggerFactory.getLogger(InstallationMode.class);
27  
28      private final String key;
29  
30      InstallationMode(String key) {
31          this.key = key;
32      }
33  
34      public String getKey() {
35          return key;
36      }
37  
38      public static Optional<InstallationMode> of(String name) {
39          for (InstallationMode mode : values()) {
40              if (mode.getKey().equalsIgnoreCase(name)) {
41                  return Optional.of(mode);
42              }
43          }
44  
45          if (!Strings.isNullOrEmpty(name)) {
46              LOGGER.warn("Could not match installation mode '{}' to any of existing {}. Ignoring.", name, values());
47          }
48  
49          return Optional.empty();
50      }
51  }