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.

PluginClassLoaderDef.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.core.platform;
  21. import com.google.common.base.Preconditions;
  22. import com.google.common.base.Strings;
  23. import java.io.File;
  24. import java.util.ArrayList;
  25. import java.util.Collection;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. import javax.annotation.Nullable;
  30. import org.sonar.classloader.Mask;
  31. /**
  32. * Temporary information about the classLoader to be created for a plugin (or a group of plugins).
  33. */
  34. class PluginClassLoaderDef {
  35. private final String basePluginKey;
  36. private final Map<String, String> mainClassesByPluginKey = new HashMap<>();
  37. private final List<File> files = new ArrayList<>();
  38. private final Mask mask = new Mask();
  39. private boolean selfFirstStrategy = false;
  40. PluginClassLoaderDef(String basePluginKey) {
  41. Preconditions.checkArgument(!Strings.isNullOrEmpty(basePluginKey));
  42. this.basePluginKey = basePluginKey;
  43. }
  44. String getBasePluginKey() {
  45. return basePluginKey;
  46. }
  47. List<File> getFiles() {
  48. return files;
  49. }
  50. void addFiles(Collection<File> f) {
  51. this.files.addAll(f);
  52. }
  53. Mask getExportMask() {
  54. return mask;
  55. }
  56. boolean isSelfFirstStrategy() {
  57. return selfFirstStrategy;
  58. }
  59. void setSelfFirstStrategy(boolean selfFirstStrategy) {
  60. this.selfFirstStrategy = selfFirstStrategy;
  61. }
  62. Map<String, String> getMainClassesByPluginKey() {
  63. return mainClassesByPluginKey;
  64. }
  65. void addMainClass(String pluginKey, @Nullable String mainClass) {
  66. if (!Strings.isNullOrEmpty(mainClass)) {
  67. mainClassesByPluginKey.put(pluginKey, mainClass);
  68. }
  69. }
  70. @Override
  71. public boolean equals(@Nullable Object o) {
  72. if (this == o) {
  73. return true;
  74. }
  75. if (o == null || getClass() != o.getClass()) {
  76. return false;
  77. }
  78. PluginClassLoaderDef that = (PluginClassLoaderDef) o;
  79. return basePluginKey.equals(that.basePluginKey);
  80. }
  81. @Override
  82. public int hashCode() {
  83. return basePluginKey.hashCode();
  84. }
  85. }