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 2019/09/11 08:28:35 UTC

[cayenne] 01/02: CAY-2615 Saving project throws IllegalArgumentException

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

commit 5318a19eeb4b491800543ac576932569d1420430
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Wed Sep 11 11:28:12 2019 +0300

    CAY-2615 Saving project throws IllegalArgumentException
---
 .../src/main/java/org/apache/cayenne/gen/CgenConfiguration.java  | 9 +++++++--
 .../main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java  | 8 +++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
index 6a6f262..de7d9ba 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
@@ -166,8 +166,13 @@ public class CgenConfiguration implements Serializable, XMLSerializable {
         this.relPath = relPath;
     }
 
-    public void setRelPath(String path) {
-		this.relPath = rootPath != null ? rootPath.relativize(Paths.get(path)) : Paths.get(path);
+    public void setRelPath(String pathStr) {
+        Path path = Paths.get(pathStr);
+        if(path.isAbsolute() && rootPath != null) {
+            this.relPath = rootPath.relativize(path);
+        } else {
+            this.relPath = path;
+        }
 	}
 
     public boolean isOverwrite() {
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 8b19d2d..037b566 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
@@ -55,7 +55,6 @@ public class CgenSaverDelegate extends BaseSaverDelegate{
         if(cgenConfiguration.getRootPath() == null) {
             return;
         }
-        Path prevPath = cgenConfiguration.buildPath();
         URL url = getBaseDirectory().getURL();
         if(url != null) {
             Path resourcePath;
@@ -68,9 +67,12 @@ public class CgenSaverDelegate extends BaseSaverDelegate{
                 resourcePath = resourcePath.getParent();
             }
             cgenConfiguration.setRootPath(resourcePath);
+            Path prevPath = cgenConfiguration.buildPath();
             if(prevPath != null) {
-                Path relPath = resourcePath.relativize(prevPath).normalize();
-                cgenConfiguration.setRelPath(relPath);
+                if(prevPath.isAbsolute()) {
+                    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());