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

@@ -35,7 +35,7 @@ public class GradleJavaProject extends LegacyJavaProject {
private static final Logger log = LoggerFactory.getLogger(GradleJavaProject.class);
private GradleJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File gradleFile, JavadocService javadocService) {
super(fileObserver, gradleFile.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.GRADLE_PROJECT_TYPE, gradleFile.toURI(), null));
super(fileObserver, gradleFile.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.GRADLE_PROJECT_TYPE, gradleFile.toURI()));
}
public static GradleJavaProject create(FileObserver fileObserver, GradleCore gradle, File gradleFile, Path projectDataCache, JavadocService javadocService) {

View File

@@ -12,17 +12,13 @@ package org.springframework.ide.vscode.commons.java;
import java.net.URI;
import org.springframework.ide.vscode.commons.protocol.java.Gav;
public interface IProjectBuild {
String getType();
URI getBuildFile();
IGav getGav();
static IProjectBuild create(String type, URI buildFile, Gav gav) {
static IProjectBuild create(String type, URI buildFile) {
return new IProjectBuild() {
@Override
@@ -35,9 +31,6 @@ public interface IProjectBuild {
return buildFile;
}
public IGav getGav() {
return IGav.create(gav);
}
};
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Pivotal, Inc.
* Copyright (c) 2019, 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
@@ -21,11 +21,13 @@ import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.services.LanguageClient;
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
import org.springframework.ide.vscode.commons.protocol.java.Gav;
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteData;
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteParams;
import org.springframework.ide.vscode.commons.protocol.java.JavaDataParams;
import org.springframework.ide.vscode.commons.protocol.java.JavaSearchParams;
import org.springframework.ide.vscode.commons.protocol.java.JavaTypeHierarchyParams;
import org.springframework.ide.vscode.commons.protocol.java.ProjectGavParams;
import org.springframework.ide.vscode.commons.protocol.java.TypeData;
import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
import org.springframework.ide.vscode.commons.protocol.spring.SpringIndexLanguageClient;
@@ -96,4 +98,7 @@ public interface STS4LanguageClient extends LanguageClient, SpringIndexLanguageC
@JsonRequest("sts/javaCodeComplete")
CompletableFuture<List<JavaCodeCompleteData>> javaCodeComplete(JavaCodeCompleteParams params);
@JsonRequest("sts/project/gav")
CompletableFuture<List<Gav>> projectGAV(ProjectGavParams params);
}

View File

@@ -10,22 +10,22 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.protocol.java;
public record ProjectBuild(String type, String buildFile, Gav gav) {
public record ProjectBuild(String type, String buildFile) {
public static final String MAVEN_PROJECT_TYPE = "maven";
public static final String GRADLE_PROJECT_TYPE = "gradle";
public static ProjectBuild createMavenBuild(String buildFile, Gav gav) {
return new ProjectBuild(MAVEN_PROJECT_TYPE, buildFile, gav);
public static ProjectBuild createMavenBuild(String buildFile) {
return new ProjectBuild(MAVEN_PROJECT_TYPE, buildFile);
}
public static ProjectBuild createGradleBuild(String buildFile, Gav gav) {
return new ProjectBuild(GRADLE_PROJECT_TYPE, buildFile, gav);
public static ProjectBuild createGradleBuild(String buildFile) {
return new ProjectBuild(GRADLE_PROJECT_TYPE, buildFile);
}
@Override
public String toString() {
return "ProjectBuild [type=" + type + ", buildFile=" + buildFile + "gav=" + gav + "]";
return "ProjectBuild [type=" + type + ", buildFile=" + buildFile + "]";
}

View File

@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.protocol.java;
import java.util.List;
public record ProjectGavParams(List<String> projectUris) {
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2019 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
@@ -55,6 +55,7 @@ import org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.commons.java.JavaUtils;
import org.springframework.ide.vscode.commons.protocol.java.Gav;
/**
* Maven Core functionality
@@ -325,5 +326,17 @@ public class MavenCore {
}
return null;
}
public Gav computeGav(File pom) {
try {
MavenProject p = readProject(pom, false);
return new Gav(p.getGroupId(), p.getArtifactId(), p.getVersion());
} catch (Exception e) {
log.error("", e);
return null;
}
}
}

View File

@@ -13,7 +13,6 @@ package org.springframework.ide.vscode.commons.maven.java;
import java.io.File;
import java.nio.file.Path;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.commons.java.ClasspathFileBasedCache;
@@ -23,13 +22,9 @@ import org.springframework.ide.vscode.commons.java.IProjectBuild;
import org.springframework.ide.vscode.commons.java.LegacyJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.JavadocService;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.protocol.java.Gav;
import org.springframework.ide.vscode.commons.protocol.java.ProjectBuild;
import org.springframework.ide.vscode.commons.util.FileObserver;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
/**
* Wrapper for Maven Core project
*
@@ -42,12 +37,9 @@ public class MavenJavaProject extends LegacyJavaProject {
private final File pom;
private Supplier<Gav> gavSupplier;
private MavenJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File pom, JavadocService javadocService, Supplier<Gav> gavSupplier) {
super(fileObserver, pom.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI(), null));
private MavenJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File pom, JavadocService javadocService) {
super(fileObserver, pom.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI()));
this.pom = pom;
this.gavSupplier = gavSupplier;
}
public static MavenJavaProject create(FileObserver fileObserver, MavenCore maven, File pom, Path projectDataCache, JavadocService javadocService) {
@@ -59,17 +51,7 @@ public class MavenJavaProject extends LegacyJavaProject {
() -> new MavenProjectClasspath(maven, pom),
fileBasedCache
);
return new MavenJavaProject(fileObserver, projectDataCache, classpath, pom, javadocService, Suppliers.memoize(() -> {
try {
MavenProject p = maven.readProject(pom, false);
return new Gav(p.getGroupId(), p.getArtifactId(), p.getVersion());
} catch (Exception e) {
log.error("", e);
return null;
}
}));
return new MavenJavaProject(fileObserver, projectDataCache, classpath, pom, javadocService);
}
public static MavenJavaProject create(FileObserver fileObserver, MavenCore maven, File pom, JavadocService javadocService) {
@@ -104,7 +86,7 @@ public class MavenJavaProject extends LegacyJavaProject {
@Override
public IProjectBuild getProjectBuild() {
return IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI(), gavSupplier.get());
return IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI());
}
}

View File

@@ -36,6 +36,7 @@ import java.util.Random;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.assertj.core.api.Condition;
@@ -120,11 +121,13 @@ import org.springframework.ide.vscode.commons.protocol.LiveProcessLoggersSummary
import org.springframework.ide.vscode.commons.protocol.LiveProcessSummary;
import org.springframework.ide.vscode.commons.protocol.STS4LanguageClient;
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
import org.springframework.ide.vscode.commons.protocol.java.Gav;
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteData;
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteParams;
import org.springframework.ide.vscode.commons.protocol.java.JavaDataParams;
import org.springframework.ide.vscode.commons.protocol.java.JavaSearchParams;
import org.springframework.ide.vscode.commons.protocol.java.JavaTypeHierarchyParams;
import org.springframework.ide.vscode.commons.protocol.java.ProjectGavParams;
import org.springframework.ide.vscode.commons.protocol.java.TypeData;
import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
@@ -155,6 +158,8 @@ public class LanguageServerHarness {
private final SimpleLanguageServer server;
private InitializeResult initResult;
private Function<File, Gav> gavSupplier;
private Map<String,TextDocumentInfo> documents = new HashMap<>();
private Multimap<String, CompletableFuture<HighlightParams>> highlights = MultimapBuilder.hashKeys().linkedListValues().build();
@@ -263,6 +268,10 @@ public class LanguageServerHarness {
intialize(null);
}
}
public void setGavSupplier(Function<File, Gav> s) {
this.gavSupplier = s;
}
public InitializeResult intialize(File workspaceRoot) throws Exception {
int parentPid = random.nextInt(40000)+1000;
@@ -449,6 +458,21 @@ public class LanguageServerHarness {
return CompletableFuture.completedFuture(new ShowDocumentResult(true));
}
@Override
public CompletableFuture<List<Gav>> projectGAV(ProjectGavParams params) {
List<Gav> gavs = new ArrayList<>(params.projectUris().size());
for (int i = 0; i < params.projectUris().size(); i++) {
gavs.add(null);
}
for (int i = 0; i < params.projectUris().size(); i++) {
Path path = Paths.get(URI.create(params.projectUris().get(i)));
if (gavSupplier != null) {
gavs.set(i, gavSupplier.apply(path.toFile()));
}
}
return CompletableFuture.completedFuture(gavs);
}
});
}