Skip to content

Commit

Permalink
[repositoryValidator] Warning for usage of a deprecated field #133
Browse files Browse the repository at this point in the history
  • Loading branch information
donmendelson committed Nov 9, 2021
1 parent 6fb13fa commit fd502a2
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dsl-antlr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.fixprotocol.orchestra</groupId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dsl-antlr</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion interfaces-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>interfaces-util</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion interfaces/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>interfaces</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion message-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>message-model</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion orchestra-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>orchestra-common</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion orchestra2doc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>orchestra2doc</artifactId>
<description>Generates humanly readable documentation</description>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Parent project for FIX Orchestra</description>
Expand Down Expand Up @@ -64,10 +64,10 @@
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr.version>4.9.2</antlr.version>
<antlr.version>4.9.3</antlr.version>
<base.java.version>11</base.java.version>
<commons-cli.version>1.4</commons-cli.version>
<junit.version>5.8.0</junit.version>
<junit.version>5.8.1</junit.version>
<log4j.version>2.14.1</log4j.version>
<saxon.version>10.6</saxon.version>
<slf4j.version>1.7.22</slf4j.version>
Expand Down
2 changes: 1 addition & 1 deletion repository-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>repository-util</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
Expand Down Expand Up @@ -110,6 +112,7 @@ public Iterator<String> getPrefixes(String arg0) {
private final EventListener eventLogger;
private int fatalErrors = 0;
private int warnings = 0;
private Set<String> deprecatedFieldTags = new HashSet<>();

public BasicRepositoryValidator(EventListener eventLogger) {
this.eventLogger = eventLogger;
Expand Down Expand Up @@ -153,6 +156,7 @@ public boolean validate(InputStream inputStream) {
Document xmlDocument;
try {
xmlDocument = validateSchema(inputStream, errorHandler);
// must validate fields first because it collects deprecated fields
validateFields(xmlDocument);
validateCodesets(xmlDocument);
validateComponents(xmlDocument);
Expand Down Expand Up @@ -283,18 +287,46 @@ protected void validateComponents(Document xmlDocument) {
warning("RepositoryValidator: component abbrName {0} is invalid (id={1})", abbrName,
id);
}
if (element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0) {
final boolean isDeprecated = element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0;
if (isDeprecated) {
warning("RepositoryValidator: component {0} (id={1}) is deprecated",
name, id);
}
validateMembers(node, name, id);
}
}
} catch (final XPathExpressionException e) {
fatalError("Failed to locate components; {}", e.getMessage());
}
}

private void validateMembers(Node parentNode, String parentName, String parentId) {
final XPath xPath = XPathFactory.newInstance().newXPath();
xPath.setNamespaceContext(nsContext);
final String expression = "fixr:fieldRef";
try {
final NodeList nodeList =
(NodeList) xPath.compile(expression).evaluate(parentNode, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
final Node node = nodeList.item(i);
final short nodeType = node.getNodeType();
if (nodeType == Node.ELEMENT_NODE) {
final Element element = (Element) node;
final String id = element.getAttribute("id");
final boolean isDeprecated = element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0;
if (!isDeprecated && this.deprecatedFieldTags.contains(id)) {
warning("RepositoryValidator: {0} has deprecated field id={1} as member",
parentName, id);
}
}
}
} catch (final XPathExpressionException e) {
fatalError("Failed to locate members; {}", e.getMessage());
}
}

protected void validateDocumentation(Document xmlDocument) {
final XPath xPath = XPathFactory.newInstance().newXPath();
xPath.setNamespaceContext(nsContext);
Expand Down Expand Up @@ -382,8 +414,10 @@ protected void validateFields(Document xmlDocument) {
if (abbrName.length() > 0 && !isValidName.test(abbrName)) {
warning("RepositoryValidator: field abbrName {0} is invalid (id={1})", abbrName, id);
}
if (element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0) {
final boolean isDeprecated = element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0;
if (isDeprecated) {
this.deprecatedFieldTags.add(id);
warning("RepositoryValidator: field {0}({1}) is deprecated",
name, id);
}
Expand Down Expand Up @@ -416,11 +450,13 @@ protected void validateGroups(Document xmlDocument) {
if (abbrName.length() > 0 && !isValidName.test(abbrName)) {
warning("RepositoryValidator: group abbrName {0} is invalid (id={1})", abbrName, id);
}
if (element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0) {
final boolean isDeprecated = element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0;
if (isDeprecated) {
warning("RepositoryValidator: group {0} (id={1}) is deprecated",
name, id);
}
validateMembers(node, name, id);
}
}
} catch (final XPathExpressionException e) {
Expand Down Expand Up @@ -449,11 +485,17 @@ protected void validateMessages(Document xmlDocument) {
if (abbrName.length() > 0 && !isValidName.test(abbrName)) {
warning("RepositoryValidator: message abbrName {0} is invalid (id={1})", abbrName, id);
}
if (element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0) {
final boolean isDeprecated = element.getAttribute("deprecated").length() > 0
|| element.getAttribute("deprecatedEP").length() > 0;
if (isDeprecated) {
warning("RepositoryValidator: message {0} (id={1}) is deprecated",
name, id);
}
NodeList children = element.getElementsByTagName("fixr:structure");
Node structureNode = children.item(0);
if (structureNode != null) {
validateMembers(structureNode, name, id);
}
}
}
} catch (final XPathExpressionException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:functx="http://www.functx.com" xmlns:fixr="http://fixprotocol.io/2020/orchestra/repository" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0" exclude-result-prefixes="fn">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:functx="http://www.functx.com" xmlns:fixr="http://fixprotocol.io/2020/orchestra/repository" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0" exclude-result-prefixes="fn functx">
<!-- argument is phrase file URL, e.g. file://FIX.5.0SP2_en_phrases.xml" -->
<xsl:param name="phrases-file"/>
<xsl:param name="name"/>
Expand Down
2 changes: 1 addition & 1 deletion repository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>repository</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion repository2010/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.fixprotocol.orchestra</groupId>
<artifactId>parent</artifactId>
<version>1.7.3</version>
<version>1.7.4-SNAPSHOT</version>
</parent>
<artifactId>repository2010</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand Down

0 comments on commit fd502a2

Please sign in to comment.