Skip to content

Commit 08982f6

Browse files
Updated Metaschema binding to latest Metaschema module model. Added support for exposing parse locations in validation results. Stubbed out SARIF format production. Added SARIF output option to validate command. Adjust constraint result production to allow for pass results to be produced, which supports producing SARIF result including both pass and fail statuses using a API-level configuration.
1 parent 67ab0b6 commit 08982f6

File tree

165 files changed

+1751
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+1751
-438
lines changed

core/metaschema

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DocumentNodeItemImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package gov.nist.secauto.metaschema.core.metapath.item.node;
2828

2929
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
30+
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
3031
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3132

3233
import java.net.URI;
@@ -80,4 +81,9 @@ public ModelContainer getModel() {
8081
public Object getValue() {
8182
return getRootAssemblyNodeItem().getValue();
8283
}
84+
85+
@Override
86+
public IResourceLocation getLocation() {
87+
return getRootAssemblyNodeItem().getLocation();
88+
}
8389
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IDefinitionNodeItem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828

2929
import gov.nist.secauto.metaschema.core.model.IDefinition;
3030
import gov.nist.secauto.metaschema.core.model.INamedInstance;
31+
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
3132
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3233

3334
import java.net.URI;
3435

3536
import javax.xml.namespace.QName;
3637

3738
import edu.umd.cs.findbugs.annotations.NonNull;
39+
import edu.umd.cs.findbugs.annotations.Nullable;
3840

3941
public interface IDefinitionNodeItem<D extends IDefinition, I extends INamedInstance> extends INodeItem {
4042
/**
@@ -69,4 +71,11 @@ default URI getNamespace() {
6971
* @return the instance of the segment, or {@code null} if it doesn't have one
7072
*/
7173
I getInstance();
74+
75+
@Override
76+
@Nullable
77+
default IResourceLocation getLocation() {
78+
Object value = getValue();
79+
return value == null ? null : getDefinition().getLocation(value);
80+
}
7281
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter;
3030
import gov.nist.secauto.metaschema.core.metapath.format.IPathSegment;
3131
import gov.nist.secauto.metaschema.core.metapath.item.IItem;
32+
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
3233
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3334

3435
import java.net.URI;
@@ -300,4 +301,7 @@ default Stream<? extends IFlagNodeItem> flags() {
300301
default Stream<? extends IModelNodeItem<?, ?>> modelItems() {
301302
return getModelItems().stream().flatMap(Collection::stream);
302303
}
304+
305+
@Nullable
306+
IResourceLocation getLocation();
303307
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/ModuleNodeItemImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package gov.nist.secauto.metaschema.core.metapath.item.node;
2828

2929
import gov.nist.secauto.metaschema.core.model.IModule;
30+
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
3031
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3132

3233
import java.net.URI;
@@ -65,4 +66,9 @@ public ModelContainer getModel() {
6566
return model.get();
6667
}
6768

69+
@Override
70+
public IResourceLocation getLocation() {
71+
// no location
72+
return null;
73+
}
6874
}

databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundObject.java renamed to core/src/main/java/gov/nist/secauto/metaschema/core/model/IBoundObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
2525
*/
2626

27-
package gov.nist.secauto.metaschema.databind.model;
27+
package gov.nist.secauto.metaschema.core.model;
2828

2929
import edu.umd.cs.findbugs.annotations.Nullable;
3030

core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javax.xml.namespace.QName;
3434

3535
import edu.umd.cs.findbugs.annotations.NonNull;
36+
import edu.umd.cs.findbugs.annotations.Nullable;
3637

3738
public interface IDefinition extends INamedModelElement, IAttributable, IFeatureValueConstrained {
3839

@@ -107,4 +108,8 @@ default String toCoordinates() {
107108
hashCode());
108109
}
109110

111+
@Nullable
112+
default IResourceLocation getLocation(@NonNull Object itemValue) {
113+
return itemValue instanceof IBoundObject ? ((IBoundObject) itemValue).getMetaschemaData() : null;
114+
}
110115
}

databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IMetaschemaData.java renamed to core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaData.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@
2424
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
2525
*/
2626

27-
package gov.nist.secauto.metaschema.databind.model;
27+
package gov.nist.secauto.metaschema.core.model;
2828

29-
public interface IMetaschemaData {
30-
int getLine();
31-
32-
int getColumn();
33-
34-
long getCharOffset();
35-
36-
long getByteOffset();
29+
public interface IMetaschemaData extends IResourceLocation {
30+
// no additional methods
3731
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Portions of this software was developed by employees of the National Institute
3+
* of Standards and Technology (NIST), an agency of the Federal Government and is
4+
* being made available as a public service. Pursuant to title 17 United States
5+
* Code Section 105, works of NIST employees are not subject to copyright
6+
* protection in the United States. This software may be subject to foreign
7+
* copyright. Permission in the United States and in foreign countries, to the
8+
* extent that NIST may hold copyright, to use, copy, modify, create derivative
9+
* works, and distribute this software and its documentation without fee is hereby
10+
* granted on a non-exclusive basis, provided that this notice and disclaimer
11+
* of warranty appears in all copies.
12+
*
13+
* THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
14+
* EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
15+
* THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
17+
* INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
18+
* SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
19+
* SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
20+
* INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
21+
* OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
22+
* CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
23+
* PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
24+
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
25+
*/
26+
27+
package gov.nist.secauto.metaschema.core.model;
28+
29+
public interface IResourceLocation {
30+
/**
31+
* Get the line for a location within a resource.
32+
*
33+
* @return the line number or {@code -1} if unknown
34+
*/
35+
int getLine();
36+
37+
/**
38+
* Get the line column for a location within a resource.
39+
*
40+
* @return the column number or {@code -1} if unknown
41+
*/
42+
int getColumn();
43+
44+
long getCharOffset();
45+
46+
long getByteOffset();
47+
}

core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ protected String newMatchDatatypeViolationMessage(
261261
*/
262262
@SuppressWarnings("null")
263263
@NonNull
264-
protected CharSequence newExpectViolationMessage(
264+
protected String newExpectViolationMessage(
265265
@NonNull IExpectConstraint constraint,
266266
@SuppressWarnings("unused") @NonNull INodeItem node,
267267
@NonNull INodeItem target,
268268
@NonNull DynamicContext dynamicContext) {
269-
CharSequence message;
269+
String message;
270270
if (constraint.getMessage() != null) {
271-
message = constraint.generateMessage(target, dynamicContext);
271+
message = constraint.generateMessage(target, dynamicContext).toString();
272272
} else {
273273
message = String.format("Expect constraint '%s' did not match the data at path '%s'",
274274
constraint.getTest(),
@@ -289,7 +289,7 @@ protected CharSequence newExpectViolationMessage(
289289
*/
290290
@SuppressWarnings("null")
291291
@NonNull
292-
protected CharSequence newAllowedValuesViolationMessage(
292+
protected String newAllowedValuesViolationMessage(
293293
@NonNull List<IAllowedValuesConstraint> constraints,
294294
@NonNull INodeItem target) {
295295

@@ -318,7 +318,7 @@ protected CharSequence newAllowedValuesViolationMessage(
318318
*/
319319
@SuppressWarnings("null")
320320
@NonNull
321-
protected CharSequence newIndexDuplicateViolationMessage(
321+
protected String newIndexDuplicateViolationMessage(
322322
@NonNull IIndexConstraint constraint,
323323
@NonNull INodeItem node) {
324324
return String.format("Duplicate index named '%s' found at path '%s'",
@@ -342,7 +342,7 @@ protected CharSequence newIndexDuplicateViolationMessage(
342342
*/
343343
@SuppressWarnings("null")
344344
@NonNull
345-
protected CharSequence newIndexMissMessage(
345+
protected String newIndexMissMessage(
346346
@NonNull IIndexHasKeyConstraint constraint,
347347
@NonNull INodeItem node,
348348
@NonNull INodeItem target,
@@ -372,7 +372,7 @@ protected CharSequence newIndexMissMessage(
372372
*/
373373
@SuppressWarnings("null")
374374
@NonNull
375-
protected CharSequence newGenericValidationViolationMessage(
375+
protected String newGenericValidationViolationMessage(
376376
@NonNull IConstraint constraint,
377377
@NonNull INodeItem node,
378378
@NonNull INodeItem target,

0 commit comments

Comments
 (0)