You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2026/08/20 14:09:05 UTC
(cayenne) 02/04: cgen schema: missing attribute
This is an automated email from the ASF dual-hosted git repository.
stariy95 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit f331ddf0ab34bd10f297314b345be18c58e29664
Author: ntimofeev <st...@gmail.com>
AuthorDate: Thu Aug 20 14:00:06 2026 +0300
cgen schema: missing attribute
---
.../apache/cayenne/gen/xml/CgenConfigHandler.java | 4 +
.../cayenne/gen/xml/CgenConfigHandlerTest.java | 94 ++++++++++++++++++++++
.../src/test/resources/cgenRoundTrip.map.xml | 21 +++++
.../org/apache/cayenne/schema/13/cgen.xsd | 1 +
4 files changed, 120 insertions(+)
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
index 002cc42d9..4711fafe4 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
@@ -106,6 +106,7 @@ public class CgenConfigHandler extends NamespaceAwareNestedTagHandler {
break;
case EMBEDDABLE_SUPER_TEMPLATE_TAG:
createEmbeddableSuperTemplate(data);
+ break;
case DATAMAP_TEMPLATE_TAG:
createDataMapTemplate(data);
break;
@@ -133,6 +134,9 @@ public class CgenConfigHandler extends NamespaceAwareNestedTagHandler {
case SUPER_PKG_TAG:
createSuperPkg(data);
break;
+ case EXTERNAL_TOOL_CONFIG_TAG:
+ createExternalToolConfig(data);
+ break;
}
return true;
}
diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/xml/CgenConfigHandlerTest.java b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/xml/CgenConfigHandlerTest.java
new file mode 100644
index 000000000..c0e55a359
--- /dev/null
+++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/xml/CgenConfigHandlerTest.java
@@ -0,0 +1,94 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * https://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 org.apache.cayenne.gen.xml;
+
+import org.apache.cayenne.configuration.DataMapLoader;
+import org.apache.cayenne.configuration.xml.DataChannelMetaData;
+import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.gen.CgenConfigList;
+import org.apache.cayenne.gen.CgenConfiguration;
+import org.apache.cayenne.gen.TemplateType;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.resource.URLResource;
+import org.apache.cayenne.tools.ToolsInjectorBuilder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.slf4j.helpers.NOPLogger;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Checks that a {@code <cgen>} block survives a load, element for element.
+ */
+public class CgenConfigHandlerTest {
+
+ @TempDir
+ static Path tempDir;
+
+ private static CgenConfiguration configuration;
+
+ @BeforeAll
+ public static void loadConfiguration() throws Exception {
+ Path mapFile = tempDir.resolve("cgenRoundTrip.map.xml");
+ try (InputStream in = CgenConfigHandlerTest.class.getResourceAsStream("/cgenRoundTrip.map.xml")) {
+ assertNotNull(in, "test DataMap is missing from the classpath");
+ Files.copy(in, mapFile);
+ }
+
+ Injector injector = new ToolsInjectorBuilder()
+ .addModule(new ToolsModule(NOPLogger.NOP_LOGGER))
+ .create();
+
+ DataMap dataMap = injector.getInstance(DataMapLoader.class)
+ .load(new URLResource(mapFile.toUri().toURL()));
+
+ CgenConfigList configurations = injector.getInstance(DataChannelMetaData.class)
+ .get(dataMap, CgenConfigList.class);
+ assertNotNull(configurations, "no cgen configuration was loaded");
+
+ configuration = configurations.getByName("Default");
+ assertNotNull(configuration);
+ }
+
+ @Test
+ public void embeddableSuperTemplate() {
+ assertEquals("custom embeddable superclass template", configuration.getEmbeddableSuperTemplate().getData());
+ assertEquals(TemplateType.DATAMAP_SUBCLASS.defaultTemplate().getData(),
+ configuration.getDataMapTemplate().getData());
+ }
+
+ @Test
+ public void externalToolConfig() {
+ assertEquals("tools.properties", configuration.getExternalToolConfig());
+ }
+
+ @Test
+ public void destDirIsResolved() {
+ assertEquals(tempDir, configuration.getRootPath());
+ assertEquals(tempDir.resolve("../java").normalize(), configuration.requireOutputDirectory());
+ }
+}
diff --git a/cayenne-cgen/src/test/resources/cgenRoundTrip.map.xml b/cayenne-cgen/src/test/resources/cgenRoundTrip.map.xml
new file mode 100644
index 000000000..6ab64d99c
--- /dev/null
+++ b/cayenne-cgen/src/test/resources/cgenRoundTrip.map.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/13/modelMap"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://cayenne.apache.org/schema/13/modelMap https://cayenne.apache.org/schema/13/modelMap.xsd"
+ project-version="13">
+ <obj-entity name="Artist" className="org.example.Artist">
+ </obj-entity>
+ <cgen xmlns="http://cayenne.apache.org/schema/13/cgen">
+ <name>Default</name>
+ <destDir>../java</destDir>
+ <mode>entity</mode>
+ <embeddableSuperTemplate><![CDATA[custom embeddable superclass template]]></embeddableSuperTemplate>
+ <outputPattern>*.java</outputPattern>
+ <makePairs>true</makePairs>
+ <usePkgPath>true</usePkgPath>
+ <overwrite>false</overwrite>
+ <createPropertyNames>false</createPropertyNames>
+ <createPKProperties>true</createPKProperties>
+ <externalToolConfig>tools.properties</externalToolConfig>
+ </cgen>
+</data-map>
diff --git a/cayenne/src/main/resources/org/apache/cayenne/schema/13/cgen.xsd b/cayenne/src/main/resources/org/apache/cayenne/schema/13/cgen.xsd
index cbc5ee823..38e8699b1 100644
--- a/cayenne/src/main/resources/org/apache/cayenne/schema/13/cgen.xsd
+++ b/cayenne/src/main/resources/org/apache/cayenne/schema/13/cgen.xsd
@@ -45,6 +45,7 @@
<xs:element name="createPropertyNames" minOccurs="0" type="xs:boolean"/>
<xs:element name="superPkg" minOccurs="0" type="xs:string"/>
<xs:element name="createPKProperties" minOccurs="0" type="xs:boolean"/>
+ <xs:element name="externalToolConfig" minOccurs="0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>