Skip to content

Commit 006858c

Browse files
- Refactored package names to better organize binding related code and to distinguish provided model bindings.
- Added support for capturing parsed location information in bound objects. This will be useful for producing context for validation results. - Fixed bugs causing the ordering of generated classes to be chaotic. Also fixed bugs causing binding configurations to match based on minor URI differences caused by inconsistent behavior between file and path URI productions. - Updated Metaschema module binding to incorporate latest module changes. - Added support for exposing parse locations in validation results. - Added support for producing Static Analysis Results Interchange Format (SARIF) results based on schema and constraint validation results. - Added SARIF CLI output option to validate command. - Added support for including rules and artifact information in SARIF results. SARIF files now work on commonly available viewers. - Added constraint formal-name and description to SARIF output, allowing human readers to better understand why the result was produced. - Added a GUID to SARIF output for each rule. - Adjusted constraint result production to allow for pass results to be produced, which supports producing SARIF result that include both pass and fail statuses using an API-level configuration. - Added methods to handle making URIs relative to another URI. - Ensured proper handling of Metapath errors during validation. Resolves usnistgov/oscal-cli#292 - Fixed compile and PMD warnings. - Added some Javadocs.
1 parent 43f6f18 commit 006858c

File tree

250 files changed

+5726
-2599
lines changed

Some content is hidden

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

250 files changed

+5726
-2599
lines changed

cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/AbstractExitStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public void generateMessage(boolean showStackTrace) {
106106

107107
if (message != null && !message.isEmpty()) {
108108
logBuilder.log(message);
109-
} else if (throwable != null && showStackTrace) {
109+
} else if (showStackTrace && throwable != null) {
110110
// log the throwable
111111
logBuilder.log();
112-
}
112+
} // otherwise there is nothing to log
113113
}
114114
}
115115

cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ public class CLIProcessor {
110110
SHOW_STACK_TRACE_OPTION,
111111
VERSION_OPTION);
112112

113+
public static final String COMMAND_VERSION = "http://csrc.nist.gov/ns/metaschema-java/cli/command-version";
114+
113115
@NonNull
114116
private final List<ICommand> commands = new LinkedList<>();
115117
@NonNull
116118
private final String exec;
117119
@NonNull
118-
private final List<IVersionInfo> versionInfos;
120+
private final Map<String, IVersionInfo> versionInfos;
119121

120122
public static void main(String... args) {
121123
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
@@ -130,10 +132,10 @@ public static void main(String... args) {
130132

131133
@SuppressWarnings("null")
132134
public CLIProcessor(@NonNull String exec) {
133-
this(exec, List.of());
135+
this(exec, Map.of());
134136
}
135137

136-
public CLIProcessor(@NonNull String exec, @NonNull List<IVersionInfo> versionInfos) {
138+
public CLIProcessor(@NonNull String exec, @NonNull Map<String, IVersionInfo> versionInfos) {
137139
this.exec = exec;
138140
this.versionInfos = versionInfos;
139141
AnsiConsole.systemInstall();
@@ -155,7 +157,7 @@ public String getExec() {
155157
* @return the versionInfo
156158
*/
157159
@NonNull
158-
public List<IVersionInfo> getVersionInfos() {
160+
public Map<String, IVersionInfo> getVersionInfos() {
159161
return versionInfos;
160162
}
161163

@@ -207,7 +209,6 @@ private static void handleNoColor() {
207209
AnsiConsole.systemUninstall();
208210
}
209211

210-
@SuppressWarnings("resource")
211212
public static void handleQuiet() {
212213
LoggerContext ctx = (LoggerContext) LogManager.getContext(false); // NOPMD not closable here
213214
Configuration config = ctx.getConfiguration();
@@ -221,7 +222,7 @@ public static void handleQuiet() {
221222

222223
protected void showVersion() {
223224
@SuppressWarnings("resource") PrintStream out = AnsiConsole.out(); // NOPMD - not owner
224-
getVersionInfos().stream().forEach(info -> {
225+
getVersionInfos().values().stream().forEach(info -> {
225226
out.println(ansi()
226227
.bold().a(info.getName()).boldOff()
227228
.a(" ")
@@ -309,6 +310,11 @@ public CallingContext(@NonNull List<String> args) {
309310
this.extraArgs = extraArgs;
310311
}
311312

313+
@NonNull
314+
public CLIProcessor getCLIProcessor() {
315+
return CLIProcessor.this;
316+
}
317+
312318
@Nullable
313319
public ICommand getTargetCommand() {
314320
return calledCommands.peekLast();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private static Stream<Class<? extends IItem>> getItemInterfaces(@NonNull Class<?
130130

131131
Class<?>[] interfaces = clazz.getInterfaces();
132132
if (interfaces.length > 0) {
133-
retval = Stream.concat(retval, Arrays.stream(interfaces).flatMap(intf -> getItemInterfaces(intf)));
133+
retval = Stream.concat(retval, Arrays.stream(interfaces).flatMap(TypeSystem::getItemInterfaces));
134134
}
135135

136136
return retval;

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
3131
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
3232

33-
import java.net.URI;
34-
3533
import edu.umd.cs.findbugs.annotations.NonNull;
3634

3735
/**
@@ -72,11 +70,6 @@ public IFlagInstance getInstance() {
7270
return parent;
7371
}
7472

75-
@Override
76-
public URI getBaseUri() {
77-
return getDefinition().getContainingModule().getLocation();
78-
}
79-
8073
@Override
8174
public String toString() {
8275
StringBuilder builder = new StringBuilder()

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
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public T load(@NonNull URI resource) throws MetaschemaException, IOException {
9292
@Override
9393
@NonNull
9494
public T load(@NonNull Path path) throws MetaschemaException, IOException {
95-
return loadInternal(ObjectUtils.notNull(path.toAbsolutePath().normalize().toUri()), new LinkedList<>());
95+
// use toURL to normalize the URI
96+
return load(ObjectUtils.notNull(path.toAbsolutePath().normalize().toUri().toURL()));
9697
}
9798

9899
/**
@@ -153,7 +154,7 @@ protected T loadInternal(@NonNull URI resource, @NonNull Deque<URI> visitedResou
153154

154155
T retval = cache.get(resource);
155156
if (retval == null) {
156-
LOGGER.info("Loading module '{}'", resource);
157+
LOGGER.info("Loading '{}'", resource);
157158

158159
try {
159160
visitedResources.push(resource);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
import edu.umd.cs.findbugs.annotations.Nullable;
30+
31+
public interface IBoundObject {
32+
@Nullable
33+
IMetaschemaData getMetaschemaData();
34+
}

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
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 IMetaschemaData extends IResourceLocation {
30+
// no additional methods
31+
}
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)