Skip to content
Permalink
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
  • Loading branch information
michaelsembwever committed Jul 4, 2021
1 parent d5174b1 commit 8b17c8dfe3fa0d062af1e861b8b204c7bbeb275b
Showing 4 changed files with 117 additions and 36 deletions.
@@ -79,3 +79,4 @@ doc/source/tools/nodetool

# Python virtual environment
venv/
/nbproject/
22 pom.xml
@@ -90,10 +90,6 @@
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
@@ -122,7 +118,6 @@
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>0.13</version>
<configuration>
<addLicenseHeaders>true</addLicenseHeaders>
</configuration>
@@ -151,30 +146,13 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<doclint>none</doclint>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</url>
<tag>0.0.6</tag>
</scm>
</project>

@@ -35,7 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Versions
public final class Versions
{
private static final Logger logger = LoggerFactory.getLogger(Versions.class);

@@ -69,7 +69,8 @@ public static URL[] getClassPath()
v22("2\\.2\\.([0-9]+)"),
v30("3\\.0\\.([0-9]+)"),
v3X("3\\.([1-9]|1[01])(\\.([0-9]+))?"),
v4("4\\.([0-9]+)");
v40("4\\.0(?:\\.|-alpha|-beta|-rc)([0-9]+)(\\.([0-9]+))?"),
v4X("4\\.([1-9][0-9]*)(\\.([0-9]+))?");
final Pattern pattern;

Major(String verify)
@@ -92,7 +93,9 @@ static Major fromFull(String version)
return v30;
return v3X;
case '4':
return v4;
if (version.startsWith("4.0"))
return v40;
return v4X;
default:
throw new IllegalArgumentException(version);
}
@@ -108,14 +111,15 @@ boolean verify(String version)
int compare(String a, String b)
{
Matcher ma = pattern.matcher(a);
Matcher mb = pattern.matcher(a);
Matcher mb = pattern.matcher(b);
if (!ma.matches()) throw new IllegalArgumentException(a);
if (!mb.matches()) throw new IllegalArgumentException(b);
int result = Integer.compare(Integer.parseInt(ma.group(1)), Integer.parseInt(mb.group(1)));
if (result == 0 && this == v3X && (ma.group(3) != null || mb.group(3) != null))
{
if (ma.group(3) != null && mb.group(3) != null)
{
// XXX likely wrong for alpha|beta|rc versions
result = Integer.compare(Integer.parseInt(ma.group(3)), Integer.parseInt(mb.group(3)));
}
else
@@ -149,7 +153,7 @@ public Version(Major major, String version, URL[] classpath)

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

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

for (File file : sourceDirectory.listFiles())
if (sourceDirectory.exists())
{
Matcher m = pattern.matcher(file.getName());
if (!m.matches())
continue;
String version = m.group(1);
Major major = Major.fromFull(version);
versions.get(major).add(new Version(major, version, new URL[]{ toURL(file) }));
for (File file : sourceDirectory.listFiles())
{
Matcher m = pattern.matcher(file.getName());
if (!m.matches())
continue;
String version = m.group(1);
Major major = Major.fromFull(version);
versions.get(major).add(new Version(major, version, new URL[]{ toURL(file) }));
}
}

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

public static URL toURL(File file)
private static URL toURL(File file)
{
try
{
@@ -0,0 +1,95 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.distributed.shared;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class VersionsTest
{
public static final String[] VERSIONS = new String[]
{
"2.2.12",
"2.2.2",
"3.0.0",
"3.0.10",
"3.11.10",
"3.11.9",
"4.0-alpha1",
"4.0-beta1",
"4.0-rc1",
"4.0.0",
"4.1.0"
};

@BeforeAll
public static void beforeAll() throws IOException
{
Path root = Files.createTempDirectory("versions");
System.setProperty(Versions.PROPERTY_PREFIX + "test.dtest_jar_path", root.toAbsolutePath().toString());

for (String version : VERSIONS)
Files.createFile(Paths.get(root.toAbsolutePath().toString(), "dtest-" + version + ".jar"));
}

@AfterAll
public static void afterAll() throws IOException
{
System.clearProperty(Versions.PROPERTY_PREFIX + "test.dtest_jar_path");
}

@Test
public void testVersions() throws IOException
{
Versions versions = Versions.find();
for (String version : VERSIONS)
assertThat(versions.get(version)).isNotNull();
}

@Test
public void testGet()
{
assertThat(Versions.find().get("2.2.2")).isNotNull();
}

@Test
public void testGetLatest()
{
Versions.find().getLatest(Versions.Major.v22);
}

@Test
public void testFind()
{
Versions versions = Versions.find();
assertThat(versions).isNotNull();

}

@Test
public void testToURL()
{
assertThat(Versions.getClassPath()).isNotEmpty();
}

}

0 comments on commit 8b17c8d

Please sign in to comment.