diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..400c729f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# To list all file extensions: +# git ls-files | awk -F . {'print $NF'}|sort -u +# +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto diff --git a/pom.xml b/pom.xml index 7b92afc9..caf038c1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,12 @@ - + 4.0.0 gov.nist.secauto oss-parent - 27 + 28-SNAPSHOT gov.nist.secauto.oscal.tools.oscal-cli cli-core @@ -78,8 +80,8 @@ - 0.12.2 - 3.0.3 + 1.0.0-M2-SNAPSHOT + 3.0.4-SNAPSHOT https://pages.nist.gov/metaschema-java/ @@ -109,16 +111,23 @@ 1.1.1 - 1.5.0 - 2.15.1 + 1.7.0 + 2.16.1 1.14.4 + 2.4.1 3.21.0 - 2.20.0 - 4.7.3 + 20240303 + 2.23.1 + 7.1.0 + 4.8.3 12.4 - 6.0.2 + 5.2.0 + 5.2.2 4.2 + 3.1.0 + 3.22.0 + 4.8.4.0 @@ -215,11 +224,22 @@ data ${dependency.xmlresolver.version} + + org.apache.xmlbeans + xmlbeans + ${dependency.xmlbeans.version} + com.github.erosb everit-json-schema ${dependency.everit-json.version} + + + org.json + json + ${dependency.json.version} + com.github.spotbugs spotbugs-annotations @@ -228,12 +248,7 @@ org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine + junit-jupiter test @@ -260,6 +275,27 @@ + + org.apache.maven.plugins + maven-toolchains-plugin + ${plugin.maven-toolchains.version} + + + + toolchain + + + + + + + 11 + temurin + + + + + org.apache.maven.plugins maven-site-plugin @@ -282,13 +318,50 @@ com.github.spotbugs spotbugs-maven-plugin + ${plugin.spotbugs.version} spotbugs-exclude.xml + + org.apache.maven.plugins + maven-pmd-plugin + ${plugin.pmd.version} + + + net.sourceforge.pmd + pmd-core + ${dependency.pmd.version} + + + net.sourceforge.pmd + pmd-java + ${dependency.pmd.version} + + + + + pmd-verify + + check + + + 2 + + true + true + sarif + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + io.github.git-commit-id git-commit-id-maven-plugin @@ -428,9 +501,8 @@ LICENSE-THIRD-PARTY.txt The Apache Software License, - Version 2.0|Apache - License, Version 2.0|Apache Public License - 2.0 + Version 2.0|Apache License, Version + 2.0|Apache Public License 2.0 diff --git a/src/main/assembly/bin.xml b/src/main/assembly/bin.xml index 4e60d186..e4cbca6b 100644 --- a/src/main/assembly/bin.xml +++ b/src/main/assembly/bin.xml @@ -14,6 +14,9 @@ /lib ${artifact.groupId}.${artifact.artifactId}-${artifact.version}.${artifact.extension} true + + org.jetbrains:annotations + diff --git a/src/main/java-templates/gov/nist/secauto/oscal/tools/cli/core/OscalCliVersion.java b/src/main/java-templates/gov/nist/secauto/oscal/tools/cli/core/OscalCliVersion.java index a447b8ca..7d1af53b 100644 --- a/src/main/java-templates/gov/nist/secauto/oscal/tools/cli/core/OscalCliVersion.java +++ b/src/main/java-templates/gov/nist/secauto/oscal/tools/cli/core/OscalCliVersion.java @@ -26,7 +26,7 @@ package gov.nist.secauto.oscal.tools.cli.core; -import gov.nist.secauto.metaschema.model.common.util.IVersionInfo; +import gov.nist.secauto.metaschema.core.util.IVersionInfo; public class OscalCliVersion implements IVersionInfo { diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java index 1b10921d..fecc8351 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java @@ -28,10 +28,10 @@ import gov.nist.secauto.metaschema.cli.processor.CLIProcessor; import gov.nist.secauto.metaschema.cli.processor.ExitStatus; -import gov.nist.secauto.metaschema.model.MetaschemaVersion; -import gov.nist.secauto.metaschema.model.common.util.IVersionInfo; -import gov.nist.secauto.metaschema.model.common.util.MetaschemaJavaVersion; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; +import gov.nist.secauto.metaschema.core.MetaschemaJavaVersion; +import gov.nist.secauto.metaschema.core.model.MetaschemaVersion; +import gov.nist.secauto.metaschema.core.util.IVersionInfo; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.LibOscalVersion; import gov.nist.secauto.oscal.lib.OscalVersion; import gov.nist.secauto.oscal.tools.cli.core.commands.assessmentplan.AssessmentPlanCommand; diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderSubcommand.java index 69242fcb..87ed59a7 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderSubcommand.java @@ -35,7 +35,7 @@ import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument; import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument; import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java index 2824d392..6b58b50d 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java @@ -26,16 +26,17 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.assessmentplan; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; -import gov.nist.secauto.metaschema.model.common.util.CollectionUtil; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; -import gov.nist.secauto.metaschema.model.common.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.util.JsonUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractOscalValidationSubcommand; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; @@ -52,16 +53,16 @@ public String getDescription() { protected List getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( - ObjectUtils.requireNonNull( - XmlUtil.getStreamSource( - OscalBindingContext.class.getResource("/schema/xml/oscal-ap_schema.xsd")))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + OscalBindingContext.class.getResource("/schema/xml/oscal-ap_schema.xsd")))); return CollectionUtil.unmodifiableList(retval); } @Override - protected JSONObject getOscalJsonSchema() { - return JsonSchemaContentValidator.toJsonObject( - ObjectUtils.requireNonNull( - OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ap_schema.json"))); + protected JSONObject getOscalJsonSchema() throws IOException { + try (InputStream is = ObjectUtils.requireNonNull( + OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ap_schema.json"))) { + return JsonUtil.toJsonObject(is); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java index fb6be566..44d11e53 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java @@ -26,16 +26,17 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.assessmentresults; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; -import gov.nist.secauto.metaschema.model.common.util.CollectionUtil; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; -import gov.nist.secauto.metaschema.model.common.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.util.JsonUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractOscalValidationSubcommand; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; @@ -52,16 +53,16 @@ public String getDescription() { protected List getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( - ObjectUtils.requireNonNull( - XmlUtil.getStreamSource( - OscalBindingContext.class.getResource("/schema/xml/oscal-ar_schema.xsd")))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + OscalBindingContext.class.getResource("/schema/xml/oscal-ar_schema.xsd")))); return CollectionUtil.unmodifiableList(retval); } @Override - protected JSONObject getOscalJsonSchema() { - return JsonSchemaContentValidator.toJsonObject( - ObjectUtils.requireNonNull( - OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ar_schema.json"))); + protected JSONObject getOscalJsonSchema() throws IOException { + try (InputStream is = ObjectUtils.requireNonNull( + OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ar_schema.json"))) { + return JsonUtil.toJsonObject(is); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java index f922ebc4..54c19f12 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java @@ -26,16 +26,17 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.catalog; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; -import gov.nist.secauto.metaschema.model.common.util.CollectionUtil; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; -import gov.nist.secauto.metaschema.model.common.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.util.JsonUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractOscalValidationSubcommand; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; @@ -52,15 +53,16 @@ public String getDescription() { protected List getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( - ObjectUtils.requireNonNull( - XmlUtil.getStreamSource(OscalBindingContext.class.getResource("/schema/xml/oscal-catalog_schema.xsd")))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + OscalBindingContext.class.getResource("/schema/xml/oscal-catalog_schema.xsd")))); return CollectionUtil.unmodifiableList(retval); } @Override - protected JSONObject getOscalJsonSchema() { - return JsonSchemaContentValidator.toJsonObject( - ObjectUtils.requireNonNull( - OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-catalog_schema.json"))); + protected JSONObject getOscalJsonSchema() throws IOException { + try (InputStream is = ObjectUtils.requireNonNull( + OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-catalog_schema.json"))) { + return JsonUtil.toJsonObject(is); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java index 6dc51d6e..d732b038 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java @@ -26,16 +26,17 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.componentdefinition; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; -import gov.nist.secauto.metaschema.model.common.util.CollectionUtil; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; -import gov.nist.secauto.metaschema.model.common.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.util.JsonUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractOscalValidationSubcommand; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; @@ -52,15 +53,16 @@ public String getDescription() { protected List getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( - ObjectUtils.requireNonNull( - XmlUtil.getStreamSource(OscalBindingContext.class.getResource("/schema/xml/oscal-component-definition_schema.xsd")))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + OscalBindingContext.class.getResource("/schema/xml/oscal-component-definition_schema.xsd")))); return CollectionUtil.unmodifiableList(retval); } @Override - protected JSONObject getOscalJsonSchema() { - return JsonSchemaContentValidator.toJsonObject( - ObjectUtils.requireNonNull( - OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-component-definition_schema.json"))); + protected JSONObject getOscalJsonSchema() throws IOException { + try (InputStream is = ObjectUtils.requireNonNull( + OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-component-definition_schema.json"))) { + return JsonUtil.toJsonObject(is); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/metaschema/MetaschemaCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/metaschema/MetaschemaCommand.java index f86918a8..9c1f0a30 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/metaschema/MetaschemaCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/metaschema/MetaschemaCommand.java @@ -28,9 +28,7 @@ import com.google.auto.service.AutoService; -import gov.nist.secauto.metaschema.cli.commands.GenerateSchemaCommand; -import gov.nist.secauto.metaschema.cli.commands.ValidateContentWithMetaschemaCommand; -import gov.nist.secauto.metaschema.cli.commands.ValidateMetaschemaCommand; +import gov.nist.secauto.metaschema.cli.commands.MetaschemaCommands; import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; import gov.nist.secauto.metaschema.cli.processor.command.ICommand; @@ -41,9 +39,7 @@ public class MetaschemaCommand public MetaschemaCommand() { super(true); - addCommandHandler(new GenerateSchemaCommand()); - addCommandHandler(new ValidateMetaschemaCommand()); - addCommandHandler(new ValidateContentWithMetaschemaCommand()); + MetaschemaCommands.COMMANDS.forEach(this::addCommandHandler); } @Override @@ -53,6 +49,6 @@ public String getName() { @Override public String getDescription() { - return "Perform an operation on a Metaschema"; + return "Perform an operation on a Module"; } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalConvertSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalConvertSubcommand.java index 7d50542a..43b9f38a 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalConvertSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalConvertSubcommand.java @@ -26,10 +26,10 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.oscal; -import gov.nist.secauto.metaschema.binding.IBindingContext; import gov.nist.secauto.metaschema.cli.commands.AbstractConvertSubcommand; import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor; +import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.oscal.lib.OscalBindingContext; import org.apache.commons.cli.CommandLine; @@ -47,7 +47,7 @@ public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine c return new OscalCommandExecutor(callingContext, commandLine); } - private class OscalCommandExecutor + private final class OscalCommandExecutor extends AbstractConversionCommandExecutor { private OscalCommandExecutor( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalValidationSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalValidationSubcommand.java index 30c19513..ebc5c21b 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalValidationSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/oscal/AbstractOscalValidationSubcommand.java @@ -26,11 +26,13 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.oscal; -import gov.nist.secauto.metaschema.binding.IBindingContext; import gov.nist.secauto.metaschema.cli.commands.AbstractValidateContentCommand; import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor; -import gov.nist.secauto.metaschema.model.common.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.core.model.xml.ExternalConstraintsModulePostProcessor; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.oscal.lib.OscalBindingContext; import org.apache.commons.cli.CommandLine; @@ -51,14 +53,14 @@ public abstract class AbstractOscalValidationSubcommand protected abstract List getOscalXmlSchemas() throws IOException; @NonNull - protected abstract JSONObject getOscalJsonSchema(); + protected abstract JSONObject getOscalJsonSchema() throws IOException; @Override public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine) { return new OscalCommandExecutor(callingContext, commandLine); } - private class OscalCommandExecutor + private final class OscalCommandExecutor extends AbstractValidationCommandExecutor { private OscalCommandExecutor( @@ -69,7 +71,16 @@ private OscalCommandExecutor( @Override protected IBindingContext getBindingContext(@NonNull Set constraintSets) { - return constraintSets.isEmpty() ? OscalBindingContext.instance() : new OscalBindingContext(constraintSets); + IBindingContext retval; + if (constraintSets.isEmpty()) { + retval = OscalBindingContext.instance(); + } else { + ExternalConstraintsModulePostProcessor postProcessor + = new ExternalConstraintsModulePostProcessor(constraintSets); + + retval = new OscalBindingContext(CollectionUtil.singletonList(postProcessor)); + } + return retval; } @Override @@ -80,7 +91,7 @@ public List getXmlSchemas() throws IOException { @Override @NonNull - public JSONObject getJsonSchema() { + public JSONObject getJsonSchema() throws IOException { return getOscalJsonSchema(); } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java index a26c4091..a4df6c9c 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java @@ -26,16 +26,17 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.poam; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; -import gov.nist.secauto.metaschema.model.common.util.CollectionUtil; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; -import gov.nist.secauto.metaschema.model.common.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.util.JsonUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractOscalValidationSubcommand; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; @@ -52,17 +53,17 @@ public String getDescription() { @Override protected List getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); - retval - .add( - ObjectUtils.requireNonNull( - XmlUtil.getStreamSource(OscalBindingContext.class.getResource("/schema/xml/oscal-poam_schema.xsd")))); + retval.add( + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + OscalBindingContext.class.getResource("/schema/xml/oscal-poam_schema.xsd")))); return CollectionUtil.unmodifiableList(retval); } @Override - protected JSONObject getOscalJsonSchema() { - return JsonSchemaContentValidator.toJsonObject( - ObjectUtils.requireNonNull( - OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-poam_schema.json"))); + protected JSONObject getOscalJsonSchema() throws IOException { + try (InputStream is = ObjectUtils.requireNonNull( + OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-poam_schema.json"))) { + return JsonUtil.toJsonObject(is); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ResolveSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ResolveSubcommand.java index b455e73a..04916815 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ResolveSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ResolveSubcommand.java @@ -26,10 +26,6 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.profile; -import gov.nist.secauto.metaschema.binding.io.DeserializationFeature; -import gov.nist.secauto.metaschema.binding.io.Format; -import gov.nist.secauto.metaschema.binding.io.IBoundLoader; -import gov.nist.secauto.metaschema.binding.io.ISerializer; import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; import gov.nist.secauto.metaschema.cli.processor.ExitCode; import gov.nist.secauto.metaschema.cli.processor.ExitStatus; @@ -39,11 +35,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument; import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument; import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor; -import gov.nist.secauto.metaschema.model.common.metapath.DynamicContext; -import gov.nist.secauto.metaschema.model.common.metapath.StaticContext; -import gov.nist.secauto.metaschema.model.common.metapath.item.IDocumentNodeItem; -import gov.nist.secauto.metaschema.model.common.util.CustomCollectors; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; +import gov.nist.secauto.metaschema.core.metapath.DynamicContext; +import gov.nist.secauto.metaschema.core.metapath.StaticContext; +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.CustomCollectors; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.DeserializationFeature; +import gov.nist.secauto.metaschema.databind.io.Format; +import gov.nist.secauto.metaschema.databind.io.FormatDetector; +import gov.nist.secauto.metaschema.databind.io.IBoundLoader; +import gov.nist.secauto.metaschema.databind.io.ISerializer; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.lib.model.Profile; @@ -56,6 +58,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintStream; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; @@ -211,7 +214,8 @@ protected ExitStatus executeCommand( } else { // attempt to determine the format try { - asFormat = loader.detectFormat(ObjectUtils.notNull(source)); + FormatDetector.Result result = loader.detectFormat(ObjectUtils.notNull(source)); + asFormat = result.getFormat(); } catch (FileNotFoundException ex) { // this case was already checked for return ExitCode.IO_ERROR.exitMessage("The provided source file '" + source + "' does not exist."); @@ -227,6 +231,7 @@ protected ExitStatus executeCommand( } source = source.toAbsolutePath(); + assert source != null; Format toFormat; if (cmdLine.hasOption(TO_OPTION)) { @@ -264,49 +269,63 @@ protected ExitStatus executeCommand( IDocumentNodeItem document; try { - document = loader.loadAsNodeItem(asFormat, loader.toInputSource(ObjectUtils.notNull(source.toUri()))); + document = loader.loadAsNodeItem(asFormat, source); } catch (IOException ex) { return ExitCode.IO_ERROR.exit().withThrowable(ex); } Object object = document.getValue(); + if (object == null) { + return ExitCode.INVALID_ARGUMENTS.exitMessage("The target profile contained no data"); + } + if (object instanceof Catalog) { // this is a catalog - return ExitCode.INVALID_ARGUMENTS.exitMessage("The target file is already a catalog"); - } else if (object instanceof Profile) { - // this is a profile - StaticContext staticContext = new StaticContext(); - URI sourceUri = ObjectUtils.notNull(source.toUri()); - staticContext.setBaseUri(sourceUri); - DynamicContext dynamicContext = staticContext.newDynamicContext(); - dynamicContext.setDocumentLoader(loader); - ProfileResolver resolver = new ProfileResolver(); - resolver.setDynamicContext(dynamicContext); + return ExitCode.INVALID_ARGUMENTS.exitMessage("The target is already a catalog"); + } - IDocumentNodeItem resolvedProfile; - try { - resolvedProfile = resolver.resolve(document); - } catch (IOException | ProfileResolutionException ex) { - return ExitCode.PROCESSING_ERROR - .exitMessage( - String.format("Unable to resolve profile '%s'. %s", document.getDocumentUri(), ex.getMessage())) - .withThrowable(ex); - } + if (!(object instanceof Profile)) { + // this is something else + return ExitCode.INVALID_ARGUMENTS.exitMessage("The target is not a profile"); + } - // DefaultConstraintValidator validator = new DefaultConstraintValidator(dynamicContext); - // ((IBoundXdmNodeItem)resolvedProfile).validate(validator); - // validator.finalizeValidation(); + // this is a profile + URI sourceUri = ObjectUtils.notNull(source.toUri()); - ISerializer serializer - = OscalBindingContext.instance().newSerializer(toFormat, Catalog.class); - try { - if (destination == null) { - serializer.serialize((Catalog) resolvedProfile.getValue(), ObjectUtils.notNull(System.out)); - } else { - serializer.serialize((Catalog) resolvedProfile.getValue(), destination); - } - } catch (IOException ex) { - return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex); + DynamicContext dynamicContext = new DynamicContext( + StaticContext.builder() + .baseUri(sourceUri) + .defaultModelNamespace(document.getNamespace()) + .build()); + dynamicContext.setDocumentLoader(loader); + ProfileResolver resolver = new ProfileResolver(); + resolver.setDynamicContext(dynamicContext); + + IDocumentNodeItem resolvedProfile; + try { + resolvedProfile = resolver.resolve(document); + } catch (IOException | ProfileResolutionException ex) { + return ExitCode.PROCESSING_ERROR + .exitMessage( + String.format("Unable to resolve profile '%s'. %s", document.getDocumentUri(), ex.getMessage())) + .withThrowable(ex); + } + + // DefaultConstraintValidator validator = new + // DefaultConstraintValidator(dynamicContext); + // ((IBoundXdmNodeItem)resolvedProfile).validate(validator); + // validator.finalizeValidation(); + + ISerializer serializer + = OscalBindingContext.instance().newSerializer(toFormat, Catalog.class); + try { + if (destination == null) { + @SuppressWarnings({ "resource", "PMD.CloseResource" }) PrintStream stdOut = ObjectUtils.notNull(System.out); + serializer.serialize((Catalog) INodeItem.toValue(resolvedProfile), stdOut); + } else { + serializer.serialize((Catalog) INodeItem.toValue(resolvedProfile), destination); } + } catch (IOException ex) { + return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex); } return ExitCode.OK.exit(); } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java index 6456b759..9a3be483 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java @@ -26,16 +26,17 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.profile; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; -import gov.nist.secauto.metaschema.model.common.util.CollectionUtil; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; -import gov.nist.secauto.metaschema.model.common.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.util.JsonUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractOscalValidationSubcommand; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; @@ -52,15 +53,16 @@ public String getDescription() { protected List getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( - ObjectUtils.requireNonNull( - XmlUtil.getStreamSource(OscalBindingContext.class.getResource("/schema/xml/oscal-profile_schema.xsd")))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + OscalBindingContext.class.getResource("/schema/xml/oscal-profile_schema.xsd")))); return CollectionUtil.unmodifiableList(retval); } @Override - protected JSONObject getOscalJsonSchema() { - return JsonSchemaContentValidator.toJsonObject( - ObjectUtils.requireNonNull( - OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-profile_schema.json"))); + protected JSONObject getOscalJsonSchema() throws IOException { + try (InputStream is = ObjectUtils.requireNonNull( + OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-profile_schema.json"))) { + return JsonUtil.toJsonObject(is); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java index 15d2e92f..64201cbc 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java @@ -26,16 +26,17 @@ package gov.nist.secauto.oscal.tools.cli.core.commands.ssp; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; -import gov.nist.secauto.metaschema.model.common.util.CollectionUtil; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; -import gov.nist.secauto.metaschema.model.common.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.util.JsonUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractOscalValidationSubcommand; import org.json.JSONObject; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; @@ -52,15 +53,16 @@ public String getDescription() { protected List getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( - ObjectUtils.requireNonNull( - XmlUtil.getStreamSource(OscalBindingContext.class.getResource("/schema/xml/oscal-ssp_schema.xsd")))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + OscalBindingContext.class.getResource("/schema/xml/oscal-ssp_schema.xsd")))); return CollectionUtil.unmodifiableList(retval); } @Override - protected JSONObject getOscalJsonSchema() { - return JsonSchemaContentValidator.toJsonObject( - ObjectUtils.requireNonNull( - OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ssp_schema.json"))); + protected JSONObject getOscalJsonSchema() throws IOException { + try (InputStream is = ObjectUtils.requireNonNull( + OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ssp_schema.json"))) { + return JsonUtil.toJsonObject(is); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/operations/XMLOperations.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/operations/XMLOperations.java index d4ec651c..50b07a60 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/operations/XMLOperations.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/operations/XMLOperations.java @@ -26,7 +26,8 @@ package gov.nist.secauto.oscal.tools.cli.core.operations; -import gov.nist.secauto.metaschema.binding.io.xml.XmlUtil; +import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import net.sf.saxon.jaxp.SaxonTransformerFactory; @@ -52,7 +53,8 @@ private XMLOperations() { public static void renderCatalogHTML(File input, File result) throws IOException, TransformerException { render(input, result, - XmlUtil.getStreamSource(XMLOperations.class.getResource("/xsl/oscal-for-bootstrap-html.xsl"))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + XMLOperations.class.getResource("/xsl/oscal-for-bootstrap-html.xsl")))); } public static void renderProfileHTML(File input, File result) throws IOException, TransformerException { @@ -63,12 +65,14 @@ public static void renderProfileHTML(File input, File result) throws IOException File temp = File.createTempFile("resolved-profile", ".xml"); try { - Transformer transformer = transfomerFactory - .newTransformer(XmlUtil.getStreamSource(XMLOperations.class.getResource("/xsl/profile-resolver.xsl"))); + Transformer transformer = transfomerFactory.newTransformer( + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + XMLOperations.class.getResource("/xsl/profile-resolver.xsl")))); transformer.transform(new StreamSource(input), new StreamResult(temp)); transformer = transfomerFactory.newTransformer( - XmlUtil.getStreamSource(XMLOperations.class.getResource("/xsl/oscal-for-bootstrap-html.xsl"))); + XmlUtil.getStreamSource(ObjectUtils.requireNonNull( + XMLOperations.class.getResource("/xsl/oscal-for-bootstrap-html.xsl")))); transformer.transform(new StreamSource(temp), new StreamResult(result)); } finally { if (!temp.delete()) { @@ -76,8 +80,10 @@ public static void renderProfileHTML(File input, File result) throws IOException } } - // TransformerHandler resolverHandler = transfomerFactory.newTransformerHandler(resolver); - // TransformerHandler rendererHandler = transfomerFactory.newTransformerHandler(renderer); + // TransformerHandler resolverHandler = + // transfomerFactory.newTransformerHandler(resolver); + // TransformerHandler rendererHandler = + // transfomerFactory.newTransformerHandler(renderer); // // resolverHandler.setResult(new SAXResult(rendererHandler)); // rendererHandler.setResult(new StreamResult(result)); diff --git a/src/test/java/gov/nist/secauto/oscal/tools/cli/core/CLITest.java b/src/test/java/gov/nist/secauto/oscal/tools/cli/core/CLITest.java index 80351e4a..d2fa91b4 100644 --- a/src/test/java/gov/nist/secauto/oscal/tools/cli/core/CLITest.java +++ b/src/test/java/gov/nist/secauto/oscal/tools/cli/core/CLITest.java @@ -30,15 +30,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import gov.nist.secauto.metaschema.binding.io.Format; import gov.nist.secauto.metaschema.cli.processor.ExitCode; import gov.nist.secauto.metaschema.cli.processor.ExitStatus; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolutionException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -61,13 +64,26 @@ void evaluateResult(@NonNull ExitStatus status, @NonNull ExitCode expectedCode, @NonNull Class thrownClass) { status.generateMessage(true); Throwable thrown = status.getThrowable(); - assert thrown != null; assertAll( () -> assertEquals(expectedCode, status.getExitCode(), "exit code mismatch"), - () -> assertEquals(thrownClass, thrown.getClass(), "expected Throwable mismatch")); + () -> assertEquals( + thrownClass, + thrown == null ? null : thrown.getClass(), + "Throwable mismatch")); } - private static Stream providesValues() { + private static String generateOutputPath(@NonNull Path source, @NonNull Format targetFormat) throws IOException { + String filename = ObjectUtils.notNull(source.getFileName()).toString(); + + int pos = filename.lastIndexOf('.'); + filename = filename.substring(0, pos) + "_converted" + targetFormat.getDefaultExtension(); + + Path dir = Files.createDirectories(Path.of("target/oscal-cli-convert")); + + return dir.resolve(filename).toString(); + } + + private static Stream providesValues() throws IOException { final String[] commands = { "ap", "ar", "catalog", "component-definition", "profile", "poam", "ssp" }; final Map> formatEntries = Map.of( Format.XML, Arrays.asList(Format.JSON, Format.YAML), @@ -76,42 +92,83 @@ private static Stream providesValues() { List values = new ArrayList<>(); values.add(Arguments.of(new String[] { "--version" }, ExitCode.OK, null)); - // TODO: Test all data formats once usnistgov/oscal-cli#216 fix merged. - Path path = Paths.get("src/test/resources/cli/example_profile_invalid" + Format.XML.getDefaultExtension()); - values.add( - Arguments.of(new String[] { "profile", "resolve", "--to=" + Format.XML.name().toLowerCase(), path.toString() }, - ExitCode.PROCESSING_ERROR, ProfileResolutionException.class)); - for (String cmd : commands) { + // test helps values.add(Arguments.of(new String[] { cmd, "validate", "-h" }, ExitCode.OK, null)); - // TODO: Update when usnistgov/oscal-cli#210 fix merged. - values.add(Arguments.of(new String[] { cmd, "convert", "-h" }, ExitCode.INVALID_COMMAND, null)); + values.add(Arguments.of(new String[] { cmd, "convert", "-h" }, ExitCode.OK, null)); for (Format format : Format.values()) { - path = Paths.get("src/test/resources/cli/example_" + cmd + "_invalid" + format.getDefaultExtension()); - values.add(Arguments.of(new String[] { cmd, "validate", path.toString() }, ExitCode.FAIL, null)); - path = Paths.get("src/test/resources/cli/example_" + cmd + "_valid" + format.getDefaultExtension()); - values.add(Arguments.of(new String[] { cmd, "validate", path.toString() }, ExitCode.OK, null)); - path = Paths.get("src/test/resources/cli/example_profile_valid" + format.getDefaultExtension()); - List targetFormats = formatEntries.get(format); - for (Format targetFormat : targetFormats) { - path = Paths.get("src/test/resources/cli/example_" + cmd + "_valid" + format.getDefaultExtension()); - String outputPath = path.toString().replace(format.getDefaultExtension(), - "_converted" + targetFormat.getDefaultExtension()); - values.add(Arguments.of(new String[] { cmd, "convert", "--to=" + targetFormat.name().toLowerCase(), - path.toString(), outputPath, "--overwrite" }, ExitCode.OK, null)); + String sourceExtension = format.getDefaultExtension(); + values.add( + Arguments.of( + new String[] { + cmd, + "validate", + Paths.get("src/test/resources/cli/example_" + cmd + "_invalid" + sourceExtension).toString() + }, + ExitCode.FAIL, + null)); + values.add( + Arguments.of( + new String[] { + cmd, + "validate", + Paths.get("src/test/resources/cli/example_" + cmd + "_valid" + sourceExtension).toString() + }, + ExitCode.OK, + null)); + + for (Format targetFormat : formatEntries.get(format)) { + Path path = Paths.get("src/test/resources/cli/example_" + cmd + "_valid" + sourceExtension); + values.add( + Arguments.of( + new String[] { + cmd, + "convert", + "--to=" + targetFormat.name().toLowerCase(), + path.toString(), + generateOutputPath(path, targetFormat), + "--overwrite" + }, + ExitCode.OK, + null)); + // TODO: Update when usnistgov/oscal#217 fix merged. - path = Paths.get("src/test/resources/cli/example_" + cmd + "_invalid" + format.getDefaultExtension()); - outputPath = path.toString().replace(format.getDefaultExtension(), - "_converted" + targetFormat.getDefaultExtension()); - values.add(Arguments.of(new String[] { cmd, "convert", "--to=" + targetFormat.name().toLowerCase(), - path.toString(), outputPath, "--overwrite" }, ExitCode.OK, null)); + path = Paths.get("src/test/resources/cli/example_" + cmd + "_invalid" + sourceExtension); + values.add( + Arguments.of( + new String[] { + cmd, + "convert", + "--to=" + targetFormat.name().toLowerCase(), + path.toString(), + generateOutputPath(path, targetFormat), + "--overwrite" + }, + ExitCode.OK, + null)); } if (cmd == "profile") { - path = Paths.get("src/test/resources/cli/example_profile_valid" + format.getDefaultExtension()); - values - .add(Arguments.of(new String[] { cmd, "resolve", "--to=" + format.name().toLowerCase(), path.toString() }, - ExitCode.OK, null)); + values.add( + Arguments.of( + new String[] { + cmd, + "resolve", + "--to=" + format.name().toLowerCase(), + Paths.get("src/test/resources/cli/example_profile_valid" + sourceExtension).toString() + }, + ExitCode.OK, + null)); + values.add( + Arguments.of( + new String[] { + "profile", + "resolve", + "--to=" + format.name().toLowerCase(), + Paths.get("src/test/resources/cli/example_profile_invalid" + sourceExtension).toString() + }, + ExitCode.PROCESSING_ERROR, + ProfileResolutionException.class)); } } } diff --git a/src/test/java/gov/nist/secauto/oscal/tools/cli/core/NullYamlValuesTest.java b/src/test/java/gov/nist/secauto/oscal/tools/cli/core/NullYamlValuesTest.java index 0e637b08..ab99c343 100644 --- a/src/test/java/gov/nist/secauto/oscal/tools/cli/core/NullYamlValuesTest.java +++ b/src/test/java/gov/nist/secauto/oscal/tools/cli/core/NullYamlValuesTest.java @@ -28,9 +28,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import gov.nist.secauto.metaschema.binding.io.Format; -import gov.nist.secauto.metaschema.binding.io.IBoundLoader; -import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.Format; +import gov.nist.secauto.metaschema.databind.io.IBoundLoader; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.AssessmentResults; @@ -38,7 +38,7 @@ import org.junit.jupiter.api.Test; import java.io.IOException; -import java.net.URISyntaxException; +import java.nio.file.Paths; public class NullYamlValuesTest { private static OscalBindingContext bindingContext; @@ -52,11 +52,12 @@ static void initialize() { @SuppressWarnings("null") @Test - void testLoadYamlNullVar1() throws IOException, URISyntaxException { - // the YAML catalog is currently malformed, this will create a proper one for this test + void testLoadYamlNullVar1() throws IOException { + // the YAML catalog is currently malformed, this will create a proper one for + // this test AssessmentResults data = loader.load( - ObjectUtils.requireNonNull(NullYamlValuesTest.class.getResource("/yaml-null/example_ar_nullvar-1.yaml"))); + ObjectUtils.requireNonNull(Paths.get("src/test/resources/yaml-null/example_ar_nullvar-1.yaml"))); bindingContext.newSerializer(Format.XML, AssessmentResults.class).serialize(data, System.out); bindingContext.newSerializer(Format.JSON, AssessmentResults.class).serialize(data, System.out); @@ -67,11 +68,12 @@ void testLoadYamlNullVar1() throws IOException, URISyntaxException { @SuppressWarnings("null") @Test - void testLoadYamlNullVar2() throws IOException, URISyntaxException { - // the YAML catalog is currently malformed, this will create a proper one for this test + void testLoadYamlNullVar2() throws IOException { + // the YAML catalog is currently malformed, this will create a proper one for + // this test AssessmentResults data = loader.load( - ObjectUtils.requireNonNull(NullYamlValuesTest.class.getResource("/yaml-null/example_ar_nullvar-2.yaml"))); + ObjectUtils.requireNonNull(Paths.get("src/test/resources/yaml-null/example_ar_nullvar-2.yaml"))); bindingContext.newSerializer(Format.XML, AssessmentResults.class).serialize(data, System.out); bindingContext.newSerializer(Format.JSON, AssessmentResults.class).serialize(data, System.out); @@ -82,11 +84,12 @@ void testLoadYamlNullVar2() throws IOException, URISyntaxException { @SuppressWarnings("null") @Test - void testLoadYamlNullVar3() throws IOException, URISyntaxException { - // the YAML catalog is currently malformed, this will create a proper one for this test + void testLoadYamlNullVar3() throws IOException { + // the YAML catalog is currently malformed, this will create a proper one for + // this test AssessmentResults data = loader.load( - ObjectUtils.requireNonNull(NullYamlValuesTest.class.getResource("/yaml-null/example_ar_nullvar-3.yaml"))); + ObjectUtils.requireNonNull(Paths.get("src/test/resources/yaml-null/example_ar_nullvar-3.yaml"))); bindingContext.newSerializer(Format.XML, AssessmentResults.class).serialize(data, System.out); bindingContext.newSerializer(Format.JSON, AssessmentResults.class).serialize(data, System.out); diff --git a/src/test/java/gov/nist/secauto/oscal/tools/cli/core/commands/Issue96ClassLoaderTest.java b/src/test/java/gov/nist/secauto/oscal/tools/cli/core/commands/Issue96ClassLoaderTest.java index f95e1b42..20eb2051 100644 --- a/src/test/java/gov/nist/secauto/oscal/tools/cli/core/commands/Issue96ClassLoaderTest.java +++ b/src/test/java/gov/nist/secauto/oscal/tools/cli/core/commands/Issue96ClassLoaderTest.java @@ -34,8 +34,8 @@ class Issue96ClassLoaderTest { /** - * Regression tests for usnistgov/oscal-cli#96. See information at this URL for more details. - * https://github.com/usnistgov/oscal-cli/issues/96 + * Regression tests for usnistgov/oscal-cli#96. See information at this URL for + * more details. https://github.com/usnistgov/oscal-cli/issues/96 */ @Test void testAssessmentPlanClassLoader() { diff --git a/src/test/resources/cli/example_ap_invalid.yml b/src/test/resources/cli/example_ap_invalid.yaml similarity index 100% rename from src/test/resources/cli/example_ap_invalid.yml rename to src/test/resources/cli/example_ap_invalid.yaml diff --git a/src/test/resources/cli/example_ap_valid.yml b/src/test/resources/cli/example_ap_valid.yaml similarity index 100% rename from src/test/resources/cli/example_ap_valid.yml rename to src/test/resources/cli/example_ap_valid.yaml diff --git a/src/test/resources/cli/example_ar_invalid.yml b/src/test/resources/cli/example_ar_invalid.yaml similarity index 100% rename from src/test/resources/cli/example_ar_invalid.yml rename to src/test/resources/cli/example_ar_invalid.yaml diff --git a/src/test/resources/cli/example_ar_valid.yml b/src/test/resources/cli/example_ar_valid.yaml similarity index 100% rename from src/test/resources/cli/example_ar_valid.yml rename to src/test/resources/cli/example_ar_valid.yaml diff --git a/src/test/resources/cli/example_catalog_invalid.yml b/src/test/resources/cli/example_catalog_invalid.yaml similarity index 100% rename from src/test/resources/cli/example_catalog_invalid.yml rename to src/test/resources/cli/example_catalog_invalid.yaml diff --git a/src/test/resources/cli/example_catalog_valid.yml b/src/test/resources/cli/example_catalog_valid.yaml similarity index 100% rename from src/test/resources/cli/example_catalog_valid.yml rename to src/test/resources/cli/example_catalog_valid.yaml diff --git a/src/test/resources/cli/example_component-definition_invalid.yml b/src/test/resources/cli/example_component-definition_invalid.yaml similarity index 100% rename from src/test/resources/cli/example_component-definition_invalid.yml rename to src/test/resources/cli/example_component-definition_invalid.yaml diff --git a/src/test/resources/cli/example_component-definition_valid.yml b/src/test/resources/cli/example_component-definition_valid.yaml similarity index 100% rename from src/test/resources/cli/example_component-definition_valid.yml rename to src/test/resources/cli/example_component-definition_valid.yaml diff --git a/src/test/resources/cli/example_poam_invalid.yml b/src/test/resources/cli/example_poam_invalid.yaml similarity index 100% rename from src/test/resources/cli/example_poam_invalid.yml rename to src/test/resources/cli/example_poam_invalid.yaml diff --git a/src/test/resources/cli/example_poam_valid.yml b/src/test/resources/cli/example_poam_valid.yaml similarity index 100% rename from src/test/resources/cli/example_poam_valid.yml rename to src/test/resources/cli/example_poam_valid.yaml diff --git a/src/test/resources/cli/example_profile_invalid.yml b/src/test/resources/cli/example_profile_invalid.yaml similarity index 100% rename from src/test/resources/cli/example_profile_invalid.yml rename to src/test/resources/cli/example_profile_invalid.yaml diff --git a/src/test/resources/cli/example_profile_valid.yml b/src/test/resources/cli/example_profile_valid.yaml similarity index 100% rename from src/test/resources/cli/example_profile_valid.yml rename to src/test/resources/cli/example_profile_valid.yaml diff --git a/src/test/resources/cli/example_ssp_invalid.yml b/src/test/resources/cli/example_ssp_invalid.yaml similarity index 100% rename from src/test/resources/cli/example_ssp_invalid.yml rename to src/test/resources/cli/example_ssp_invalid.yaml diff --git a/src/test/resources/cli/example_ssp_valid.yml b/src/test/resources/cli/example_ssp_valid.yaml similarity index 100% rename from src/test/resources/cli/example_ssp_valid.yml rename to src/test/resources/cli/example_ssp_valid.yaml