Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced "latest" xsd file path #2886

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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