Skip to content

Commit

Permalink
Resolves#236 Update the namespace detection for the root namespace to…
Browse files Browse the repository at this point in the history
… support stability level qualifiers.
  • Loading branch information
darranl committed Sep 5, 2024
1 parent 6cb92d4 commit 185e2a7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
import java.util.regex.Pattern;

final class OfflineServerVersion {
private static final Pattern ROOT_XMLNS = Pattern.compile("[\"']urn:jboss:domain:(\\d+)\\.(\\d+)[\"']");

/*
* The namespaces in WildFly may also contain an optional Stabilty qualifier e.g.
*
* urn:jboss:domain:community:21.0
*
* Within the regular expression "(?:[a-z]+:)?":
* - This it a non capturing group to avoid changing the index of the versions.
* - The group is optional so can appear 0 or 1 times.
* - The format is [a-z]+: which is one or more lowercase letters followed by a colon.
*/

private static final Pattern ROOT_XMLNS = Pattern.compile("[\"']urn:jboss:domain:(?:community:|preview:|experimental:)?(\\d+)\\.(\\d+)[\"']");

private OfflineServerVersion() {
// avoid instantiation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class OfflineServerVersionTest {
private static final String WFLY27_ROOT = "20.0";
private static final String WFLY28_ROOT = "21.0";

private static final String COMMUNITY = "community";
private static final String PREVIEW = "preview";
private static final String EXPERIMENTAL = "experimental";

@Rule
public final TemporaryFolder tmp = new TemporaryFolder();

Expand Down Expand Up @@ -196,6 +200,23 @@ public void discoverStandaloneXml_wfly28() throws IOException {
test(ServerVersion.VERSION_21_0_0, STANDALONE_XML, WFLY28_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverStandaloneXml_wfly34_community() throws IOException {
test(ServerVersion.VERSION_20_0_0, STANDALONE_XML, COMMUNITY, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverStandaloneXml_wfly34_experimental() throws IOException {
// Doesn't currently exist but verify it can be parsed correctly.
test(ServerVersion.VERSION_20_0_0, STANDALONE_XML, EXPERIMENTAL, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverStandaloneXml_wfly34_preview() throws IOException {
// Doesn't currently exist but verify it can be parsed correctly.
test(ServerVersion.VERSION_20_0_0, STANDALONE_XML, PREVIEW, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverHostXml_eap6() throws IOException {
test(ServerVersion.VERSION_1_7_0, HOST_XML, EAP6_ROOT, EAP6_LOGGING, EAP6_EE);
Expand Down Expand Up @@ -296,6 +317,23 @@ public void discoverHostXml_wfly28() throws IOException {
test(ServerVersion.VERSION_21_0_0, HOST_XML, WFLY28_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverHostXml_wfly34_community() throws IOException {
test(ServerVersion.VERSION_20_0_0, HOST_XML, COMMUNITY, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverHostXml_wfly34_preview() throws IOException {
// Doesn't currently exist but verify it can be parsed correctly.
test(ServerVersion.VERSION_20_0_0, HOST_XML, PREVIEW, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverHostXml_wfly34_experimental() throws IOException {
// Doesn't currently exist but verify it can be parsed correctly.
test(ServerVersion.VERSION_20_0_0, HOST_XML, EXPERIMENTAL, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverDomainXml_eap6() throws IOException {
test(ServerVersion.VERSION_1_7_0, DOMAIN_XML, EAP6_ROOT, EAP6_LOGGING, EAP6_EE);
Expand Down Expand Up @@ -396,10 +434,33 @@ public void discoverDomainXml_wfly28() throws IOException {
test(ServerVersion.VERSION_21_0_0, DOMAIN_XML, WFLY28_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverDomainXml_wfly34_community() throws IOException {
test(ServerVersion.VERSION_20_0_0, DOMAIN_XML, COMMUNITY, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverDomainXml_wfly34_preview() throws IOException {
// Doesn't currently exist but verify it can be parsed correctly.
test(ServerVersion.VERSION_20_0_0, DOMAIN_XML, PREVIEW, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

@Test
public void discoverDomainXml_wfly34_experimental() throws IOException {
// Doesn't currently exist but verify it can be parsed correctly.
test(ServerVersion.VERSION_20_0_0, DOMAIN_XML, EXPERIMENTAL, WFLY27_ROOT, EAP7_LOGGING, EAP8_EE);
}

private void test(ServerVersion expected, String xmlPattern,
String rootVersion, String loggingVersion, String eeVersion) throws IOException {
test(expected, xmlPattern, null, rootVersion, loggingVersion, eeVersion);
}

private void test(ServerVersion expected, String xmlPattern, String stability,
String rootVersion, String loggingVersion, String eeVersion) throws IOException {
String version = stability == null ? rootVersion : stability + ":" + rootVersion;
String xml = xmlPattern
.replace("%ROOT_VERSION%", rootVersion)
.replace("%ROOT_VERSION%", version)
.replace("%LOGGING_VERSION%", loggingVersion)
.replace("%EE_VERSION%", eeVersion);

Expand Down

0 comments on commit 185e2a7

Please sign in to comment.