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 2020/10/06 13:16:41 UTC

[cayenne] branch STABLE-4.1 updated: CAY-2676 Degradation: Custom class generation templates are not working anymore

This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.1 by this push:
     new 8690799  CAY-2676 Degradation: Custom class generation templates are not working anymore
8690799 is described below

commit 86907992cdd4b34ed8f2bba6547fae53100968a3
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Tue Oct 6 16:16:24 2020 +0300

    CAY-2676 Degradation: Custom class generation templates are not working anymore
---
 RELEASE-NOTES.txt                                          |  1 +
 .../java/org/apache/cayenne/gen/ClassGenerationAction.java |  3 +++
 .../org/apache/cayenne/modeler/CodeTemplateManager.java    | 14 +++++++++-----
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 9542257..a7cd5e5 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -15,6 +15,7 @@ Date:
 Bug Fixes:
 
 CAY-2670 CommitLog does not include FKs for deleted objects with one-way relationships
+CAY-2676 Degradation: Custom class generation templates are not working anymore
 CAY-2679 Unstable ordering of relationships in the .map.xml file
 CAY-2681 Modeler: All selected checkboxes cause project to become dirty at initialization
 
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
index 6138d96..1c2ec70 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
@@ -283,6 +283,9 @@ public class ClassGenerationAction {
 			props.put("resource.loader", "cayenne");
 			props.put("cayenne.resource.loader.class", ClassGeneratorResourceLoader.class.getName());
 			props.put("cayenne.resource.loader.cache", "false");
+			if (cgenConfiguration.getRootPath() != null) {
+				props.put("cayenne.resource.loader.path", cgenConfiguration.getRootPath().toString());
+			}
 
 			VelocityEngine velocityEngine = new VelocityEngine();
 			velocityEngine.init(props);
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
index 9b4b4f1..f9f6108 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
@@ -19,6 +19,7 @@
 
 package org.apache.cayenne.modeler;
 
+import java.net.URISyntaxException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -166,13 +167,16 @@ public class CodeTemplateManager {
 	public String getTemplatePath(String name, Resource rootPath) {
 		Object value = customTemplates.get(name);
 		if (value != null) {
-			if(rootPath != null) {
-				Path path = Paths.get(rootPath.getURL().getPath()).getParent();
-				value = path.relativize(Paths.get((String) value));
+			try {
+				if(rootPath != null) {
+						Path path = Paths.get(rootPath.getURL().toURI()).getParent();
+						value = path.relativize(Paths.get((String) value));
+				}
+				return value.toString();
+			} catch (URISyntaxException e) {
+				logger.warn("Path for template named '{}' could not be resolved", name);
 			}
-			return value.toString();
 		}
-
 		value = standardTemplates.get(name);
 		return value != null ? value.toString() : null;
 	}