Skip to content

Commit b8e6ad9

Browse files
committed
Merge branch '4.0.x' into 4.1.x
Closes gh-1595
2 parents 5bb7422 + 12ad317 commit b8e6ad9

File tree

10 files changed

+656
-0
lines changed

10 files changed

+656
-0
lines changed

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ version=4.1.1-SNAPSHOT
33
org.gradle.caching=true
44
org.gradle.parallel=true
55

6+
versionUpgradePolicy=same_minor_version
7+
68
compatibilityTestPluginVersion=0.0.3
79
springFrameworkVersion=6.2.7

gradle/plugins/conventions-plugin/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ plugins {
55
}
66

77
repositories {
8+
gradlePluginPortal()
89
mavenCentral()
910
}
1011

1112
dependencies {
13+
api(platform("org.junit:junit-bom:${junitVersion}"))
1214
checkstyle("com.puppycrawl.tools:checkstyle:${checkstyle.toolVersion}")
1315
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")
16+
17+
testImplementation("org.junit.jupiter:junit-jupiter")
18+
testImplementation("org.assertj:assertj-core:${assertJVersion}")
19+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
1420
}
1521

1622
gradlePlugin {
@@ -23,5 +29,10 @@ gradlePlugin {
2329
}
2430

2531
dependencies {
32+
implementation("com.github.ben-manes:gradle-versions-plugin:$gradleVersionsPluginVersion")
2633
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:$javaFormatVersion")
2734
}
35+
36+
tasks.named('test') {
37+
useJUnitPlatform()
38+
}

gradle/plugins/conventions-plugin/src/main/java/org/springframework/ws/gradle/conventions/JavaPluginConventions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void apply(Project project) {
5151
enableSourceAndJavadocJars(java);
5252
configureSourceAndTargetCompatibility(java);
5353
configureDependencyManagement(project);
54+
configureVersionUpgradePolicy(project);
5455
configureJarManifest(project);
5556
configureToolchain(project, java);
5657
configureJavadocClasspath(project, java);
@@ -98,6 +99,10 @@ private void configureDependencyManagement(Project project) {
9899
.add(dependencies.enforcedPlatform(dependencies.project(Map.of("path", ":spring-ws-platform"))));
99100
}
100101

102+
private void configureVersionUpgradePolicy(Project project) {
103+
new VersionUpgradePluginConventions().apply(project);
104+
}
105+
101106
private void configureJarManifest(Project project) {
102107
project.getTasks().named("jar", Jar.class, (jar) -> jar.manifest((manifest) -> {
103108
Map<String, Object> attributes = new TreeMap<>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2005-2025 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.ws.gradle.conventions;
18+
19+
import java.util.Locale;
20+
21+
import com.github.benmanes.gradle.versions.VersionsPlugin;
22+
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask;
23+
import org.gradle.api.Project;
24+
25+
import org.springframework.ws.gradle.conventions.support.Version;
26+
import org.springframework.ws.gradle.conventions.support.VersionUpgradePolicy;
27+
28+
/**
29+
* Conventions for {@code gradle-versions-plugin}.
30+
*
31+
* @author Stephane Nicoll
32+
*/
33+
class VersionUpgradePluginConventions {
34+
35+
void apply(Project project) {
36+
project.getPlugins().apply(VersionsPlugin.class);
37+
project.getTasks().withType(DependencyUpdatesTask.class, (updateTask) -> {
38+
updateTask.setFilterConfigurations((configuration) -> !(configuration.getName().contains("_")
39+
&& configuration.getName().endsWith("+")));
40+
VersionUpgradePolicy upgradePolicy = getUpgradePolicy(project);
41+
updateTask.rejectVersionIf((candidate) -> {
42+
Version currentVersion = Version.from(candidate.getCurrentVersion());
43+
Version candidateVersion = Version.from(candidate.getCandidate().getVersion());
44+
return !upgradePolicy.isCandidate(currentVersion, candidateVersion);
45+
});
46+
});
47+
}
48+
49+
private VersionUpgradePolicy getUpgradePolicy(Project project) {
50+
Object versionUpgradePolicy = project.findProperty("versionUpgradePolicy");
51+
if (versionUpgradePolicy == null) {
52+
return VersionUpgradePolicy.SAME_MINOR_VERSION;
53+
}
54+
else if (versionUpgradePolicy instanceof String value) {
55+
return VersionUpgradePolicy.valueOf(value.toUpperCase(Locale.ROOT));
56+
}
57+
throw new IllegalArgumentException("Unsupported version upgrade policy: " + versionUpgradePolicy);
58+
}
59+
60+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* Copyright 2012-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 org.springframework.ws.gradle.conventions.support;
18+
19+
import java.io.Serializable;
20+
import java.util.Objects;
21+
22+
/**
23+
* ë A version representation that provides a major and minor identifier. For instance,
24+
* {@code 1.2.5} would have a {@code major} of "1" and {@code minor} of "1.2".
25+
*
26+
* @author Stephane Nicoll
27+
*/
28+
public class Version {
29+
30+
private final String id;
31+
32+
private final String major;
33+
34+
private final String minor;
35+
36+
private final Qualifier qualifier;
37+
38+
private final Parts parts;
39+
40+
Version(String id, String major, String minor, Qualifier qualifer, Parts parts) {
41+
this.id = id;
42+
this.major = major;
43+
this.minor = minor;
44+
this.qualifier = qualifer;
45+
this.parts = parts;
46+
}
47+
48+
public static Version from(String version) {
49+
return VersionParser.safeParse(version);
50+
}
51+
52+
/**
53+
* Return the version.
54+
* @return the version
55+
*/
56+
public String getId() {
57+
return this.id;
58+
}
59+
60+
/**
61+
* Return the major qualifier or {@code null}.
62+
* @return the major
63+
*/
64+
public String getMajor() {
65+
return this.major;
66+
}
67+
68+
/**
69+
* Return the minor qualifier or {@code null}.
70+
* @return the minor
71+
*/
72+
public String getMinor() {
73+
return this.minor;
74+
}
75+
76+
/**
77+
* Return tue {@link Qualifier} or {@code null}.
78+
* @return the qualifier
79+
*/
80+
public Qualifier getQualifier() {
81+
return this.qualifier;
82+
}
83+
84+
/**
85+
* Return the elements of the version, if any. Does not apply for non-numeric version
86+
* such as a release train.
87+
* @return the parts
88+
*/
89+
public Parts getParts() {
90+
return this.parts;
91+
}
92+
93+
/**
94+
* Returns whether this version has the same major and minor versions as the
95+
* {@code other} version.
96+
* @param other the version to test
97+
* @return {@code true} if this version has the same major and minor, otherwise
98+
* {@code false}
99+
*/
100+
public boolean isSameMinor(Version other) {
101+
return isSameMajor(other) && Objects.equals(this.parts.minor, other.parts.minor);
102+
}
103+
104+
/**
105+
* Returns whether this version has the same major version as the {@code other}
106+
* version.
107+
* @param other the version to test
108+
* @return {@code true} if this version has the same major, otherwise {@code false}
109+
*/
110+
public boolean isSameMajor(Version other) {
111+
return (this.parts != null && other.parts != null && Objects.equals(this.parts.major, other.parts.major));
112+
}
113+
114+
@Override
115+
public boolean equals(Object o) {
116+
if (this == o) {
117+
return true;
118+
}
119+
if (!(o instanceof Version version)) {
120+
return false;
121+
}
122+
return Objects.equals(this.id, version.id);
123+
}
124+
125+
@Override
126+
public int hashCode() {
127+
return Objects.hashCode(this.id);
128+
}
129+
130+
@Override
131+
public String toString() {
132+
return this.id;
133+
}
134+
135+
public record Parts(Integer major, Integer minor, Integer patch, Integer hotPatch) {
136+
137+
/**
138+
* Return a unique number for this instance that allows to compare two versions.
139+
* @return a comparable number
140+
*/
141+
public long toNumber() {
142+
String paddedValue = paddedNumber(this.major) + paddedNumber(this.minor) + paddedNumber(this.patch)
143+
+ paddedNumber(this.hotPatch);
144+
return Long.parseLong(paddedValue);
145+
}
146+
147+
private String paddedNumber(Integer number) {
148+
if (number != null) {
149+
return String.format("%02d", number);
150+
}
151+
return "00";
152+
}
153+
154+
}
155+
156+
/**
157+
* A version qualifier.
158+
*
159+
* @param id the identifier of the qualifier
160+
* @param version the version or {@code null}
161+
* @param separator the separator
162+
*/
163+
public record Qualifier(String id, Integer version, String separator) implements Serializable {
164+
165+
public Qualifier(String id) {
166+
this(id, null, ".");
167+
}
168+
169+
}
170+
171+
}

0 commit comments

Comments
 (0)