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 3.5KB

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