Class MavenUriCatalogResolver


  • public final class MavenUriCatalogResolver
    extends Object
    Pre-processes an OASIS XML Catalog file by resolving maven: URIs into concrete jar:file:// URLs backed by artifacts in the local Maven repository.

    The maven: URI scheme

    The scheme follows the format used by the jaxb-tools project:

       maven:groupId:artifactId:type:classifier!/path/in/jar
     

    Examples:

    • maven:com.example:shared-schemas:jar:!/schemas/common.xsd
    • maven:com.example:shared-schemas:jar::!/schemas/common.xsd (empty classifier)
    • maven:com.example:shared-schemas:jar!/schemas/common.xsd (omit classifier segment)

    Resolution

    Each maven: URI is resolved via the Aether RepositorySystem to obtain the artifact's local file. The resolved URI becomes a jar:file:///…!/path/in/jar URL that XJC's built-in catalog support can follow without any further custom resolver.

    Catalog pre-processing

    The original catalog file is read, all maven:… occurrences are replaced, and the result is written to a new file in the build directory. The new file path is returned and used as the catalog argument to XJC in place of the original.

    Since:
    4.1.1
    • Constructor Detail

      • MavenUriCatalogResolver

        public MavenUriCatalogResolver​(org.eclipse.aether.RepositorySystem repositorySystem,
                                       org.eclipse.aether.RepositorySystemSession session,
                                       List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories,
                                       org.apache.maven.plugin.logging.Log log)
        Creates a new resolver.
        Parameters:
        repositorySystem - Aether repository system, injected by the mojo
        session - the current repository system session
        remoteRepositories - the project's remote repositories
        log - the Maven build log
    • Method Detail

      • containsMavenUris

        public static boolean containsMavenUris​(String catalogText)
        Returns true if the given catalog file text contains at least one maven: URI.

        Used as a fast-path guard: catalogs without maven: references are passed straight to XJC without any pre-processing.

        Parameters:
        catalogText - the full text of the catalog file
        Returns:
        true when a maven:…!/… pattern is present
      • resolve

        public File resolve​(File originalCatalog,
                            File resolvedCatalog)
                     throws org.apache.maven.plugin.MojoExecutionException
        Reads originalCatalog, resolves all maven: URIs within it to jar:file:// URLs, and writes the result to resolvedCatalog.

        If the catalog does not contain any maven: URIs this method simply returns originalCatalog without touching the filesystem.

        Parameters:
        originalCatalog - the user-supplied catalog file
        resolvedCatalog - the target file for the pre-processed catalog in the build directory
        Returns:
        resolvedCatalog when any maven: URIs were found and replaced, or originalCatalog if the file contained no maven: URIs
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if an artifact cannot be resolved or the file cannot be written
      • setProjectArtifacts

        public void setProjectArtifacts​(Set<org.apache.maven.artifact.Artifact> projectArtifacts)
        Provides the set of resolved project artifacts.

        Must be called before resolve(java.io.File, java.io.File) when the catalog may contain maven: URIs. Typically populated from MavenProject.getArtifacts() in the calling mojo.

        Parameters:
        projectArtifacts - the resolved artifacts of the current Maven project