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.

ClassLoadingStrategy.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.List;
  19. /**
  20. * {@link ClassLoadingStrategy} will be used to configure {@link PluginClassLoader} loading order
  21. * and contains all possible options supported by {@link PluginClassLoader} where:
  22. * {@code
  23. * A = Application Source (load classes from parent classLoader)
  24. * P = Plugin Source (load classes from this classloader)
  25. * D = Dependencies (load classes from dependencies)
  26. * }
  27. */
  28. public class ClassLoadingStrategy {
  29. /**
  30. * application(parent) -> plugin -> dependencies
  31. */
  32. public static final ClassLoadingStrategy APD = new ClassLoadingStrategy(Arrays.asList(Source.APPLICATION, Source.PLUGIN, Source.DEPENDENCIES));
  33. /**
  34. * application(parent) -> dependencies -> plugin
  35. */
  36. public static final ClassLoadingStrategy ADP = new ClassLoadingStrategy(Arrays.asList(Source.APPLICATION, Source.DEPENDENCIES, Source.PLUGIN));
  37. /**
  38. * plugin -> application(parent) -> dependencies
  39. */
  40. public static final ClassLoadingStrategy PAD = new ClassLoadingStrategy(Arrays.asList(Source.PLUGIN, Source.APPLICATION, Source.DEPENDENCIES));
  41. /**
  42. * dependencies -> application(parent) -> plugin
  43. */
  44. public static final ClassLoadingStrategy DAP = new ClassLoadingStrategy(Arrays.asList(Source.DEPENDENCIES, Source.APPLICATION, Source.PLUGIN));
  45. /**
  46. * dependencies -> plugin -> application(parent)
  47. */
  48. public static final ClassLoadingStrategy DPA = new ClassLoadingStrategy(Arrays.asList(Source.DEPENDENCIES, Source.PLUGIN, Source.APPLICATION));
  49. /**
  50. * plugin -> dependencies -> application(parent)
  51. */
  52. public static final ClassLoadingStrategy PDA = new ClassLoadingStrategy(Arrays.asList(Source.PLUGIN, Source.DEPENDENCIES, Source.APPLICATION));
  53. private final List<Source> sources;
  54. public ClassLoadingStrategy(List<Source> sources) {
  55. this.sources = sources;
  56. }
  57. public List<Source> getSources() {
  58. return sources;
  59. }
  60. public enum Source {
  61. PLUGIN, APPLICATION, DEPENDENCIES;
  62. }
  63. }