You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PluginDescriptor.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright 2012 Decebal Suiu
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.pf4j;
  17. import java.util.ArrayList;
  18. import java.util.Collections;
  19. import java.util.List;
  20. /**
  21. * A plugin descriptor contains information about a plug-in obtained
  22. * from the manifest (META-INF) file.
  23. *
  24. * @author Decebal Suiu
  25. */
  26. public class PluginDescriptor {
  27. private String pluginId;
  28. private String pluginDescription;
  29. private String pluginClass;
  30. private String version;
  31. private String requires = "*"; // SemVer format
  32. private String provider;
  33. private List<PluginDependency> dependencies;
  34. private String license;
  35. public PluginDescriptor() {
  36. dependencies = new ArrayList<>();
  37. }
  38. /**
  39. * Returns the unique identifier of this plugin.
  40. */
  41. public String getPluginId() {
  42. return pluginId;
  43. }
  44. /**
  45. * Returns the description of this plugin.
  46. */
  47. public String getPluginDescription() {
  48. return pluginDescription;
  49. }
  50. /**
  51. * Returns the name of the class that implements Plugin interface.
  52. */
  53. public String getPluginClass() {
  54. return pluginClass;
  55. }
  56. /**
  57. * Returns the version of this plugin.
  58. */
  59. public String getVersion() {
  60. return version;
  61. }
  62. /**
  63. * Returns string version of requires
  64. * @return String with requires expression on SemVer format
  65. */
  66. public String getRequires() {
  67. return requires;
  68. }
  69. /**
  70. * Returns the provider name of this plugin.
  71. */
  72. public String getProvider() {
  73. return provider;
  74. }
  75. /**
  76. * Returns the legal license of this plugin, e.g. "Apache-2.0", "MIT" etc
  77. */
  78. public String getLicense() {
  79. return license;
  80. }
  81. /**
  82. * Returns all dependencies declared by this plugin.
  83. * Returns an empty array if this plugin does not declare any require.
  84. */
  85. public List<PluginDependency> getDependencies() {
  86. return dependencies;
  87. }
  88. @Override
  89. public String toString() {
  90. return "PluginDescriptor [pluginId=" + pluginId + ", pluginClass="
  91. + pluginClass + ", version=" + version + ", provider="
  92. + provider + ", dependencies=" + dependencies + ", description="
  93. + pluginDescription + ", requires=" + requires + ", license="
  94. + license + "]";
  95. }
  96. PluginDescriptor setPluginId(String pluginId) {
  97. this.pluginId = pluginId;
  98. return this;
  99. }
  100. PluginDescriptor setPluginDescription(String pluginDescription) {
  101. this.pluginDescription = pluginDescription;
  102. return this;
  103. }
  104. PluginDescriptor setPluginClass(String pluginClassName) {
  105. this.pluginClass = pluginClassName;
  106. return this;
  107. }
  108. PluginDescriptor setPluginVersion(String version) {
  109. this.version = version;
  110. return this;
  111. }
  112. PluginDescriptor setProvider(String provider) {
  113. this.provider = provider;
  114. return this;
  115. }
  116. PluginDescriptor setRequires(String requires) {
  117. this.requires = requires;
  118. return this;
  119. }
  120. PluginDescriptor setDependencies(String dependencies) {
  121. if (dependencies != null) {
  122. dependencies = dependencies.trim();
  123. if (dependencies.isEmpty()) {
  124. this.dependencies = Collections.emptyList();
  125. } else {
  126. this.dependencies = new ArrayList<>();
  127. String[] tokens = dependencies.split(",");
  128. for (String dependency : tokens) {
  129. dependency = dependency.trim();
  130. if (!dependency.isEmpty()) {
  131. this.dependencies.add(new PluginDependency(dependency));
  132. }
  133. }
  134. if (this.dependencies.isEmpty()) {
  135. this.dependencies = Collections.emptyList();
  136. }
  137. }
  138. } else {
  139. this.dependencies = Collections.emptyList();
  140. }
  141. return this;
  142. }
  143. public PluginDescriptor setLicense(String license) {
  144. this.license = license;
  145. return this;
  146. }
  147. }