Skip to content

Commit 2894114

Browse files
committed
Use Java version and vendor from pipeline properties.
Ensure that we use always the specified Java version. See #193
1 parent 33f8966 commit 2894114

File tree

11 files changed

+171
-80
lines changed

11 files changed

+171
-80
lines changed

release-tools/src/main/java/org/springframework/data/release/build/BuildExecutor.java

+31-19
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
package org.springframework.data.release.build;
1717

1818
import lombok.NonNull;
19+
import lombok.RequiredArgsConstructor;
20+
import lombok.SneakyThrows;
1921

22+
import java.io.File;
23+
import java.io.FileInputStream;
2024
import java.util.Arrays;
2125
import java.util.HashSet;
2226
import java.util.List;
2327
import java.util.Map;
28+
import java.util.Properties;
2429
import java.util.Set;
2530
import java.util.concurrent.CompletableFuture;
2631
import java.util.concurrent.ConcurrentHashMap;
@@ -35,11 +40,12 @@
3540

3641
import org.apache.commons.io.IOUtils;
3742

38-
import org.springframework.data.release.model.JavaVersionAware;
43+
import org.springframework.data.release.dependency.InfrastructureOperations;
44+
import org.springframework.data.release.io.Workspace;
45+
import org.springframework.data.release.model.JavaVersion;
3946
import org.springframework.data.release.model.Project;
4047
import org.springframework.data.release.model.ProjectAware;
4148
import org.springframework.data.release.utils.ListWrapperCollector;
42-
import org.springframework.data.release.utils.Logger;
4349
import org.springframework.data.util.Streamable;
4450
import org.springframework.plugin.core.PluginRegistry;
4551
import org.springframework.stereotype.Component;
@@ -51,19 +57,13 @@
5157
* @author Mark Paluch
5258
*/
5359
@Component
60+
@RequiredArgsConstructor
5461
class BuildExecutor {
5562

5663
private final @NonNull PluginRegistry<BuildSystem, Project> buildSystems;
5764
private final MavenProperties mavenProperties;
5865
private final ExecutorService executor;
59-
60-
public BuildExecutor(PluginRegistry<BuildSystem, Project> buildSystems, Logger logger,
61-
MavenProperties mavenProperties, ExecutorService buildExecutor) {
62-
63-
this.buildSystems = buildSystems;
64-
this.mavenProperties = mavenProperties;
65-
this.executor = buildExecutor;
66-
}
66+
private final Workspace workspace;
6767

6868
@PreDestroy
6969
public void shutdown() {
@@ -162,20 +162,14 @@ private <T, M extends ProjectAware> CompletableFuture<T> run(M module, BiFunctio
162162
Supplier<IllegalStateException> exception = () -> new IllegalStateException(
163163
String.format("No build system plugin found for project %s!", module.getProject()));
164164

165-
BuildSystem buildSystem = buildSystems.getPluginFor(module.getProject(), exception);
166-
BuildSystem buildSystemToUse;
167-
168-
if (module instanceof JavaVersionAware) {
169-
buildSystemToUse = buildSystem.withJavaVersion(((JavaVersionAware) module).getJavaVersion());
170-
} else {
171-
buildSystemToUse = buildSystem;
172-
}
165+
BuildSystem buildSystem = buildSystems.getPluginFor(module.getProject(), exception)
166+
.withJavaVersion(detectJavaVersion(module.getProject()));
173167

174168
Runnable runnable = () -> {
175169

176170
try {
177171

178-
result.complete(function.apply(buildSystemToUse, module));
172+
result.complete(function.apply(buildSystem, module));
179173
} catch (Exception e) {
180174
result.completeExceptionally(e);
181175
}
@@ -186,6 +180,24 @@ private <T, M extends ProjectAware> CompletableFuture<T> run(M module, BiFunctio
186180
return result;
187181
}
188182

183+
@SneakyThrows
184+
public JavaVersion detectJavaVersion(Project project) {
185+
186+
File ciProperties = workspace.getFile(InfrastructureOperations.CI_PROPERTIES, project);
187+
188+
if (!ciProperties.exists()) {
189+
throw new IllegalStateException(String.format("Cannot find %s for project %s", ciProperties, project));
190+
}
191+
192+
Properties properties = new Properties();
193+
194+
try (FileInputStream fis = new FileInputStream(ciProperties)) {
195+
properties.load(fis);
196+
}
197+
198+
return JavaVersion.fromDockerTag(properties.getProperty("java.main.tag"));
199+
}
200+
189201
/**
190202
* Returns a new collector to toSummaryCollector {@link ExecutionResult} as {@link Summary} using the {@link Stream}
191203
* API.

release-tools/src/main/java/org/springframework/data/release/build/BuildOperations.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private <T> T doWithBuildSystem(ModuleIteration module, BiFunction<BuildSystem,
222222

223223
BuildSystem buildSystem = buildSystems.getPluginFor(module.getProject(), exception);
224224

225-
return function.apply(buildSystem.withJavaVersion(module.getJavaVersion()), module);
225+
return function.apply(buildSystem.withJavaVersion(executor.detectJavaVersion(module.getProject())), module);
226226
}
227227

228228
}

release-tools/src/main/java/org/springframework/data/release/io/JavaRuntimes.java

+57-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public static JdkInstallation getJdk(Predicate<JdkInstallation> filter, Supplier
9191
.orElseThrow(() -> new NoSuchElementException(String.format("%s%nAvailable JDK: %s", message.get(), jdks)));
9292
}
9393

94+
public static List<JdkInstallation> getJdks() {
95+
return JDKS.get();
96+
}
97+
9498
/**
9599
* JDK detection strategy.
96100
*/
@@ -125,7 +129,10 @@ public static Selector builder() {
125129
}
126130

127131
public static Selector from(JavaVersion javaVersion) {
128-
return builder().and(it -> javaVersion.getVersionDetector().test(it.getVersion()))
132+
133+
return builder()
134+
.and(it -> javaVersion.getVersionDetector().test(it.getVersion())
135+
&& javaVersion.getImplementor().test(it.getImplementor()))
129136
.message("Cannot find Java " + javaVersion.getName());
130137
}
131138

@@ -184,10 +191,29 @@ public List<JdkInstallation> detect() {
184191
version = Version.parse(candidateVersion);
185192
}
186193

187-
return new JdkInstallation(version, it.getName(), it);
194+
String implementor = normalizeImplementor(parseImplementor(it));
195+
196+
return new JdkInstallation(version, toDisplayName(implementor, candidateVersion), implementor, it);
188197

189198
}).collect(Collectors.toList());
190199
}
200+
201+
@SneakyThrows
202+
private String parseImplementor(File candidateHome) {
203+
204+
List<String> release = FileUtils.readLines(new File(candidateHome, "release"));
205+
206+
for (String line : release) {
207+
208+
if (line.startsWith("IMPLEMENTOR=")) {
209+
String substring = line.substring(line.indexOf("=\""));
210+
substring = substring.substring(2, substring.length() - 1);
211+
return substring;
212+
}
213+
}
214+
215+
return "?";
216+
}
191217
}
192218

193219
/**
@@ -208,7 +234,8 @@ public boolean isAvailable() {
208234
public List<JdkInstallation> detect() {
209235

210236
return Collections
211-
.singletonList(new JdkInstallation(JavaVersion.parse(javaVersion), javaVendor + " " + javaVersion, javaHome));
237+
.singletonList(new JdkInstallation(JavaVersion.parse(javaVersion), toDisplayName(javaVendor, javaVersion),
238+
normalizeImplementor(javaVendor), javaHome));
212239
}
213240
}
214241

@@ -252,14 +279,17 @@ public List<JdkInstallation> detect() {
252279
String jvmHomePath = dict.get("JVMHomePath").toJavaObject(String.class);
253280
String name = dict.get("JVMName").toJavaObject(String.class);
254281
String version = dict.get("JVMVersion").toJavaObject(String.class);
282+
String vendor = dict.get("JVMVendor").toJavaObject(String.class);
255283

256284
Matcher matcher = VERSION.matcher(version);
257285
if (!matcher.find()) {
258286
throw new IllegalArgumentException("Cannot determine JVM version number from JVMVersion " + version
259287
+ ". This should not happen in an ideal world, check the VERSION regex.");
260288
}
261289

262-
return new JdkInstallation(JavaVersion.parse(matcher.group(1)), name, new File(jvmHomePath));
290+
String implementor = normalizeImplementor(vendor);
291+
return new JdkInstallation(JavaVersion.parse(matcher.group(1)), toDisplayName(implementor, version),
292+
implementor, new File(jvmHomePath));
263293

264294
}).collect(Collectors.toList());
265295
}
@@ -270,11 +300,34 @@ public static class JdkInstallation implements Comparable<JdkInstallation> {
270300

271301
Version version;
272302
String name;
303+
String implementor;
273304
File home;
274305

275306
@Override
276307
public int compareTo(JdkInstallation o) {
277308
return this.version.compareTo(o.version);
278309
}
279310
}
311+
312+
static String normalizeImplementor(String implementor) {
313+
314+
if (implementor.equals("Eclipse Adoptium")) {
315+
return "Eclipse Temurin";
316+
}
317+
318+
if (implementor.equals("Eclipse Foundation")) {
319+
return "Eclipse Temurin";
320+
}
321+
322+
return implementor;
323+
}
324+
325+
static String toDisplayName(String implementor, String version) {
326+
327+
if (implementor.startsWith("Oracle")) {
328+
implementor = "Oracle Java";
329+
}
330+
331+
return implementor + " " + version;
332+
}
280333
}

release-tools/src/main/java/org/springframework/data/release/model/JavaVersion.java

+33-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import lombok.Value;
1919

2020
import java.util.function.Predicate;
21+
import java.util.regex.Matcher;
22+
import java.util.regex.Pattern;
2123

2224
/**
2325
* Value object representing a Java version.
@@ -27,20 +29,49 @@
2729
@Value(staticConstructor = "of")
2830
public class JavaVersion {
2931

32+
private static final Pattern DOCKER_TAG_PATTERN = Pattern.compile("((:?\\d+(:?u\\d+)?(:?\\.\\d+)*)).*");
33+
3034
public static final JavaVersion JAVA_8 = of("1.8.0_312");
3135

32-
public static final JavaVersion JAVA_17 = of("Java 17", version -> version.getMajor() == 17);
36+
public static final JavaVersion JAVA_17 = of("Java 17", version -> version.getMajor() == 17, it -> true);
3337

3438
String name;
3539
Predicate<Version> versionDetector;
40+
Predicate<String> implementor;
3641

3742
public static JavaVersion of(String version) {
3843
Version expectedVersion = parse(version);
39-
return of("Java " + version, candidate -> candidate.is(expectedVersion));
44+
return of("Java " + version, candidate -> candidate.is(expectedVersion), it -> true);
4045
}
4146

4247
public static Version parse(String version) {
4348
return Version.parse(version.replace('_', '.'));
4449
}
4550

51+
/**
52+
* Parse a docker tag into a Java version using {@code eclipse-temurin} conventions.
53+
*
54+
* @param tagName
55+
* @return
56+
*/
57+
public static JavaVersion fromDockerTag(String tagName) {
58+
59+
Pattern versionExtractor = Pattern.compile("(:?\\d+(:?u\\d+)?(:?\\.\\d+)*).*");
60+
Matcher matcher = versionExtractor.matcher(tagName);
61+
if (!matcher.find()) {
62+
throw new IllegalStateException(String.format("Cannot parse Java version '%s'", tagName));
63+
}
64+
65+
String plainVersion = matcher.group(1);
66+
67+
if (plainVersion.startsWith("8u")) {
68+
return of("1.8.0_" + plainVersion.substring(2));
69+
}
70+
71+
return of(plainVersion).withImplementor("Temurin");
72+
}
73+
74+
public JavaVersion withImplementor(String implementor) {
75+
return of(String.format("%s (%s)", name, implementor), versionDetector, it -> it.contains(implementor));
76+
}
4677
}

release-tools/src/main/java/org/springframework/data/release/model/JavaVersionAware.java

-24
This file was deleted.

release-tools/src/main/java/org/springframework/data/release/model/Module.java

+3-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import lombok.AccessLevel;
1919
import lombok.AllArgsConstructor;
2020
import lombok.Value;
21-
import lombok.With;
2221

2322
import org.springframework.util.Assert;
2423

@@ -28,31 +27,25 @@
2827
*/
2928
@Value
3029
@AllArgsConstructor(access = AccessLevel.PRIVATE)
31-
public class Module implements VersionAware, ProjectAware, JavaVersionAware, Comparable<Module> {
30+
public class Module implements VersionAware, ProjectAware, Comparable<Module> {
3231

3332
Project project;
3433
Version version;
3534
Iteration customFirstIteration;
36-
@With JavaVersion javaVersion;
3735

3836
public Module(Project project, String version) {
39-
this(project, version, null, JavaVersion.JAVA_8);
37+
this(project, version, null);
4038
}
4139

42-
Module(Project project, String version, String customFirstIteration) {
43-
this(project, version, customFirstIteration, JavaVersion.JAVA_8);
44-
}
4540

46-
Module(Project project, String version, String customFirstIteration, JavaVersion javaVersion) {
41+
Module(Project project, String version, String customFirstIteration) {
4742

4843
Assert.notNull(project, "Project must not be null!");
49-
Assert.notNull(javaVersion, "JavaVersion must not be null!");
5044

5145
this.project = project;
5246
this.version = Version.parse(version);
5347
this.customFirstIteration = customFirstIteration == null ? null
5448
: new Iteration(customFirstIteration, Iteration.RC1);
55-
this.javaVersion = javaVersion;
5649
}
5750

5851
public boolean hasName(String name) {
@@ -97,8 +90,4 @@ public String toString() {
9790
return String.format("Spring Data %s %s - %s", project.getName(), version, project.getKey());
9891
}
9992

100-
public Module withJavaVersion(JavaVersion javaVersion) {
101-
return this.javaVersion == javaVersion ? this
102-
: new Module(this.project, this.version, this.customFirstIteration, javaVersion);
103-
}
10493
}

release-tools/src/main/java/org/springframework/data/release/model/ModuleIteration.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
@RequiredArgsConstructor
2727
@EqualsAndHashCode
28-
public class ModuleIteration implements IterationVersion, ProjectAware, JavaVersionAware {
28+
public class ModuleIteration implements IterationVersion, ProjectAware {
2929

3030
private final @Getter Module module;
3131
private final @Getter TrainIteration trainIteration;
@@ -46,11 +46,6 @@ public Project getProject() {
4646
return module.getProject();
4747
}
4848

49-
@Override
50-
public JavaVersion getJavaVersion() {
51-
return trainIteration.getTrain().getJavaVersion();
52-
}
53-
5449
/*
5550
* (non-Javadoc)
5651
* @see org.springframework.data.release.model.IterationVersion#getVersion()

release-tools/src/main/java/org/springframework/data/release/model/ReleaseTrains.java

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public class ReleaseTrains {
7777
TURING = PASCAL.next("Turing", Transition.MAJOR, //
7878
new Module(R2DBC, "3.0")) //
7979
.withCalver("2022.0") //
80-
.withJavaVersion(JavaVersion.JAVA_17)
8180
.filterModules(module -> !module.getProject().equals(ENVERS))
8281
.withAlwaysUseBranch(true)
8382
.withIterations(new Train.Iterations(M1, M2, M3, M4, M5, RC1, RC2, GA, SR1, SR2, SR3, SR4, SR5));

0 commit comments

Comments
 (0)