Skip to content

Commit 4e8b7df

Browse files
committed
add minorVersionBump
Closes gh-9709
1 parent 8c11853 commit 4e8b7df

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

buildSrc/src/main/java/org/springframework/security/convention/versions/UpdateDependenciesExtension.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ public DependencyExcludes majorVersionBump() {
147147
return this;
148148
}
149149

150+
public DependencyExcludes minorVersionBump() {
151+
this.actions.add(createExcludeMinorVersionBump());
152+
return this;
153+
}
154+
155+
public Action<ComponentSelectionWithCurrent> createExcludeMinorVersionBump() {
156+
return (selection) -> {
157+
String currentVersion = selection.getCurrentVersion();
158+
int majorSeparator = currentVersion.indexOf(".");
159+
int separator = currentVersion.indexOf(".", majorSeparator + 1);
160+
String majorMinor = separator > 0 ? currentVersion.substring(0, separator) : currentVersion;
161+
String candidateVersion = selection.getCandidate().getVersion();
162+
if (!candidateVersion.startsWith(majorMinor)) {
163+
selection.reject("Cannot upgrade to new Minor Version");
164+
}
165+
};
166+
}
167+
150168
public DependencyExcludes releaseCandidatesVersions() {
151169
this.actions.add(excludeVersionWithRegex("(?i).*?rc\\d+.*", "a release candidate version"));
152170
return this;

buildSrc/src/main/java/org/springframework/security/convention/versions/UpdateDependenciesPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ private Mono<GitHubApi.FindCreateIssueResult> createIssueResultMono(UpdateDepend
179179
}
180180

181181
private void updateGradleVersion(Result result, Project project, UpdateDependenciesExtension updateDependenciesSettings) {
182+
if (!result.getGradle().isEnabled()) {
183+
return;
184+
}
182185
GradleUpdateResult current = result.getGradle().getCurrent();
183186
GradleUpdateResult running = result.getGradle().getRunning();
184187
if (current.compareTo(running) > 0) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2019-2020 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 org.springframework.security.convention.versions;
18+
19+
import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent;
20+
import org.gradle.api.Action;
21+
import org.gradle.api.artifacts.ComponentSelection;
22+
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
23+
import org.junit.Test;
24+
25+
import java.util.Collections;
26+
import java.util.List;
27+
28+
import static org.mockito.ArgumentMatchers.any;
29+
import static org.mockito.BDDMockito.given;
30+
import static org.mockito.Mockito.*;
31+
32+
public class DependencyExcludesTests {
33+
34+
@Test
35+
public void createExcludeMinorVersionBumpWhenMajorVersionBumpThenReject() {
36+
ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "2.0.0");
37+
verify(componentSelection).reject(any());
38+
}
39+
40+
@Test
41+
public void createExcludeMinorVersionBumpWhenMajorCalVersionBumpThenReject() {
42+
ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("2000.0.0", "2001.0.0");
43+
verify(componentSelection).reject(any());
44+
}
45+
46+
@Test
47+
public void createExcludeMinorVersionBumpWhenMinorVersionBumpThenReject() {
48+
ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "1.1.0");
49+
verify(componentSelection).reject(any());
50+
}
51+
52+
@Test
53+
public void createExcludeMinorVersionBumpWhenMinorCalVersionBumpThenReject() {
54+
ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("2000.0.0", "2000.1.0");
55+
verify(componentSelection).reject(any());
56+
}
57+
58+
@Test
59+
public void createExcludeMinorVersionBumpWhenMinorAndPatchVersionBumpThenReject() {
60+
ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "1.1.1");
61+
verify(componentSelection).reject(any());
62+
}
63+
64+
@Test
65+
public void createExcludeMinorVersionBumpWhenPatchVersionBumpThenDoesNotReject() {
66+
ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "1.0.1");
67+
verify(componentSelection, times(0)).reject(any());
68+
}
69+
70+
private ComponentSelection executeCreateExcludeMinorVersionBump(String currentVersion, String candidateVersion) {
71+
ComponentSelection componentSelection = mock(ComponentSelection.class);
72+
UpdateDependenciesExtension.DependencyExcludes excludes = new UpdateDependenciesExtension(() -> Collections.emptyList()).new DependencyExcludes();
73+
Action<ComponentSelectionWithCurrent> excludeMinorVersionBump = excludes.createExcludeMinorVersionBump();
74+
ComponentSelectionWithCurrent selection = currentVersionAndCandidateVersion(componentSelection, currentVersion, candidateVersion);
75+
excludeMinorVersionBump.execute(selection);
76+
return componentSelection;
77+
}
78+
79+
private ComponentSelectionWithCurrent currentVersionAndCandidateVersion(ComponentSelection componentSelection, String currentVersion, String candidateVersion) {
80+
ModuleComponentIdentifier candidate = mock(ModuleComponentIdentifier.class);
81+
given(componentSelection.getCandidate()).willReturn(candidate);
82+
ComponentSelectionWithCurrent selection = new ComponentSelectionWithCurrent(currentVersion, componentSelection);
83+
given(candidate.getVersion()).willReturn(candidateVersion);
84+
given(componentSelection.getCandidate()).willReturn(candidate);
85+
return selection;
86+
}
87+
}

0 commit comments

Comments
 (0)