cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [30/32] cayenne git commit: Rel path for template bug fix
Date Wed, 14 Nov 2018 14:28:01 GMT
Rel path for template bug fix


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/51803e43
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/51803e43
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/51803e43

Branch: refs/heads/master
Commit: 51803e43be67029f97c47a0d03ae395795ed0d07
Parents: 5128e66
Author: Arseni Bulatski <ancarseni@gmail.com>
Authored: Wed Nov 14 16:52:10 2018 +0300
Committer: Arseni Bulatski <ancarseni@gmail.com>
Committed: Wed Nov 14 16:52:10 2018 +0300

----------------------------------------------------------------------
 .../java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java   | 8 ++++++++
 .../java/org/apache/cayenne/modeler/CodeTemplateManager.java | 8 ++++++--
 .../apache/cayenne/modeler/editor/cgen/CustomModePanel.java  | 6 ++++--
 3 files changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/51803e43/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
----------------------------------------------------------------------
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
index 92453c7..5f381ea 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
@@ -64,6 +64,14 @@ public class CgenSaverDelegate extends BaseSaverDelegate{
             if(prevPath != null) {
                 Path relPath = resourcePath.relativize(prevPath).normalize();
                 cgenConfiguration.setRelPath(relPath);
+                Path templatePath = Paths.get(cgenConfiguration.getTemplate());
+                if(templatePath.isAbsolute()) {
+                    cgenConfiguration.setTemplate(resourcePath.relativize(templatePath).normalize().toString());
+                }
+                Path superTemplatePath = Paths.get(cgenConfiguration.getSuperTemplate());
+                if(superTemplatePath.isAbsolute()) {
+                    cgenConfiguration.setSuperTemplate(resourcePath.relativize(superTemplatePath).normalize().toString());
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/51803e43/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
----------------------------------------------------------------------
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 a5d2fb6..76dd2b2 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
@@ -22,6 +22,7 @@ package org.apache.cayenne.modeler;
 import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.modeler.pref.FSPath;
+import org.apache.cayenne.resource.Resource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -157,10 +158,13 @@ public class CodeTemplateManager {
 	// TODO: andrus, 12/5/2007 - this should also take a "pairs" parameter to
 	// correctly
 	// assign standard templates
-	public String getTemplatePath(String name, Path rootPath) {
+	public String getTemplatePath(String name, Resource rootPath) {
 		Object value = customTemplates.get(name);
 		if (value != null) {
-			value = rootPath.relativize(Paths.get((String)value));
+			if(rootPath != null) {
+				Path path = Paths.get(rootPath.getURL().getPath()).getParent();
+				value = path.relativize(Paths.get((String) value));
+			}
 			return value.toString();
 		}
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/51803e43/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
index ea5f1ce..18a1929 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
@@ -55,7 +55,8 @@ public class CustomModePanel extends GeneratorControllerPanel {
             @Override
             protected void updateModel(String item) throws ValidationException {
                 CgenConfiguration cgenConfiguration = getCgenByDataMap();
-                cgenConfiguration.setSuperTemplate(Application.getInstance().getCodeTemplateManager().getTemplatePath(item,
cgenConfiguration.getRootPath()));
+                cgenConfiguration.setSuperTemplate(Application.getInstance().getCodeTemplateManager().getTemplatePath(item,
+                        cgenConfiguration.getDataMap().getConfigurationSource()));
                 if(!codeGeneratorControllerBase.isInitFromModel()) {
                     projectController.setDirty(true);
                 }
@@ -67,7 +68,8 @@ public class CustomModePanel extends GeneratorControllerPanel {
             @Override
             protected void updateModel(String item) throws ValidationException {
                 CgenConfiguration cgenConfiguration = getCgenByDataMap();
-                cgenConfiguration.setTemplate(Application.getInstance().getCodeTemplateManager().getTemplatePath(item,
cgenConfiguration.getRootPath()));
+                cgenConfiguration.setTemplate(Application.getInstance().getCodeTemplateManager().getTemplatePath(item,
+                        cgenConfiguration.getDataMap().getConfigurationSource()));
                 if(!codeGeneratorControllerBase.isInitFromModel()) {
                     projectController.setDirty(true);
                 }


Mime
View raw message