Skip to content

Commit a4fb963

Browse files
PLUGINAPI-145 Adapt plugin-api to support hidden files analysis (#232)
1 parent dee6a72 commit a4fb963

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

CHANGELOG.md

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

33
## 12.0
4+
* Introduced support for hidden file analysis:
5+
* Introduce `org.sonar.api.batch.fs.IndexedFile.isHidden`.
6+
* Introduce `org.sonar.api.batch.sensor.SensorDescriptor.processesHiddenFiles`.
47
* Remove `org.sonar.api.issue.DefaultTransitions.SET_AS_IN_REVIEW`.
58
* Remove `org.sonar.api.issue.DefaultTransitions.OPEN_AS_VULNERABILITY`.
69
* Remove `org.sonar.api.issue.Issue.STATUS_IN_REVIEW`.

plugin-api/src/main/java/org/sonar/api/batch/fs/IndexedFile.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,13 @@ public interface IndexedFile extends InputPath {
113113
* @since 6.2
114114
*/
115115
InputStream inputStream() throws IOException;
116+
117+
/**
118+
* Check if the file is hidden by the file system.
119+
* Implementations depend on the runtime context, returns false by default.
120+
* @since 12.0
121+
*/
122+
default boolean isHidden() {
123+
return false;
124+
}
116125
}

plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.sonar.api.batch.sensor;
2121

2222
import java.util.function.Predicate;
23+
import org.sonar.api.batch.fs.IndexedFile;
2324
import org.sonar.api.batch.fs.InputFile;
2425
import org.sonar.api.config.Configuration;
2526
import org.sonar.api.scanner.sensor.ProjectSensor;
@@ -91,4 +92,13 @@ public interface SensorDescriptor {
9192
* @since 9.3
9293
*/
9394
SensorDescriptor processesFilesIndependently();
95+
96+
/**
97+
* Advertise that this sensor processes hidden files.
98+
* By default, sensors will not receive hidden files, specifically where {@link IndexedFile#isHidden()} evaluates to true.
99+
* If hidden file processing is activated, the sensor signals that it processes files where {@link IndexedFile#isHidden()} is true.
100+
* Depending on the runtime context, the {@link org.sonar.api.batch.fs.FileSystem} will then supply additional hidden files to the sensor.
101+
* @since 12.0
102+
*/
103+
SensorDescriptor processesHiddenFiles();
94104
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Sonar Plugin API
3+
* Copyright (C) 2009-2025 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.batch.fs;
21+
22+
import java.io.File;
23+
import java.io.InputStream;
24+
import java.net.URI;
25+
import java.nio.file.Path;
26+
import javax.annotation.CheckForNull;
27+
import org.junit.jupiter.api.Test;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
32+
class IndexedFileTest {
33+
34+
@Test
35+
void file_should_be_hidden_on_default() {
36+
IndexedFile file = new MyIndexedFile();
37+
38+
assertThat(file.isHidden()).isFalse();
39+
}
40+
41+
private static class MyIndexedFile implements IndexedFile {
42+
@Override
43+
public String key() {
44+
return "";
45+
}
46+
47+
@Override
48+
public boolean isFile() {
49+
return false;
50+
}
51+
52+
@Override
53+
public String relativePath() {
54+
return "";
55+
}
56+
57+
@Override
58+
public String absolutePath() {
59+
return "";
60+
}
61+
62+
@Override
63+
public File file() {
64+
return new File("");
65+
}
66+
67+
@Override
68+
public Path path() {
69+
return file().toPath();
70+
}
71+
72+
@Override
73+
public URI uri() {
74+
return file().toURI();
75+
}
76+
77+
@Override
78+
public String filename() {
79+
return "";
80+
}
81+
82+
@CheckForNull
83+
@Override
84+
public String language() {
85+
return "";
86+
}
87+
88+
@Override
89+
public InputFile.Type type() {
90+
return null;
91+
}
92+
93+
@Override
94+
public InputStream inputStream() {
95+
return null;
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)