Skip to content

Commit eb6990d

Browse files
committed
Simplify Updater for single version replacement
1 parent 15896a9 commit eb6990d

File tree

3 files changed

+37
-63
lines changed

3 files changed

+37
-63
lines changed

junit-jupiter-starter-ant/build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ set -e
44
#
55
# Set constants.
66
#
7-
junit_platform_version='6.0.0-SNAPSHOT'
7+
junit_version='6.0.0-SNAPSHOT'
88
ant_version='1.10.15'
99
ant_folder="apache-ant-${ant_version}"
1010
ant_archive="${ant_folder}-bin.tar.gz"
11-
standalone_jar="${ant_folder}/lib/junit-platform-console-standalone-${junit_platform_version}.jar"
11+
standalone_jar="${ant_folder}/lib/junit-platform-console-standalone-${junit_version}.jar"
1212

1313
#
1414
# Load and extract Apache Ant.
@@ -23,8 +23,8 @@ fi
2323
# Load and store junit-platform-console-standalone jar into ${ANT_HOME}/lib.
2424
#
2525
if [ ! -f "${standalone_jar}" ]; then
26-
echo "Downloading junit-platform-console-standalone $junit_platform_version..."
27-
curl --silent --show-error --fail "https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/${junit_platform_version}/junit-platform-console-standalone-${junit_platform_version}.jar" \
26+
echo "Downloading junit-platform-console-standalone $junit_version..."
27+
curl --silent --show-error --fail "https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/${junit_version}/junit-platform-console-standalone-${junit_version}.jar" \
2828
--output "${standalone_jar}"
2929
fi
3030

junit-modular-world/src/build/Project.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ void compile() throws Exception {
4343
//
4444
// download main and test dependencies
4545
//
46-
String platformVersion = "1.13.1";
47-
String jupiterVersion = "5.13.1";
48-
String vintageVersion = "5.13.1";
49-
get("lib", "org.junit.platform", "junit-platform-commons", platformVersion);
50-
get("lib", "org.junit.platform", "junit-platform-console", platformVersion);
51-
get("lib", "org.junit.platform", "junit-platform-engine", platformVersion);
52-
get("lib", "org.junit.platform", "junit-platform-launcher", platformVersion);
53-
get("lib", "org.junit.platform", "junit-platform-reporting", platformVersion);
54-
get("lib", "org.junit.jupiter", "junit-jupiter-api", jupiterVersion);
55-
get("lib", "org.junit.jupiter", "junit-jupiter-params", jupiterVersion);
56-
get("lib", "org.junit.jupiter", "junit-jupiter-engine", jupiterVersion);
57-
get("lib", "org.junit.vintage", "junit-vintage-engine", vintageVersion);
46+
String junitVersion = "6.0.0-SNAPSHOT";
47+
get("lib", "org.junit.platform", "junit-platform-commons", junitVersion);
48+
get("lib", "org.junit.platform", "junit-platform-console", junitVersion);
49+
get("lib", "org.junit.platform", "junit-platform-engine", junitVersion);
50+
get("lib", "org.junit.platform", "junit-platform-launcher", junitVersion);
51+
get("lib", "org.junit.platform", "junit-platform-reporting", junitVersion);
52+
get("lib", "org.junit.jupiter", "junit-jupiter-api", junitVersion);
53+
get("lib", "org.junit.jupiter", "junit-jupiter-params", junitVersion);
54+
get("lib", "org.junit.jupiter", "junit-jupiter-engine", junitVersion);
55+
get("lib", "org.junit.vintage", "junit-vintage-engine", junitVersion);
5856
get("lib", "junit", "junit", "4.13.2");
5957
get("lib", "org.hamcrest", "hamcrest-core", "1.3");
6058
get("lib", "org.apiguardian", "apiguardian-api", "1.1.2");

src/Updater.java

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,76 +22,72 @@
2222
@SuppressWarnings({"WeakerAccess", "SameParameterValue"})
2323
class Updater {
2424

25-
private static final String VERSION_REGEX = "([0-9.]+)";
25+
private static final String VERSION_REGEX = "([0-9.]+(?:-[A-Z]+[0-9]*)?)";
2626

2727
public static void main(String[] args) throws Exception {
2828
new Updater(args[0]).update();
2929
}
3030

31-
private final String jupiterVersion;
31+
private final String newVersion;
3232

33-
public Updater(String jupiterVersion) {
34-
this.jupiterVersion = jupiterVersion;
33+
public Updater(String newVersion) {
34+
this.newVersion = newVersion;
3535
}
3636

3737
void update() throws IOException {
38-
var gradleBomReplacement = new Replacement("org.junit:junit-bom:" + VERSION_REGEX, VersionType.BOM);
39-
var mavenBomReplacement = new Replacement(
40-
Pattern.compile("""
41-
\\s*<groupId>org.junit</groupId>
42-
\\s*<artifactId>junit-bom</artifactId>
43-
\\s*<version>([0-9.]+)</version>
44-
""", Pattern.MULTILINE),
45-
VersionType.BOM
38+
var gradleBomReplacement = Pattern.compile("org.junit:junit-bom:" + VERSION_REGEX);
39+
var mavenBomReplacement = Pattern.compile(
40+
"""
41+
\\s*<groupId>org.junit</groupId>
42+
\\s*<artifactId>junit-bom</artifactId>
43+
\\s*<version>""" + VERSION_REGEX + "</version>",
44+
Pattern.MULTILINE
4645
);
46+
System.out.println(mavenBomReplacement);
4747

4848
update(Path.of("junit-jupiter-extensions/build.gradle"), List.of(gradleBomReplacement));
4949
update(Path.of("junit-jupiter-starter-ant/build.sh"), List.of(
50-
new Replacement("junit_platform_version='" + VERSION_REGEX + "'", VersionType.PLATFORM)
50+
Pattern.compile("junit_version='" + VERSION_REGEX + "'")
5151
));
5252
update(Path.of("junit-jupiter-starter-bazel/MODULE.bazel"), List.of(
53-
new Replacement("JUNIT_JUPITER_VERSION = \"" + VERSION_REGEX + '"', VersionType.JUPITER),
54-
new Replacement("JUNIT_PLATFORM_VERSION = \"" + VERSION_REGEX + '"', VersionType.PLATFORM)
53+
Pattern.compile("JUNIT_VERSION = \"" + VERSION_REGEX + '"')
5554
));
5655
update(Path.of("junit-jupiter-starter-gradle/build.gradle"), List.of(gradleBomReplacement));
5756
update(Path.of("junit-jupiter-starter-gradle-groovy/build.gradle"), List.of(gradleBomReplacement));
5857
update(Path.of("junit-jupiter-starter-gradle-kotlin/build.gradle.kts"), List.of(gradleBomReplacement));
5958
update(Path.of("junit-jupiter-starter-maven/pom.xml"), List.of(mavenBomReplacement));
6059
update(Path.of("junit-jupiter-starter-maven-kotlin/pom.xml"), List.of(mavenBomReplacement));
6160
update(Path.of("junit-jupiter-starter-sbt/build.sbt"), List.of(
62-
new Replacement("\"org.junit.jupiter\" % \"junit-jupiter\" % \"" + VERSION_REGEX + '"', VersionType.JUPITER),
63-
new Replacement("\"org.junit.platform\" % \"junit-platform-launcher\" % \"" + VERSION_REGEX + '"', VersionType.PLATFORM)
61+
Pattern.compile("\"org.junit.jupiter\" % \"junit-jupiter\" % \"" + VERSION_REGEX + '"'),
62+
Pattern.compile("\"org.junit.platform\" % \"junit-platform-launcher\" % \"" + VERSION_REGEX + '"')
6463
));
6564
update(Path.of("junit-migration-gradle/build.gradle"), List.of(gradleBomReplacement));
6665
update(Path.of("junit-migration-gradle/README.md"), List.of(
67-
new Replacement("org.junit.jupiter:junit-jupiter:" + VERSION_REGEX, VersionType.JUPITER),
68-
new Replacement("org.junit.vintage:junit-vintage-engine:" + VERSION_REGEX, VersionType.VINTAGE)
66+
Pattern.compile("org.junit.jupiter:junit-jupiter:" + VERSION_REGEX),
67+
Pattern.compile("org.junit.vintage:junit-vintage-engine:" + VERSION_REGEX)
6968
));
7069
update(Path.of("junit-migration-maven/pom.xml"), List.of(mavenBomReplacement));
7170
update(Path.of("junit-modular-world/src/build/Project.java"), List.of(
72-
new Replacement("platformVersion = \"" + VERSION_REGEX + '"', VersionType.PLATFORM),
73-
new Replacement("jupiterVersion = \"" + VERSION_REGEX + '"', VersionType.JUPITER),
74-
new Replacement("vintageVersion = \"" + VERSION_REGEX + '"', VersionType.VINTAGE)
71+
Pattern.compile("junitVersion = \"" + VERSION_REGEX + '"')
7572
));
7673
update(Path.of("junit-multiple-engines/build.gradle.kts"), List.of(
77-
new Replacement("junitBomVersion = \"" + VERSION_REGEX + '"', VersionType.BOM)
74+
Pattern.compile("junitBomVersion = \"" + VERSION_REGEX + '"')
7875
));
7976
}
8077

81-
void update(Path path, List<Replacement> replacements) throws IOException {
78+
void update(Path path, List<Pattern> patterns) throws IOException {
8279
System.out.printf("Updating %s...", path);
8380
System.out.flush();
8481
int matches = 0;
8582
var content = new StringBuilder(Files.readString(path));
86-
for (var replacement : replacements) {
83+
for (var pattern : patterns) {
8784
var minIndex = 0;
88-
var matcher = replacement.regex.matcher(content);
85+
var matcher = pattern.matcher(content);
8986
while (matcher.find(minIndex)) {
9087
matches++;
9188
int start = matcher.start(1);
9289
int end = matcher.end(1);
9390
int oldLength = end - start;
94-
String newVersion = replacement.newVersion(jupiterVersion);
9591
content.replace(start, end, newVersion);
9692
minIndex = end + newVersion.length() - oldLength;
9793
}
@@ -102,24 +98,4 @@ void update(Path path, List<Replacement> replacements) throws IOException {
10298
throw new IllegalStateException("No matches found in " + path);
10399
}
104100
}
105-
106-
record Replacement(Pattern regex, VersionType versionType) {
107-
Replacement(String regex, VersionType versionType) {
108-
this(Pattern.compile(regex), versionType);
109-
}
110-
111-
String newVersion(String jupiterVersion) {
112-
return switch (versionType) {
113-
case BOM, JUPITER, VINTAGE -> jupiterVersion;
114-
case PLATFORM -> jupiterVersion.replaceFirst("\\d+\\.", "1.");
115-
};
116-
}
117-
}
118-
119-
enum VersionType {
120-
BOM,
121-
JUPITER,
122-
PLATFORM,
123-
VINTAGE
124-
}
125101
}

0 commit comments

Comments
 (0)