Skip to content

Commit ba6fc2a

Browse files
committed
Change GAV computation for TestJars
1 parent d0270b8 commit ba6fc2a

File tree

25 files changed

+370
-1358
lines changed

25 files changed

+370
-1358
lines changed

eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/TestJarLaunchListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ private static boolean isTestJarsOnClasspath(String[] classpath) {
148148

149149
private CompletableFuture<Map<String, String>> getTestJarArtifactsMap() {
150150
try {
151-
Optional<?> opt = BootLsCommandUtils.executeCommand(TypeToken.getParameterized(List.class, ExecutableProject.class), "sts/spring-boot/executableBootProjects").get(3, TimeUnit.SECONDS);
151+
Optional<?> opt = BootLsCommandUtils.executeCommand(TypeToken.getParameterized(List.class, ExecutableProject.class), "sts/spring-boot/executableBootProjects").get(20, TimeUnit.SECONDS);
152152
if (opt.isPresent() && opt.get() instanceof List<?> projects) {
153153
Map<String, String> gavToFile = new ConcurrentHashMap<>();
154-
CompletableFuture<?>[] futures = projects.stream().map(ExecutableProject.class::cast).map(p -> CompletableFuture.runAsync(() -> {
154+
CompletableFuture<?>[] futures = projects.stream().map(ExecutableProject.class::cast).filter(p -> p.gav() != null).map(p -> CompletableFuture.runAsync(() -> {
155155
try {
156156
Path file = Files.createTempFile("%s_".formatted(p.gav().replace(":", "_")), UUID.randomUUID().toString());
157157
Files.write(file, List.of(

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2023 Pivotal, Inc.
2+
* Copyright (c) 2017, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -19,6 +19,10 @@
1919
import java.util.Objects;
2020
import java.util.concurrent.CompletableFuture;
2121
import java.util.concurrent.ConcurrentHashMap;
22+
import java.util.concurrent.Executor;
23+
import java.util.concurrent.LinkedBlockingQueue;
24+
import java.util.concurrent.ThreadPoolExecutor;
25+
import java.util.concurrent.TimeUnit;
2226
import java.util.stream.Collectors;
2327

2428
import org.eclipse.core.resources.IFile;
@@ -72,15 +76,18 @@
7276
import org.springframework.ide.vscode.commons.protocol.LiveProcessSummary;
7377
import org.springframework.ide.vscode.commons.protocol.STS4LanguageClient;
7478
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
79+
import org.springframework.ide.vscode.commons.protocol.java.Gav;
7580
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteData;
7681
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteParams;
7782
import org.springframework.ide.vscode.commons.protocol.java.JavaDataParams;
7883
import org.springframework.ide.vscode.commons.protocol.java.JavaSearchParams;
7984
import org.springframework.ide.vscode.commons.protocol.java.JavaTypeHierarchyParams;
85+
import org.springframework.ide.vscode.commons.protocol.java.ProjectGavParams;
8086
import org.springframework.ide.vscode.commons.protocol.java.TypeData;
8187
import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
8288
import org.springframework.tooling.jdt.ls.commons.Logger;
8389
import org.springframework.tooling.jdt.ls.commons.classpath.ReusableClasspathListenerHandler;
90+
import org.springframework.tooling.jdt.ls.commons.java.BuildInfo;
8491
import org.springframework.tooling.jdt.ls.commons.java.JavaCodeCompletion;
8592
import org.springframework.tooling.jdt.ls.commons.java.JavaData;
8693
import org.springframework.tooling.jdt.ls.commons.java.JavaFluxSearch;
@@ -96,6 +103,8 @@
96103
@SuppressWarnings("restriction")
97104
public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4LanguageClient {
98105

106+
private final Executor executor;
107+
99108
public static final ReusableClasspathListenerHandler CLASSPATH_SERVICE = new ReusableClasspathListenerHandler (
100109
Logger.forEclipsePlugin(LanguageServerCommonsActivator::getInstance),
101110
new LSP4ECommandExecutor(),
@@ -413,6 +422,7 @@ public synchronized void highlight(HighlightParams highlights) {
413422

414423

415424
public STS4LanguageClientImpl() {
425+
this.executor = new ThreadPoolExecutor(1, 5, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
416426
CLASSPATH_SERVICE.addNotificationsSentCallback(projectNames -> {
417427
List<IProject> projects = projectNames.stream().map(projectName -> ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)).filter(Objects::nonNull).collect(Collectors.toList());
418428
for (IWorkbenchWindow ww : PlatformUI.getWorkbench().getWorkbenchWindows()) {
@@ -631,4 +641,9 @@ public void liveProcessLogLevelUpdated(LiveProcessLoggersSummary summary) {
631641
// Nothing to do for now
632642
}
633643

644+
@Override
645+
public CompletableFuture<List<Gav>> projectGAV(ProjectGavParams params) {
646+
return BuildInfo.projectGAV(params, executor, Logger.forEclipsePlugin(LanguageServerCommonsActivator::getInstance));
647+
}
648+
634649
}

headless-services/commons/commons-gradle/src/main/java/org/springframework/ide/vscode/commons/gradle/GradleJavaProject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class GradleJavaProject extends LegacyJavaProject {
3535
private static final Logger log = LoggerFactory.getLogger(GradleJavaProject.class);
3636

3737
private GradleJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File gradleFile, JavadocService javadocService) {
38-
super(fileObserver, gradleFile.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.GRADLE_PROJECT_TYPE, gradleFile.toURI(), null));
38+
super(fileObserver, gradleFile.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.GRADLE_PROJECT_TYPE, gradleFile.toURI()));
3939
}
4040

4141
public static GradleJavaProject create(FileObserver fileObserver, GradleCore gradle, File gradleFile, Path projectDataCache, JavadocService javadocService) {

headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/java/IProjectBuild.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212

1313
import java.net.URI;
1414

15-
import org.springframework.ide.vscode.commons.protocol.java.Gav;
16-
1715
public interface IProjectBuild {
1816

1917
String getType();
2018

2119
URI getBuildFile();
2220

23-
IGav getGav();
24-
25-
static IProjectBuild create(String type, URI buildFile, Gav gav) {
21+
static IProjectBuild create(String type, URI buildFile) {
2622
return new IProjectBuild() {
2723

2824
@Override
@@ -35,9 +31,6 @@ public URI getBuildFile() {
3531
return buildFile;
3632
}
3733

38-
public IGav getGav() {
39-
return IGav.create(gav);
40-
}
4134
};
4235
}
4336

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/STS4LanguageClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2023 Pivotal, Inc.
2+
* Copyright (c) 2019, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -21,11 +21,13 @@
2121
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
2222
import org.eclipse.lsp4j.services.LanguageClient;
2323
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
24+
import org.springframework.ide.vscode.commons.protocol.java.Gav;
2425
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteData;
2526
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteParams;
2627
import org.springframework.ide.vscode.commons.protocol.java.JavaDataParams;
2728
import org.springframework.ide.vscode.commons.protocol.java.JavaSearchParams;
2829
import org.springframework.ide.vscode.commons.protocol.java.JavaTypeHierarchyParams;
30+
import org.springframework.ide.vscode.commons.protocol.java.ProjectGavParams;
2931
import org.springframework.ide.vscode.commons.protocol.java.TypeData;
3032
import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
3133
import org.springframework.ide.vscode.commons.protocol.spring.SpringIndexLanguageClient;
@@ -96,4 +98,7 @@ public interface STS4LanguageClient extends LanguageClient, SpringIndexLanguageC
9698
@JsonRequest("sts/javaCodeComplete")
9799
CompletableFuture<List<JavaCodeCompleteData>> javaCodeComplete(JavaCodeCompleteParams params);
98100

101+
@JsonRequest("sts/project/gav")
102+
CompletableFuture<List<Gav>> projectGAV(ProjectGavParams params);
103+
99104
}

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/java/ProjectBuild.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.commons.protocol.java;
1212

13-
public record ProjectBuild(String type, String buildFile, Gav gav) {
13+
public record ProjectBuild(String type, String buildFile) {
1414

1515
public static final String MAVEN_PROJECT_TYPE = "maven";
1616
public static final String GRADLE_PROJECT_TYPE = "gradle";
1717

18-
public static ProjectBuild createMavenBuild(String buildFile, Gav gav) {
19-
return new ProjectBuild(MAVEN_PROJECT_TYPE, buildFile, gav);
18+
public static ProjectBuild createMavenBuild(String buildFile) {
19+
return new ProjectBuild(MAVEN_PROJECT_TYPE, buildFile);
2020
}
2121

22-
public static ProjectBuild createGradleBuild(String buildFile, Gav gav) {
23-
return new ProjectBuild(GRADLE_PROJECT_TYPE, buildFile, gav);
22+
public static ProjectBuild createGradleBuild(String buildFile) {
23+
return new ProjectBuild(GRADLE_PROJECT_TYPE, buildFile);
2424
}
2525

2626
@Override
2727
public String toString() {
28-
return "ProjectBuild [type=" + type + ", buildFile=" + buildFile + "gav=" + gav + "]";
28+
return "ProjectBuild [type=" + type + ", buildFile=" + buildFile + "]";
2929
}
3030

3131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.commons.protocol.java;
12+
13+
import java.util.List;
14+
15+
public record ProjectGavParams(List<String> projectUris) {
16+
17+
}

headless-services/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/MavenCore.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2019 Pivotal, Inc.
2+
* Copyright (c) 2016, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -55,6 +55,7 @@
5555
import org.slf4j.Logger;
5656
import org.slf4j.LoggerFactory;
5757
import org.springframework.ide.vscode.commons.java.JavaUtils;
58+
import org.springframework.ide.vscode.commons.protocol.java.Gav;
5859

5960
/**
6061
* Maven Core functionality
@@ -325,5 +326,17 @@ public MavenProject findPeerProject(MavenProject currentProject, Artifact depend
325326
}
326327
return null;
327328
}
329+
330+
public Gav computeGav(File pom) {
331+
try {
332+
MavenProject p = readProject(pom, false);
333+
return new Gav(p.getGroupId(), p.getArtifactId(), p.getVersion());
334+
} catch (Exception e) {
335+
log.error("", e);
336+
return null;
337+
}
338+
}
339+
340+
328341

329342
}

headless-services/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/MavenJavaProject.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.io.File;
1414
import java.nio.file.Path;
1515

16-
import org.apache.maven.project.MavenProject;
1716
import org.slf4j.Logger;
1817
import org.slf4j.LoggerFactory;
1918
import org.springframework.ide.vscode.commons.java.ClasspathFileBasedCache;
@@ -23,13 +22,9 @@
2322
import org.springframework.ide.vscode.commons.java.LegacyJavaProject;
2423
import org.springframework.ide.vscode.commons.languageserver.java.JavadocService;
2524
import org.springframework.ide.vscode.commons.maven.MavenCore;
26-
import org.springframework.ide.vscode.commons.protocol.java.Gav;
2725
import org.springframework.ide.vscode.commons.protocol.java.ProjectBuild;
2826
import org.springframework.ide.vscode.commons.util.FileObserver;
2927

30-
import com.google.common.base.Supplier;
31-
import com.google.common.base.Suppliers;
32-
3328
/**
3429
* Wrapper for Maven Core project
3530
*
@@ -42,12 +37,9 @@ public class MavenJavaProject extends LegacyJavaProject {
4237

4338
private final File pom;
4439

45-
private Supplier<Gav> gavSupplier;
46-
47-
private MavenJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File pom, JavadocService javadocService, Supplier<Gav> gavSupplier) {
48-
super(fileObserver, pom.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI(), null));
40+
private MavenJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File pom, JavadocService javadocService) {
41+
super(fileObserver, pom.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI()));
4942
this.pom = pom;
50-
this.gavSupplier = gavSupplier;
5143
}
5244

5345
public static MavenJavaProject create(FileObserver fileObserver, MavenCore maven, File pom, Path projectDataCache, JavadocService javadocService) {
@@ -59,17 +51,7 @@ public static MavenJavaProject create(FileObserver fileObserver, MavenCore maven
5951
() -> new MavenProjectClasspath(maven, pom),
6052
fileBasedCache
6153
);
62-
63-
64-
return new MavenJavaProject(fileObserver, projectDataCache, classpath, pom, javadocService, Suppliers.memoize(() -> {
65-
try {
66-
MavenProject p = maven.readProject(pom, false);
67-
return new Gav(p.getGroupId(), p.getArtifactId(), p.getVersion());
68-
} catch (Exception e) {
69-
log.error("", e);
70-
return null;
71-
}
72-
}));
54+
return new MavenJavaProject(fileObserver, projectDataCache, classpath, pom, javadocService);
7355
}
7456

7557
public static MavenJavaProject create(FileObserver fileObserver, MavenCore maven, File pom, JavadocService javadocService) {
@@ -104,7 +86,7 @@ public String toString() {
10486

10587
@Override
10688
public IProjectBuild getProjectBuild() {
107-
return IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI(), gavSupplier.get());
89+
return IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI());
10890
}
10991

11092
}

headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Set;
3737
import java.util.concurrent.CompletableFuture;
3838
import java.util.concurrent.Future;
39+
import java.util.function.Function;
3940
import java.util.stream.Collectors;
4041

4142
import org.assertj.core.api.Condition;
@@ -120,11 +121,13 @@
120121
import org.springframework.ide.vscode.commons.protocol.LiveProcessSummary;
121122
import org.springframework.ide.vscode.commons.protocol.STS4LanguageClient;
122123
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
124+
import org.springframework.ide.vscode.commons.protocol.java.Gav;
123125
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteData;
124126
import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompleteParams;
125127
import org.springframework.ide.vscode.commons.protocol.java.JavaDataParams;
126128
import org.springframework.ide.vscode.commons.protocol.java.JavaSearchParams;
127129
import org.springframework.ide.vscode.commons.protocol.java.JavaTypeHierarchyParams;
130+
import org.springframework.ide.vscode.commons.protocol.java.ProjectGavParams;
128131
import org.springframework.ide.vscode.commons.protocol.java.TypeData;
129132
import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
130133
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
@@ -155,6 +158,8 @@ public class LanguageServerHarness {
155158
private final SimpleLanguageServer server;
156159

157160
private InitializeResult initResult;
161+
162+
private Function<File, Gav> gavSupplier;
158163

159164
private Map<String,TextDocumentInfo> documents = new HashMap<>();
160165
private Multimap<String, CompletableFuture<HighlightParams>> highlights = MultimapBuilder.hashKeys().linkedListValues().build();
@@ -263,6 +268,10 @@ public void ensureInitialized() throws Exception {
263268
intialize(null);
264269
}
265270
}
271+
272+
public void setGavSupplier(Function<File, Gav> s) {
273+
this.gavSupplier = s;
274+
}
266275

267276
public InitializeResult intialize(File workspaceRoot) throws Exception {
268277
int parentPid = random.nextInt(40000)+1000;
@@ -449,6 +458,21 @@ public CompletableFuture<ShowDocumentResult> showDocument(ShowDocumentParams par
449458
return CompletableFuture.completedFuture(new ShowDocumentResult(true));
450459
}
451460

461+
@Override
462+
public CompletableFuture<List<Gav>> projectGAV(ProjectGavParams params) {
463+
List<Gav> gavs = new ArrayList<>(params.projectUris().size());
464+
for (int i = 0; i < params.projectUris().size(); i++) {
465+
gavs.add(null);
466+
}
467+
for (int i = 0; i < params.projectUris().size(); i++) {
468+
Path path = Paths.get(URI.create(params.projectUris().get(i)));
469+
if (gavSupplier != null) {
470+
gavs.set(i, gavSupplier.apply(path.toFile()));
471+
}
472+
}
473+
return CompletableFuture.completedFuture(gavs);
474+
}
475+
452476
});
453477

454478
}

0 commit comments

Comments
 (0)