Skip to content

Commit 2f441f1

Browse files
committed
Make MIN_SPRING_VERSION Dynamic
Fixes: gh-5065 # Conflicts: # core/src/main/java/org/springframework/security/core/SpringSecurityCoreVersion.java
1 parent a7de1e3 commit 2f441f1

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2002-2018 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+
* http://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+
package versions
17+
18+
import org.gradle.api.DefaultTask
19+
import org.gradle.api.tasks.Input
20+
import org.gradle.api.tasks.OutputFile
21+
import org.gradle.api.tasks.TaskAction
22+
23+
/**
24+
* @author Rob Winch
25+
*/
26+
class VersionsResourceTasks extends DefaultTask {
27+
@OutputFile
28+
File versionsFile;
29+
30+
@Input
31+
Closure<Map<String,String>> versions;
32+
33+
void setVersions(Map<String,String> versions) {
34+
this.versions = { versions };
35+
}
36+
37+
void setVersions(Closure<Map<String,String>> versions) {
38+
this.versions = versions
39+
}
40+
41+
@TaskAction
42+
void generateVersions() {
43+
versionsFile.parentFile.mkdirs()
44+
versionsFile.createNewFile()
45+
Properties versionsProperties = new Properties()
46+
versionsProperties.putAll(versions.call())
47+
versionsProperties.store(versionsFile.newWriter(), null)
48+
}
49+
}

core/spring-security-core.gradle

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ dependencies {
3434
testRuntime 'org.hsqldb:hsqldb'
3535
}
3636

37+
task springVersion(type: versions.VersionsResourceTasks) {
38+
versionsFile = file("${buildDir}/versions/spring-security.versions")
39+
versions = { project.dependencyManagement.managedVersions }
40+
}
41+
42+
tasks.processResources {
43+
into('META-INF') {
44+
from project.tasks.springVersion.outputs
45+
}
46+
}
47+
3748
tasks.jar.from { includeProject.sourceSets.main.output }
3849

3950
tasks.sourcesJar.from {includeProject.sourceSets.main.java}

core/src/main/java/org/springframework/security/core/SpringSecurityCoreVersion.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import org.springframework.core.SpringVersion;
2222

23+
import java.io.IOException;
24+
import java.util.Properties;
25+
2326
/**
2427
* Internal class used for checking version compatibility in a deployed application.
2528
*
@@ -40,7 +43,7 @@ public class SpringSecurityCoreVersion {
4043
*/
4144
public static final long SERIAL_VERSION_UID = 500L;
4245

43-
static final String MIN_SPRING_VERSION = "5.0.5.RELEASE";
46+
static final String MIN_SPRING_VERSION = getSpringVersion();
4447

4548
static {
4649
performVersionChecks();
@@ -64,6 +67,9 @@ private static void performVersionChecks() {
6467
* @param minSpringVersion
6568
*/
6669
private static void performVersionChecks(String minSpringVersion) {
70+
if (minSpringVersion == null) {
71+
return;
72+
}
6773
// Check Spring Compatibility
6874
String springVersion = SpringVersion.getVersion();
6975
String version = getVersion();
@@ -95,4 +101,18 @@ private static boolean disableChecks(String springVersion,
95101
}
96102
return Boolean.getBoolean(DISABLE_CHECKS);
97103
}
104+
105+
/**
106+
* Loads the spring version or null if it cannot be found.
107+
* @return
108+
*/
109+
private static String getSpringVersion() {
110+
Properties properties = new Properties();
111+
try {
112+
properties.load(SpringSecurityCoreVersion.class.getClassLoader().getResourceAsStream("META-INF/spring-security.versions"));
113+
} catch (IOException e) {
114+
return null;
115+
}
116+
return properties.getProperty("org.springframework:spring-core");
117+
}
98118
}

0 commit comments

Comments
 (0)