Skip to content

Commit

Permalink
Added toptoc format
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Nov 28, 2023
1 parent d91df6d commit 929d3da
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ph-diver-repo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</goals>
<id>ves</id>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemas/repotoc</schemaDirectory>
<schemaDirectory>${basedir}/src/main/resources/schemas</schemaDirectory>
<bindingIncludes>
<bindingInclude>bindings.xjb</bindingInclude>
</bindingIncludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RepoToc1Marshaller extends GenericJAXBMarshaller <RepoTocType>
/**
* The XML Schema path to validate against.
*/
public static final ClassPathResource XSD_RES = new ClassPathResource ("schemas/repotoc/repotoc-1.0.xsd",
public static final ClassPathResource XSD_RES = new ClassPathResource ("schemas/repotoc-1.0.xsd",
RepoToc1Marshaller.class.getClassLoader ());

public RepoToc1Marshaller ()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2023 Philip Helger & ecosio
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.diver.repo.toptoc;

import com.helger.commons.collection.impl.CommonsArrayList;
import com.helger.commons.io.resource.ClassPathResource;
import com.helger.diver.repo.toptoc.jaxb.v10.ObjectFactory;
import com.helger.diver.repo.toptoc.jaxb.v10.RepoTopTocType;
import com.helger.jaxb.GenericJAXBMarshaller;

/**
* JAXB marshaller for {@link RepoTopTocType} objects.
*
* @author Philip Helger
*/
public class RepoTopToc1Marshaller extends GenericJAXBMarshaller <RepoTopTocType>
{
/**
* The namespace URI of the RepoToc1 XML data model
*/
public static final String NAMESPACE_URI = "urn:com:helger:diver:repotoptoc:v1.0";

/**
* The XML Schema path to validate against.
*/
public static final ClassPathResource XSD_RES = new ClassPathResource ("schemas/repotoptoc-1.0.xsd",
RepoTopToc1Marshaller.class.getClassLoader ());

public RepoTopToc1Marshaller ()
{
super (RepoTopTocType.class, new CommonsArrayList <> (XSD_RES), new ObjectFactory ()::createRepotoptoc);
}
}
7 changes: 6 additions & 1 deletion ph-diver-repo/src/main/jaxb/bindings.xjb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@
<xjc:javaType name="com.helger.commons.datetime.XMLOffsetDate" xmlType="xsd:date" adapter="com.helger.jaxb.adapter.AdapterXMLOffsetDate" />
<xjc:javaType name="com.helger.commons.datetime.XMLOffsetTime" xmlType="xsd:time" adapter="com.helger.jaxb.adapter.AdapterXMLOffsetTime" />
</globalBindings>
<bindings schemaLocation="../resources/schemas/repotoc/repotoc-1.0.xsd">
<bindings schemaLocation="../resources/schemas/repotoc-1.0.xsd">
<schemaBindings>
<package name="com.helger.diver.repo.toc.jaxb.v10" />
</schemaBindings>
</bindings>
<bindings schemaLocation="../resources/schemas/repotoptoc-1.0.xsd">
<schemaBindings>
<package name="com.helger.diver.repo.toptoc.jaxb.v10" />
</schemaBindings>
</bindings>
</bindings>
88 changes: 88 additions & 0 deletions ph-diver-repo/src/main/resources/schemas/repotoptoc-1.0.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2023 Philip Helger & ecosio
philip[at]helger[dot]com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:com:helger:diver:repotoptoc:v1.0"
targetNamespace="urn:com:helger:diver:repotoptoc:v1.0"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.0">
<xs:annotation>
<xs:documentation>
This XML Schema is used to describe a single Diver Repository top-level Table of Contents for all groups and artifacts.

Version: 2023-11-28
</xs:documentation>
</xs:annotation>

<xs:complexType name="ArtifactType">
<xs:sequence>
<!-- empty -->
</xs:sequence>
<xs:attribute name="name" type="xs:normalizedString" use="required">
<xs:annotation>
<xs:documentation>The name of the artifact</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>

<xs:complexType name="GroupType">
<xs:sequence>
<!-- Recursive type! -->
<xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>Nested child groups</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="artifact" type="ArtifactType" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>All the artifact names of this group</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:normalizedString" use="required">
<xs:annotation>
<xs:documentation>The name of the group</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>

<xs:complexType name="RepoTopTocType">
<xs:annotation>
<xs:documentation>
Top-level element may only contain groups but no artifacts.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>All top level groups</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>

<xs:element name="repotoptoc" type="RepoTopTocType">
<xs:annotation>
<xs:documentation>
The root element of the Repository top-level Table of Contents of all groups and artifacts.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2023 Philip Helger & ecosio
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.diver.repo.toptoc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;

import com.helger.commons.io.resource.ClassPathResource;
import com.helger.diver.repo.toptoc.jaxb.v10.GroupType;
import com.helger.diver.repo.toptoc.jaxb.v10.RepoTopTocType;

/**
* Test class for class {@link RepoTopToc1Marshaller}.
*
* @author Philip Helger
*/
public final class RepoTopToc1MarshallerTest
{
@Test
public void testRepoToc1 ()
{
final RepoTopToc1Marshaller m = new RepoTopToc1Marshaller ();
final RepoTopTocType aRepoTopToc1 = m.read (new ClassPathResource ("repotoptoc/repotoptoc-1.xml"));
assertNotNull (aRepoTopToc1);

assertEquals (2, aRepoTopToc1.getGroupCount ());
assertEquals ("com", aRepoTopToc1.getGroupAtIndex (0).getName ());
assertEquals ("org", aRepoTopToc1.getGroupAtIndex (1).getName ());

final GroupType aCom = aRepoTopToc1.getGroupAtIndex (0);
assertEquals (3, aCom.getGroupCount ());
assertEquals ("ecosio", aCom.getGroupAtIndex (0).getName ());
assertEquals ("helger", aCom.getGroupAtIndex (1).getName ());
assertEquals ("rest", aCom.getGroupAtIndex (2).getName ());

assertEquals (0, aCom.getGroupAtIndex (0).getGroupCount ());
assertEquals (2, aCom.getGroupAtIndex (0).getArtifactCount ());
assertEquals (0, aCom.getGroupAtIndex (1).getGroupCount ());
assertEquals (1, aCom.getGroupAtIndex (1).getArtifactCount ());
assertEquals (0, aCom.getGroupAtIndex (2).getGroupCount ());
assertEquals (0, aCom.getGroupAtIndex (2).getArtifactCount ());
}
}
38 changes: 38 additions & 0 deletions ph-diver-repo/src/test/resources/repotoptoc/repotoptoc-1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2023 Philip Helger & ecosio
philip[at]helger[dot]com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<repotoptoc xmlns="urn:com:helger:diver:repotoptoc:v1.0">
<group name="com">
<group name="ecosio">
<artifact name="artifact1" />
<artifact name="artifact2" />
</group>
<group name="helger">
<artifact name="artifact3" />
</group>
<group name="rest">
<!-- empty -->
</group>
</group>
<group name="org">
<group name="example">
<artifact name="artifact4" />
</group>
</group>
</repotoptoc>

0 comments on commit 929d3da

Please sign in to comment.