22
22
@ SuppressWarnings ({"WeakerAccess" , "SameParameterValue" })
23
23
class Updater {
24
24
25
- private static final String VERSION_REGEX = "([0-9.]+)" ;
25
+ private static final String VERSION_REGEX = "([0-9.]+(?:-[A-Z]+[0-9]*)? )" ;
26
26
27
27
public static void main (String [] args ) throws Exception {
28
28
new Updater (args [0 ]).update ();
29
29
}
30
30
31
- private final String jupiterVersion ;
31
+ private final String newVersion ;
32
32
33
- public Updater (String jupiterVersion ) {
34
- this .jupiterVersion = jupiterVersion ;
33
+ public Updater (String newVersion ) {
34
+ this .newVersion = newVersion ;
35
35
}
36
36
37
37
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
46
45
);
46
+ System .out .println (mavenBomReplacement );
47
47
48
48
update (Path .of ("junit-jupiter-extensions/build.gradle" ), List .of (gradleBomReplacement ));
49
49
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 + "'" )
51
51
));
52
52
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 + '"' )
55
54
));
56
55
update (Path .of ("junit-jupiter-starter-gradle/build.gradle" ), List .of (gradleBomReplacement ));
57
56
update (Path .of ("junit-jupiter-starter-gradle-groovy/build.gradle" ), List .of (gradleBomReplacement ));
58
57
update (Path .of ("junit-jupiter-starter-gradle-kotlin/build.gradle.kts" ), List .of (gradleBomReplacement ));
59
58
update (Path .of ("junit-jupiter-starter-maven/pom.xml" ), List .of (mavenBomReplacement ));
60
59
update (Path .of ("junit-jupiter-starter-maven-kotlin/pom.xml" ), List .of (mavenBomReplacement ));
61
60
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 + '"' )
64
63
));
65
64
update (Path .of ("junit-migration-gradle/build.gradle" ), List .of (gradleBomReplacement ));
66
65
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 )
69
68
));
70
69
update (Path .of ("junit-migration-maven/pom.xml" ), List .of (mavenBomReplacement ));
71
70
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 + '"' )
75
72
));
76
73
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 + '"' )
78
75
));
79
76
}
80
77
81
- void update (Path path , List <Replacement > replacements ) throws IOException {
78
+ void update (Path path , List <Pattern > patterns ) throws IOException {
82
79
System .out .printf ("Updating %s..." , path );
83
80
System .out .flush ();
84
81
int matches = 0 ;
85
82
var content = new StringBuilder (Files .readString (path ));
86
- for (var replacement : replacements ) {
83
+ for (var pattern : patterns ) {
87
84
var minIndex = 0 ;
88
- var matcher = replacement . regex .matcher (content );
85
+ var matcher = pattern .matcher (content );
89
86
while (matcher .find (minIndex )) {
90
87
matches ++;
91
88
int start = matcher .start (1 );
92
89
int end = matcher .end (1 );
93
90
int oldLength = end - start ;
94
- String newVersion = replacement .newVersion (jupiterVersion );
95
91
content .replace (start , end , newVersion );
96
92
minIndex = end + newVersion .length () - oldLength ;
97
93
}
@@ -102,24 +98,4 @@ void update(Path path, List<Replacement> replacements) throws IOException {
102
98
throw new IllegalStateException ("No matches found in " + path );
103
99
}
104
100
}
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
- }
125
101
}
0 commit comments