Change GAV computation for TestJars

This commit is contained in:
aboyko
2024-06-03 14:36:41 -04:00
parent d0270b8688
commit ba6fc2ac1b
25 changed files with 370 additions and 1358 deletions

View File

@@ -23,12 +23,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.commons.java.IGav;
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.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.protocol.java.Classpath;
import org.springframework.ide.vscode.commons.protocol.java.Gav;
import org.springframework.ide.vscode.commons.protocol.java.ProjectGavParams;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.protocol.spring.BeansParams;
@@ -42,8 +43,10 @@ public class WorkspaceBootExecutableProjects {
final private JavaProjectFinder projectFinder;
final private SpringSymbolIndex symbolIndex;
final private SimpleLanguageServer server;
public WorkspaceBootExecutableProjects(SimpleLanguageServer server, JavaProjectFinder projectFinder, SpringSymbolIndex symbolIndex) {
this.server = server;
this.projectFinder = projectFinder;
this.symbolIndex = symbolIndex;
server.onCommand(CMD, params -> findExecutableProjects());
@@ -64,9 +67,7 @@ public class WorkspaceBootExecutableProjects {
.filter(cpe -> !cpe.isTest() && !cpe.isSystem())
.map(cpe -> Classpath.isSource(cpe) ? cpe.getOutputFolder() : cpe.getPath())
.collect(Collectors.toSet());
IGav gav = project.getProjectBuild().getGav();
String gavStr = "%s:%s:%s".formatted(gav.getGroupId(), gav.getArtifactId(), gav.getVersion());
return Optional.of(new ExecutableProject(project.getElementName(), project.getLocationUri().toASCIIString(), gavStr, appBean.getType(), classpath));
return Optional.of(new ExecutableProject(project.getElementName(), project.getLocationUri().toASCIIString(), null, appBean.getType(), classpath));
} catch (Exception e) {
log.error("", e);
}
@@ -77,13 +78,28 @@ public class WorkspaceBootExecutableProjects {
private CompletableFuture<List<ExecutableProject>> findExecutableProjects() {
List<CompletableFuture<Optional<ExecutableProject>>> futures = projectFinder.all().stream()
.filter(p -> p.getProjectBuild().getGav() != null)
.filter(p -> SpringProjectUtil.isBootProject(p))
.map(this::mapToExecProject)
.collect(Collectors.toList());
List<ExecutableProject> executableProjects = Collections.synchronizedList(new ArrayList<>());
futures.forEach(f -> f.thenAccept(opt -> opt.ifPresent(executableProjects::add)));
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> executableProjects);
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenCompose(v -> {
final long start = System.currentTimeMillis();
return server.getClient().projectGAV(new ProjectGavParams(executableProjects.stream().map(p -> p.uri()).toList())).thenApply(gavs -> {
List<ExecutableProject> filteredExecProjects = new ArrayList<>(executableProjects.size());
for (int i = 0; i < executableProjects.size(); i++) {
ExecutableProject ep = executableProjects.get(i);
if (gavs.get(i) != null) {
Gav gav = gavs.get(i);
filteredExecProjects.add(new ExecutableProject(ep.name(), ep.uri(), "%s:%s:%s".formatted(gav.groupId(), gav.artifactId(), gav.version()), ep.mainClass(), ep.classpath()));
} else {
filteredExecProjects.add(ep);
}
}
log.info("GAV for %d projects took: %d".formatted(executableProjects.size(), System.currentTimeMillis() - start));
return filteredExecProjects;
});
});
}
}

View File

@@ -385,7 +385,7 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService, Serv
}
private static IProjectBuild from(ProjectBuild projectBuild) {
return projectBuild == null ? null : IProjectBuild.create(projectBuild.type(), projectBuild.buildFile() == null ? null : URI.create(projectBuild.buildFile()), projectBuild.gav());
return projectBuild == null ? null : IProjectBuild.create(projectBuild.type(), projectBuild.buildFile() == null ? null : URI.create(projectBuild.buildFile()));
}
}

View File

@@ -50,6 +50,7 @@ public class WorkspaceBootExecutableProjectsTest {
@BeforeEach
public void setup() throws Exception {
harness.intialize(null);
harness.setGavSupplier(ProjectsHarness.GAV_SUPPLIER);
}
@SuppressWarnings("unchecked")

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2022 Pivotal, Inc.
* Copyright (c) 2016, 2024 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
@@ -17,6 +17,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Function;
import org.apache.commons.io.FileUtils;
import org.springframework.ide.vscode.commons.java.DelegatingCachedClasspath;
@@ -26,6 +27,7 @@ import org.springframework.ide.vscode.commons.javadoc.JavaDocProviders;
import org.springframework.ide.vscode.commons.maven.MavenBuilder;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
import org.springframework.ide.vscode.commons.protocol.java.Gav;
import org.springframework.ide.vscode.commons.util.BasicFileObserver;
import org.springframework.ide.vscode.commons.util.FileObserver;
import org.springframework.ide.vscode.commons.util.IOUtil;
@@ -50,6 +52,18 @@ public class ProjectsHarness {
public Cache<Object, IJavaProject> cache = CacheBuilder.newBuilder().concurrencyLevel(1).build();
private final FileObserver fileObserver;
public static final Function<File, Gav> GAV_SUPPLIER = f -> {
if ("pom.xml".equals(f.getName())) {
return MavenCore.getDefault().computeGav(f);
} else if (f.isDirectory()) {
File pom = new File(f, "pom.xml");
if (pom.exists()) {
return MavenCore.getDefault().computeGav(pom);
}
}
return null;
};
/**
* A callback that is given a chance to make changes to test project contents before the test project