Skip to content

Commit ddd10f0

Browse files
Use try-with-resources statement for reading File Watcher ignore file
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent cac779f commit ddd10f0

1 file changed

Lines changed: 23 additions & 25 deletions

File tree

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/watcher/FileWatcherIgnoreFileTracker.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.Set;
4242
import java.util.concurrent.ConcurrentHashMap;
4343
import java.util.function.Consumer;
44+
import java.util.stream.Stream;
4445

4546
import static com.google.common.base.Strings.isNullOrEmpty;
4647
import static com.google.common.collect.Sets.newConcurrentHashSet;
@@ -205,22 +206,20 @@ private void addFileWatcherExcludesMatcher() {
205206
}
206207

207208
private void fillUpExcludesFromIgnoreFile(String ignoreFileLocation) {
208-
try {
209-
if (isNullOrEmpty(ignoreFileLocation)) {
210-
return;
211-
}
209+
if (isNullOrEmpty(ignoreFileLocation)) {
210+
return;
211+
}
212212

213-
Path ignoreFilePath = toNormalPath(root, ignoreFileLocation);
214-
if (!exists(ignoreFilePath)) {
215-
return;
216-
}
213+
Path ignoreFilePath = toNormalPath(root, ignoreFileLocation);
214+
if (!exists(ignoreFilePath)) {
215+
return;
216+
}
217217

218-
Path projectPath = ignoreFilePath.getParent().getParent();
219-
excludes.remove(projectPath);
218+
Path projectPath = ignoreFilePath.getParent().getParent();
219+
excludes.remove(projectPath);
220220

221-
List<String> lines = lines(ignoreFilePath).collect(toList());
222-
Set<Path> projectExcludes = lines.stream()
223-
.filter(line -> !isNullOrEmpty(line.trim()))
221+
try (Stream<String> lines = lines(ignoreFilePath)) {
222+
Set<Path> projectExcludes = lines.filter(line -> !isNullOrEmpty(line.trim()))
224223
.map(line -> projectPath.resolve(line.trim()))
225224
.filter(excludePath -> exists(excludePath))
226225
.collect(toSet());
@@ -277,19 +276,18 @@ private boolean removeExcludesFromIgnoreFile(List<String> pathsToRemove) {
277276
}
278277

279278
private void removeExcludesFromIgnoreFile(Path ignoreFilePath, Set<String> pathsToExclude) {
280-
try {
281-
if (!exists(ignoreFilePath)) {
282-
throw new JsonRpcException(400,
283-
"Can not remove paths from File Watcher excludes: ignore file is not found by path " +
284-
ignoreFilePath);
285-
}
279+
if (!exists(ignoreFilePath)) {
280+
throw new JsonRpcException(400,
281+
"Can not remove paths from File Watcher excludes: ignore file is not found by path " +
282+
ignoreFilePath);
283+
}
286284

287-
Set<String> projectExcludes = lines(ignoreFilePath)
288-
.filter(line -> {
289-
String location = line.trim();
290-
return !location.isEmpty() && !pathsToExclude.contains(location);
291-
})
292-
.collect(toSet());
285+
try (Stream<String> lines = lines(ignoreFilePath)) {
286+
Set<String> projectExcludes = lines.filter(line -> {
287+
String location = line.trim();
288+
return !location.isEmpty() && !pathsToExclude.contains(location);
289+
})
290+
.collect(toSet());
293291

294292
write(ignoreFilePath, projectExcludes, UTF_8);
295293
} catch (IOException e) {

0 commit comments

Comments
 (0)