Skip to content

Commit

Permalink
Code refactoring and cleanup for 1.0.0 release (#204)
Browse files Browse the repository at this point in the history
* Migrated modules:
  - Relocated metaschema-model-common to metaschema-core in folder core.
  - Relocated metaschema-model to metaschema-core in folder core.
    - Moved metaschema submodule to core.
  - Relocated the "metaschema-java-binding" and "metaschema-java-codegen" modules to the databind module.
  - Moved metaschema-schema-generator to schemagen.
* Cleaned up reports.
* Ensured generated resources are included for site generation.
* Cleaned up some unneeded generics in the implementation.
* Added many Javadoc comments.
* Relocated unit tests to match new package structure.
* Added a new mock model builder (MockedModelTestSupport) to facilitate creation of unit tests around using a mocked Metaschema model.
* Setup JPMS module-info for the core module.
* Some Maven dependency cleanup, including removing unused dependencies.
  - Removed dependency on JAXB.
* Removed aggregate javadoc.
* Eliminated a significant number of compile, PMD, CPD duplications, and Spotbugs warnings.
* Cleaned up some unused/unneeded classes and methods.
* Improved some logging messages.
* Use treeless Git clones on GHA builds
* Updating to latest oss-maven release.
* Core changes:
  - Added `true()` and `false()` metapath function.
  - Refactored error handling for step-related Metapath expressions to ensure the provided context node item is non-null and a document. This also lays ground work for null node contexts in Metapath expressions that do not require a focused node.
  - Refactored code to remove the IRequiredValue* interfaces.
  - Migrated node item classes to a new package.
  - Refactored INodeItem handling to implement the following correct behaviors:
    - IDocumentNodeItem instances will never have a value (i.e. getValue == null)
    - Root metapaths (i.e. `/`) must be executed against an IDocumentNodeItem or an error should be raised.
  - Refactored node item implementation to provide better interface segregation and to limit class responsibility.
  - Refactored Metapath focus to allow for Metapath evaluations against no focus, as well as cases where the focus is not a node item.
  - Improved memory footprint for Axis expressions, which now use static objects for evaluation. Refactored the Step and ParentItem ASTs to use the new Axis support.
  - Added support for function namespaces.
  - Removed collapsible per usnistgov/metaschema#354.
  - Moved property info factory to static method on IModelPropertyInfo.
  - Adjusted IDataTypeHandler creation to avoid extra method callbacks.
  - Reduced unnecessary overridden methods.
  - Removed the need for specific root assembly model interfaces and classes.
  - Renamed IMetaschema to IModule to be more consistent with terminology.
Deleted unused submodule.
  - For index constraints, enhanced index key miss error reporting to include the key data that missed.
  - Added new String initializer for IAnyAtomicItem.
* Databind changes:
  - Refactored JSON reader and writer to use common instance logic. The collection of instances are now lazy generated and cached, improving read and write performance for commonly accessed Metaschema-based JSON objects.
  - Refactored XML parsing, extracting XML parsing logic into the XmlParser class. This resulted in a cleaner set of bound definition/property classes. Also optimized deserialization to return the Object value directly, instead of first creating an unneeded node item.
  - Refactored JSON parsing, extracting JSON parsing logic into the MetaschemaJsonParser class. This resulted in a cleaner set of bound definition/property classes that no contain no parsing code.
  - Renamed XmlParser to MetaschemaXmlReader, MetaschemaJsonParser to MetaschemaJsonReader, and MetaschemaXmlGenerator to MetaschemaXmlWriter.
  - Cleaned up some collapse unit testing files.
  - Implemented XML problem handler for parsing. Further code cleanup and refactoring of XML parsing code.
  - Implemented the JSON problem handler. Resolved #131.
  - Refactored JSON parser tests.
  - Refactored input stream handling. Input streams should now be properly closed.
  - Adjusted problem handlers to use interface defaults and a common implementation of default handling for missing instances.
  - Refactored binding context to allow for dynamic class generation, compilation, and loading. Removed DynamicBindingContext.java, which is no longer needed.
  - Adjusted YAML parser configuration to set a higher default codepoint limit.
  - Refactored code generation, moving code generation methods into a dedicated class.
  - Refactored code generation production classes to simplify and reduce the number of classes.
* Schema generation changes:
  - Refactored XML and JSON generation by moving generation code into format specific classes (i.e. MetaschemaJsonWriter, MetaschemaXmlWriter).
  - Improved XML schema generation testing.
* Metaschema Maven plugin changes:
  - Adjusted generate sources mojo default phase to a more reasonable value (generate-sources).
  • Loading branch information
david-waltermire authored Sep 26, 2023
1 parent 151d97b commit 2e91fac
Show file tree
Hide file tree
Showing 973 changed files with 25,219 additions and 22,800 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
with:
submodules: recursive
fetch-depth: 0
filter: tree:0
# -------------------------
# Java Environment Setup
# -------------------------
Expand Down Expand Up @@ -79,6 +79,11 @@ jobs:
- name: Perform CodeQL Analysis
if: github.event_name == 'push'
uses: github/codeql-action/analyze@6a28655e3dcb49cb0840ea372fd6d17733edd8a4
- name: Upload CodeQL SARIF file
uses: github/codeql-action/upload-sarif@a09933a12a80f87b87005513f0abb1494c27a716
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref_name == 'develop'
with:
token: ${{ secrets.COMMIT_TOKEN }}
- name: Test Website
run: |
# this needs to be run as a second build to ensure source is fully generated by the previous step
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
with:
submodules: recursive
fetch-depth: 0
filter: tree:0
# -------------------------
# Java
# -------------------------
Expand Down
11 changes: 7 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[submodule "metaschema"]
path = metaschema-model/metaschema
url = https://github.com/usnistgov/metaschema
branch = master
[submodule "core/core/metaschema"]
path = core/metaschema
url = https://github.com/usnistgov/metaschema.git
branch = main
[submodule "core/qt3tests"]
path = core/qt3tests
url = https://github.com/w3c/qt3tests.git
9 changes: 9 additions & 0 deletions .mvn/maven-build-cache-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
</discovery>
</multiModule>
</configuration>
<executionControl>
<runAlways>
<plugins>
<!-- the two following plugins are needed to add sources to the source list -->
<plugin groupId="org.antlr" artifactId="antlr4-maven-plugin"/>
<plugin groupId="org.codehaus.mojo" artifactId="build-helper-maven-plugin"/>
</plugins>
</runAlways>
</executionControl>
</cache>
15 changes: 2 additions & 13 deletions cli-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependencies>
<dependency>
<groupId>gov.nist.secauto.metaschema</groupId>
<artifactId>metaschema-model-common</artifactId>
<artifactId>metaschema-core</artifactId>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
Expand All @@ -43,7 +43,7 @@
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<artifactId>auto-service-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand All @@ -53,17 +53,6 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ICommand;
import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor;
import gov.nist.secauto.metaschema.model.common.util.IVersionInfo;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.util.IVersionInfo;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -183,7 +183,8 @@ private ExitStatus parseCommand(String... args) {
CallingContext callingContext = new CallingContext(commandArgs);

ExitStatus status;
// the first two arguments should be the <command> and <operation>, where <type> is the object type
// the first two arguments should be the <command> and <operation>, where <type>
// is the object type
// the <operation> is performed against.
if (commandArgs.isEmpty()) {
status = ExitCode.INVALID_COMMAND.exit();
Expand All @@ -205,9 +206,9 @@ private static void handleNoColor() {
AnsiConsole.systemUninstall();
}

@SuppressWarnings("resource")
public static void handleQuiet() {
@SuppressWarnings("resource") LoggerContext ctx = (LoggerContext) LogManager.getContext(false); // NOPMD not
// closable here
LoggerContext ctx = (LoggerContext) LogManager.getContext(false); // NOPMD not closable here
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
Level oldLevel = loggerConfig.getLevel();
Expand Down Expand Up @@ -240,7 +241,8 @@ protected void showVersion() {
// @SuppressWarnings("null")
// @NonNull
// public String[] getArgArray() {
// return Stream.concat(options.stream(), extraArgs.stream()).toArray(size -> new String[size]);
// return Stream.concat(options.stream(), extraArgs.stream()).toArray(size ->
// new String[size]);
// }

public class CallingContext {
Expand Down Expand Up @@ -367,7 +369,8 @@ public ExitStatus processCommand() {
retval = ExitCode.OK.exit();
// } else {
// retval = handleInvalidCommand(commandResult, options,
// "Invalid command arguments: " + cmdLine.getArgList().stream().collect(Collectors.joining(" ")));
// "Invalid command arguments: " +
// cmdLine.getArgList().stream().collect(Collectors.joining(" ")));
}

if (retval == null) {
Expand Down Expand Up @@ -578,9 +581,10 @@ public void showHelp() {
AnsiPrintStream out = AnsiConsole.out();
int terminalWidth = Math.max(out.getTerminalWidth(), 40);

@SuppressWarnings("resource") PrintWriter writer = new PrintWriter(out, true, StandardCharsets.UTF_8); // NOPMD -
// not
// owned
@SuppressWarnings("resource") PrintWriter writer = new PrintWriter( // NOPMD not owned
out,
true,
StandardCharsets.UTF_8);
formatter.printHelp(
writer,
terminalWidth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public enum ExitCode {
*/
IO_ERROR(2),
/**
* A command was requested by name that doesn't exist or required arguments are missing.
* A command was requested by name that doesn't exist or required arguments are
* missing.
*/
INVALID_COMMAND(3),
/**
Expand All @@ -58,7 +59,8 @@ public enum ExitCode {
*/
RUNTIME_ERROR(6),
/**
* The provided argument information for a command fails to match argument use requirements.
* The provided argument information for a command fails to match argument use
* requirements.
*/
INVALID_ARGUMENTS(7);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public InvalidArgumentException(String message) {
}

/**
* Return the option requiring an argument that wasn't provided on the command line.
* Return the option requiring an argument that wasn't provided on the command
* line.
*
* @return the related option
*/
Expand All @@ -64,7 +65,8 @@ public Option getOption() {
}

/**
* Assign the option requiring an argument that wasn't provided on the command line.
* Assign the option requiring an argument that wasn't provided on the command
* line.
*
* @param option
* the option to set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class MessageExitStatus
* @param code
* the exit code to use.
* @param messageArguments
* the arguments that can be passed to a formatted string to generate the message
* the arguments that can be passed to a formatted string to generate
* the message
*/
public MessageExitStatus(@NonNull ExitCode code, @NonNull Object... messageArguments) {
super(code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import org.apache.commons.cli.CommandLine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
import gov.nist.secauto.metaschema.cli.processor.InvalidArgumentException;
import gov.nist.secauto.metaschema.model.common.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ExitStatus execute() {
}

@FunctionalInterface
public interface ExecutionFunction {
interface ExecutionFunction {
@NonNull
ExitStatus execute(
@NonNull CallingContext callingContext,
Expand Down
1 change: 1 addition & 0 deletions core/metaschema
Submodule metaschema added at e54d01
Loading

0 comments on commit 2e91fac

Please sign in to comment.