Skip to content

Commit 16ae1c5

Browse files
committed
Adapt to changes in spring-website-content
Closes gh-28
1 parent ae9649c commit 16ae1c5

21 files changed

+441
-430
lines changed

src/main/java/io/spring/projectapi/ProjectRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import io.spring.projectapi.github.Project;
2323
import io.spring.projectapi.github.ProjectDocumentation;
24-
import io.spring.projectapi.github.ProjectSupport;
24+
import io.spring.projectapi.github.ProjectGeneration;
2525
import io.spring.projectapi.web.webhook.CacheController;
2626

2727
/**
@@ -39,7 +39,7 @@ public interface ProjectRepository {
3939

4040
List<ProjectDocumentation> getProjectDocumentations(String projectSlug);
4141

42-
List<ProjectSupport> getProjectSupports(String projectSlug);
42+
ProjectGeneration getProjectGenerations(String projectSlug);
4343

4444
String getProjectSupportPolicy(String projectSlug);
4545

src/main/java/io/spring/projectapi/github/GithubProjectRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public List<ProjectDocumentation> getProjectDocumentations(String projectSlug) {
6666
}
6767

6868
@Override
69-
public List<ProjectSupport> getProjectSupports(String projectSlug) {
70-
List<ProjectSupport> projectSupports = this.projectData.support().get(projectSlug);
71-
NoSuchGithubProjectException.throwIfNotFound(projectSupports, projectSlug);
72-
return projectSupports;
69+
public ProjectGeneration getProjectGenerations(String projectSlug) {
70+
ProjectGeneration projectGeneration = this.projectData.generation().get(projectSlug);
71+
NoSuchGithubProjectException.throwIfNotFound(projectGeneration, projectSlug);
72+
return projectGeneration;
7373
}
7474

7575
@Override

src/main/java/io/spring/projectapi/github/GithubQueries.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public class GithubQueries {
5050
private static final TypeReference<@NotNull List<ProjectDocumentation>> DOCUMENTATION_LIST = new TypeReference<>() {
5151
};
5252

53-
private static final TypeReference<List<ProjectSupport>> SUPPORT_LIST = new TypeReference<>() {
54-
};
55-
5653
private static final String GITHUB_URI = "https://api.github.com/repos/spring-io/spring-website-content/contents";
5754

5855
private static final Logger logger = LoggerFactory.getLogger(GithubOperations.class);
@@ -85,28 +82,28 @@ public GithubQueries(RestTemplateBuilder restTemplateBuilder, ObjectMapper objec
8582
ProjectData getData() {
8683
Map<String, Project> projects = new LinkedHashMap<>();
8784
Map<String, List<ProjectDocumentation>> documentation = new LinkedHashMap<>();
88-
Map<String, List<ProjectSupport>> support = new LinkedHashMap<>();
85+
Map<String, ProjectGeneration> generation = new LinkedHashMap<>();
8986
Map<String, String> supportPolicy = new LinkedHashMap<>();
9087
try {
9188
RequestEntity<Void> request = RequestEntity.get("/project?ref=" + this.branch).build();
9289
ResponseEntity<List<Map<String, Object>>> exchange = this.restTemplate.exchange(request,
9390
STRING_OBJECT_MAP_LIST);
9491
InvalidGithubResponseException.throwIfInvalid(exchange);
9592
List<Map<String, Object>> body = exchange.getBody();
96-
body.forEach((project) -> populateData(project, projects, documentation, support, supportPolicy));
93+
body.forEach((project) -> populateData(project, projects, documentation, generation, supportPolicy));
9794
}
9895
catch (Exception ex) {
9996
logger.debug("Could not get projects due to '%s'".formatted(ex.getMessage()));
10097
// Return empty list
10198
}
102-
return new ProjectData(projects, documentation, support, supportPolicy);
99+
return new ProjectData(projects, documentation, generation, supportPolicy);
103100
}
104101

105102
ProjectData updateData(ProjectData data, List<String> changes) {
106103
Assert.notNull(data, "Project data should not be null");
107104
Map<String, Project> projects = new LinkedHashMap<>(data.project());
108105
Map<String, List<ProjectDocumentation>> documentation = new LinkedHashMap<>(data.documentation());
109-
Map<String, List<ProjectSupport>> support = new LinkedHashMap<>(data.support());
106+
Map<String, ProjectGeneration> generation = new LinkedHashMap<>(data.generation());
110107
Map<String, String> supportPolicy = new LinkedHashMap<>(data.supportPolicy());
111108
Map<String, Boolean> checkedProjects = new LinkedHashMap<>();
112109
try {
@@ -115,18 +112,18 @@ ProjectData updateData(ProjectData data, List<String> changes) {
115112
if (ProjectFile.OTHER.equals(file)) {
116113
return;
117114
}
118-
updateData(change, file, projects, supportPolicy, documentation, support, checkedProjects);
115+
updateData(change, file, projects, supportPolicy, documentation, generation, checkedProjects);
119116
});
120117
}
121118
catch (Exception ex) {
122119
logger.debug("Could not update data due to '%s'".formatted(ex.getMessage()));
123120
}
124-
return new ProjectData(projects, documentation, support, supportPolicy);
121+
return new ProjectData(projects, documentation, generation, supportPolicy);
125122
}
126123

127124
private void updateData(String change, ProjectFile file, Map<String, Project> projects,
128125
Map<String, String> supportPolicy, Map<String, List<ProjectDocumentation>> documentation,
129-
Map<String, List<ProjectSupport>> support, Map<String, Boolean> checkedprojects) {
126+
Map<String, ProjectGeneration> generation, Map<String, Boolean> checkedprojects) {
130127
Matcher matcher = PROJECT_FILE.matcher(change);
131128
if (!matcher.matches()) {
132129
return;
@@ -138,18 +135,18 @@ private void updateData(String change, ProjectFile file, Map<String, Project> pr
138135
if (checkedprojects.get(slug)) {
139136
updateFromIndex(file, projects, supportPolicy, slug);
140137
updateDocumentation(file, documentation, slug);
141-
updateSupport(file, support, slug);
138+
updateGeneration(file, generation, slug);
142139
return;
143140
}
144141
projects.remove(slug);
145142
documentation.remove(slug);
146-
support.remove(slug);
143+
generation.remove(slug);
147144
supportPolicy.remove(slug);
148145
}
149146

150-
private void updateSupport(ProjectFile file, Map<String, List<ProjectSupport>> support, String slug) {
147+
private void updateGeneration(ProjectFile file, Map<String, ProjectGeneration> support, String slug) {
151148
if (ProjectFile.SUPPORT.equals(file)) {
152-
List<ProjectSupport> projectSupports = getProjectSupports(slug);
149+
ProjectGeneration projectSupports = getProjectSupports(slug);
153150
support.put(slug, projectSupports);
154151
}
155152
}
@@ -192,7 +189,7 @@ private boolean doesProjectExist(String projectSlug) {
192189
}
193190

194191
private void populateData(Map<String, Object> project, Map<String, Project> projects,
195-
Map<String, List<ProjectDocumentation>> documentation, Map<String, List<ProjectSupport>> support,
192+
Map<String, List<ProjectDocumentation>> documentation, Map<String, ProjectGeneration> support,
196193
Map<String, String> supportPolicy) {
197194
String projectSlug = (String) project.get("name");
198195
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "index.md");
@@ -202,7 +199,7 @@ private void populateData(Map<String, Object> project, Map<String, Project> proj
202199
}
203200
List<ProjectDocumentation> projectDocumentations = getProjectDocumentations(projectSlug);
204201
documentation.put(projectSlug, projectDocumentations);
205-
List<ProjectSupport> projectSupports = getProjectSupports(projectSlug);
202+
ProjectGeneration projectSupports = getProjectSupports(projectSlug);
206203
support.put(projectSlug, projectSupports);
207204
String policy = getProjectSupportPolicy(response, projectSlug);
208205
supportPolicy.put(projectSlug, policy);
@@ -234,16 +231,17 @@ private List<ProjectDocumentation> getProjectDocumentations(String projectSlug)
234231
return Collections.emptyList();
235232
}
236233

237-
private List<ProjectSupport> getProjectSupports(String projectSlug) {
234+
private ProjectGeneration getProjectSupports(String projectSlug) {
238235
try {
239-
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "support.json");
236+
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "generations.json");
240237
String contents = getFileContent(response);
241-
return List.copyOf(readValue(contents, SUPPORT_LIST));
238+
return this.objectMapper.readValue(contents, ProjectGeneration.class);
242239
}
243240
catch (Exception ex) {
244-
logger.debug("Could not get project support for '%s' due to '%s'".formatted(projectSlug, ex.getMessage()));
241+
logger
242+
.debug("Could not get project generation for '%s' due to '%s'".formatted(projectSlug, ex.getMessage()));
245243
}
246-
return Collections.emptyList();
244+
return new ProjectGeneration(Collections.emptyList());
247245
}
248246

249247
private String getProjectSupportPolicy(ResponseEntity<Map<String, Object>> response, String projectSlug) {
@@ -255,7 +253,7 @@ private String getProjectSupportPolicy(ResponseEntity<Map<String, Object>> respo
255253
return (supportPolicy != null) ? supportPolicy : DEFAULT_SUPPORT_POLICY;
256254
}
257255
catch (Exception ex) {
258-
logger.debug("Could not get project support policy for '%s' due to '%s'".formatted(projectSlug,
256+
logger.debug("Could not get project generation policy for '%s' due to '%s'".formatted(projectSlug,
259257
ex.getMessage()));
260258
}
261259
return DEFAULT_SUPPORT_POLICY;
@@ -300,7 +298,7 @@ static ProjectFile from(String fileName) {
300298
if (fileName.contains("documentation.json")) {
301299
return DOCUMENTATION;
302300
}
303-
if (fileName.contains("support.json")) {
301+
if (fileName.contains("generations.json")) {
304302
return SUPPORT;
305303
}
306304
return OTHER;

src/main/java/io/spring/projectapi/github/ProjectData.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
*
2727
* @param project all projects
2828
* @param documentation map of project slug to project documentations
29-
* @param support map of project slug to project supports
30-
* @param supportPolicy map of project slug to project support policy
29+
* @param generation map of project slug to project generations
30+
* @param supportPolicy map of project slug to project generation policy
3131
* @author Phillip Webb
3232
* @author Madhura Bhave
3333
*/
3434
record ProjectData(Map<String, Project> project, Map<String, List<ProjectDocumentation>> documentation,
35-
Map<String, List<ProjectSupport>> support, Map<String, String> supportPolicy) {
35+
Map<String, ProjectGeneration> generation, Map<String, String> supportPolicy) {
3636

3737
public static ProjectData load(GithubQueries githubQueries) {
3838
ProjectData data = githubQueries.getData();
@@ -48,9 +48,9 @@ public static ProjectData update(ProjectData data, List<String> changes, GithubQ
4848
private static ProjectData getImmutableProjectData(ProjectData updatedData) {
4949
Map<String, Project> projects = updatedData.project();
5050
Map<String, List<ProjectDocumentation>> documentation = updatedData.documentation();
51-
Map<String, List<ProjectSupport>> support = updatedData.support();
51+
Map<String, ProjectGeneration> generation = updatedData.generation();
5252
Map<String, String> supportPolicy = updatedData.supportPolicy();
53-
return new ProjectData(Map.copyOf(projects), Map.copyOf(documentation), Map.copyOf(support),
53+
return new ProjectData(Map.copyOf(projects), Map.copyOf(documentation), Map.copyOf(generation),
5454
Map.copyOf(supportPolicy));
5555
}
5656

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright 2022-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.projectapi.github;
18+
19+
import java.time.YearMonth;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
import com.fasterxml.jackson.annotation.JsonCreator;
24+
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
25+
import com.fasterxml.jackson.annotation.JsonFormat;
26+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
27+
28+
/**
29+
* Java representation of the {@code project generation} type as defined in
30+
* <a href= "https://github.com/spring-io/spring-website/">spring-io/spring-website</a>.
31+
*
32+
* @author Madhura Bhave
33+
* @author Phillip Webb
34+
*/
35+
@JsonIgnoreProperties(ignoreUnknown = true)
36+
public class ProjectGeneration {
37+
38+
private List<Generation> generations = new ArrayList<>();
39+
40+
@JsonCreator(mode = Mode.PROPERTIES)
41+
public ProjectGeneration(List<Generation> generations) {
42+
this.generations.addAll(generations);
43+
}
44+
45+
public List<Generation> getGenerations() {
46+
return this.generations;
47+
}
48+
49+
@JsonIgnoreProperties(ignoreUnknown = true)
50+
public static class Generation {
51+
52+
private final String generation;
53+
54+
@JsonFormat(pattern = "yyyy-MM")
55+
private final YearMonth initialRelease;
56+
57+
@JsonFormat(pattern = "yyyy-MM")
58+
private final YearMonth ossSupportEnd;
59+
60+
@JsonFormat(pattern = "yyyy-MM")
61+
private final YearMonth enterpriseSupportEnd;
62+
63+
private final boolean lastMinor;
64+
65+
@JsonCreator(mode = Mode.PROPERTIES)
66+
public Generation(String generation, YearMonth initialRelease, YearMonth ossSupportEnd,
67+
YearMonth enterpriseSupportEnd, boolean lastMinor) {
68+
this.generation = generation;
69+
this.initialRelease = initialRelease;
70+
this.ossSupportEnd = ossSupportEnd;
71+
this.enterpriseSupportEnd = enterpriseSupportEnd;
72+
this.lastMinor = lastMinor;
73+
}
74+
75+
public String getGeneration() {
76+
return this.generation;
77+
}
78+
79+
public YearMonth getInitialRelease() {
80+
return this.initialRelease;
81+
}
82+
83+
public YearMonth getOssSupportEnd() {
84+
return this.ossSupportEnd;
85+
}
86+
87+
public YearMonth getEnterpriseSupportEnd() {
88+
return this.enterpriseSupportEnd;
89+
}
90+
91+
public boolean isLastMinor() {
92+
return this.lastMinor;
93+
}
94+
95+
}
96+
97+
}

src/main/java/io/spring/projectapi/github/ProjectSupport.java

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

0 commit comments

Comments
 (0)