fix issue with special characters in docURIs and converting those to path objects

This commit is contained in:
Martin Lippert
2020-11-16 13:09:34 +01:00
parent ad7a2a2e39
commit 17482b6316
3 changed files with 16 additions and 11 deletions

View File

@@ -10,11 +10,12 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.util;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -131,8 +132,8 @@ public class BasicFileObserver implements FileObserver {
// Added in an attempt to learn what causes: https://www.pivotaltracker.com/story/show/175715622
private static Path paths_get(String uri) {
try {
return Paths.get(URI.create(uri));
} catch (IllegalArgumentException e) {
return new File(new URI(uri)).toPath();
} catch (IllegalArgumentException | URISyntaxException e) {
//make the error more specific (reveal the uri string that causes it)
throw new IllegalArgumentException("uri = '"+uri+"'", e);
}

View File

@@ -13,9 +13,9 @@ package org.springframework.ide.vscode.boot.java.utils;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -162,11 +162,16 @@ public class SpringIndexerJava implements SpringIndexer {
}
private boolean shouldProcessDocument(IJavaProject project, String docURI) {
Path path = Paths.get(URI.create(docURI));
return foldersToScan(project)
.filter(sourceFolder -> path.startsWith(sourceFolder.toPath()))
.findFirst()
.isPresent();
try {
Path path = new File(new URI(docURI)).toPath();
return foldersToScan(project)
.filter(sourceFolder -> path.startsWith(sourceFolder.toPath()))
.findFirst()
.isPresent();
} catch (URISyntaxException e) {
log.info("shouldProcessDocument - docURI syntax problem: {}", docURI);
return false;
}
}
private boolean isCacheOutdated(SymbolCacheKey cacheKey, String docURI, long modifiedTimestamp) {

View File

@@ -15,7 +15,6 @@ import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -246,7 +245,7 @@ public class SpringIndexerXML implements SpringIndexer {
private String[] getFiles(IJavaProject project) throws Exception {
long start = System.currentTimeMillis();
Path projectPath = Paths.get(project.getLocationUri());
Path projectPath = new File(project.getLocationUri()).toPath();
String[] xmlFiles = Arrays.stream(scanFolders)
.map(folder -> projectPath.resolve(folder))
.filter(Files::isDirectory)