Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,35 @@ Metapath is an implementation of XPath 3.1. The [XPath 3.1 specification](https:
### Generated Code

Code generation occurs during Maven build:
- **XMLBeans**: Generated from XSD schemas in `core/metaschema/schema/xml`
- **Metaschema bindings**: Generated from Metaschema modules via metaschema-maven-plugin
- **ANTLR4**: Metapath parser from `core/src/main/antlr4`

Generated sources are placed in `target/generated-sources/` and excluded from style checks.

### Bootstrap Binding Classes

The `metaschema-testing` module contains pre-generated binding classes that cannot be generated during the normal build due to circular dependencies (metaschema-maven-plugin → metaschema-schema-generator → metaschema-testing).

To regenerate these classes when the test suite Metaschema module changes:

```bash
# Generate binding classes using bootstrap POM
mvn -f metaschema-testing/pom-bootstrap.xml generate-sources

# Copy to source directory
cp -r metaschema-testing/target/generated-sources/metaschema/gov/nist/secauto/metaschema/model/testing/testsuite/* \
metaschema-testing/src/main/java/gov/nist/secauto/metaschema/model/testing/testsuite/
```

See `metaschema-testing/README.md` for details.

### Metaschema Module Authoring

**YAML-first approach**: When creating new Metaschema modules, prefer YAML format over XML.
- YAML modules use `.yaml` extension and are stored in `src/main/metaschema/`
- Use the JSON schema at `databind-metaschema/target/generated-resources/schema/json/metaschema-model_schema.json` for IDE validation
- Reference existing YAML modules (e.g., `databind/src/main/metaschema/metaschema-bindings.yaml`) for structure examples

### Key Interfaces

- `IModule` - Represents a Metaschema module with definitions
Expand Down Expand Up @@ -168,7 +192,7 @@ Checkstyle enforces these rules (configured in [oss-maven checkstyle.xml](https:
Exceptions (no Javadoc required):
- `@Override` methods (inherit documentation)
- `@Test` methods (use descriptive names)
- Generated code (`*.xmlbeans`, `*.antlr` packages)
- Generated code (`*.antlr` packages)

```bash
# Check Javadoc compliance
Expand Down
37 changes: 19 additions & 18 deletions PRDs/20251221-xmlbeans-removal/implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ Use this schema for IDE validation when authoring the YAML Metaschema modules.

| Attribute | Value |
|-----------|-------|
| **Files Changed** | ~15-20 |
| **Files Changed** | 15 |
| **Risk Level** | Low |
| **Dependencies** | PR 1 |
| **Target Branch** | develop |
| **Status** | Pending |
| **Pull Request** | |
| **Status** | Complete |
| **Pull Request** | [#567](https://github.com/metaschema-framework/metaschema-java/pull/567) |

#### Files to Create

Expand All @@ -145,10 +145,11 @@ Use this schema for IDE validation when authoring the YAML Metaschema modules.

| File | Reason |
|------|--------|
| `core/metaschema/test-suite/unit-tests.xsd` | Replaced by Metaschema module |
| `metaschema-testing/src/schema/xmlconfig.xml` | XMLBeans configuration no longer needed |
| `metaschema-testing/src/main/java/gov/nist/secauto/metaschema/model/testing/xml/xmlbeans/` | Entire XMLBeans handler package |

**Note**: `core/metaschema/test-suite/unit-tests.xsd` is in the metaschema specification submodule (separate repository) and was not deleted.

#### Implementation Approach

1. **Create Metaschema module**: Translate `unit-tests.xsd` to a Metaschema module (YAML format)
Expand Down Expand Up @@ -177,19 +178,19 @@ Use this schema for IDE validation when authoring the YAML Metaschema modules.

#### Acceptance Criteria

- [ ] Metaschema module created at `metaschema-testing/src/main/metaschema/unit-tests.yaml`
- [ ] metaschema-maven-plugin configured in testing POM
- [ ] `AbstractTestSuite.java` uses generated binding classes
- [ ] No XMLBeans imports in metaschema-testing module
- [ ] XMLBeans dependency removed from `metaschema-testing/pom.xml`
- [ ] XMLBeans removed from parent `pom.xml`
- [ ] XSD file deleted from `core/metaschema/test-suite/`
- [ ] XMLBeans handler package deleted
- [ ] Existing test suite files parse correctly
- [ ] All metaschema-testing tests pass
- [ ] All dependent module tests pass
- [ ] Full CI build succeeds: `mvn install -PCI -Prelease`
- [ ] No XMLBeans references remain in codebase (verify with grep)
- [x] Metaschema module created at `metaschema-testing/src/main/metaschema/unit-tests.yaml`
- [x] metaschema-maven-plugin configured in testing POM
- [x] `AbstractTestSuite.java` uses generated binding classes
- [x] No XMLBeans imports in metaschema-testing module
- [x] XMLBeans dependency removed from `metaschema-testing/pom.xml`
- [x] XMLBeans removed from parent `pom.xml`
- [x] XSD file in `core/metaschema/test-suite/` is in submodule (separate repo), no longer referenced
- [x] XMLBeans handler package deleted
- [x] Existing test suite files parse correctly
- [x] All metaschema-testing tests pass
- [x] All dependent module tests pass
- [x] Full CI build succeeds: `mvn install -PCI -Prelease`
- [x] No XMLBeans references remain in codebase (verify with grep)

---

Expand All @@ -198,7 +199,7 @@ Use this schema for IDE validation when authoring the YAML Metaschema modules.
| PR | Description | Files | Risk | Dependencies | Status |
|----|-------------|-------|------|--------------|--------|
| 1 | databind module: XMLBeans → Metaschema bindings (bootstrap) | 14 | Medium | None | Complete ([#566](https://github.com/metaschema-framework/metaschema-java/pull/566)) |
| 2 | metaschema-testing module + parent POM cleanup | ~15-20 | Low | PR 1 | Pending |
| 2 | metaschema-testing module + parent POM cleanup | 15 | Low | PR 1 | Complete ([#567](https://github.com/metaschema-framework/metaschema-java/pull/567)) |

**Total Estimated PRs**: 2
**Total Estimated Files**: ~30-40
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
* messages and other output. The selection can be explicit (forcing a specific
* format) or automatic (selecting based on document format).
*
* @see IPathFormatter#resolveFormatter(PathFormatSelection,
* gov.nist.secauto.metaschema.databind.io.Format)
* @see IPathFormatter#METAPATH_PATH_FORMATER
* @see IPathFormatter#XPATH_PATH_FORMATTER
* @see IPathFormatter#JSON_POINTER_PATH_FORMATTER
*/
public enum PathFormatSelection {
/**
Expand Down
15 changes: 11 additions & 4 deletions databind/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<excludes>
<exclude>gov/nist/secauto/metaschema/databind/model/metaschema/binding/*.java</exclude>
<exclude>gov/nist/secauto/metaschema/databind/config/binding/*.java</exclude>
</excludes>
<rulesets>
<ruleset>src/main/config/pmd/ruleset.xml</ruleset>
<ruleset>src/main/config/pmd/field-naming-ruleset.xml</ruleset>
</rulesets>
</configuration>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<configuration>
<excludeFilterFile>src/main/config/spotbugs/exclude.xml</excludeFilterFile>
</configuration>
</plugin>
<plugin>
Expand Down
18 changes: 18 additions & 0 deletions databind/src/main/config/pmd/field-naming-ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Metaschema Databind Field Naming Ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.net/ruleset_2_0_0.xsd">

<description>
FieldNamingConventions rule for metaschema-databind.
Excludes generated binding classes that use underscore-prefixed fields.
</description>

<!-- Exclude generated binding classes that use underscore-prefixed fields -->
<exclude-pattern>.*/binding/.*\.java</exclude-pattern>

<!-- Apply FieldNamingConventions to non-generated code only -->
<rule ref="category/java/codestyle.xml/FieldNamingConventions"/>

</ruleset>
27 changes: 27 additions & 0 deletions databind/src/main/config/pmd/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Metaschema Databind Base Ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.net/ruleset_2_0_0.xsd">

<description>
Base PMD ruleset for metaschema-databind excluding FieldNamingConventions.
FieldNamingConventions is handled separately to exclude generated binding classes.
</description>

<!-- Include the parent oss-maven ruleset with project exclusions -->
<rule ref="pmd/category/java/custom.xml">
<!-- Exclude TypeParameterNamingConventions since this project uses descriptive
type parameter names like TYPE, RESULT, CONTEXT instead of single letters -->
<exclude name="TypeParameterNamingConventions"/>
<!-- Exclude OnlyOneReturn - multiple returns improve readability for guard clauses -->
<exclude name="OnlyOneReturn"/>
<!-- Exclude ShortMethodName - factory methods like of(), as() are idiomatic Java -->
<exclude name="ShortMethodName"/>
<!-- Exclude ShortClassName - short class names like If, Or, For are acceptable for DSL-style APIs -->
<exclude name="ShortClassName"/>
<!-- Exclude FieldNamingConventions - handled in separate ruleset -->
<exclude name="FieldNamingConventions"/>
</rule>

</ruleset>

This file was deleted.

4 changes: 2 additions & 2 deletions docs/javadoc-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This guide defines the Javadoc requirements for the metaschema-java project, bas
The project's `pom.xml` configures `maven-javadoc-plugin` with:
- `failOnWarnings: false` - Javadoc warnings do not fail the build (currently)
- `failOnError: false` - Javadoc errors do not fail the build (currently)
- Excluded packages: `*.xmlbeans`, `*.xmlbeans.*`, `*.antlr` (generated code)
- Excluded packages: `*.antlr` (generated code)

**Important**: While these settings currently allow builds to pass with Javadoc issues, the goal is to progressively improve documentation coverage until these can be set to `true`.

Expand Down Expand Up @@ -351,6 +351,6 @@ When working in a file, consider documenting nearby undocumented members, especi
### Excluded Code

Do not add Javadoc to:
- Generated code (`*.xmlbeans`, `*.antlr` packages)
- Generated code (`*.antlr` packages)
- `module-info.java` files
- Test classes and methods (use descriptive method names instead)
26 changes: 26 additions & 0 deletions metaschema-testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Metaschema Testing Module

This module provides unit testing support used by other modules in this project.

## Bootstrap Binding Classes

The test suite binding classes in `gov.nist.secauto.metaschema.model.testing.testsuite` are pre-generated and checked into source control. This is necessary because:

1. The `metaschema-maven-plugin` depends on `metaschema-schema-generator`
2. `metaschema-schema-generator` depends on `metaschema-testing` for test utilities
3. Using the plugin during normal build would create a circular dependency

### Regenerating Binding Classes

When the test suite Metaschema module (`src/main/metaschema/unit-tests.yaml`) changes, regenerate the binding classes:

```bash
# From the project root
mvn -f metaschema-testing/pom-bootstrap.xml generate-sources

# Copy generated classes to source
cp -r metaschema-testing/target/generated-sources/metaschema/gov/nist/secauto/metaschema/model/testing/testsuite/* \
metaschema-testing/src/main/java/gov/nist/secauto/metaschema/model/testing/testsuite/
```

The binding configuration (`src/main/metaschema-bindings/test-suite-bindings.xml`) maps the namespace to the `gov.nist.secauto.metaschema.model.testing.testsuite` package.
53 changes: 53 additions & 0 deletions metaschema-testing/pom-bootstrap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This POM is used to regenerate the test suite binding classes.
It is NOT part of the normal build due to circular dependencies.

Usage: mvn -f metaschema-testing/pom-bootstrap.xml generate-sources

After running, copy the generated classes from:
target/generated-sources/metaschema/gov/nist/secauto/metaschema/model/testing/testsuite/
to:
src/main/java/gov/nist/secauto/metaschema/model/testing/testsuite/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.metaschema.java</groupId>
<artifactId>metaschema-framework</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>metaschema-testing-bootstrap</artifactId>
<packaging>pom</packaging>
<name>Metaschema Testing - Binding Class Generator</name>
<description>Standalone POM for regenerating test suite binding classes.</description>

<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>metaschema-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>metaschema-codegen</id>
<phase>generate-sources</phase>
<goals>
<goal>generate-sources</goal>
</goals>
<configuration>
<metaschemaDir>${project.basedir}/src/main/metaschema</metaschemaDir>
<outputDirectory>${project.build.directory}/generated-sources/metaschema</outputDirectory>
<configs>
<config>${project.basedir}/src/main/metaschema-bindings/test-suite-bindings.xml</config>
</configs>
<includes>
<include>unit-tests.yaml</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading