Skip to content

Commit

Permalink
Updated Metaschema binding to latest Metaschema module model. Added s…
Browse files Browse the repository at this point in the history
…upport 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.
  • Loading branch information
david-waltermire committed Jun 19, 2024
1 parent 67ab0b6 commit 08982f6
Show file tree
Hide file tree
Showing 165 changed files with 1,751 additions and 438 deletions.
2 changes: 1 addition & 1 deletion core/metaschema
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package gov.nist.secauto.metaschema.core.metapath.item.node;

import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.net.URI;
Expand Down Expand Up @@ -80,4 +81,9 @@ public ModelContainer getModel() {
public Object getValue() {
return getRootAssemblyNodeItem().getValue();
}

@Override
public IResourceLocation getLocation() {
return getRootAssemblyNodeItem().getLocation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@

import gov.nist.secauto.metaschema.core.model.IDefinition;
import gov.nist.secauto.metaschema.core.model.INamedInstance;
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.net.URI;

import javax.xml.namespace.QName;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

public interface IDefinitionNodeItem<D extends IDefinition, I extends INamedInstance> extends INodeItem {
/**
Expand Down Expand Up @@ -69,4 +71,11 @@ default URI getNamespace() {
* @return the instance of the segment, or {@code null} if it doesn't have one
*/
I getInstance();

@Override
@Nullable
default IResourceLocation getLocation() {
Object value = getValue();
return value == null ? null : getDefinition().getLocation(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter;
import gov.nist.secauto.metaschema.core.metapath.format.IPathSegment;
import gov.nist.secauto.metaschema.core.metapath.item.IItem;
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.net.URI;
Expand Down Expand Up @@ -300,4 +301,7 @@ default Stream<? extends IFlagNodeItem> flags() {
default Stream<? extends IModelNodeItem<?, ?>> modelItems() {
return getModelItems().stream().flatMap(Collection::stream);
}

@Nullable
IResourceLocation getLocation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package gov.nist.secauto.metaschema.core.metapath.item.node;

import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.model.IResourceLocation;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.net.URI;
Expand Down Expand Up @@ -65,4 +66,9 @@ public ModelContainer getModel() {
return model.get();
}

@Override
public IResourceLocation getLocation() {
// no location
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/

package gov.nist.secauto.metaschema.databind.model;
package gov.nist.secauto.metaschema.core.model;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.xml.namespace.QName;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

public interface IDefinition extends INamedModelElement, IAttributable, IFeatureValueConstrained {

Expand Down Expand Up @@ -107,4 +108,8 @@ default String toCoordinates() {
hashCode());
}

@Nullable
default IResourceLocation getLocation(@NonNull Object itemValue) {
return itemValue instanceof IBoundObject ? ((IBoundObject) itemValue).getMetaschemaData() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/

package gov.nist.secauto.metaschema.databind.model;
package gov.nist.secauto.metaschema.core.model;

public interface IMetaschemaData {
int getLine();

int getColumn();

long getCharOffset();

long getByteOffset();
public interface IMetaschemaData extends IResourceLocation {
// no additional methods
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Portions of this software was developed by employees of the National Institute
* of Standards and Technology (NIST), an agency of the Federal Government and is
* being made available as a public service. Pursuant to title 17 United States
* Code Section 105, works of NIST employees are not subject to copyright
* protection in the United States. This software may be subject to foreign
* copyright. Permission in the United States and in foreign countries, to the
* extent that NIST may hold copyright, to use, copy, modify, create derivative
* works, and distribute this software and its documentation without fee is hereby
* granted on a non-exclusive basis, provided that this notice and disclaimer
* of warranty appears in all copies.
*
* THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
* EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
* THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
* INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
* SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
* SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
* INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
* OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
* CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
* PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/

package gov.nist.secauto.metaschema.core.model;

public interface IResourceLocation {
/**
* Get the line for a location within a resource.
*
* @return the line number or {@code -1} if unknown
*/
int getLine();

/**
* Get the line column for a location within a resource.
*
* @return the column number or {@code -1} if unknown
*/
int getColumn();

long getCharOffset();

long getByteOffset();
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ protected String newMatchDatatypeViolationMessage(
*/
@SuppressWarnings("null")
@NonNull
protected CharSequence newExpectViolationMessage(
protected String newExpectViolationMessage(
@NonNull IExpectConstraint constraint,
@SuppressWarnings("unused") @NonNull INodeItem node,
@NonNull INodeItem target,
@NonNull DynamicContext dynamicContext) {
CharSequence message;
String message;
if (constraint.getMessage() != null) {
message = constraint.generateMessage(target, dynamicContext);
message = constraint.generateMessage(target, dynamicContext).toString();
} else {
message = String.format("Expect constraint '%s' did not match the data at path '%s'",
constraint.getTest(),
Expand All @@ -289,7 +289,7 @@ protected CharSequence newExpectViolationMessage(
*/
@SuppressWarnings("null")
@NonNull
protected CharSequence newAllowedValuesViolationMessage(
protected String newAllowedValuesViolationMessage(
@NonNull List<IAllowedValuesConstraint> constraints,
@NonNull INodeItem target) {

Expand Down Expand Up @@ -318,7 +318,7 @@ protected CharSequence newAllowedValuesViolationMessage(
*/
@SuppressWarnings("null")
@NonNull
protected CharSequence newIndexDuplicateViolationMessage(
protected String newIndexDuplicateViolationMessage(
@NonNull IIndexConstraint constraint,
@NonNull INodeItem node) {
return String.format("Duplicate index named '%s' found at path '%s'",
Expand All @@ -342,7 +342,7 @@ protected CharSequence newIndexDuplicateViolationMessage(
*/
@SuppressWarnings("null")
@NonNull
protected CharSequence newIndexMissMessage(
protected String newIndexMissMessage(
@NonNull IIndexHasKeyConstraint constraint,
@NonNull INodeItem node,
@NonNull INodeItem target,
Expand Down Expand Up @@ -372,7 +372,7 @@ protected CharSequence newIndexMissMessage(
*/
@SuppressWarnings("null")
@NonNull
protected CharSequence newGenericValidationViolationMessage(
protected String newGenericValidationViolationMessage(
@NonNull IConstraint constraint,
@NonNull INodeItem node,
@NonNull INodeItem target,
Expand Down
Loading

0 comments on commit 08982f6

Please sign in to comment.