Skip to content

Commit f53e828

Browse files
committed
take multiple version resolver strategies into account, not just one
1 parent b98f615 commit f53e828

File tree

6 files changed

+35
-48
lines changed

6 files changed

+35
-48
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/WebConfigCodeLensProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private CodeLens createCodeLens(WebConfigIndexElement webConfig, TypeDeclaration
9696
}
9797

9898
if (webConfig.isVersioningSupported()) {
99-
label += " - Versioning via " + webConfig.getVersionSupportStrategy();
99+
label += " - Versioning via " + String.join(", ", webConfig.getVersionSupportStrategies());
100100
label += " - Supported Versions: " + String.join(", ", webConfig.getSupportedVersions());
101101
}
102102

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/WebConfigIndexElement.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public class WebConfigIndexElement extends AbstractSpringIndexElement {
2121
private final String pathPrefix;
2222

2323
private final boolean isVersioningSupported;
24-
private final String versionSupportStrategy;
25-
private final String[] supportedVersions;
24+
private final List<String> versionSupportStrategies;
25+
private final List<String> supportedVersions;
2626
private final Location location;
2727

28-
public WebConfigIndexElement(String pathPrefix, boolean isVersioningSupported, String versionSupportStrategy, String[] supportedVersions, Location location) {
28+
public WebConfigIndexElement(String pathPrefix, boolean isVersioningSupported, List<String> versionSupportStrategies, List<String> supportedVersions, Location location) {
2929
this.pathPrefix = pathPrefix;
3030
this.isVersioningSupported = isVersioningSupported;
31-
this.versionSupportStrategy = versionSupportStrategy;
31+
this.versionSupportStrategies = versionSupportStrategies;
3232
this.supportedVersions = supportedVersions;
3333
this.location = location;
3434
}
@@ -41,11 +41,11 @@ public boolean isVersioningSupported() {
4141
return isVersioningSupported;
4242
}
4343

44-
public String getVersionSupportStrategy() {
45-
return versionSupportStrategy;
44+
public List<String> getVersionSupportStrategies() {
45+
return versionSupportStrategies;
4646
}
4747

48-
public String[] getSupportedVersions() {
48+
public List<String> getSupportedVersions() {
4949
return supportedVersions;
5050
}
5151

@@ -56,17 +56,18 @@ public Location getLocation() {
5656
public static class Builder {
5757

5858
private String pathPrefix = null;
59+
5960
private boolean isVersioningSupported = false;
60-
private String versionSupportStrategy = null;
61-
private List<String> supportedVersions = new ArrayList<>(10);
61+
private List<String> versionSupportStrategies = new ArrayList<>(2);
62+
private List<String> supportedVersions = new ArrayList<>(2);
6263

6364
public Builder pathPrefix(String pathPrefix) {
6465
this.pathPrefix = pathPrefix;
6566
return this;
6667
}
6768

6869
public Builder versionStrategy(String versionSupportStrategy) {
69-
this.versionSupportStrategy = versionSupportStrategy;
70+
this.versionSupportStrategies.add(versionSupportStrategy);
7071
this.isVersioningSupported = true;
7172
return this;
7273
}
@@ -78,7 +79,7 @@ public Builder supportedVersion(String supportedVersion) {
7879
}
7980

8081
public WebConfigIndexElement buildFor(Location location) {
81-
return new WebConfigIndexElement(this.pathPrefix, this.isVersioningSupported, this.versionSupportStrategy, (String[]) this.supportedVersions.toArray(new String[this.supportedVersions.size()]), location);
82+
return new WebConfigIndexElement(this.pathPrefix, this.isVersioningSupported, this.versionSupportStrategies, this.supportedVersions, location);
8283
}
8384

8485
}

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/requestmapping/test/WebConfigCodeLensProviderTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
package org.springframework.ide.vscode.boot.java.requestmapping.test;
1212

1313
import static org.junit.Assert.assertEquals;
14-
import static org.junit.Assert.assertTrue;
1514

1615
import java.nio.charset.StandardCharsets;
1716
import java.nio.file.Files;
1817
import java.nio.file.Path;
1918
import java.nio.file.Paths;
2019
import java.util.List;
2120
import java.util.Map;
22-
import java.util.Optional;
2321
import java.util.concurrent.CompletableFuture;
2422
import java.util.concurrent.TimeUnit;
2523

@@ -78,14 +76,10 @@ void codeLensOverMethod() throws Exception {
7876
Editor editor = harness.newEditor(LanguageId.JAVA, new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8), filePath.toUri().toASCIIString());
7977

8078
List<CodeLens> cls = editor.getCodeLenses("MappingClassWithMultipleVersions", 1);
79+
assertEquals(1, cls.size());
8180

82-
Optional<CodeLens> lens1 = cls.stream().filter(lens -> lens.getCommand().getTitle().equals("Web Config - Versioning via Request Header: X-API-Version - Supported Versions: 1")).findFirst();
83-
assertTrue(lens1.isPresent());
84-
85-
Optional<CodeLens> lens2 = cls.stream().filter(lens -> lens.getCommand().getTitle().equals("Web Config - Path Prefix: /{version} - Versioning via Path Segment: 0 - Supported Versions: 1.1, 1.2")).findFirst();
86-
assertTrue(lens2.isPresent());
87-
88-
assertEquals(2, cls.size());
81+
assertEquals("Web Config - Path Prefix: /{version} - Versioning via Request Header: X-API-Version, Path Segment: 0 - Supported Versions: 1.1, 1.2",
82+
cls.get(0).getCommand().getTitle());
8983
}
9084

9185
}

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/requestmapping/test/WebMvcVersionSupportTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
@Import(SymbolProviderTestConf.class)
5050
public class WebMvcVersionSupportTest {
5151

52-
private static final String PROJECT_NAME = "test-request-mapping-version-support-symbols";
52+
private static final String PROJECT_NAME = "test-web-config-support";
5353

5454
@Autowired private BootLanguageServerHarness harness;
5555
@Autowired private JavaProjectFinder projectFinder;
@@ -130,9 +130,16 @@ void testWebConfigIndexElement() throws Exception {
130130

131131
WebConfigIndexElement webConfigElement = webConfigElements.get(0);
132132
assertTrue(webConfigElement.isVersioningSupported());
133-
assertEquals("Request Header: X-API-Version", webConfigElement.getVersionSupportStrategy());
134-
assertEquals(1, webConfigElement.getSupportedVersions().length);
135-
assertEquals("1", webConfigElement.getSupportedVersions()[0]);
133+
134+
List<String> versionSupportStrategies = webConfigElement.getVersionSupportStrategies();
135+
assertEquals(2, versionSupportStrategies.size());
136+
assertTrue(versionSupportStrategies.contains("Request Header: X-API-Version"));
137+
assertTrue(versionSupportStrategies.contains("Path Segment: 0"));
138+
139+
List<String> supportedVersions = webConfigElement.getSupportedVersions();
140+
assertEquals(2, supportedVersions.size());
141+
assertTrue(supportedVersions.contains("1.1"));
142+
assertTrue(supportedVersions.contains("1.2"));
136143
}
137144

138145
private boolean containsSymbol(List<? extends WorkspaceSymbol> symbols, String name, String uri) {

headless-services/spring-boot-language-server/src/test/resources/test-projects/test-web-config-support/src/main/java/org/test/versions/WebConfig.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
import org.springframework.context.annotation.Configuration;
44
import org.springframework.web.servlet.config.annotation.ApiVersionConfigurer;
5+
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
56
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
67

78
@Configuration
89
public class WebConfig implements WebMvcConfigurer {
910

11+
@Override
12+
public void configurePathMatch(PathMatchConfigurer configurer) {
13+
configurer.addPathPrefix("/{version}", (aClass) -> true);
14+
}
15+
1016
@Override
1117
public void configureApiVersioning(ApiVersionConfigurer configurer) {
12-
configurer.useRequestHeader("X-API-Version").addSupportedVersions("1");
13-
// configurer.usePathSegment(0).addSupportedVersions("1");
18+
configurer.useRequestHeader("X-API-Version");
19+
configurer.usePathSegment(0).addSupportedVersions("1.1", "1.2");
1420
}
1521

1622
}

headless-services/spring-boot-language-server/src/test/resources/test-projects/test-web-config-support/src/main/java/org/test/versions/WebConfigForPathVersioning.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)