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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  18. * @author Decebal Suiu
  19. */
  20. public class PluginDependency {
  21. private String pluginId;
  22. private String pluginVersionSupport = "*";
  23. private boolean optional;
  24. public PluginDependency(String dependency) {
  25. int index = dependency.indexOf('@');
  26. if (index == -1) {
  27. this.pluginId = dependency;
  28. } else {
  29. this.pluginId = dependency.substring(0, index);
  30. if (dependency.length() > index + 1) {
  31. this.pluginVersionSupport = dependency.substring(index + 1);
  32. }
  33. }
  34. // A dependency is considered as optional,
  35. // 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. }