Skip to content

Commit

Permalink
#15 improved Adoptium regex patter to extract version and target os
Browse files Browse the repository at this point in the history
  • Loading branch information
raydac committed Sep 4, 2024
1 parent 3ec37b4 commit 14fbd84
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mvn-jlink-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-jlink</artifactId>
<version>1.2.3</version>
<version>1.2.4-SNAPSHOT</version>
</parent>

<artifactId>mvn-jlink-tests</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion mvn-jlink-wrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-jlink</artifactId>
<version>1.2.3</version>
<version>1.2.4-SNAPSHOT</version>
</parent>

<artifactId>mvn-jlink-wrapper</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void downloadAndUnpack(
}
}

private static class ReleaseList {
static class ReleaseList {
private final List<Release> releases = new ArrayList<>();

private ReleaseList() {
Expand Down Expand Up @@ -370,10 +370,10 @@ public String makeReport() {
return this.releases.stream().map(Release::toString).collect(joining("\n"));
}

private static class Release {
static class Release {

private static final Pattern ADOPTGIT_FILENAME_PATTERN = Pattern.compile(
"^OpenJDK([\\da-z]*)-([a-z]+)_([0-9a-z\\-]+)_([0-9a-z]+)_([0-9a-z_]+)_([\\-a-zA-Z0-9]+).(.+)$",
static final Pattern ADOPTGIT_FILENAME_PATTERN = Pattern.compile(
"^OpenJDK([\\da-z]*)-([a-z]+)_([0-9a-z\\-]+)_([0-9a-z\\-]+)_([a-z0-9]+)_([\\-a-zA-Z0-9]+|\\d[\\d._]+\\d(?![a-z\\-])).([.a-z0-9]+)$",
Pattern.CASE_INSENSITIVE);

private final String version;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.igormaznitsa.mvnjlink.jdkproviders.providers;

import static com.igormaznitsa.meta.common.utils.Assertions.assertEquals;
import static com.igormaznitsa.meta.common.utils.Assertions.fail;

import java.util.regex.Matcher;
import org.junit.jupiter.api.Test;

public class AdoptiumOpenJdkProviderTest {

private static void assertFileNameParseable(final String expectedOs, final String expectedBuild,
final String expectedExtension,
final String version) {
final Matcher matcher =
AdoptiumOpenJdkProvider.ReleaseList.Release.ADOPTGIT_FILENAME_PATTERN.matcher(version);
if (matcher.find()) {
assertEquals(expectedOs, matcher.group(4));
assertEquals(expectedBuild, matcher.group(6));
assertEquals(expectedExtension, matcher.group(7));
} else {
fail("Doesn't match pattern: " + version);
}
}

@Test
public void testFileNameForPattern() {
assertFileNameParseable("alpine-linux", "2022-09-26-18-05", "tar.gz",
"OpenJDK8U-debugimage_aarch64_alpine-linux_hotspot_2022-09-26-18-05.tar.gz");
assertFileNameParseable("windows", "21.0.4_7", "7zip",
"OpenJDK21U-debugimage_x64_windows_hotspot_21.0.4_7.7zip");
assertFileNameParseable("windows", "21.0.4_7", "zip",
"OpenJDK21U-debugimage_x64_windows_hotspot_21.0.4_7.zip");
assertFileNameParseable("alpine-linux", "21.0.4_7", "tar.gz",
"OpenJDK21U-debugimage_aarch64_alpine-linux_hotspot_21.0.4_7.tar.gz");
assertFileNameParseable("windows", "2022-06-15-11-45", "zip",
"OpenJDK19-testimage_x64_windows_hotspot_2022-06-15-11-45.zip");
assertFileNameParseable("linux", "21.0.4_7", "tar.gz",
"OpenJDK21U-jdk_x64_linux_hotspot_21.0.4_7.tar.gz");
assertFileNameParseable("linux", "17.0.12_7", "tar.gz",
"OpenJDK17U-debugimage_aarch64_linux_hotspot_17.0.12_7.tar.gz");
assertFileNameParseable("linux", "17.0.12_7", "7zip",
"OpenJDK17U-debugimage_aarch64_linux_hotspot_17.0.12_7.7zip");
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-jlink</artifactId>
<version>1.2.3</version>
<version>1.2.4-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Maven Jlink plugin</name>
Expand Down

0 comments on commit 14fbd84

Please sign in to comment.