Skip to content

Commit 8b17c8d

Browse files
Update Versions for trunk as 4.1 and new release branch cassandra-4.0
Includes VersionsTest, version regexp fix, and handling non-existant build directory. patch by Mick Semb Wever; reviewed by Alex Petrov for CASSANDRA-16649
1 parent d5174b1 commit 8b17c8d

File tree

4 files changed

+117
-36
lines changed

4 files changed

+117
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ doc/source/tools/nodetool
7979

8080
# Python virtual environment
8181
venv/
82+
/nbproject/

pom.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@
9090
</excludes>
9191
</configuration>
9292
</plugin>
93-
<plugin>
94-
<artifactId>maven-surefire-plugin</artifactId>
95-
<version>2.22.2</version>
96-
</plugin>
9793
</plugins>
9894
</pluginManagement>
9995
<plugins>
@@ -122,7 +118,6 @@
122118
<plugin>
123119
<groupId>org.apache.rat</groupId>
124120
<artifactId>apache-rat-plugin</artifactId>
125-
<version>0.13</version>
126121
<configuration>
127122
<addLicenseHeaders>true</addLicenseHeaders>
128123
</configuration>
@@ -151,30 +146,13 @@
151146
</execution>
152147
</executions>
153148
</plugin>
154-
<plugin>
155-
<groupId>org.apache.maven.plugins</groupId>
156-
<artifactId>maven-javadoc-plugin</artifactId>
157-
<version>3.0.1</version>
158-
<executions>
159-
<execution>
160-
<id>attach-javadocs</id>
161-
<goals>
162-
<goal>jar</goal>
163-
</goals>
164-
<configuration>
165-
<doclint>none</doclint>
166-
</configuration>
167-
</execution>
168-
</executions>
169-
</plugin>
170149
</plugins>
171150
</build>
172151

173152
<scm>
174153
<connection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</connection>
175154
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</developerConnection>
176155
<url>https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</url>
177-
<tag>0.0.6</tag>
178156
</scm>
179157
</project>
180158

src/main/java/org/apache/cassandra/distributed/shared/Versions.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.slf4j.Logger;
3636
import org.slf4j.LoggerFactory;
3737

38-
public class Versions
38+
public final class Versions
3939
{
4040
private static final Logger logger = LoggerFactory.getLogger(Versions.class);
4141

@@ -69,7 +69,8 @@ public enum Major
6969
v22("2\\.2\\.([0-9]+)"),
7070
v30("3\\.0\\.([0-9]+)"),
7171
v3X("3\\.([1-9]|1[01])(\\.([0-9]+))?"),
72-
v4("4\\.([0-9]+)");
72+
v40("4\\.0(?:\\.|-alpha|-beta|-rc)([0-9]+)(\\.([0-9]+))?"),
73+
v4X("4\\.([1-9][0-9]*)(\\.([0-9]+))?");
7374
final Pattern pattern;
7475

7576
Major(String verify)
@@ -92,7 +93,9 @@ static Major fromFull(String version)
9293
return v30;
9394
return v3X;
9495
case '4':
95-
return v4;
96+
if (version.startsWith("4.0"))
97+
return v40;
98+
return v4X;
9699
default:
97100
throw new IllegalArgumentException(version);
98101
}
@@ -108,14 +111,15 @@ boolean verify(String version)
108111
int compare(String a, String b)
109112
{
110113
Matcher ma = pattern.matcher(a);
111-
Matcher mb = pattern.matcher(a);
114+
Matcher mb = pattern.matcher(b);
112115
if (!ma.matches()) throw new IllegalArgumentException(a);
113116
if (!mb.matches()) throw new IllegalArgumentException(b);
114117
int result = Integer.compare(Integer.parseInt(ma.group(1)), Integer.parseInt(mb.group(1)));
115118
if (result == 0 && this == v3X && (ma.group(3) != null || mb.group(3) != null))
116119
{
117120
if (ma.group(3) != null && mb.group(3) != null)
118121
{
122+
// XXX likely wrong for alpha|beta|rc versions
119123
result = Integer.compare(Integer.parseInt(ma.group(3)), Integer.parseInt(mb.group(3)));
120124
}
121125
else
@@ -149,7 +153,7 @@ public Version(Major major, String version, URL[] classpath)
149153

150154
private final Map<Major, List<Version>> versions;
151155

152-
public Versions(Map<Major, List<Version>> versions)
156+
private Versions(Map<Major, List<Version>> versions)
153157
{
154158
this.versions = versions;
155159
}
@@ -173,19 +177,22 @@ public static Versions find()
173177
final String dtestJarDirectory = System.getProperty(PROPERTY_PREFIX + "test.dtest_jar_path", "build");
174178
final File sourceDirectory = new File(dtestJarDirectory);
175179
logger.info("Looking for dtest jars in " + sourceDirectory.getAbsolutePath());
176-
final Pattern pattern = Pattern.compile("dtest-(?<fullversion>(\\d+)\\.(\\d+)(\\.\\d+)?(\\.\\d+)?)([~\\-]\\w[.\\w]*(?:\\-\\w[.\\w]*)*)?(\\+[.\\w]+)?\\.jar");
180+
final Pattern pattern = Pattern.compile("dtest-(?<fullversion>(\\d+)\\.(\\d+)((\\.|-alpha|-beta|-rc)([0-9]+))?(\\.\\d+)?)([~\\-]\\w[.\\w]*(?:\\-\\w[.\\w]*)*)?(\\+[.\\w]+)?\\.jar");
177181
final Map<Major, List<Version>> versions = new HashMap<>();
178182
for (Major major : Major.values())
179183
versions.put(major, new ArrayList<>());
180184

181-
for (File file : sourceDirectory.listFiles())
185+
if (sourceDirectory.exists())
182186
{
183-
Matcher m = pattern.matcher(file.getName());
184-
if (!m.matches())
185-
continue;
186-
String version = m.group(1);
187-
Major major = Major.fromFull(version);
188-
versions.get(major).add(new Version(major, version, new URL[]{ toURL(file) }));
187+
for (File file : sourceDirectory.listFiles())
188+
{
189+
Matcher m = pattern.matcher(file.getName());
190+
if (!m.matches())
191+
continue;
192+
String version = m.group(1);
193+
Major major = Major.fromFull(version);
194+
versions.get(major).add(new Version(major, version, new URL[]{ toURL(file) }));
195+
}
189196
}
190197

191198
for (Map.Entry<Major, List<Version>> e : versions.entrySet())
@@ -199,7 +206,7 @@ public static Versions find()
199206
return new Versions(versions);
200207
}
201208

202-
public static URL toURL(File file)
209+
private static URL toURL(File file)
203210
{
204211
try
205212
{
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package org.apache.cassandra.distributed.shared;
15+
16+
17+
import java.io.IOException;
18+
import java.nio.file.Files;
19+
import java.nio.file.Path;
20+
import java.nio.file.Paths;
21+
22+
import org.junit.jupiter.api.AfterAll;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
public class VersionsTest
29+
{
30+
public static final String[] VERSIONS = new String[]
31+
{
32+
"2.2.12",
33+
"2.2.2",
34+
"3.0.0",
35+
"3.0.10",
36+
"3.11.10",
37+
"3.11.9",
38+
"4.0-alpha1",
39+
"4.0-beta1",
40+
"4.0-rc1",
41+
"4.0.0",
42+
"4.1.0"
43+
};
44+
45+
@BeforeAll
46+
public static void beforeAll() throws IOException
47+
{
48+
Path root = Files.createTempDirectory("versions");
49+
System.setProperty(Versions.PROPERTY_PREFIX + "test.dtest_jar_path", root.toAbsolutePath().toString());
50+
51+
for (String version : VERSIONS)
52+
Files.createFile(Paths.get(root.toAbsolutePath().toString(), "dtest-" + version + ".jar"));
53+
}
54+
55+
@AfterAll
56+
public static void afterAll() throws IOException
57+
{
58+
System.clearProperty(Versions.PROPERTY_PREFIX + "test.dtest_jar_path");
59+
}
60+
61+
@Test
62+
public void testVersions() throws IOException
63+
{
64+
Versions versions = Versions.find();
65+
for (String version : VERSIONS)
66+
assertThat(versions.get(version)).isNotNull();
67+
}
68+
69+
@Test
70+
public void testGet()
71+
{
72+
assertThat(Versions.find().get("2.2.2")).isNotNull();
73+
}
74+
75+
@Test
76+
public void testGetLatest()
77+
{
78+
Versions.find().getLatest(Versions.Major.v22);
79+
}
80+
81+
@Test
82+
public void testFind()
83+
{
84+
Versions versions = Versions.find();
85+
assertThat(versions).isNotNull();
86+
87+
}
88+
89+
@Test
90+
public void testToURL()
91+
{
92+
assertThat(Versions.getClassPath()).isNotEmpty();
93+
}
94+
95+
}

0 commit comments

Comments
 (0)