|
41 | 41 | import java.util.Set; |
42 | 42 | import java.util.concurrent.ConcurrentHashMap; |
43 | 43 | import java.util.function.Consumer; |
| 44 | +import java.util.stream.Stream; |
44 | 45 |
|
45 | 46 | import static com.google.common.base.Strings.isNullOrEmpty; |
46 | 47 | import static com.google.common.collect.Sets.newConcurrentHashSet; |
@@ -205,22 +206,20 @@ private void addFileWatcherExcludesMatcher() { |
205 | 206 | } |
206 | 207 |
|
207 | 208 | private void fillUpExcludesFromIgnoreFile(String ignoreFileLocation) { |
208 | | - try { |
209 | | - if (isNullOrEmpty(ignoreFileLocation)) { |
210 | | - return; |
211 | | - } |
| 209 | + if (isNullOrEmpty(ignoreFileLocation)) { |
| 210 | + return; |
| 211 | + } |
212 | 212 |
|
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 | + } |
217 | 217 |
|
218 | | - Path projectPath = ignoreFilePath.getParent().getParent(); |
219 | | - excludes.remove(projectPath); |
| 218 | + Path projectPath = ignoreFilePath.getParent().getParent(); |
| 219 | + excludes.remove(projectPath); |
220 | 220 |
|
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())) |
224 | 223 | .map(line -> projectPath.resolve(line.trim())) |
225 | 224 | .filter(excludePath -> exists(excludePath)) |
226 | 225 | .collect(toSet()); |
@@ -277,19 +276,18 @@ private boolean removeExcludesFromIgnoreFile(List<String> pathsToRemove) { |
277 | 276 | } |
278 | 277 |
|
279 | 278 | 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 | + } |
286 | 284 |
|
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()); |
293 | 291 |
|
294 | 292 | write(ignoreFilePath, projectExcludes, UTF_8); |
295 | 293 | } catch (IOException e) { |
|
0 commit comments