Skip to content

Commit 9af1937

Browse files
committed
Backport build and CI concerns
Backport build and CI concerns primarily related to repo.spring.io changes and Docker config.
1 parent e2365ff commit 9af1937

File tree

32 files changed

+278
-216
lines changed

32 files changed

+278
-216
lines changed

buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.gradle.api.tasks.PathSensitivity;
3131
import org.gradle.api.tasks.Sync;
3232

33-
import org.springframework.boot.build.artifactory.ArtifactoryRepository;
33+
import org.springframework.boot.build.artifacts.ArtifactRelease;
3434
import org.springframework.util.StringUtils;
3535

3636
/**
@@ -66,6 +66,7 @@
6666
* </ul>
6767
*
6868
* @author Andy Wilkinson
69+
* @author Scott Frederick
6970
*/
7071
class AsciidoctorConventions {
7172

@@ -128,10 +129,12 @@ private void configureAsciidoctorTask(Project project, AbstractAsciidoctorTask a
128129
}
129130

130131
private void configureCommonAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) {
132+
ArtifactRelease artifacts = ArtifactRelease.forProject(project);
131133
Map<String, Object> attributes = new HashMap<>();
132134
attributes.put("attribute-missing", "warn");
133135
attributes.put("github-tag", determineGitHubTag(project));
134-
attributes.put("spring-boot-artifactory-repo", ArtifactoryRepository.forProject(project));
136+
attributes.put("artifact-release-type", artifacts.getType());
137+
attributes.put("artifact-download-repo", artifacts.getDownloadRepo());
135138
attributes.put("revnumber", null);
136139
asciidoctorTask.attributes(attributes);
137140
}

buildSrc/src/main/java/org/springframework/boot/build/artifactory/ArtifactoryRepository.java

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2012-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.boot.build.artifacts;
18+
19+
import org.gradle.api.Project;
20+
21+
/**
22+
* Information about artifacts produced by a build.
23+
*
24+
* @author Andy Wilkinson
25+
* @author Scott Frederick
26+
*/
27+
public final class ArtifactRelease {
28+
29+
private static final String SNAPSHOT = "snapshot";
30+
31+
private static final String MILESTONE = "milestone";
32+
33+
private static final String RELEASE = "release";
34+
35+
private static final String SPRING_REPO = "https://repo.spring.io/%s";
36+
37+
private static final String MAVEN_REPO = "https://repo.maven.apache.org/maven2";
38+
39+
private final String type;
40+
41+
private ArtifactRelease(String type) {
42+
this.type = type;
43+
}
44+
45+
public String getType() {
46+
return this.type;
47+
}
48+
49+
public String getDownloadRepo() {
50+
return (this.isRelease()) ? MAVEN_REPO : String.format(SPRING_REPO, this.getType());
51+
}
52+
53+
public boolean isRelease() {
54+
return RELEASE.equals(this.type);
55+
}
56+
57+
public static ArtifactRelease forProject(Project project) {
58+
return new ArtifactRelease(determineReleaseType(project));
59+
}
60+
61+
private static String determineReleaseType(Project project) {
62+
String version = project.getVersion().toString();
63+
int modifierIndex = version.lastIndexOf('-');
64+
if (modifierIndex == -1) {
65+
return RELEASE;
66+
}
67+
String type = version.substring(modifierIndex + 1);
68+
if (type.startsWith("M") || type.startsWith("RC")) {
69+
return MILESTONE;
70+
}
71+
return SNAPSHOT;
72+
}
73+
74+
}

buildSrc/src/main/java/org/springframework/boot/build/cli/AbstractPackageManagerDefinitionTask.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.apache.commons.codec.digest.DigestUtils;
2525
import org.gradle.api.DefaultTask;
26+
import org.gradle.api.Project;
2627
import org.gradle.api.file.RegularFile;
2728
import org.gradle.api.provider.Provider;
2829
import org.gradle.api.tasks.InputFile;
@@ -31,13 +32,14 @@
3132
import org.gradle.api.tasks.PathSensitivity;
3233
import org.gradle.api.tasks.TaskExecutionException;
3334

34-
import org.springframework.boot.build.artifactory.ArtifactoryRepository;
35+
import org.springframework.boot.build.artifacts.ArtifactRelease;
3536

3637
/**
3738
* Base class for generating a package manager definition file such as a Scoop manifest or
3839
* a Homebrew formula.
3940
*
4041
* @author Andy Wilkinson
42+
* @author Phillip Webb
4143
*/
4244
public abstract class AbstractPackageManagerDefinitionTask extends DefaultTask {
4345

@@ -84,14 +86,19 @@ protected void createDescriptor(Map<String, Object> additionalProperties) {
8486
getProject().copy((copy) -> {
8587
copy.from(this.template);
8688
copy.into(this.outputDir);
87-
Map<String, Object> properties = new HashMap<>(additionalProperties);
88-
properties.put("hash", sha256(this.archive.get().getAsFile()));
89-
properties.put("repo", ArtifactoryRepository.forProject(getProject()));
90-
properties.put("project", getProject());
91-
copy.expand(properties);
89+
copy.expand(getProperties(additionalProperties));
9290
});
9391
}
9492

93+
private Map<String, Object> getProperties(Map<String, Object> additionalProperties) {
94+
Map<String, Object> properties = new HashMap<>(additionalProperties);
95+
Project project = getProject();
96+
properties.put("hash", sha256(this.archive.get().getAsFile()));
97+
properties.put("repo", ArtifactRelease.forProject(project).getDownloadRepo());
98+
properties.put("project", project);
99+
return properties;
100+
}
101+
95102
private String sha256(File file) {
96103
try {
97104
MessageDigest digest = MessageDigest.getInstance("SHA-256");

buildSrc/src/test/java/org/springframework/boot/build/artifactory/ArtifactoryRepositoryTests.java

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2012-2021 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.boot.build.artifacts;
18+
19+
import org.gradle.api.Project;
20+
import org.gradle.testfixtures.ProjectBuilder;
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Tests for {@link ArtifactRelease}.
27+
*
28+
* @author Andy Wilkinson
29+
* @author Scott Frederick
30+
*/
31+
class ArtifactReleaseTests {
32+
33+
@Test
34+
void whenProjectVersionIsSnapshotThenTypeIsSnapshot() {
35+
Project project = ProjectBuilder.builder().build();
36+
project.setVersion("1.2.3-SNAPSHOT");
37+
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("snapshot");
38+
}
39+
40+
@Test
41+
void whenProjectVersionIsMilestoneThenTypeIsMilestone() {
42+
Project project = ProjectBuilder.builder().build();
43+
project.setVersion("1.2.3-M1");
44+
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("milestone");
45+
}
46+
47+
@Test
48+
void whenProjectVersionIsReleaseCandidateThenTypeIsMilestone() {
49+
Project project = ProjectBuilder.builder().build();
50+
project.setVersion("1.2.3-RC1");
51+
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("milestone");
52+
}
53+
54+
@Test
55+
void whenProjectVersionIsReleaseThenTypeIsRelease() {
56+
Project project = ProjectBuilder.builder().build();
57+
project.setVersion("1.2.3");
58+
assertThat(ArtifactRelease.forProject(project).getType()).isEqualTo("release");
59+
}
60+
61+
@Test
62+
void whenProjectVersionIsSnapshotThenRepositoryIsArtifactorySnapshot() {
63+
Project project = ProjectBuilder.builder().build();
64+
project.setVersion("1.2.3-SNAPSHOT");
65+
assertThat(ArtifactRelease.forProject(project).getDownloadRepo()).contains("repo.spring.io/snapshot");
66+
}
67+
68+
@Test
69+
void whenProjectVersionIsMilestoneThenRepositoryIsArtifactoryMilestone() {
70+
Project project = ProjectBuilder.builder().build();
71+
project.setVersion("1.2.3-M1");
72+
assertThat(ArtifactRelease.forProject(project).getDownloadRepo()).contains("repo.spring.io/milestone");
73+
}
74+
75+
@Test
76+
void whenProjectVersionIsReleaseCandidateThenRepositoryIsArtifactoryMilestone() {
77+
Project project = ProjectBuilder.builder().build();
78+
project.setVersion("1.2.3-RC1");
79+
assertThat(ArtifactRelease.forProject(project).getDownloadRepo()).contains("repo.spring.io/milestone");
80+
}
81+
82+
@Test
83+
void whenProjectVersionIsReleaseThenRepositoryIsMavenCentral() {
84+
Project project = ProjectBuilder.builder().build();
85+
project.setVersion("1.2.3");
86+
assertThat(ArtifactRelease.forProject(project).getDownloadRepo())
87+
.contains("https://repo.maven.apache.org/maven2");
88+
}
89+
90+
}

ci/images/ci-image-jdk11/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:focal-20220426
1+
FROM ubuntu:focal-20220922
22

33
ADD setup.sh /setup.sh
44
ADD get-jdk-url.sh /get-jdk-url.sh
@@ -8,5 +8,3 @@ RUN ./setup.sh java11
88
ENV JAVA_HOME /opt/openjdk
99
ENV PATH $JAVA_HOME/bin:$PATH
1010
ADD docker-lib.sh /docker-lib.sh
11-
12-
ENTRYPOINT [ "switch", "shell=/bin/bash", "--", "codep", "/bin/docker daemon" ]

ci/images/ci-image-jdk17/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:focal-20220426
1+
FROM ubuntu:focal-20220922
22

33
ADD setup.sh /setup.sh
44
ADD get-jdk-url.sh /get-jdk-url.sh
@@ -8,5 +8,3 @@ RUN ./setup.sh java8 java17
88
ENV JAVA_HOME /opt/openjdk
99
ENV PATH $JAVA_HOME/bin:$PATH
1010
ADD docker-lib.sh /docker-lib.sh
11-
12-
ENTRYPOINT [ "switch", "shell=/bin/bash", "--", "codep", "/bin/docker daemon" ]

0 commit comments

Comments
 (0)