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.

PluginDependency.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2012-present the original author or authors.
  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.Objects;
  18. /**
  19. * @author Decebal Suiu
  20. */
  21. public class PluginDependency {
  22. private String pluginId;
  23. private String pluginVersionSupport = "*";
  24. private boolean optional;
  25. public PluginDependency(String dependency) {
  26. int index = dependency.indexOf('@');
  27. if (index == -1) {
  28. this.pluginId = dependency;
  29. } else {
  30. this.pluginId = dependency.substring(0, index);
  31. if (dependency.length() > index + 1) {
  32. this.pluginVersionSupport = dependency.substring(index + 1);
  33. }
  34. }
  35. // A dependency is considered as optional, if the plugin id ends with a question mark.
  36. this.optional = this.pluginId.endsWith("?");
  37. if (this.optional) {
  38. this.pluginId = this.pluginId.substring(0, this.pluginId.length() - 1);
  39. }
  40. }
  41. public String getPluginId() {
  42. return pluginId;
  43. }
  44. public String getPluginVersionSupport() {
  45. return pluginVersionSupport;
  46. }
  47. public boolean isOptional() {
  48. return optional;
  49. }
  50. @Override
  51. public String toString() {
  52. return "PluginDependency [pluginId=" + pluginId + ", pluginVersionSupport="
  53. + pluginVersionSupport + ", optional="
  54. + optional + "]";
  55. }
  56. @Override
  57. public boolean equals(Object o) {
  58. if (this == o) return true;
  59. if (!(o instanceof PluginDependency)) return false;
  60. PluginDependency that = (PluginDependency) o;
  61. return optional == that.optional &&
  62. pluginId.equals(that.pluginId) &&
  63. pluginVersionSupport.equals(that.pluginVersionSupport);
  64. }
  65. @Override
  66. public int hashCode() {
  67. return Objects.hash(pluginId, pluginVersionSupport, optional);
  68. }
  69. }