Skip to content

Commit

Permalink
Updated existing implementation based on changes to the metaschema-co…
Browse files Browse the repository at this point in the history
…re and metaschema-databind modules.
  • Loading branch information
david-waltermire committed Aug 4, 2023
1 parent f47aa8a commit a316ea2
Show file tree
Hide file tree
Showing 63 changed files with 773 additions and 632 deletions.
73 changes: 43 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -27,8 +29,8 @@
<url>https://github.com/usnistgov/liboscal-java</url>
<connection>scm:git:git@github.com:usnistgov/liboscal-java.git</connection>
<developerConnection>scm:git:git@github.com:usnistgov/liboscal-java.git</developerConnection>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>

<distributionManagement>
<snapshotRepository>
Expand Down Expand Up @@ -122,7 +124,7 @@
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<dependency.metaschema-framework.version>0.12.0</dependency.metaschema-framework.version>
<dependency.metaschema-framework.version>1.0.0-SNAPSHOT</dependency.metaschema-framework.version>

<dependency.auto-service.version>1.0.1</dependency.auto-service.version>
<dependency.commons-lang3.version>3.13.0</dependency.commons-lang3.version>
Expand All @@ -135,7 +137,7 @@
<dependency.xmlresolver.version>4.6.0</dependency.xmlresolver.version>

<plugin.cyclonedx.version>2.7.3</plugin.cyclonedx.version>
<plugin.maven-toolchains.version>3.1.0</plugin.maven-toolchains.version>
<plugin.maven-toolchains.version>3.1.0</plugin.maven-toolchains.version>

<cyclonedx.schema.version>1.3</cyclonedx.schema.version>
<oscal-content.commit>main</oscal-content.commit>
Expand Down Expand Up @@ -203,7 +205,7 @@
<dependencies>
<dependency>
<groupId>gov.nist.secauto.metaschema</groupId>
<artifactId>metaschema-java-binding</artifactId>
<artifactId>metaschema-databind</artifactId>
<version>${dependency.metaschema-framework.version}</version>
</dependency>

Expand Down Expand Up @@ -307,26 +309,26 @@
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>${plugin.maven-toolchains.version}</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>11</version>
<vendor>temurin</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>${plugin.maven-toolchains.version}</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>11</version>
<vendor>temurin</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
Expand Down Expand Up @@ -378,13 +380,24 @@
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<sourceDirectory>
${project.build.testSourceDirectory}</sourceDirectory>
</sourceDirectories>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package gov.nist.secauto.oscal.lib;

import gov.nist.secauto.metaschema.model.common.util.IVersionInfo;
import gov.nist.secauto.metaschema.core.util.IVersionInfo;

public final class LibOscalVersion implements IVersionInfo {
public static final String NAME = "liboscal-java";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package gov.nist.secauto.oscal.lib;

import gov.nist.secauto.metaschema.model.common.util.IVersionInfo;
import gov.nist.secauto.metaschema.core.util.IVersionInfo;

public final class OscalVersion implements IVersionInfo {
public static final String NAME = "oscal";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import gov.nist.secauto.metaschema.binding.DefaultBindingContext;
import gov.nist.secauto.metaschema.binding.IBindingMatcher;
import gov.nist.secauto.metaschema.model.common.constraint.IConstraintSet;
import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet;
import gov.nist.secauto.oscal.lib.model.AssessmentPlan;
import gov.nist.secauto.oscal.lib.model.AssessmentResults;
import gov.nist.secauto.oscal.lib.model.Catalog;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;

import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.model.BackMatter.Resource;
import gov.nist.secauto.oscal.lib.model.BackMatter.Resource.Base64;
import gov.nist.secauto.oscal.lib.model.BackMatter.Resource.Rlink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@

package gov.nist.secauto.oscal.lib.metapath.function.library;

import gov.nist.secauto.metaschema.model.common.metapath.DynamicContext;
import gov.nist.secauto.metaschema.model.common.metapath.ISequence;
import gov.nist.secauto.metaschema.model.common.metapath.MetapathException;
import gov.nist.secauto.metaschema.model.common.metapath.function.FunctionUtils;
import gov.nist.secauto.metaschema.model.common.metapath.function.IArgument;
import gov.nist.secauto.metaschema.model.common.metapath.function.IFunction;
import gov.nist.secauto.metaschema.model.common.metapath.function.InvalidTypeFunctionException;
import gov.nist.secauto.metaschema.model.common.metapath.item.IBooleanItem;
import gov.nist.secauto.metaschema.model.common.metapath.item.IDefinitionNodeItem;
import gov.nist.secauto.metaschema.model.common.metapath.item.IItem;
import gov.nist.secauto.metaschema.model.common.metapath.item.INodeItem;
import gov.nist.secauto.metaschema.model.common.metapath.item.IStringItem;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
import gov.nist.secauto.metaschema.core.metapath.ISequence;
import gov.nist.secauto.metaschema.core.metapath.MetapathException;
import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils;
import gov.nist.secauto.metaschema.core.metapath.function.IArgument;
import gov.nist.secauto.metaschema.core.metapath.function.IFunction;
import gov.nist.secauto.metaschema.core.metapath.function.InvalidTypeFunctionException;
import gov.nist.secauto.metaschema.core.metapath.item.IItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.model.AssessmentPart;
import gov.nist.secauto.oscal.lib.model.ControlPart;
import gov.nist.secauto.oscal.lib.model.Property;
Expand Down Expand Up @@ -72,7 +71,7 @@ public final class HasOscalNamespace {
.name("has-oscal-namespace")
.argument(IArgument.newBuilder()
.name("propOrPart")
.type(IDefinitionNodeItem.class)
.type(IAssemblyNodeItem.class)
.one()
.build())
.argument(IArgument.newBuilder()
Expand Down Expand Up @@ -101,19 +100,16 @@ public static ISequence<?> executeOneArg(
@NonNull IFunction function,
@NonNull List<ISequence<?>> arguments,
@NonNull DynamicContext dynamicContext,
INodeItem focus) {
INodeItem node = focus;
if (node == null) {
return ISequence.empty();
}

IItem focus) {
assert arguments.size() == 1;
ISequence<? extends IStringItem> namespaceArgs = FunctionUtils.asType(
ObjectUtils.notNull(arguments.get(0)));

if (namespaceArgs.isEmpty()) {
return ISequence.empty();
}

IAssemblyNodeItem node = FunctionUtils.requireType(IAssemblyNodeItem.class, focus);
return ISequence.of(hasNamespace(FunctionUtils.asType(node), namespaceArgs));
}

Expand All @@ -125,29 +121,27 @@ public static ISequence<?> executeTwoArg(
@NonNull IFunction function,
@NonNull List<ISequence<?>> arguments,
@NonNull DynamicContext dynamicContext,
INodeItem focus) {
ISequence<? extends IDefinitionNodeItem> nodeSequence = FunctionUtils.asType(
ObjectUtils.notNull(arguments.get(0)));

IItem node = FunctionUtils.getFirstItem(nodeSequence, true);
if (node == null) {
return ISequence.empty();
}

IItem focus) {
assert arguments.size() == 2;

ISequence<? extends IStringItem> namespaceArgs = FunctionUtils.asType(
ObjectUtils.notNull(arguments.get(1)));
if (namespaceArgs.isEmpty()) {
return ISequence.empty();
}

return ISequence.of(hasNamespace(FunctionUtils.asType(node), namespaceArgs));
ISequence<? extends IAssemblyNodeItem> nodeSequence = FunctionUtils.asType(
ObjectUtils.notNull(arguments.get(0)));

// always not null, since the first item is required
IAssemblyNodeItem node = FunctionUtils.requireFirstItem(nodeSequence, true);
return ISequence.of(hasNamespace(node, namespaceArgs));
}

@SuppressWarnings("PMD.LinguisticNaming") // false positive
@NonNull
public static IBooleanItem hasNamespace(
@NonNull IDefinitionNodeItem propOrPart,
@NonNull IAssemblyNodeItem propOrPart,
@NonNull ISequence<? extends IStringItem> namespaces)
throws MetapathException {
Object propOrPartObject = propOrPart.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

import com.google.auto.service.AutoService;

import gov.nist.secauto.metaschema.model.common.metapath.function.FunctionLibrary;
import gov.nist.secauto.metaschema.model.common.metapath.function.IFunctionLibrary;
import gov.nist.secauto.metaschema.core.metapath.function.FunctionLibrary;
import gov.nist.secauto.metaschema.core.metapath.function.IFunctionLibrary;

@AutoService(IFunctionLibrary.class)
public class OscalFunctionLibrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@

package gov.nist.secauto.oscal.lib.metapath.function.library;

import gov.nist.secauto.metaschema.model.common.metapath.DynamicContext;
import gov.nist.secauto.metaschema.model.common.metapath.ISequence;
import gov.nist.secauto.metaschema.model.common.metapath.MetapathException;
import gov.nist.secauto.metaschema.model.common.metapath.function.FunctionUtils;
import gov.nist.secauto.metaschema.model.common.metapath.function.IArgument;
import gov.nist.secauto.metaschema.model.common.metapath.function.IFunction;
import gov.nist.secauto.metaschema.model.common.metapath.item.IDocumentNodeItem;
import gov.nist.secauto.metaschema.model.common.metapath.item.IItem;
import gov.nist.secauto.metaschema.model.common.metapath.item.INodeItem;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
import gov.nist.secauto.metaschema.core.metapath.ISequence;
import gov.nist.secauto.metaschema.core.metapath.MetapathException;
import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils;
import gov.nist.secauto.metaschema.core.metapath.function.IArgument;
import gov.nist.secauto.metaschema.core.metapath.function.IFunction;
import gov.nist.secauto.metaschema.core.metapath.item.IItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.model.Catalog;
import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolutionException;
import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolver;
Expand Down Expand Up @@ -86,13 +86,12 @@ public static ISequence<?> executeNoArg(
@NonNull IFunction function,
@NonNull List<ISequence<?>> arguments,
@NonNull DynamicContext dynamicContext,
INodeItem focus) {
IItem focus) {

INodeItem item = focus;
if (item == null) {
if (focus == null) {
return ISequence.empty();
}
return ISequence.of(resolveProfile(FunctionUtils.asType(item), dynamicContext));
return ISequence.of(resolveProfile(FunctionUtils.asType(focus), dynamicContext));
}

@SuppressWarnings({ "unused",
Expand All @@ -103,7 +102,7 @@ public static ISequence<?> executeOneArg(
@NonNull IFunction function,
@NonNull List<ISequence<?>> arguments,
@NonNull DynamicContext dynamicContext,
INodeItem focus) {
IItem focus) {
ISequence<? extends IDocumentNodeItem> arg = FunctionUtils.asType(
ObjectUtils.notNull(arguments.get(0)));

Expand All @@ -118,7 +117,7 @@ public static ISequence<?> executeOneArg(
@NonNull
public static IDocumentNodeItem resolveProfile(@NonNull IDocumentNodeItem profile,
@NonNull DynamicContext dynamicContext) {
Object profileObject = profile.getValue();
Object profileObject = INodeItem.toValue(profile);

IDocumentNodeItem retval;
if (profileObject instanceof Catalog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

package gov.nist.secauto.oscal.lib.model.control;

import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.model.common.util.CollectionUtil;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.model.Link;
import gov.nist.secauto.oscal.lib.model.Parameter;
import gov.nist.secauto.oscal.lib.model.ParameterConstraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

package gov.nist.secauto.oscal.lib.model.control;

import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.model.common.datatype.markup.flexmark.InsertAnchorExtension.InsertAnchorNode;
import gov.nist.secauto.metaschema.model.common.util.CollectionUtil;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.InsertAnchorExtension.InsertAnchorNode;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.model.ControlPart;
import gov.nist.secauto.oscal.lib.model.Link;
import gov.nist.secauto.oscal.lib.model.Property;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

package gov.nist.secauto.oscal.lib.model.control;

import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.model.common.datatype.markup.flexmark.InsertAnchorExtension.InsertAnchorNode;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.InsertAnchorExtension.InsertAnchorNode;
import gov.nist.secauto.oscal.lib.model.ControlPart;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

package gov.nist.secauto.oscal.lib.model.control.catalog;

import gov.nist.secauto.metaschema.model.common.util.CollectionUtil;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.model.AbstractOscalInstance;

import java.util.stream.Stream;
Expand Down
Loading

0 comments on commit a316ea2

Please sign in to comment.