Skip to content

Commit 3e0cf15

Browse files
committed
Add support for extended support policy
Closes gh-27
1 parent bec47aa commit 3e0cf15

File tree

10 files changed

+67
-33
lines changed

10 files changed

+67
-33
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ public class ProjectSupport {
4242
@JsonFormat(pattern = "yyyy-MM-dd")
4343
private final LocalDate commercialPolicyEnd;
4444

45+
private final boolean isLastMinor;
46+
4547
@JsonCreator(mode = Mode.PROPERTIES)
4648
public ProjectSupport(String branch, LocalDate initialRelease, LocalDate ossPolicyEnd,
47-
LocalDate commercialPolicyEnd) {
49+
LocalDate commercialPolicyEnd, boolean isLastMinor) {
4850
this.branch = branch;
4951
this.initialDate = initialRelease;
5052
this.ossPolicyEnd = ossPolicyEnd;
5153
this.commercialPolicyEnd = commercialPolicyEnd;
54+
this.isLastMinor = isLastMinor;
5255
}
5356

5457
public String getBranch() {
@@ -67,4 +70,8 @@ public LocalDate getCommercialPolicyEnd() {
6770
return this.commercialPolicyEnd;
6871
}
6972

73+
public boolean isLastMinor() {
74+
return this.isLastMinor;
75+
}
76+
7077
}

src/main/java/io/spring/projectapi/web/generation/GenerationsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private Generation asGeneration(ProjectSupport support, String supportPolicy) {
8686
LocalDate ossPolicyEnd = SupportPolicyCalculator.getOSSPolicyEnd(support.getInitialDate(),
8787
support.getOssPolicyEnd(), supportPolicy);
8888
LocalDate commercialPolicyEnd = SupportPolicyCalculator.getEnterprisePolicyEnd(support.getInitialDate(),
89-
support.getCommercialPolicyEnd(), supportPolicy);
89+
support.getCommercialPolicyEnd(), supportPolicy, support.isLastMinor());
9090
return new Generation(support.getBranch(), support.getInitialDate(), ossPolicyEnd, commercialPolicyEnd);
9191
}
9292

src/main/java/io/spring/projectapi/web/generation/SupportPolicyCalculator.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.spring.projectapi.web.generation;
1818

1919
import java.time.LocalDate;
20+
import java.time.temporal.TemporalAdjusters;
2021

2122
/**
2223
* Calculates end of support dates when only initial release date is available.
@@ -33,33 +34,39 @@ static LocalDate getOSSPolicyEnd(LocalDate initialDate, LocalDate ossEnforcedPol
3334
return ossEnforcedPolicy;
3435
}
3536
SupportPolicy policy = SupportPolicy.valueOf(supportPolicy);
36-
return initialDate.plusMonths(policy.getOssPolicyMonths());
37+
return initialDate.plusMonths(policy.getOssPolicyMonths()).with(TemporalAdjusters.lastDayOfMonth());
3738
}
3839

3940
static LocalDate getEnterprisePolicyEnd(LocalDate initialDate, LocalDate enterpriseEnforcedPolicy,
40-
String supportPolicy) {
41+
String supportPolicy, boolean isLastMinor) {
4142
if (enterpriseEnforcedPolicy != null) {
4243
return enterpriseEnforcedPolicy;
4344
}
4445
SupportPolicy policy = SupportPolicy.valueOf(supportPolicy);
45-
return initialDate.plusMonths(policy.getEnterprisePolicyMonths());
46+
if (isLastMinor) {
47+
return initialDate.plusMonths(policy.getExtendedPolicyMonths()).with(TemporalAdjusters.lastDayOfMonth());
48+
}
49+
return initialDate.plusMonths(policy.getEnterprisePolicyMonths()).with(TemporalAdjusters.lastDayOfMonth());
4650
}
4751

4852
private enum SupportPolicy {
4953

50-
SPRING_BOOT(12, 15),
54+
SPRING_BOOT(13, 25, 85),
5155

52-
DOWNSTREAM(12, 12),
56+
DOWNSTREAM(12, 24, 84),
5357

54-
UPSTREAM(12, 16);
58+
UPSTREAM(13, 25, 85);
5559

5660
private final int ossPolicyMonths;
5761

5862
private final int enterprisePolicyMonths;
5963

60-
SupportPolicy(int ossPolicyMonths, int enterprisePolicyMonths) {
64+
private final int extendedPolicyMonths;
65+
66+
SupportPolicy(int ossPolicyMonths, int enterprisePolicyMonths, int extendedPolicyMonths) {
6167
this.ossPolicyMonths = ossPolicyMonths;
6268
this.enterprisePolicyMonths = enterprisePolicyMonths;
69+
this.extendedPolicyMonths = extendedPolicyMonths;
6370
}
6471

6572
int getOssPolicyMonths() {
@@ -70,6 +77,10 @@ int getEnterprisePolicyMonths() {
7077
return this.enterprisePolicyMonths;
7178
}
7279

80+
int getExtendedPolicyMonths() {
81+
return this.extendedPolicyMonths;
82+
}
83+
7384
}
7485

7586
}

src/test/java/io/spring/projectapi/github/GithubProjectRepositoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ private Map<String, Project> getProjects(String project) {
149149
}
150150

151151
private Map<String, List<ProjectSupport>> getProjectSupports(String project) {
152-
ProjectSupport support1 = new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"), null, null);
153-
ProjectSupport support2 = new ProjectSupport("2.3.x", LocalDate.parse("2021-02-01"), null, null);
152+
ProjectSupport support1 = new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"), null, null, false);
153+
ProjectSupport support2 = new ProjectSupport("2.3.x", LocalDate.parse("2021-02-01"), null, null, false);
154154
return Map.of(project, List.of(support1, support2));
155155
}
156156

src/test/java/io/spring/projectapi/github/GithubQueriesTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ private Map<String, Project> getProjects() {
205205
}
206206

207207
private Map<String, List<ProjectSupport>> getProjectSupports() {
208-
ProjectSupport support1 = new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"), null, null);
209-
ProjectSupport support2 = new ProjectSupport("2.3.x", LocalDate.parse("2021-02-01"), null, null);
208+
ProjectSupport support1 = new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"), null, null, false);
209+
ProjectSupport support2 = new ProjectSupport("2.3.x", LocalDate.parse("2021-02-01"), null, null, false);
210210
return Map.of("spring-boot", List.of(support1, support2));
211211
}
212212

src/test/java/io/spring/projectapi/github/ProjectSupportJsonTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void readObjectReadsJson() throws Exception {
4545
assertThat(projectSupport.getInitialDate()).isEqualTo("2017-01-30");
4646
assertThat(projectSupport.getOssPolicyEnd()).isEqualTo("2019-08-07");
4747
assertThat(projectSupport.getCommercialPolicyEnd()).isEqualTo("2020-11-06");
48+
assertThat(projectSupport.isLastMinor()).isTrue();
4849
}
4950

5051
}

src/test/java/io/spring/projectapi/web/generation/GenerationsControllerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void generationsReturnsGenerations() throws Exception {
7474
.andExpect(jsonPath("$._embedded.generations.length()").value("2"))
7575
.andExpect(jsonPath("$._embedded.generations[0].name").value("2.2.x"))
7676
.andExpect(jsonPath("$._embedded.generations[0].initialReleaseDate").value("2020-02-01"))
77-
.andExpect(jsonPath("$._embedded.generations[0].ossSupportEndDate").value("2021-02-01"))
78-
.andExpect(jsonPath("$._embedded.generations[0].commercialSupportEndDate").value("2021-05-01"))
77+
.andExpect(jsonPath("$._embedded.generations[0].ossSupportEndDate").value("2021-03-31"))
78+
.andExpect(jsonPath("$._embedded.generations[0].commercialSupportEndDate").value("2027-03-31"))
7979
.andExpect(jsonPath("$._embedded.generations[0]._links.self.href")
8080
.value("https://api.spring.io/projects/spring-boot/generations/2.2.x"))
8181
.andExpect(jsonPath("$._embedded.generations[0]._links.project.href")
@@ -119,9 +119,9 @@ void generationWhenNotFoundReturns404() throws Exception {
119119

120120
private List<ProjectSupport> getProjectSupports() {
121121
List<ProjectSupport> result = new ArrayList<>();
122-
result.add(new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"), null, null));
122+
result.add(new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"), null, null, true));
123123
result.add(new ProjectSupport("2.1.x", LocalDate.parse("2020-01-01"), LocalDate.parse("2021-03-01"),
124-
LocalDate.parse("2022-03-01")));
124+
LocalDate.parse("2022-03-01"), false));
125125
return result;
126126
}
127127

src/test/java/io/spring/projectapi/web/generation/SupportPolicyCalculatorTests.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class SupportPolicyCalculatorTests {
3333
void ossSupportPolicyWhenEnforcedDateIsEmpty() {
3434
LocalDate ossPolicyEndSpringBoot = SupportPolicyCalculator.getOSSPolicyEnd(LocalDate.parse("2022-11-24"), null,
3535
"SPRING_BOOT");
36-
assertThat(ossPolicyEndSpringBoot).isEqualTo(LocalDate.of(2023, 11, 24));
36+
assertThat(ossPolicyEndSpringBoot).isEqualTo(LocalDate.of(2023, 12, 31));
3737
LocalDate ossPolicyEndUpstream = SupportPolicyCalculator.getOSSPolicyEnd(LocalDate.parse("2022-11-24"), null,
3838
"UPSTREAM");
39-
assertThat(ossPolicyEndUpstream).isEqualTo(LocalDate.of(2023, 11, 24));
40-
LocalDate ossPolicyEndDownstream = SupportPolicyCalculator.getOSSPolicyEnd(LocalDate.parse("2022-11-24"), null,
39+
assertThat(ossPolicyEndUpstream).isEqualTo(LocalDate.of(2023, 12, 31));
40+
LocalDate ossPolicyEndDownstream = SupportPolicyCalculator.getOSSPolicyEnd(LocalDate.parse("2022-12-24"), null,
4141
"DOWNSTREAM");
42-
assertThat(ossPolicyEndDownstream).isEqualTo(LocalDate.of(2023, 11, 24));
42+
assertThat(ossPolicyEndDownstream).isEqualTo(LocalDate.of(2023, 12, 31));
4343
}
4444

4545
@Test
@@ -58,26 +58,39 @@ void ossSupportPolicyWhenEnforcedDateIsNotEmpty() {
5858
@Test
5959
void enterpriseSupportPolicyWhenEnforcedDateIsEmpty() {
6060
LocalDate ossPolicyEndSpringBoot = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
61-
null, "SPRING_BOOT");
62-
assertThat(ossPolicyEndSpringBoot).isEqualTo(LocalDate.of(2024, 2, 24));
61+
null, "SPRING_BOOT", false);
62+
assertThat(ossPolicyEndSpringBoot).isEqualTo(LocalDate.of(2024, 12, 31));
6363
LocalDate ossPolicyEndUpstream = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
64-
null, "UPSTREAM");
65-
assertThat(ossPolicyEndUpstream).isEqualTo(LocalDate.of(2024, 3, 24));
66-
LocalDate ossPolicyEndDownstream = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
67-
null, "DOWNSTREAM");
68-
assertThat(ossPolicyEndDownstream).isEqualTo(LocalDate.of(2023, 11, 24));
64+
null, "UPSTREAM", false);
65+
assertThat(ossPolicyEndUpstream).isEqualTo(LocalDate.of(2024, 12, 31));
66+
LocalDate ossPolicyEndDownstream = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-12-24"),
67+
null, "DOWNSTREAM", false);
68+
assertThat(ossPolicyEndDownstream).isEqualTo(LocalDate.of(2024, 12, 31));
69+
}
70+
71+
@Test
72+
void enterpriseSupportPolicyWhenEnforcedDateIsEmptyAndLastMinor() {
73+
LocalDate ossPolicyEndSpringBoot = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
74+
null, "SPRING_BOOT", true);
75+
assertThat(ossPolicyEndSpringBoot).isEqualTo(LocalDate.of(2029, 12, 31));
76+
LocalDate ossPolicyEndUpstream = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
77+
null, "UPSTREAM", true);
78+
assertThat(ossPolicyEndUpstream).isEqualTo(LocalDate.of(2029, 12, 31));
79+
LocalDate ossPolicyEndDownstream = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-12-24"),
80+
null, "DOWNSTREAM", true);
81+
assertThat(ossPolicyEndDownstream).isEqualTo(LocalDate.of(2029, 12, 31));
6982
}
7083

7184
@Test
7285
void enterpriseSupportPolicyWhenEnforcedDateIsNotEmpty() {
7386
LocalDate policyEndSpringBoot = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
74-
LocalDate.parse("2025-02-02"), "SPRING_BOOT");
87+
LocalDate.parse("2025-02-02"), "SPRING_BOOT", false);
7588
assertThat(policyEndSpringBoot).isEqualTo(LocalDate.of(2025, 2, 2));
7689
LocalDate policyEndUpstream = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
77-
LocalDate.parse("2025-02-02"), "UPSTREAM");
90+
LocalDate.parse("2025-02-02"), "UPSTREAM", false);
7891
assertThat(policyEndUpstream).isEqualTo(LocalDate.of(2025, 2, 2));
7992
LocalDate policyEndDownstream = SupportPolicyCalculator.getEnterprisePolicyEnd(LocalDate.parse("2022-11-24"),
80-
LocalDate.parse("2025-02-02"), "DOWNSTREAM");
93+
LocalDate.parse("2025-02-02"), "DOWNSTREAM", false);
8194
assertThat(policyEndDownstream).isEqualTo(LocalDate.of(2025, 2, 2));
8295
}
8396

src/test/resources/io/spring/projectapi/github/project-support-content.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"branch": "2.7.x",
2020
"initialDate": "2022-05-19",
2121
"ossPolicyEnd": "2023-11-24",
22-
"commercialPolicyEnd": "2026-12-31"
22+
"commercialPolicyEnd": "2026-12-31",
23+
"isLastMinor": true
2324
},
2425
{ "branch": "3.0.x", "initialDate": "2022-11-24" },
2526
{ "branch": "3.1.x", "initialDate": "2023-05-18" },

src/test/resources/io/spring/projectapi/github/project-support.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"branch": "1.5.x",
33
"initialDate": "2017-01-30",
44
"ossPolicyEnd": "2019-08-07",
5-
"commercialPolicyEnd": "2020-11-06"
5+
"commercialPolicyEnd": "2020-11-06",
6+
"isLastMinor": true
67
}

0 commit comments

Comments
 (0)