2222@ SuppressWarnings ({"WeakerAccess" , "SameParameterValue" })
2323class 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/compile.jsh" ), 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