Skip to content

Commit e763627

Browse files
committed
Merge branch '2.3.x' into 2.4.x
Closes gh-25257
2 parents 12c3c80 + 63402a2 commit e763627

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeApplicator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,14 +65,19 @@ private void updateGradleProperties(Upgrade upgrade, String version) throws IOEx
6565
String gradlePropertiesContents = new String(Files.readAllBytes(this.gradleProperties), StandardCharsets.UTF_8);
6666
String modified = gradlePropertiesContents.replace(property + "=" + upgrade.getLibrary().getVersion(),
6767
property + "=" + upgrade.getVersion());
68-
Files.write(this.gradleProperties, modified.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
68+
overwrite(this.gradleProperties, modified);
6969
}
7070

7171
private void updateBuildFile(Upgrade upgrade, String buildFileContents) throws IOException {
7272
String modified = buildFileContents.replace(
7373
"library(\"" + upgrade.getLibrary().getName() + "\", \"" + upgrade.getLibrary().getVersion() + "\")",
7474
"library(\"" + upgrade.getLibrary().getName() + "\", \"" + upgrade.getVersion() + "\")");
75-
Files.write(this.buildFile, modified.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
75+
overwrite(this.buildFile, modified);
76+
}
77+
78+
private void overwrite(Path target, String content) throws IOException {
79+
Files.write(target, content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.WRITE,
80+
StandardOpenOption.TRUNCATE_EXISTING);
7681
}
7782

7883
}

buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/UpgradeApplicatorTests.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import org.springframework.util.FileCopyUtils;
3333

3434
import static org.assertj.core.api.Assertions.assertThat;
35+
import static org.assertj.core.api.Assertions.entry;
3536

3637
/**
3738
* Tests for {@link UpgradeApplicator}.
@@ -47,13 +48,14 @@ class UpgradeApplicatorTests {
4748
void whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated() throws IOException {
4849
File bom = new File(this.temp, "bom.gradle");
4950
FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
51+
String originalContents = new String(Files.readAllBytes(bom.toPath()), StandardCharsets.UTF_8);
5052
File gradleProperties = new File(this.temp, "gradle.properties");
5153
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
5254
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
5355
.apply(new Upgrade(new Library("ActiveMQ", DependencyVersion.parse("5.15.11"), null, null),
5456
DependencyVersion.parse("5.16")));
5557
String bomContents = new String(Files.readAllBytes(bom.toPath()), StandardCharsets.UTF_8);
56-
assertThat(bomContents).contains("library(\"ActiveMQ\", \"5.16\")");
58+
assertThat(bomContents.length()).isEqualTo(originalContents.length() - 3);
5759
}
5860

5961
@Test
@@ -62,14 +64,14 @@ void whenUpgradeIsAppliedToLibraryWithVersionPropertyThenGradlePropertiesIsUpdat
6264
FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
6365
File gradleProperties = new File(this.temp, "gradle.properties");
6466
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
65-
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
66-
.apply(new Upgrade(new Library("Kotlin", DependencyVersion.parse("1.3.70"), null, null),
67-
DependencyVersion.parse("1.3.71")));
67+
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()).apply(new Upgrade(
68+
new Library("Kotlin", DependencyVersion.parse("1.3.70"), null, null), DependencyVersion.parse("1.4")));
6869
Properties properties = new Properties();
6970
try (InputStream in = new FileInputStream(gradleProperties)) {
7071
properties.load(in);
7172
}
72-
assertThat(properties).containsEntry("kotlinVersion", "1.3.71");
73+
assertThat(properties).containsOnly(entry("a", "alpha"), entry("b", "bravo"), entry("kotlinVersion", "1.4"),
74+
entry("t", "tango"));
7375
}
7476

7577
}

0 commit comments

Comments
 (0)