Skip to content

Commit 769b275

Browse files
committed
PLUGINAPI-38 Add filenamePatterns on the Language extension point
1 parent 491e891 commit 769b275

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 9.16
4+
5+
* Extension point `org.sonar.api.resources.Language` now supports `filenamePatterns` to detect files' language based on more complex filename patterns than only filename extensions.
6+
37
## 9.15
48

59
* `org.sonar.api.utils.log.Loggers` and `org.sonar.api.utils.log.Logger` are now deprecated in favor of the direct use of [SLF4J](https://www.slf4j.org/):

plugin-api/src/main/java/org/sonar/api/resources/Language.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ public interface Language {
4848
String getName();
4949

5050
/**
51-
* For example ["jav", "java"].
52-
* If empty, then all files in source directories are considered as sources.
51+
* Filename extensions, without the dot. For example <code>["jav", "java"]</code>. Source files having any of those extensions will
52+
* be associated to this language. This is equivalent to have {@link #filenamePatterns()}
53+
* returning <code>["&#42;&#42;/&#42;.jav", "&#42;&#42;/&#42;.java"]</code>.<br/>
54+
* The filename extension matching is case-insensitive, so declaring <code>["java"]</code> will match "src/main/java/Foo.java" and
55+
* "src/main/java/Foo.JAVA".<br/>
56+
* If both {@link #getFileSuffixes()} and {@link #filenamePatterns()} are provided, both will be considered.
5357
*/
5458
String[] getFileSuffixes();
5559

@@ -60,4 +64,17 @@ public interface Language {
6064
default boolean publishAllFiles() {
6165
return true;
6266
}
67+
68+
/**
69+
* Provide a list of patterns following the {@link org.sonar.api.utils.WildcardPattern} syntax. Source files matching any of those patterns will
70+
* be associated to this language.
71+
* Pattern are considered relative: <code>["pom.xml"]</code> is equivalent to <code>["&#42;&#42;/pom.xml"]</code> <br/>
72+
* The filename extension matching is case-insensitive, so declaring <code>["&#42;&#42;/&#42;Test.java"]</code> will match "FooTest.java" and
73+
* "FooTest.JAVA" but <strong>not</strong> "FooTEST.java".<br/>
74+
* If both {@link #getFileSuffixes()} and {@link #filenamePatterns()} are provided, both will be considered.
75+
* @since 9.16
76+
*/
77+
default String[] filenamePatterns() {
78+
return new String[0];
79+
}
6380
}

plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@
5353
* e.g. <code>org/Foo.java</code> or <code>org/foo/Bar.java</code> or <code>org/foo/bar/Baz.java</code></li>
5454
* </ul>
5555
* <p>
56-
* Another implementation, which is also based on Java Regular Expressions, can be found in
57-
* <a href="https://github.com/JetBrains/intellij-community/blob/idea/107.743/platform/util/src/com/intellij/openapi/util/io/FileUtil.java#L847">FileUtil</a>
58-
* from IntelliJ OpenAPI.
59-
*
56+
*
6057
* @since 1.10
6158
*/
6259
@ThreadSafe

0 commit comments

Comments
 (0)