You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2023/04/19 07:41:37 UTC
[jackrabbit-filevault] branch master updated: JCRVLT-704 expose line and column from NodeContext (#290)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
The following commit(s) were added to refs/heads/master by this push:
new fcce9df5 JCRVLT-704 expose line and column from NodeContext (#290)
fcce9df5 is described below
commit fcce9df53c71db03667b28c11be90a8227d6610d
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Apr 19 09:41:31 2023 +0200
JCRVLT-704 expose line and column from NodeContext (#290)
Leverage that for creating more detailedValidationMessages
---
.../impl/util/ValidatorDocViewParserHandler.java | 4 +-
.../vault/validation/spi/NodeContext.java | 22 +++++++++-
.../vault/validation/spi/ValidationMessage.java | 4 +-
.../vault/validation/spi/package-info.java | 2 +-
.../vault/validation/spi/util/NodeContextImpl.java | 49 +++++++++++-----------
.../vault/validation/spi/util/package-info.java | 2 +-
.../DocumentViewParserValidatorTest.java | 16 +++----
7 files changed, 59 insertions(+), 40 deletions(-)
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/ValidatorDocViewParserHandler.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/ValidatorDocViewParserHandler.java
index 70bfb3fe..6e169131 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/ValidatorDocViewParserHandler.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/ValidatorDocViewParserHandler.java
@@ -125,9 +125,9 @@ public class ValidatorDocViewParserHandler implements DocViewParserHandler {
try {
final Collection<ValidationMessage> messages;
if (isStart) {
- messages = entry.getValue().validate(docViewNode, new NodeContextImpl(nodePath, filePath, basePath), !parentDocViewNode.isPresent());
+ messages = entry.getValue().validate(docViewNode, new NodeContextImpl(nodePath, filePath, basePath, lineNumber, columnNumber), !parentDocViewNode.isPresent());
} else {
- messages = entry.getValue().validateEnd(docViewNode, new NodeContextImpl(nodePath, filePath, basePath), !parentDocViewNode.isPresent());
+ messages = entry.getValue().validateEnd(docViewNode, new NodeContextImpl(nodePath, filePath, basePath, lineNumber, columnNumber), !parentDocViewNode.isPresent());
}
if (messages != null && !messages.isEmpty()) {
violations.addAll(ValidationViolation.wrapMessages(entry.getKey(), messages, filePath, null, nodePath,
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodeContext.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodeContext.java
index c808367c..028f6617 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodeContext.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodeContext.java
@@ -23,8 +23,9 @@ import org.jetbrains.annotations.NotNull;
/**
* Meta information about a node:
* <ul>
- * <li>jcr path</li>
- * <li>file path of the file which defined the node</li>
+ * <li>JCR path</li>
+ * <li>file system path of the file which defined the node</li>
+ * <li>optionally line and column in the the file which defined the node</li>
* </ul>
*/
public interface NodeContext {
@@ -47,4 +48,21 @@ public interface NodeContext {
*/
@NotNull Path getBasePath();
+ /**
+ *
+ * @return the line where the serialization of the node was found, 0 for unspecified. This is only set for a node context originating from a DocView XML file.
+ * @since 3.6.10
+ */
+ default int getLine() {
+ return 0;
+ }
+
+ /**
+ *
+ * @return the column where the serialization of the node was found, 0 for unspecified. This is only set for a node context originating from a DocView XML file.
+ * @since 3.6.10
+ */
+ default int getColumn() {
+ return 0;
+ }
}
\ No newline at end of file
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/ValidationMessage.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/ValidationMessage.java
index aaa32540..de83c168 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/ValidationMessage.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/ValidationMessage.java
@@ -56,11 +56,11 @@ public class ValidationMessage {
}
public ValidationMessage(@NotNull ValidationMessageSeverity severity, @NotNull String message, @NotNull NodeContext nodeContext) {
- this(severity, message, nodeContext.getNodePath(), nodeContext.getFilePath(), nodeContext.getBasePath(), 0, 0, null);
+ this(severity, message, nodeContext.getNodePath(), nodeContext.getFilePath(), nodeContext.getBasePath(), nodeContext.getLine(), nodeContext.getColumn(), null);
}
public ValidationMessage(@NotNull ValidationMessageSeverity severity, @NotNull String message, @NotNull NodeContext nodeContext, Throwable throwable) {
- this(severity, message, nodeContext.getNodePath(), nodeContext.getFilePath(), nodeContext.getBasePath(), 0, 0, throwable);
+ this(severity, message, nodeContext.getNodePath(), nodeContext.getFilePath(), nodeContext.getBasePath(), nodeContext.getLine(), nodeContext.getColumn(), throwable);
}
public ValidationMessage(@NotNull ValidationMessageSeverity severity, @NotNull String message, Path filePath, Path basePath, int line, int column, Throwable throwable) {
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/package-info.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/package-info.java
index b172b794..3aa5fe5d 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/package-info.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/package-info.java
@@ -18,7 +18,7 @@
/**
* The FileVault validation framework SPI. Provides classes/interfaces to implement validators on FileVault packages.
*/
-@Version("1.6.0")
+@Version("1.7.0")
package org.apache.jackrabbit.vault.validation.spi;
import org.osgi.annotation.versioning.Version;
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/NodeContextImpl.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/NodeContextImpl.java
index c075d1d1..4bb5b3e8 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/NodeContextImpl.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/NodeContextImpl.java
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.vault.validation.spi.util;
import java.nio.file.Path;
+import java.util.Objects;
import org.apache.jackrabbit.vault.validation.spi.NodeContext;
import org.jetbrains.annotations.NotNull;
@@ -25,12 +26,20 @@ public final class NodeContextImpl implements NodeContext {
private final @NotNull String nodePath;
private final @NotNull Path filePath;
private final @NotNull Path basePath;
+ private final int line;
+ private final int column;
public NodeContextImpl(@NotNull String nodePath, @NotNull Path filePath, @NotNull Path basePath) {
+ this(nodePath, filePath, basePath, 0, 0);
+ }
+
+ public NodeContextImpl(@NotNull String nodePath, @NotNull Path filePath, @NotNull Path basePath, int line, int column) {
super();
this.nodePath = nodePath;
this.filePath = filePath;
this.basePath = basePath;
+ this.line = line;
+ this.column = column;
}
@Override
@@ -48,14 +57,19 @@ public final class NodeContextImpl implements NodeContext {
return basePath;
}
+ @Override
+ public int getLine() {
+ return line;
+ }
+
+ @Override
+ public int getColumn() {
+ return column;
+ }
+
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((basePath == null) ? 0 : basePath.hashCode());
- result = prime * result + ((filePath == null) ? 0 : filePath.hashCode());
- result = prime * result + ((nodePath == null) ? 0 : nodePath.hashCode());
- return result;
+ return Objects.hash(basePath, column, filePath, line, nodePath);
}
@Override
@@ -67,27 +81,14 @@ public final class NodeContextImpl implements NodeContext {
if (getClass() != obj.getClass())
return false;
NodeContextImpl other = (NodeContextImpl) obj;
- if (basePath == null) {
- if (other.basePath != null)
- return false;
- } else if (!basePath.equals(other.basePath))
- return false;
- if (filePath == null) {
- if (other.filePath != null)
- return false;
- } else if (!filePath.equals(other.filePath))
- return false;
- if (nodePath == null) {
- if (other.nodePath != null)
- return false;
- } else if (!nodePath.equals(other.nodePath))
- return false;
- return true;
+ return Objects.equals(basePath, other.basePath) && column == other.column && Objects.equals(filePath, other.filePath)
+ && line == other.line && Objects.equals(nodePath, other.nodePath);
}
@Override
public String toString() {
- return "NodeContextImpl [" + (nodePath != null ? "nodePath=" + nodePath + ", " : "")
- + (filePath != null ? "filePath=" + filePath + ", " : "") + (basePath != null ? "basePath=" + basePath : "") + "]";
+ return "NodeContextImpl [nodePath=" + nodePath + ", filePath=" + filePath + ", basePath=" + basePath + ", line=" + line
+ + ", column=" + column + "]";
}
+
}
\ No newline at end of file
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/package-info.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/package-info.java
index 9aa27a44..dae66baf 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/package-info.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/util/package-info.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-@Version("1.0.0")
+@Version("1.1.0")
package org.apache.jackrabbit.vault.validation.spi.util;
import org.osgi.annotation.versioning.Version;
diff --git a/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java b/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java
index 1e4a00c4..08314f45 100644
--- a/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java
+++ b/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java
@@ -115,7 +115,7 @@ public class DocumentViewParserValidatorTest {
new DocViewProperty2(NameConstants.JCR_PRIMARYTYPE, "sling:Folder"));
NameFactory nameFactory = NameFactoryImpl.getInstance();
DocViewNode2 node = new DocViewNode2(nameFactory.create("{}apps"), properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps", Paths.get("apps", ".content.xml"), Paths.get("")), true);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps", Paths.get("apps", ".content.xml"), Paths.get(""), 19, 35), true);
properties = new ArrayList<>();
properties.add(
@@ -123,13 +123,13 @@ public class DocumentViewParserValidatorTest {
properties.add(
new DocViewProperty2(nameFactory.create("{}attribute1"), "value1"));
node = new DocViewNode2(nameFactory.create("{}somepath"), properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/somepath", Paths.get("apps", ".content.xml"), Paths.get("")), false);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/somepath", Paths.get("apps", ".content.xml"), Paths.get(""), 21, 29), false);
properties = new ArrayList<>();
properties.add(
new DocViewProperty2(NameConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
node = new DocViewNode2(NameConstants.JCR_CONTENT, properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/somepath/jc:content", Paths.get("apps", ".content.xml"), Paths.get("")), false);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/somepath/jc:content", Paths.get("apps", ".content.xml"), Paths.get(""), 22, 54), false);
}
}
@@ -155,7 +155,7 @@ public class DocumentViewParserValidatorTest {
properties.add(new DocViewProperty2(NAME_SLING_TARGET, "/index.html"));
DocViewNode2 node = new DocViewNode2(NameConstants.ROOT, properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/", Paths.get(".content.xml"), Paths.get("")), true);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/", Paths.get(".content.xml"), Paths.get(""), 6, 32), true);
}
}
@@ -208,13 +208,13 @@ public class DocumentViewParserValidatorTest {
Collection<DocViewProperty2> properties = new ArrayList<>();
properties.add(new DocViewProperty2(NameConstants.JCR_PRIMARYTYPE, "sling:Folder"));
DocViewNode2 node = new DocViewNode2(nameFactory.create("{}child1"), properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1", Paths.get("apps", "child1.xml"), Paths.get("")), true);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1", Paths.get("apps", "child1.xml"), Paths.get(""), 20, 36), true);
properties = new ArrayList<>();
properties.add(new DocViewProperty2(NameConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
properties.add(new DocViewProperty2(nameFactory.create("{}attribute1"), "value1"));
node = new DocViewNode2(nameFactory.create("{}somepath"), properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1/somepath", Paths.get("apps", "child1.xml"), Paths.get("")), false);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1/somepath", Paths.get("apps", "child1.xml"), Paths.get(""), 23, 6), false);
// verify node names
Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
@@ -250,13 +250,13 @@ public class DocumentViewParserValidatorTest {
Collection<DocViewProperty2> properties = new ArrayList<>();
properties.add(new DocViewProperty2(NameConstants.JCR_PRIMARYTYPE, "sling:Folder"));
DocViewNode2 node = new DocViewNode2(nameFactory.create("{}child3"), properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3", Paths.get("apps", "child2", ".content.xml"), Paths.get("")), true);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3", Paths.get("apps", "child2", ".content.xml"), Paths.get(""), 20, 36), true);
properties.clear();
properties.add(new DocViewProperty2(NameConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
properties.add(new DocViewProperty2(nameFactory.create("{}attribute1"), "value1"));
node = new DocViewNode2(nameFactory.create("{}somepath"), properties);
- Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3/somepath", Paths.get("apps", "child2", ".content.xml"), Paths.get("")), false);
+ Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3/somepath", Paths.get("apps", "child2", ".content.xml"), Paths.get(""), 23, 6), false);
// verify node names
Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();