copilot spring boot agent implementation
This commit is contained in:
@@ -18,6 +18,8 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.lsp4j.ExecuteCommandParams;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
||||
@@ -33,12 +35,18 @@ import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.BeansParams;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public class WorkspaceBootExecutableProjects {
|
||||
|
||||
public record ExecutableProject(String name, String uri, String gav, String mainClass, Collection<String> classpath) {}
|
||||
|
||||
public record BootProjectInfo(String name, String uri, String mainClass, String buildTool, String springBootVersion, String javaVersion) {}
|
||||
|
||||
final static String CMD = "sts/spring-boot/executableBootProjects";
|
||||
|
||||
final static String BOOT_PROJECT_INFO_CMD = "sts/spring-boot/bootProjectInfo";
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(WorkspaceBootExecutableProjects.class);
|
||||
|
||||
final private JavaProjectFinder projectFinder;
|
||||
@@ -50,6 +58,10 @@ public class WorkspaceBootExecutableProjects {
|
||||
this.projectFinder = projectFinder;
|
||||
this.symbolIndex = symbolIndex;
|
||||
server.onCommand(CMD, params -> findExecutableProjects());
|
||||
|
||||
server.onCommand(BOOT_PROJECT_INFO_CMD, (params) -> {
|
||||
return getBootProjectInfo(params);
|
||||
});
|
||||
}
|
||||
|
||||
private CompletableFuture<Optional<ExecutableProject>> mapToExecProject(IJavaProject project) {
|
||||
@@ -113,4 +125,36 @@ public class WorkspaceBootExecutableProjects {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
private CompletableFuture<Optional<BootProjectInfo>> mapToBootProjectInfo(IJavaProject project) {
|
||||
BeansParams params = new BeansParams();
|
||||
params.setProjectName(project.getElementName());
|
||||
return symbolIndex.beans(params).thenApply(beans -> {
|
||||
List<Bean> bootAppBeans = beans.stream()
|
||||
.filter(b -> hasAnnotation(b, Annotations.BOOT_APP))
|
||||
.limit(2)
|
||||
.collect(Collectors.toList());
|
||||
if (bootAppBeans.size() > 0) {
|
||||
try {
|
||||
String appBean = bootAppBeans.get(0) != null ? bootAppBeans.get(0).getType() : null;
|
||||
String springBootVersion = SpringProjectUtil.getSpringBootVersion(project).toString();
|
||||
String buildTool = project.getProjectBuild().getType();
|
||||
String javaVersion = project.getClasspath().getJavaVersion();
|
||||
return Optional
|
||||
.of(new BootProjectInfo(project.getElementName(), project.getLocationUri().toASCIIString(),
|
||||
appBean, buildTool, springBootVersion, javaVersion));
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
});
|
||||
}
|
||||
|
||||
private CompletableFuture<BootProjectInfo> getBootProjectInfo(ExecuteCommandParams params) {
|
||||
String projectUri = ((JsonElement) params.getArguments().get(0)).getAsString();
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(projectUri)).orElse(null);
|
||||
|
||||
return mapToBootProjectInfo(project).thenApply(opt -> opt.orElse(null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -358,7 +358,7 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService, Serv
|
||||
} else {
|
||||
log.debug("deleted = false");
|
||||
URI projectUri = new URI(uri);
|
||||
ClasspathData classpath = new ClasspathData(event.name, event.classpath.getEntries());
|
||||
ClasspathData classpath = new ClasspathData(event.name, event.classpath.getEntries(), event.classpath.getJavaVersion());
|
||||
IJavaProject oldProject = table.get(uri);
|
||||
if (oldProject != null && classpath.equals(oldProject.getClasspath())) {
|
||||
// nothing has changed
|
||||
|
||||
@@ -80,6 +80,7 @@ public class MockProjects {
|
||||
|
||||
final private File root;
|
||||
final private String name;
|
||||
// final private String javaVersion;
|
||||
final private List<File> sourceFolders = new ArrayList<File>();
|
||||
private File defaultOutputFolder;
|
||||
|
||||
@@ -100,12 +101,19 @@ public class MockProjects {
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJavaVersion() {
|
||||
// return javaVersion;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
public MockProject(String name) {
|
||||
synchronized (projectsByName) {
|
||||
assertFalse(projectsByName.containsKey(name));
|
||||
this.name = name;
|
||||
// this.javaVersion = "";
|
||||
this.root = Files.createTempDir();
|
||||
createSourceFolder("src/main/java");
|
||||
createSourceFolder("src/main/resources");
|
||||
|
||||
Reference in New Issue
Block a user