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.

FileExclusions.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.api.scan.filesystem;
  21. import java.util.Arrays;
  22. import java.util.stream.Stream;
  23. import org.apache.commons.lang.StringUtils;
  24. import org.sonar.api.CoreProperties;
  25. import org.sonar.api.batch.ScannerSide;
  26. import org.sonar.api.config.Configuration;
  27. /**
  28. * Configuration of file inclusions and exclusions.
  29. * <p>Plugins must not extend nor instantiate this class. An instance is injected at
  30. * runtime.
  31. *
  32. * @since 3.5
  33. * @deprecated since 7.6
  34. */
  35. @Deprecated
  36. @ScannerSide
  37. public class FileExclusions {
  38. private final Configuration config;
  39. public FileExclusions(Configuration config) {
  40. this.config = config;
  41. }
  42. public String[] sourceInclusions() {
  43. return inclusions(CoreProperties.PROJECT_INCLUSIONS_PROPERTY);
  44. }
  45. public String[] testInclusions() {
  46. return inclusions(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY);
  47. }
  48. private String[] inclusions(String propertyKey) {
  49. return Arrays.stream(config.getStringArray(propertyKey))
  50. .map(StringUtils::trim)
  51. .filter(s -> !"**/*".equals(s))
  52. .filter(s -> !"file:**/*".equals(s))
  53. .toArray(String[]::new);
  54. }
  55. public String[] sourceExclusions() {
  56. return exclusions(CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY, CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
  57. }
  58. public String[] testExclusions() {
  59. return exclusions(CoreProperties.GLOBAL_TEST_EXCLUSIONS_PROPERTY, CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY);
  60. }
  61. private String[] exclusions(String globalExclusionsProperty, String exclusionsProperty) {
  62. String[] globalExclusions = config.getStringArray(globalExclusionsProperty);
  63. String[] exclusions = config.getStringArray(exclusionsProperty);
  64. return Stream.concat(Arrays.stream(globalExclusions), Arrays.stream(exclusions))
  65. .map(StringUtils::trim)
  66. .toArray(String[]::new);
  67. }
  68. }