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.

PluginClasspath.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.Arrays;
  18. import java.util.Collection;
  19. import java.util.HashSet;
  20. import java.util.Objects;
  21. import java.util.Set;
  22. /**
  23. * The classpath of the plugin.
  24. * <p>
  25. * It contains {@code classes} directories (directories that contain classes files)
  26. * and {@code jars} directories (directories that contain jars files).
  27. * <p>
  28. * The classpath is used to create the {@link ClassLoader} for the plugin.
  29. *
  30. * @author Decebal Suiu
  31. */
  32. public class PluginClasspath {
  33. private final Set<String> classesDirectories = new HashSet<>();
  34. private final Set<String> jarsDirectories = new HashSet<>();
  35. /**
  36. * Get the classes directories.
  37. *
  38. * @return a set of directories that contain classes files
  39. */
  40. public Set<String> getClassesDirectories() {
  41. return classesDirectories;
  42. }
  43. /**
  44. * Add classes directories.
  45. *
  46. * @param classesDirectories a set of directories that contain classes files
  47. * @return this object for chaining
  48. */
  49. public PluginClasspath addClassesDirectories(String... classesDirectories) {
  50. return addClassesDirectories(Arrays.asList(classesDirectories));
  51. }
  52. /**
  53. * Add classes directories.
  54. *
  55. * @param classesDirectories a collection of directories that contain classes files
  56. * @return this object for chaining
  57. */
  58. public PluginClasspath addClassesDirectories(Collection<String> classesDirectories) {
  59. this.classesDirectories.addAll(classesDirectories);
  60. return this;
  61. }
  62. /**
  63. * Get the jars directories.
  64. *
  65. * @return a set of directories that contain jars files
  66. */
  67. public Set<String> getJarsDirectories() {
  68. return jarsDirectories;
  69. }
  70. /**
  71. * Add jars directories.
  72. *
  73. * @param jarsDirectories a set of directories that contain jars files
  74. * @return this object for chaining
  75. */
  76. public PluginClasspath addJarsDirectories(String... jarsDirectories) {
  77. return addJarsDirectories(Arrays.asList(jarsDirectories));
  78. }
  79. /**
  80. * Add jars directories.
  81. *
  82. * @param jarsDirectories a collection of directories that contain jars files
  83. * @return this object for chaining
  84. */
  85. public PluginClasspath addJarsDirectories(Collection<String> jarsDirectories) {
  86. this.jarsDirectories.addAll(jarsDirectories);
  87. return this;
  88. }
  89. @Override
  90. public boolean equals(Object o) {
  91. if (this == o) return true;
  92. if (!(o instanceof PluginClasspath)) return false;
  93. PluginClasspath that = (PluginClasspath) o;
  94. return classesDirectories.equals(that.classesDirectories) &&
  95. jarsDirectories.equals(that.jarsDirectories);
  96. }
  97. @Override
  98. public int hashCode() {
  99. return Objects.hash(classesDirectories, jarsDirectories);
  100. }
  101. }