Skip to content

Commit

Permalink
Merge pull request #2886 from liquibase/introduce-latest-xsd
Browse files Browse the repository at this point in the history
Introduced "latest" xsd file path
  • Loading branch information
nvoxland committed Jun 6, 2022
2 parents 3adcc27 + 8e6c187 commit 6d1b853
Show file tree
Hide file tree
Showing 7 changed files with 1,448 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ public interface NamespaceDetails extends PrioritizedService{
String getSchemaUrl(String namespaceOrUrl);

String[] getNamespaces();

String getLocalPath(String namespaceOrUrl);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class StandardNamespaceDetails implements NamespaceDetails {
private final Pattern oldStandardUrlPattern;

public StandardNamespaceDetails() {
standardUrlPattern = Pattern.compile("http://www.liquibase.org/xml/ns/dbchangelog/(dbchangelog-[\\d\\.]+.xsd)");
oldStandardUrlPattern = Pattern.compile("http://www.liquibase.org/xml/ns/migrator/(dbchangelog-[\\d\\.]+.xsd)");
standardUrlPattern = Pattern.compile("http://www.liquibase.org/xml/ns/dbchangelog/(dbchangelog-[\\w\\.]+.xsd)");
oldStandardUrlPattern = Pattern.compile("http://www.liquibase.org/xml/ns/migrator/(dbchangelog-[\\w\\.]+.xsd)");
}

@Override
Expand Down Expand Up @@ -54,27 +54,8 @@ public String[] getNamespaces() {
@Override
public String getSchemaUrl(String namespaceOrUrl) {
if (namespaceOrUrl.equals(LiquibaseSerializable.STANDARD_CHANGELOG_NAMESPACE)) {
return "http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-" + XMLChangeLogSAXParser.getSchemaVersion() + ".xsd";
return "http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd";
}
return GENERIC_EXTENSION_XSD;
}

@Override
public String getLocalPath(String namespaceOrUrl) {

if (namespaceOrUrl.equals(GENERIC_EXTENSION_XSD)) {
return "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd";
}
Matcher matcher = standardUrlPattern.matcher(namespaceOrUrl);
if (matcher.matches()) {
return "www.liquibase.org/xml/ns/dbchangelog/"+matcher.group(1);
}

matcher = oldStandardUrlPattern.matcher(namespaceOrUrl);
if (matcher.matches()) {
return "www.liquibase.org/xml/ns/dbchangelog/"+matcher.group(1);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import liquibase.resource.ResourceAccessor;
import liquibase.util.BomAwareInputStream;
import liquibase.util.FileUtil;
import liquibase.util.LiquibaseUtil;
import org.xml.sax.*;

import javax.xml.XMLConstants;
Expand All @@ -18,9 +19,13 @@

public class XMLChangeLogSAXParser extends AbstractChangeLogParser {

public static final String LIQUIBASE_SCHEMA_VERSION = "4.6";
public static final String LIQUIBASE_SCHEMA_VERSION;
private SAXParserFactory saxParserFactory;

static {
LIQUIBASE_SCHEMA_VERSION = computeSchemaVersion(LiquibaseUtil.getBuildVersion());
}

private final LiquibaseEntityResolver resolver = new LiquibaseEntityResolver();

public XMLChangeLogSAXParser() {
Expand Down Expand Up @@ -151,4 +156,17 @@ private void trySetSchemaLanguageProperty(SAXParser parser) {
//ok, parser need not support it
}
}

static String computeSchemaVersion(String version) {
String finalVersion = null;

if (version != null && version.contains(".")) {
String[] splitVersion = version.split("\\.");
finalVersion = splitVersion[0] + "." + splitVersion[1];
}
if (finalVersion == null) {
finalVersion = "next";
}
return finalVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd ">
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd ">

<changeSet id="1" author="author name">
<!--Insert XML change objects here https://www.liquibase.org/documentation/xml_format.html-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd ">
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd ">

<changeSet id="1" author="your.name" labels="example-label" context="example-context">
<comment>example-comment</comment>
Expand Down

0 comments on commit 6d1b853

Please sign in to comment.