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.

CompoundPluginRepository.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.nio.file.Path;
  18. import java.util.ArrayList;
  19. import java.util.LinkedHashSet;
  20. import java.util.List;
  21. import java.util.Set;
  22. import java.util.function.BooleanSupplier;
  23. /**
  24. * @author Decebal Suiu
  25. * @author Mário Franco
  26. */
  27. public class CompoundPluginRepository implements PluginRepository {
  28. private List<PluginRepository> repositories = new ArrayList<>();
  29. public CompoundPluginRepository add(PluginRepository repository) {
  30. if (repository == null) {
  31. throw new IllegalArgumentException("null not allowed");
  32. }
  33. repositories.add(repository);
  34. return this;
  35. }
  36. /**
  37. * Add a {@link PluginRepository} only if the {@code condition} is satisfied.
  38. *
  39. * @param repository
  40. * @param condition
  41. * @return
  42. */
  43. public CompoundPluginRepository add(PluginRepository repository, BooleanSupplier condition) {
  44. if (condition.getAsBoolean()) {
  45. return add(repository);
  46. }
  47. return this;
  48. }
  49. @Override
  50. public List<Path> getPluginsPaths() {
  51. Set<Path> paths = new LinkedHashSet<>();
  52. for (PluginRepository repository : repositories) {
  53. paths.addAll(repository.getPluginsPaths());
  54. }
  55. return new ArrayList<>(paths);
  56. }
  57. @Override
  58. public boolean deletePluginPath(Path pluginPath) throws PluginException {
  59. for (PluginRepository repository : repositories) {
  60. if (repository.deletePluginPath(pluginPath)) {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. }