From dd09f88fde0286f8fc81c3a84c0e4e28552e79ef Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Mon, 11 Nov 2024 10:50:53 -0500 Subject: [PATCH 1/2] Fixed remaining compile and PMD warnings. --- .../oscal/tools/cli/core/OscalCliVersion.java | 17 ++++--- .../secauto/oscal/tools/cli/core/CLI.java | 16 +++++++ ...ctDeprecatedOscalValidationSubcommand.java | 6 ++- .../commands/AbstractOscalConvertCommand.java | 11 +++++ .../AbstractOscalValidationCommand.java | 36 ++++++++++++-- .../core/commands/AbstractRenderCommand.java | 47 +++++++++++-------- .../core/commands/AbstractResolveCommand.java | 30 ++++++++---- .../cli/core/commands/ConvertCommand.java | 7 ++- .../commands/ListAllowedValuesCommand.java | 5 ++ .../cli/core/commands/ResolveCommand.java | 4 ++ .../cli/core/commands/ValidateCommand.java | 14 +++++- .../assessmentplan/AssessmentPlanCommand.java | 7 +++ .../assessmentplan/ConvertSubcommand.java | 7 +++ .../assessmentplan/ValidateSubcommand.java | 4 +- .../AssessmentResultsCommand.java | 7 +++ .../assessmentresults/ConvertSubcommand.java | 7 +++ .../assessmentresults/ValidateSubcommand.java | 4 +- .../core/commands/catalog/CatalogCommand.java | 7 +++ .../commands/catalog/ConvertSubcommand.java | 7 +++ .../commands/catalog/ValidateSubcommand.java | 4 +- .../ComponentDefinitionCommand.java | 7 +++ .../ConvertSubcommand.java | 7 +++ .../ValidateSubcommand.java | 4 +- .../metaschema/MetaschemaCommand.java | 7 +++ .../core/commands/poam/ConvertSubcommand.java | 7 +++ .../PlanOfActionsAndMilestonesCommand.java | 7 +++ .../commands/poam/ValidateSubcommand.java | 4 +- .../core/commands/profile/ProfileCommand.java | 7 +++ .../commands/profile/ValidateSubcommand.java | 4 +- .../core/commands/ssp/ConvertSubcommand.java | 7 +++ .../ssp/SystemSecurityPlanCommand.java | 7 +++ .../core/commands/ssp/ValidateSubcommand.java | 4 +- .../cli/core/operations/XMLOperations.java | 44 +++++++++-------- 33 files changed, 278 insertions(+), 85 deletions(-) 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 7d1af53..df659bc 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 @@ -28,15 +28,18 @@ import gov.nist.secauto.metaschema.core.util.IVersionInfo; +/** + * Provides version information for this application. + */ public class OscalCliVersion implements IVersionInfo { - public static final String NAME = "oscal-cli"; - public static final String BUILD_VERSION = "${project.version}"; - public static final String BUILD_TIMESTAMP = "${timestamp}"; - public static final String COMMIT = "@git.commit.id.abbrev@"; - public static final String BRANCH = "@git.branch@"; - public static final String CLOSEST_TAG = "@git.closest.tag.name@"; - public static final String ORIGIN = "@git.remote.origin.url@"; + private static final String NAME = "oscal-cli"; + private static final String BUILD_VERSION = "${project.version}"; + private static final String BUILD_TIMESTAMP = "${timestamp}"; + private static final String COMMIT = "@git.commit.id.abbrev@"; + private static final String BRANCH = "@git.branch@"; + private static final String CLOSEST_TAG = "@git.closest.tag.name@"; + private static final String ORIGIN = "@git.remote.origin.url@"; @Override public String getName() { 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 381a736..90b6a01 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 @@ -31,8 +31,17 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * Provides the main entry point for executing the command line interface. + */ @SuppressWarnings("PMD.ShortClassName") public final class CLI { + /** + * Executes the CLI and handled the exit code. + * + * @param args + * the CLI arguments + */ public static void main(String[] args) { System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager"); @@ -41,6 +50,13 @@ public static void main(String[] args) { System.exit(exitCode); } + /** + * Executes the CLI. + * + * @param args + * the CLI arguments + * @return the result of executing the CLI + */ @NonNull public static ExitStatus runCli(String... args) { @SuppressWarnings("PMD.UseConcurrentHashMap") diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractDeprecatedOscalValidationSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractDeprecatedOscalValidationSubcommand.java index a7b00c2..63c5ffb 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractDeprecatedOscalValidationSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractDeprecatedOscalValidationSubcommand.java @@ -15,6 +15,10 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * This abstract command implementation provides user feedback about extending + * command being deprecated in favor of the {@link ValidateCommand}. + */ public abstract class AbstractDeprecatedOscalValidationSubcommand extends AbstractOscalValidationCommand { private static final Logger LOGGER = LogManager.getLogger(AbstractDeprecatedOscalValidationSubcommand.class); @@ -24,7 +28,7 @@ public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine c return new CommandExecutor(callingContext, commandLine); } - protected final class CommandExecutor + private final class CommandExecutor extends AbstractOscalValidationCommand.OscalValidationCommandExecutor { private CommandExecutor( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalConvertCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalConvertCommand.java index 38407ea..307c493 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalConvertCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalConvertCommand.java @@ -26,10 +26,21 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * Used by implementing classes to provide an OSCAL content conversion command. + *

+ * This executor provides user feedback about extending command being deprecated + * in favor of the {@link ConvertCommand}. + */ public abstract class AbstractOscalConvertCommand extends AbstractConvertSubcommand { private static final Logger LOGGER = LogManager.getLogger(AbstractOscalConvertCommand.class); + /** + * Get the bound object class for the assembly associated with the command. + * + * @return the bound object class for the associated assembly + */ @NonNull public abstract Class getOscalClass(); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java index e5215b2..05725bc 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java @@ -28,24 +28,50 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * Used by implementing classes to provide an OSCAL content validation command. + */ public abstract class AbstractOscalValidationCommand extends AbstractValidateContentCommand { + /** + * Load the OSCAL XML schemas. + * + * @return the XML schema validator instance + * @throws IOException + * if an error occurred while parsing the provided XML schemas + */ @NonNull - protected abstract XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException; - + protected abstract XmlSchemaContentValidator getOscalXmlSchemas() throws IOException; + + /** + * Load the OSCAL JSON schemas. + * + * @return the XML schema validator instance + * @throws IOException + * if an error occurred while parsing the provided XML schemas + */ @NonNull protected abstract JsonSchemaContentValidator getOscalJsonSchema() throws IOException; @Override - public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine) { - return new AbstractOscalValidationCommand.OscalValidationCommandExecutor(callingContext, commandLine); - } + public abstract ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine); + /** + * Provides OSCAL validation command execution support. + */ protected class OscalValidationCommandExecutor extends AbstractValidateContentCommand.AbstractValidationCommandExecutor implements ISchemaValidationProvider { + /** + * Construct a new command executor. + * + * @param callingContext + * the context of the command execution + * @param commandLine + * the parsed command line details + */ protected OscalValidationCommandExecutor( @NonNull CallingContext callingContext, @NonNull CommandLine commandLine) { diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java index 31c89b5..0b7160c 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java @@ -8,7 +8,6 @@ import gov.nist.secauto.metaschema.cli.commands.MetaschemaCommands; import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; import gov.nist.secauto.metaschema.cli.processor.ExitCode; -import gov.nist.secauto.metaschema.cli.processor.InvalidArgumentException; import gov.nist.secauto.metaschema.cli.processor.command.AbstractTerminalCommand; import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException; import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument; @@ -21,7 +20,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.file.Path; @@ -33,6 +31,10 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +/** + * An abstract command implementation supporting the rendering of an OSCAL + * content instance. + */ public abstract class AbstractRenderCommand extends AbstractTerminalCommand { private static final Logger LOGGER = LogManager.getLogger(AbstractRenderCommand.class); @@ -68,30 +70,23 @@ public List getExtraArguments() { return EXTRA_ARGUMENTS; } - @Override - public void validateOptions(CallingContext callingContext, CommandLine cmdLine) throws InvalidArgumentException { - List extraArgs = cmdLine.getArgList(); - if (extraArgs.size() != 2) { - throw new InvalidArgumentException("Both a source and destination argument must be provided."); - } - - File source = new File(extraArgs.get(0)); - if (!source.exists()) { - throw new InvalidArgumentException("The provided source '" + source.getPath() + "' does not exist."); - } - if (!source.canRead()) { - throw new InvalidArgumentException("The provided source '" + source.getPath() + "' is not readable."); - } - } - @Override public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine cmdLine) { return ICommandExecutor.using(callingContext, cmdLine, this::executeCommand); } + /** + * Process the command line arguments and execute the rendering operation. + * + * @param callingContext + * the context information for the execution + * @param cmdLine + * the parsed command line details + * @throws CommandExecutionException + * if an error occurred while determining the source format + */ @SuppressWarnings({ - "PMD.OnlyOneReturn", // readability - "unused" + "PMD.OnlyOneReturn" // readability }) protected void executeCommand( @NonNull CallingContext callingContext, @@ -119,6 +114,18 @@ protected void executeCommand( } } + /** + * Perform the rendering operation. + * + * @param input + * the OSCAL content resource to render + * @param result + * the destination file to create rendered content in + * @throws IOException + * if an error occurred while loading the input + * @throws TransformerException + * if an error occurred while creating the rendered content + */ protected abstract void performRender(@NonNull URI input, Path result) throws IOException, TransformerException; } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java index 4b7c7d2..a8b9970 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java @@ -40,6 +40,9 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * A command implementation supporting the resolution of an OSCAL profile. + */ public abstract class AbstractResolveCommand extends AbstractTerminalCommand { @NonNull @@ -78,9 +81,20 @@ public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine c return ICommandExecutor.using(callingContext, cmdLine, this::executeCommand); } + /** + * Process the command line arguments and execute the profile resolution + * operation. + * + * @param callingContext + * the context information for the execution + * @param cmdLine + * the parsed command line details + * @throws CommandExecutionException + * if an error occurred while determining the source format + */ @SuppressWarnings({ "PMD.OnlyOneReturn", // readability - "unused" + "PMD.CyclomaticComplexity" }) protected void executeCommand( @NonNull CallingContext callingContext, @@ -102,17 +116,12 @@ protected void executeCommand( loader, source); - Path destination = null; - if (extraArgs.size() > 1) { - destination = MetaschemaCommands.handleDestination(ObjectUtils.requireNonNull(extraArgs.get(1)), cmdLine); - } - IDocumentNodeItem document; try { document = loader.loadAsNodeItem(asFormat, source); } catch (IOException ex) { throw new CommandExecutionException( - ExitCode.INVALID_ARGUMENTS, + ExitCode.IO_ERROR, String.format("Unable to load content '%s'. %s", source, ex.getMessage()), @@ -129,7 +138,7 @@ protected void executeCommand( if (object instanceof Catalog) { // this is a catalog throw new CommandExecutionException( - ExitCode.INVALID_ARGUMENTS, + ExitCode.OK, String.format("The source '%s' is already a catalog.", source)); } @@ -140,6 +149,11 @@ protected void executeCommand( String.format("The source '%s' is not a profile.", source)); } + Path destination = null; + if (extraArgs.size() > 1) { + destination = MetaschemaCommands.handleDestination(ObjectUtils.requireNonNull(extraArgs.get(1)), cmdLine); + } + // this is a profile DynamicContext dynamicContext = new DynamicContext(document.getStaticContext()); dynamicContext.setDocumentLoader(loader); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java index 02d67d4..432045c 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java @@ -27,6 +27,9 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * Provides an OSCAL content conversion command. + */ public class ConvertCommand extends AbstractConvertSubcommand { @Override @@ -61,10 +64,10 @@ protected void handleConversion(URI source, Format toFormat, Writer writer, IBou IBoundObject object; try (InputStream is = source.toURL().openStream()) { assert is != null; - FormatDetector.Result formatResult = loader.detectFormat(is); + FormatDetector.Result formatResult = loader.detectFormat(is, source); Format sourceformat = formatResult.getFormat(); try (InputStream fis = formatResult.getDataStream()) { - try (ModelDetector.Result modelResult = loader.detectModel(fis, sourceformat)) { + try (ModelDetector.Result modelResult = loader.detectModel(fis, source, sourceformat)) { boundClass = modelResult.getBoundClass(); try (InputStream mis = modelResult.getDataStream()) { object = loader.load(boundClass, sourceformat, mis, source); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java index 35a61a9..ff3e601 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java @@ -61,6 +61,11 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +/** + * A CLI command that provides a listing of allowed values constraints by + * targeted node. + */ +@SuppressWarnings("PMD.CouplingBetweenObjects") public class ListAllowedValuesCommand extends AbstractTerminalCommand { private static final Logger LOGGER = LogManager.getLogger(ListAllowedValuesCommand.class); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ResolveCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ResolveCommand.java index b108b3a..db7dc75 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ResolveCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ResolveCommand.java @@ -7,6 +7,10 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * A CLI command that supports resolving an OSCAL profile into a resolved + * catalog. + */ public class ResolveCommand extends AbstractResolveCommand { diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java index 3cf681d..39a21e8 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java @@ -5,6 +5,8 @@ package gov.nist.secauto.oscal.tools.cli.core.commands; +import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; +import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor; import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; @@ -13,7 +15,7 @@ import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; -import org.xml.sax.SAXException; +import org.apache.commons.cli.CommandLine; import java.io.IOException; import java.io.InputStream; @@ -24,6 +26,9 @@ import edu.umd.cs.findbugs.annotations.NonNull; +/** + * A CLI command that supports validating that an OSCAL instance is valid. + */ public class ValidateCommand extends AbstractOscalValidationCommand { @Override @@ -31,9 +36,14 @@ public String getDescription() { return "Check that the specified OSCAL instance is well-formed and valid to an OSCAL model."; } + @Override + public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine) { + return new AbstractOscalValidationCommand.OscalValidationCommandExecutor(callingContext, commandLine); + } + @Override @NonNull - public XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + public XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/AssessmentPlanCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/AssessmentPlanCommand.java index 8d78f32..39caed6 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/AssessmentPlanCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/AssessmentPlanCommand.java @@ -7,10 +7,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to an OSCAL + * assessment plan. + */ public class AssessmentPlanCommand extends AbstractParentCommand { private static final String COMMAND = "ap"; + /** + * Construct a new parent command. + */ public AssessmentPlanCommand() { super(true); addCommandHandler(new ValidateSubcommand()); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ConvertSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ConvertSubcommand.java index 18cd1b3..a8918bd 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ConvertSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ConvertSubcommand.java @@ -8,7 +8,14 @@ import gov.nist.secauto.metaschema.core.model.IBoundObject; import gov.nist.secauto.oscal.lib.model.AssessmentPlan; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractOscalConvertCommand; +import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand; +/** + * Provides an OSCAL content conversion command. + *

+ * This executor provides user feedback stating that this command is deprecated + * in favor of the {@link ConvertCommand}. + */ public class ConvertSubcommand extends AbstractOscalConvertCommand { @Override 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 7d3e628..2977cc5 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 @@ -14,8 +14,6 @@ import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand; -import org.xml.sax.SAXException; - import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; @@ -31,7 +29,7 @@ public String getDescription() { } @Override - protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/AssessmentResultsCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/AssessmentResultsCommand.java index 1197b2e..11f9fae 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/AssessmentResultsCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/AssessmentResultsCommand.java @@ -7,10 +7,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to an OSCAL + * assessment results. + */ public class AssessmentResultsCommand extends AbstractParentCommand { private static final String COMMAND = "ar"; + /** + * Construct a new parent command. + */ public AssessmentResultsCommand() { super(true); addCommandHandler(new ValidateSubcommand()); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ConvertSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ConvertSubcommand.java index 1d1caeb..5fc0e3a 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ConvertSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ConvertSubcommand.java @@ -8,7 +8,14 @@ import gov.nist.secauto.metaschema.core.model.IBoundObject; import gov.nist.secauto.oscal.lib.model.AssessmentResults; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractOscalConvertCommand; +import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand; +/** + * Provides an OSCAL content conversion command. + *

+ * This executor provides user feedback stating that this command is deprecated + * in favor of the {@link ConvertCommand}. + */ public class ConvertSubcommand extends AbstractOscalConvertCommand { @Override 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 abd5685..3ef5d7d 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 @@ -14,8 +14,6 @@ import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand; -import org.xml.sax.SAXException; - import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; @@ -31,7 +29,7 @@ public String getDescription() { } @Override - protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java index 923b427..42fb271 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java @@ -7,10 +7,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to an OSCAL + * catalog. + */ public class CatalogCommand extends AbstractParentCommand { private static final String COMMAND = "catalog"; + /** + * Construct a new parent command. + */ public CatalogCommand() { super(true); addCommandHandler(new ValidateSubcommand()); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ConvertSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ConvertSubcommand.java index fb16c2a..c465159 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ConvertSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ConvertSubcommand.java @@ -8,7 +8,14 @@ import gov.nist.secauto.metaschema.core.model.IBoundObject; import gov.nist.secauto.oscal.lib.model.Catalog; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractOscalConvertCommand; +import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand; +/** + * Provides an OSCAL content conversion command. + *

+ * This executor provides user feedback stating that this command is deprecated + * in favor of the {@link ConvertCommand}. + */ public class ConvertSubcommand extends AbstractOscalConvertCommand { 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 e925ad9..7e2dc7d 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 @@ -14,8 +14,6 @@ import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand; -import org.xml.sax.SAXException; - import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; @@ -31,7 +29,7 @@ public String getDescription() { } @Override - protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java index 3c7cf08..a2f1e9b 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java @@ -7,10 +7,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to an OSCAL + * component definition. + */ public class ComponentDefinitionCommand extends AbstractParentCommand { private static final String COMMAND = "component-definition"; + /** + * Construct a new parent command. + */ public ComponentDefinitionCommand() { super(true); addCommandHandler(new ValidateSubcommand()); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ConvertSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ConvertSubcommand.java index 2e73972..59d6807 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ConvertSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ConvertSubcommand.java @@ -8,7 +8,14 @@ import gov.nist.secauto.metaschema.core.model.IBoundObject; import gov.nist.secauto.oscal.lib.model.ComponentDefinition; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractOscalConvertCommand; +import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand; +/** + * Provides an OSCAL content conversion command. + *

+ * This executor provides user feedback stating that this command is deprecated + * in favor of the {@link ConvertCommand}. + */ public class ConvertSubcommand extends AbstractOscalConvertCommand { @Override 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 60051b5..4178536 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 @@ -14,8 +14,6 @@ import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand; -import org.xml.sax.SAXException; - import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; @@ -31,7 +29,7 @@ public String getDescription() { } @Override - protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( 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 97f7eba..6a3fe84 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 @@ -8,10 +8,17 @@ import gov.nist.secauto.metaschema.cli.commands.MetaschemaCommands; import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to Metaschema + * operations. + */ public class MetaschemaCommand extends AbstractParentCommand { private static final String COMMAND = "metaschema"; + /** + * Construct a new parent command. + */ public MetaschemaCommand() { super(true); MetaschemaCommands.COMMANDS.forEach(this::addCommandHandler); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ConvertSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ConvertSubcommand.java index 2b2b702..c3c7fcb 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ConvertSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ConvertSubcommand.java @@ -8,7 +8,14 @@ import gov.nist.secauto.metaschema.core.model.IBoundObject; import gov.nist.secauto.oscal.lib.model.PlanOfActionAndMilestones; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractOscalConvertCommand; +import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand; +/** + * Provides an OSCAL content conversion command. + *

+ * This executor provides user feedback stating that this command is deprecated + * in favor of the {@link ConvertCommand}. + */ public class ConvertSubcommand extends AbstractOscalConvertCommand { @Override diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java index efd6911..0c95753 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java @@ -7,10 +7,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to an OSCAL + * plan of actions and milestone. + */ public class PlanOfActionsAndMilestonesCommand extends AbstractParentCommand { private static final String COMMAND = "poam"; + /** + * Construct a new parent command. + */ public PlanOfActionsAndMilestonesCommand() { super(true); addCommandHandler(new ValidateSubcommand()); 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 7214218..e72df5d 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 @@ -14,8 +14,6 @@ import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand; -import org.xml.sax.SAXException; - import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; @@ -32,7 +30,7 @@ public String getDescription() { } @Override - protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java index 0633a9b..05d6882 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java @@ -7,10 +7,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to an OSCAL + * profile. + */ public class ProfileCommand extends AbstractParentCommand { private static final String COMMAND = "profile"; + /** + * Construct a new parent command. + */ public ProfileCommand() { super(true); addCommandHandler(new ValidateSubcommand()); 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 5925b97..9dd5764 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 @@ -14,8 +14,6 @@ import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand; -import org.xml.sax.SAXException; - import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; @@ -31,7 +29,7 @@ public String getDescription() { } @Override - protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ConvertSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ConvertSubcommand.java index 4a28f26..31a5219 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ConvertSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ConvertSubcommand.java @@ -8,7 +8,14 @@ import gov.nist.secauto.metaschema.core.model.IBoundObject; import gov.nist.secauto.oscal.lib.model.SystemSecurityPlan; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractOscalConvertCommand; +import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand; +/** + * Provides an OSCAL content conversion command. + *

+ * This executor provides user feedback stating that this command is deprecated + * in favor of the {@link ConvertCommand}. + */ public class ConvertSubcommand extends AbstractOscalConvertCommand { @Override diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/SystemSecurityPlanCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/SystemSecurityPlanCommand.java index f27b868..d3dfa66 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/SystemSecurityPlanCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/SystemSecurityPlanCommand.java @@ -7,10 +7,17 @@ import gov.nist.secauto.metaschema.cli.processor.command.AbstractParentCommand; +/** + * A parent command implementation that organizes commands related to an OSCAL + * system security plan. + */ public class SystemSecurityPlanCommand extends AbstractParentCommand { private static final String COMMAND = "ssp"; + /** + * Construct a new parent command. + */ public SystemSecurityPlanCommand() { super(true); addCommandHandler(new ValidateSubcommand()); 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 5bb1313..622f4f9 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 @@ -14,8 +14,6 @@ import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.AbstractDeprecatedOscalValidationSubcommand; -import org.xml.sax.SAXException; - import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; @@ -31,7 +29,7 @@ public String getDescription() { } @Override - protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( 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 5679663..8fee85e 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 @@ -30,12 +30,36 @@ private XMLOperations() { // disable construction } + /** + * Render the input catalog as HTML. + * + * @param input + * the source to render + * @param result + * the file to write the rendered HTML to + * @throws IOException + * if an error occurred while loading the input + * @throws TransformerException + * if an error occurred while creating the rendered content + */ public static void renderCatalogHTML(File input, File result) throws IOException, TransformerException { render(input, result, XmlUtil.getStreamSource(ObjectUtils.requireNonNull( XMLOperations.class.getResource("/xsl/oscal-for-bootstrap-html.xsl")))); } + /** + * Render the input profile as HTML. + * + * @param input + * the source to render + * @param result + * the file to write the rendered HTML to + * @throws IOException + * if an error occurred while loading the input + * @throws TransformerException + * if an error occurred while creating the rendered content + */ public static void renderProfileHTML(File input, File result) throws IOException, TransformerException { SaxonTransformerFactory transfomerFactory = (SaxonTransformerFactory) TransformerFactory.newInstance(); // Templates resolver = transfomerFactory.newTemplates(); @@ -78,28 +102,10 @@ public static void renderProfileHTML(File input, File result) throws IOException // t.transform(source, new SAXResult(resolverHandler)); } - public static void render(File input, File result, Source transform) throws TransformerException { + private static void render(File input, File result, Source transform) throws TransformerException { TransformerFactory transfomerFactory = TransformerFactory.newInstance(); assert transfomerFactory instanceof SaxonTransformerFactory; Transformer transformer = transfomerFactory.newTransformer(transform); transformer.transform(new StreamSource(input), new StreamResult(result)); } - - // private static class LoggingURIResolver implements URIResolver { - // private final URIResolver delegate; - // - // - // public LoggingURIResolver(URIResolver delegate) { - // super(); - // this.delegate = delegate; - // } - // - // - // @Override - // public Source resolve(String href, String base) throws TransformerException { - // log.info("Resolve: base='{}', href='{}'", base, href); - // return delegate.resolve(href, base); - // } - // - // } } From d619e002ebe3ca6169a2f731980426123f46e0cf Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Mon, 25 Nov 2024 11:37:02 -0500 Subject: [PATCH 2/2] Refactored assembly descriptors to remove build warnings related to the directory build. Integrated metaschema-java 2.1.0. --- pom.xml | 27 ++-- src/main/assembly/assembly.xml | 14 ++ src/main/assembly/{bin.xml => component.xml} | 17 +-- src/main/assembly/dir.xml | 13 ++ .../core/commands/AbstractRenderCommand.java | 131 ------------------ .../core/commands/AbstractResolveCommand.java | 5 +- .../commands/ListAllowedValuesCommand.java | 3 +- .../assessmentplan/AssessmentPlanCommand.java | 1 - .../AssessmentResultsCommand.java | 1 - .../core/commands/catalog/CatalogCommand.java | 1 - .../ComponentDefinitionCommand.java | 1 - .../metaschema/MetaschemaCommand.java | 1 - .../commands/metaschema/package-info.java | 4 + .../PlanOfActionsAndMilestonesCommand.java | 1 - .../core/commands/profile/ProfileCommand.java | 1 - .../ssp/SystemSecurityPlanCommand.java | 1 - .../cli/core/operations/XMLOperations.java | 111 --------------- src/site/site.xml | 16 +-- .../secauto/oscal/tools/cli/core/CLITest.java | 2 + 19 files changed, 64 insertions(+), 287 deletions(-) create mode 100644 src/main/assembly/assembly.xml rename src/main/assembly/{bin.xml => component.xml} (77%) create mode 100644 src/main/assembly/dir.xml delete mode 100644 src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java delete mode 100644 src/main/java/gov/nist/secauto/oscal/tools/cli/core/operations/XMLOperations.java diff --git a/pom.xml b/pom.xml index c34eb9d..1d758f1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ dev.metaschema oss-parent - 5 + 6-SNAPSHOT dev.metaschema.oscal oscal-cli-enhanced @@ -105,7 +105,6 @@ 2.24.1 7.4.0 4.8.6 - 12.5 5.2.2 6.0.11 @@ -223,11 +222,6 @@ commons-io ${dependency.commons-io.version} - - net.sf.saxon - Saxon-HE - ${dependency.saxon-he.version} - org.xmlresolver xmlresolver @@ -329,6 +323,7 @@ JAVA_TOOL_OPTIONS + @@ -465,7 +460,21 @@ - make-assembly-bin + package + + single + + + false + + src/main/assembly/dir.xml + + + + + make-assembly-archives package @@ -473,7 +482,7 @@ - src/main/assembly/bin.xml + src/main/assembly/assembly.xml diff --git a/src/main/assembly/assembly.xml b/src/main/assembly/assembly.xml new file mode 100644 index 0000000..0192a21 --- /dev/null +++ b/src/main/assembly/assembly.xml @@ -0,0 +1,14 @@ + + oscal-cli + + zip + tar.bz2 + + false + + component.xml + + \ No newline at end of file diff --git a/src/main/assembly/bin.xml b/src/main/assembly/component.xml similarity index 77% rename from src/main/assembly/bin.xml rename to src/main/assembly/component.xml index 30add15..86ba675 100644 --- a/src/main/assembly/bin.xml +++ b/src/main/assembly/component.xml @@ -1,14 +1,7 @@ - - oscal-cli - - dir - zip - tar.bz2 - - false + + /lib @@ -65,4 +58,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/assembly/dir.xml b/src/main/assembly/dir.xml new file mode 100644 index 0000000..67d045a --- /dev/null +++ b/src/main/assembly/dir.xml @@ -0,0 +1,13 @@ + + oscal-cli + + dir + + false + + component.xml + + \ No newline at end of file diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java deleted file mode 100644 index 0b7160c..0000000 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractRenderCommand.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * SPDX-FileCopyrightText: none - * SPDX-License-Identifier: CC0-1.0 - */ - -package gov.nist.secauto.oscal.tools.cli.core.commands; - -import gov.nist.secauto.metaschema.cli.commands.MetaschemaCommands; -import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; -import gov.nist.secauto.metaschema.cli.processor.ExitCode; -import gov.nist.secauto.metaschema.cli.processor.command.AbstractTerminalCommand; -import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException; -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.core.util.ObjectUtils; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.IOException; -import java.net.URI; -import java.nio.file.Path; -import java.util.Collection; -import java.util.List; - -import javax.xml.transform.TransformerException; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -/** - * An abstract command implementation supporting the rendering of an OSCAL - * content instance. - */ -public abstract class AbstractRenderCommand - extends AbstractTerminalCommand { - private static final Logger LOGGER = LogManager.getLogger(AbstractRenderCommand.class); - - @NonNull - private static final String COMMAND = "render"; - @NonNull - private static final List EXTRA_ARGUMENTS = ObjectUtils.notNull(List.of( - new DefaultExtraArgument("source file", true), - new DefaultExtraArgument("destination file", false))); - - @NonNull - private static final Option OVERWRITE_OPTION = ObjectUtils.notNull( - Option.builder() - .longOpt("overwrite") - .desc("overwrite the destination if it exists") - .build()); - - @Override - public String getName() { - return COMMAND; - } - - @SuppressWarnings("null") - @Override - public Collection gatherOptions() { - return List.of(OVERWRITE_OPTION); - } - - @Override - @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "unmodifiable collection and immutable item") - public List getExtraArguments() { - return EXTRA_ARGUMENTS; - } - - @Override - public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine cmdLine) { - return ICommandExecutor.using(callingContext, cmdLine, this::executeCommand); - } - - /** - * Process the command line arguments and execute the rendering operation. - * - * @param callingContext - * the context information for the execution - * @param cmdLine - * the parsed command line details - * @throws CommandExecutionException - * if an error occurred while determining the source format - */ - @SuppressWarnings({ - "PMD.OnlyOneReturn" // readability - }) - protected void executeCommand( - @NonNull CallingContext callingContext, - @NonNull CommandLine cmdLine) throws CommandExecutionException { - List extraArgs = cmdLine.getArgList(); - Path destination = null; - if (extraArgs.size() > 1) { - destination = MetaschemaCommands.handleDestination(ObjectUtils.requireNonNull(extraArgs.get(1)), cmdLine); - } - - URI source = MetaschemaCommands.handleSource( - ObjectUtils.requireNonNull(extraArgs.get(0)), - ObjectUtils.notNull(getCurrentWorkingDirectory().toUri())); - - try { - performRender(source, destination); - } catch (IOException ex) { - throw new CommandExecutionException(ExitCode.IO_ERROR, ex); - } catch (TransformerException ex) { - throw new CommandExecutionException(ExitCode.PROCESSING_ERROR, ex); - } - - if (destination != null && LOGGER.isInfoEnabled()) { - LOGGER.info("Generated HTML file: " + destination.toString()); - } - } - - /** - * Perform the rendering operation. - * - * @param input - * the OSCAL content resource to render - * @param result - * the destination file to create rendered content in - * @throws IOException - * if an error occurred while loading the input - * @throws TransformerException - * if an error occurred while creating the rendered content - */ - protected abstract void performRender(@NonNull URI input, Path result) - throws IOException, TransformerException; -} diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java index a8b9970..f4bfbbe 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java @@ -10,7 +10,6 @@ import gov.nist.secauto.metaschema.cli.processor.ExitCode; import gov.nist.secauto.metaschema.cli.processor.command.AbstractTerminalCommand; import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException; -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.core.metapath.DynamicContext; @@ -47,8 +46,8 @@ public abstract class AbstractResolveCommand extends AbstractTerminalCommand { @NonNull private static final List EXTRA_ARGUMENTS = ObjectUtils.notNull(List.of( - new DefaultExtraArgument("URI to resolve", true), - new DefaultExtraArgument("destination file", false))); + ExtraArgument.newInstance("URI to resolve", true), + ExtraArgument.newInstance("destination file", false))); @NonNull private static final List