Cache projects
This commit is contained in:
@@ -2,6 +2,7 @@ package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
public class DefaultJavaProjectFinder implements JavaProjectFinder {
|
||||
|
||||
@@ -18,8 +19,8 @@ public class DefaultJavaProjectFinder implements JavaProjectFinder {
|
||||
if (project != null) {
|
||||
return project;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// Log perhaps?
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -22,6 +22,6 @@ import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
|
||||
@FunctionalInterface
|
||||
public interface IJavaProjectFinderStrategy {
|
||||
|
||||
IJavaProject find(IDocument document);
|
||||
IJavaProject find(IDocument document) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
|
||||
import org.springframework.ide.vscode.commons.maven.MavenCore;
|
||||
@@ -20,22 +21,26 @@ import org.springframework.ide.vscode.commons.maven.java.classpathfile.JavaProje
|
||||
import org.springframework.ide.vscode.commons.util.FileUtils;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
public class JavaProjectWithClasspathFileFinderStrategy implements IJavaProjectFinderStrategy {
|
||||
|
||||
public Cache<File, JavaProjectWithClasspathFile> cache = CacheBuilder.newBuilder().build();
|
||||
|
||||
@Override
|
||||
public JavaProjectWithClasspathFile find(IDocument d) {
|
||||
public JavaProjectWithClasspathFile find(IDocument d) throws ExecutionException, URISyntaxException {
|
||||
String uriStr = d.getUri();
|
||||
if (StringUtil.hasText(uriStr)) {
|
||||
try {
|
||||
URI uri = new URI(uriStr);
|
||||
//TODO: This only work with File uri. Should it work with others too?
|
||||
// TODO: This only work with File uri. Should it work with others
|
||||
// too?
|
||||
File file = new File(uri).getAbsoluteFile();
|
||||
File cpFile = FileUtils.findFile(file, MavenCore.CLASSPATH_TXT);
|
||||
if (cpFile != null) {
|
||||
return cache.get(cpFile, () -> {
|
||||
return new JavaProjectWithClasspathFile(cpFile);
|
||||
}
|
||||
} catch (URISyntaxException | IllegalArgumentException e) {
|
||||
//garbage data. Ignore it.
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -13,6 +13,7 @@ package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
|
||||
import org.springframework.ide.vscode.commons.maven.MavenCore;
|
||||
@@ -20,6 +21,9 @@ import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.FileUtils;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
/**
|
||||
* Finds Maven Project based
|
||||
*
|
||||
@@ -28,22 +32,21 @@ import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
*/
|
||||
public class MavenProjectFinderStrategy implements IJavaProjectFinderStrategy {
|
||||
|
||||
public Cache<File, MavenJavaProject> cache = CacheBuilder.newBuilder().build();
|
||||
|
||||
@Override
|
||||
public MavenJavaProject find(IDocument d) {
|
||||
public MavenJavaProject find(IDocument d) throws ExecutionException, URISyntaxException {
|
||||
String uriStr = d.getUri();
|
||||
if (StringUtil.hasText(uriStr)) {
|
||||
try {
|
||||
URI uri = new URI(uriStr);
|
||||
//TODO: This only work with File uri. Should it work with others too?
|
||||
// TODO: This only work with File uri. Should it work with others
|
||||
// too?
|
||||
File file = new File(uri).getAbsoluteFile();
|
||||
File pomFile = FileUtils.findFile(file, MavenCore.POM_XML);
|
||||
if (pomFile != null) {
|
||||
return cache.get(pomFile, () -> {
|
||||
return new MavenJavaProject(pomFile);
|
||||
}
|
||||
} catch (URISyntaxException | IllegalArgumentException e) {
|
||||
//garbage data. Ignore it.
|
||||
} catch (Exception e) {
|
||||
//TODO: Erroneous Pom file. Ignore it? Log?
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user