enable symbol indexing for regular, non-boot spring projects

This commit is contained in:
Martin Lippert
2018-12-28 09:03:55 +01:00
parent 251e7e67b2
commit 09380b75ed
3 changed files with 17 additions and 10 deletions

View File

@@ -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);
}
}