try to auto-connect to processes only if the corresponding project is known and has actuators in the classpath

This commit is contained in:
Martin Lippert
2020-05-04 16:04:34 +02:00
parent 40e4885bda
commit 67c4e44e63
4 changed files with 31 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 Pivotal, Inc.
* Copyright (c) 2017, 2020 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,18 +20,22 @@ public class SpringProjectUtil {
public static final Logger log = LoggerFactory.getLogger(SpringProjectUtil.class);
public static boolean isSpringProject(IJavaProject jp) {
return hasSpecificLibraryOnClasspath(jp, "spring-core");
return hasSpecificLibraryOnClasspath(jp, "spring-core", true);
}
public static boolean isBootProject(IJavaProject jp) {
return hasSpecificLibraryOnClasspath(jp, "spring-boot");
return hasSpecificLibraryOnClasspath(jp, "spring-boot", true);
}
private static boolean hasSpecificLibraryOnClasspath(IJavaProject jp, String libraryNamePrefix) {
public static boolean hasBootActuators(IJavaProject jp) {
return hasSpecificLibraryOnClasspath(jp, "spring-boot-actuator-", true);
}
private static boolean hasSpecificLibraryOnClasspath(IJavaProject jp, String libraryNamePrefix, boolean onlyLibs) {
try {
IClasspath cp = jp.getClasspath();
if (cp!=null) {
return IClasspathUtil.getBinaryRoots(cp, (cpe) -> !cpe.isSystem()).stream().anyMatch(cpe -> isEntry(cpe, libraryNamePrefix));
return IClasspathUtil.getBinaryRoots(cp, (cpe) -> !cpe.isSystem()).stream().anyMatch(cpe -> isEntry(cpe, libraryNamePrefix, onlyLibs));
}
} catch (Exception e) {
log.error("Failed to determine whether '" + jp.getElementName() + "' is Spring Boot project", e);
@@ -39,8 +43,8 @@ public class SpringProjectUtil {
return false;
}
private static boolean isEntry(File cpe, String libNamePrefix) {
private static boolean isEntry(File cpe, String libNamePrefix, boolean onlyLibs) {
String name = cpe.getName();
return name.endsWith(".jar") && name.startsWith(libNamePrefix);
return name.startsWith(libNamePrefix) && (!onlyLibs || name.endsWith(".jar"));
}
}