enable symbol indexing for regular, non-boot spring projects
This commit is contained in:
@@ -15,16 +15,23 @@ import java.io.File;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class BootProjectUtil {
|
||||
public class SpringProjectUtil {
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(BootProjectUtil.class);
|
||||
public static final Logger log = LoggerFactory.getLogger(SpringProjectUtil.class);
|
||||
|
||||
public static boolean isSpringProject(IJavaProject jp) {
|
||||
return hasSpecificLibraryOnClasspath(jp, "spring-core");
|
||||
}
|
||||
|
||||
public static boolean isBootProject(IJavaProject jp) {
|
||||
return hasSpecificLibraryOnClasspath(jp, "spring-boot");
|
||||
}
|
||||
|
||||
private static boolean hasSpecificLibraryOnClasspath(IJavaProject jp, String libraryNamePrefix) {
|
||||
try {
|
||||
IClasspath cp = jp.getClasspath();
|
||||
if (cp!=null) {
|
||||
return IClasspathUtil.getBinaryRoots(cp, (cpe) -> !cpe.isSystem()).stream().anyMatch(cpe -> isBootEntry(cpe));
|
||||
return IClasspathUtil.getBinaryRoots(cp, (cpe) -> !cpe.isSystem()).stream().anyMatch(cpe -> isEntry(cpe, libraryNamePrefix));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to determine whether '" + jp.getElementName() + "' is Spring Boot project", e);
|
||||
@@ -32,8 +39,8 @@ public class BootProjectUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBootEntry(File cpe) {
|
||||
private static boolean isEntry(File cpe, String libNamePrefix) {
|
||||
String name = cpe.getName();
|
||||
return name.endsWith(".jar") && name.startsWith("spring-boot");
|
||||
return name.endsWith(".jar") && name.startsWith(libNamePrefix);
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ import org.springframework.ide.vscode.boot.metadata.types.TypeUtilProvider;
|
||||
import org.springframework.ide.vscode.commons.gradle.GradleCore;
|
||||
import org.springframework.ide.vscode.commons.gradle.GradleProjectCache;
|
||||
import org.springframework.ide.vscode.commons.gradle.GradleProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.java.BootProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.javadoc.JavaDocProviders;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.CompositeJavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.CompositeProjectOvserver;
|
||||
@@ -98,7 +98,7 @@ public class BootLanguageServerParams {
|
||||
indexProvider.setProgressService(server.getProgressService());
|
||||
|
||||
return new BootLanguageServerParams(
|
||||
jdtProjectCache.filter(BootProjectUtil::isBootProject),
|
||||
jdtProjectCache.filter(SpringProjectUtil::isBootProject),
|
||||
jdtProjectCache,
|
||||
indexProvider,
|
||||
(IDocument doc) -> new TypeUtil(jdtProjectCache.find(new TextDocumentIdentifier(doc.getUri()))),
|
||||
@@ -161,7 +161,7 @@ public class BootLanguageServerParams {
|
||||
indexProvider.setProgressService(server.getProgressService());
|
||||
|
||||
return new BootLanguageServerParams(
|
||||
javaProjectFinder.filter(BootProjectUtil::isBootProject),
|
||||
javaProjectFinder.filter(SpringProjectUtil::isBootProject),
|
||||
projectObserver,
|
||||
indexProvider,
|
||||
(IDocument doc) -> new TypeUtil(javaProjectFinder.find(new TextDocumentIdentifier(doc.getUri()))),
|
||||
|
||||
@@ -58,10 +58,10 @@ import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyA
|
||||
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.SymbolProvider;
|
||||
import org.springframework.ide.vscode.commons.java.BootProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener;
|
||||
@@ -179,7 +179,7 @@ public class SpringIndexer {
|
||||
|
||||
public CompletableFuture<Void> initializeProject(IJavaProject project) {
|
||||
try {
|
||||
if (BootProjectUtil.isBootProject(project)) {
|
||||
if (SpringProjectUtil.isBootProject(project) || SpringProjectUtil.isSpringProject(project)) {
|
||||
if (project.getElementName() == null) {
|
||||
// Projects indexed by name. No name - no index for it
|
||||
log.debug("Project with NULL name is being initialized");
|
||||
|
||||
Reference in New Issue
Block a user