diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-14 15:00:23 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-18 13:44:43 +0200 |
commit | af16acdd1d54abc22c2b1daeaef0107c50682360 (patch) | |
tree | c6be398cb958aeff8873c6577a5992a0296b19dc /sonar-plugin-api | |
parent | d2f6fb75b63824b6dea2ad9c9591f59815155a23 (diff) | |
download | sonarqube-af16acdd1d54abc22c2b1daeaef0107c50682360.tar.gz sonarqube-af16acdd1d54abc22c2b1daeaef0107c50682360.zip |
SONAR-9138 Improve logs displaying servlet filter patterns at server startup
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java | 18 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java | 13 |
2 files changed, 31 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java index 927cbb6a33c..c71ec53ee43 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java @@ -102,6 +102,24 @@ public abstract class ServletFilter implements Filter { throw new IllegalStateException("this method is deprecated and should not be used anymore"); } + public String label() { + return "UrlPattern{" + + "inclusions=[" + convertPatternsToString(inclusions) + "]" + + ", exclusions=[" + convertPatternsToString(exclusions) + "]" + + '}'; + } + + private static String convertPatternsToString(List<String> input) { + StringBuilder output = new StringBuilder(); + if (input.isEmpty()) { + return ""; + } + if (input.size() == 1) { + return output.append(input.get(0)).toString(); + } + return output.append(input.get(0)).append(", ...").toString(); + } + /** * Defines only a single inclusion pattern. This is a shortcut for {@code builder().includes(inclusionPattern).build()}. */ diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java index 21367e83ec4..503a0732b88 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/ServletFilterTest.java @@ -228,6 +228,19 @@ public class ServletFilterTest { "/mstile*"); } + @Test + public void test_label() throws Exception { + assertThat(ServletFilter.UrlPattern.builder().build().label()).isEqualTo("UrlPattern{inclusions=[], exclusions=[]}"); + assertThat(ServletFilter.UrlPattern.builder() + .includes("/foo/*") + .excludes("/foo/login") + .build().label()).isEqualTo("UrlPattern{inclusions=[/foo/*], exclusions=[/foo/login]}"); + assertThat(ServletFilter.UrlPattern.builder() + .includes("/foo/*", "/foo/lo*") + .excludes("/foo/login", "/foo/logout", "/foo/list") + .build().label()).isEqualTo("UrlPattern{inclusions=[/foo/*, ...], exclusions=[/foo/login, ...]}"); + } + private static class FakeFilter extends ServletFilter { @Override public UrlPattern doGetPattern() { |