Merge branch 'master' of github.com:spring-projects/sts4

This commit is contained in:
Kris De Volder
2018-02-13 11:12:32 -08:00
6 changed files with 49 additions and 12 deletions

View File

@@ -46,7 +46,7 @@ public abstract class JandexClasspath implements IClasspath {
private Supplier<JandexIndex> javaIndex;
public JandexClasspath() {
this.javaIndex = Suppliers.memoize(() -> createIndex());
this.javaIndex = Suppliers.synchronizedSupplier(Suppliers.memoize(() -> createIndex()));
}
protected JandexIndex createIndex() {
@@ -102,6 +102,11 @@ public abstract class JandexClasspath implements IClasspath {
public Optional<File> findClasspathResourceContainer(String fqName) {
return javaIndex.get().findClasspathResourceForType(fqName);
}
@Override
public void reindex() {
this.javaIndex = Suppliers.synchronizedSupplier(Suppliers.memoize(() -> createIndex()));
}
abstract protected IJavadocProvider createParserJavadocProvider(File classpathResource);

View File

@@ -127,12 +127,12 @@ public class JandexIndex {
this.knownPackages = new HashMap<>();
this.javadocProviderFactory = javadocProviderFactory;
classpathEntries.forEach(file -> {
index.put(file, Suppliers.memoize(() -> createIndex(file, indexFileFinder)));
index.put(file, Suppliers.synchronizedSupplier(Suppliers.memoize(() -> createIndex(file, indexFileFinder))));
knownTypes.put(file, Suppliers.memoize(() -> getKnownTypesStream(file).collect(Collectors.toList())));
knownPackages.put(file, Suppliers.memoize(() -> getKnownPackages(file).collect(Collectors.toList())));
});
}
private Optional<IndexView> createIndex(File file, IndexFileFinder indexFileFinder) {
if (file != null && file.isFile() && file.getName().endsWith(".jar")) {
return indexJar(file, indexFileFinder);
@@ -239,7 +239,12 @@ public class JandexIndex {
// If not found look at indices owned by this
// JandexIndex instance
.orElseGet(() -> streamOfIndices()
.map(e -> Tuples.of(e.getT1(), Optional.ofNullable(e.getT2().getClassByName(fqName))))
.map(e -> {
IndexView view = e.getT2();
ClassInfo info = view.getClassByName(fqName);
return Tuples.of(e.getT1(), Optional.ofNullable(info));
// return Tuples.of(e.getT1(), Optional.ofNullable(e.getT2().getClassByName(fqName)));
})
.filter(t -> t.getT2().isPresent())
.map(e -> Tuples.of(e.getT1(), e.getT2().get())).findFirst());
}

View File

@@ -171,4 +171,12 @@ public class DelegatingCachedClasspath<T extends IClasspath> implements IClasspa
return t == null ? Optional.empty() : t.findClasspathResourceContainer(fqName);
}
@Override
public void reindex() {
T t = cachedClasspath.get();
if (t != null) {
t.reindex();
}
}
}

View File

@@ -62,4 +62,6 @@ public interface IClasspath {
Optional<File> findClasspathResourceContainer(String fqName);
ClasspathData createClasspathData() throws Exception;
void reindex();
}

View File

@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.commons.languageserver.java;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -30,8 +31,7 @@ import org.springframework.ide.vscode.commons.languageserver.Sts4LanguageServer;
*/
public abstract class AbstractFileToProjectCache<P extends IJavaProject> extends AbstractJavaProjectCache<File, P> {
private String changeSubscription;
private String deleteSubscription;
private List<String> subscriptions;
protected boolean asyncUpdate;
protected final Path projectCacheFolder;
private boolean alwaysFireEventOnUpdate;
@@ -42,6 +42,7 @@ public abstract class AbstractFileToProjectCache<P extends IJavaProject> extends
super(server);
this.projectCacheFolder = projectCacheFolder;
this.asyncUpdate = asyncUpdate;
this.subscriptions = new ArrayList<>();
}
@@ -52,14 +53,26 @@ public abstract class AbstractFileToProjectCache<P extends IJavaProject> extends
@Override
protected void attachListeners(File file, P project) {
super.attachListeners(file, project);
List<String> globPattern = Arrays.asList(file.toString().replaceAll("\\\\", "/"));
changeSubscription = getFileObserver().onFileChanged(globPattern, (uri) -> performUpdate(project, asyncUpdate, true));
deleteSubscription = getFileObserver().onFileDeleted(globPattern, (uri) -> {
List<String> globPattern = Arrays.asList(file.toString().replace(File.separator, "/"));
subscriptions.add(getFileObserver().onFileChanged(globPattern, (uri) -> performUpdate(project, asyncUpdate, true)));
subscriptions.add(getFileObserver().onFileDeleted(globPattern, (uri) -> {
cache.invalidate(file);
notifyProjectDeleted(project);
getFileObserver().unsubscribe(changeSubscription);
getFileObserver().unsubscribe(deleteSubscription);
});
dispose();
}));
Path outputFolder = project.getClasspath().getOutputFolder();
if (outputFolder != null) {
final List<String> rebuildGlobPattern = Arrays.asList(outputFolder.toString().replace(File.separator, "/") + "/**/*.class");
subscriptions.add(getFileObserver().onFileChanged(rebuildGlobPattern, (uri) -> project.getClasspath().reindex()));
subscriptions.add(getFileObserver().onFileCreated(rebuildGlobPattern, (uri) -> project.getClasspath().reindex()));
subscriptions.add(getFileObserver().onFileDeleted(rebuildGlobPattern, (uri) -> project.getClasspath().reindex()));
}
}
private void dispose() {
subscriptions.forEach(s -> getFileObserver().unsubscribe(s));
subscriptions.clear();
}
final protected void performUpdate(P project, boolean async, boolean notify) {

View File

@@ -104,4 +104,8 @@ public class FileClasspath implements IClasspath {
public ClasspathData createClasspathData() throws Exception {
return ClasspathData.from(getName(), getClasspathEntries(), getClasspathResources(), getOutputFolder());
}
@Override
public void reindex() {
}
}