cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1420294 - in /cayenne/main/trunk/framework/cayenne-project/src: main/java/org/apache/cayenne/project/FileProjectSaver.java test/java/org/apache/cayenne/project/FileProjectSaverTest.java
Date Tue, 11 Dec 2012 17:20:59 GMT
Author: aadamchik
Date: Tue Dec 11 17:20:58 2012
New Revision: 1420294

URL: http://svn.apache.org/viewvc?rev=1420294&view=rev
Log:
CAY-1780  cdbimport do not create xml file in resource folder

patch by Ilya Drabenia

Modified:
    cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/FileProjectSaver.java
    cayenne/main/trunk/framework/cayenne-project/src/test/java/org/apache/cayenne/project/FileProjectSaverTest.java

Modified: cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/FileProjectSaver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/FileProjectSaver.java?rev=1420294&r1=1420293&r2=1420294&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/FileProjectSaver.java
(original)
+++ cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/FileProjectSaver.java
Tue Dec 11 17:20:58 2012
@@ -106,8 +106,13 @@ public class FileProjectSaver implements
             clearTempFiles(units);
         }
 
-        if (deleteOldResources) {
-            clearOldFiles(units);
+        try {
+            if (deleteOldResources) {
+                clearOldFiles(units);
+            }
+        }
+        catch (IOException ex) {
+            throw new CayenneRuntimeException(ex);
         }
     }
 
@@ -274,7 +279,7 @@ public class FileProjectSaver implements
         }
     }
 
-    private void clearOldFiles(Collection<SaveUnit> units) {
+    private void clearOldFiles(Collection<SaveUnit> units) throws IOException {
         for (SaveUnit unit : units) {
 
             if (unit.sourceConfiguration == null) {
@@ -299,18 +304,30 @@ public class FileProjectSaver implements
             // target matches, skip this file
             boolean isTarget = false;
             for (SaveUnit xunit : units) {
-                if (sourceFile.equals(xunit.targetFile)) {
+                if (isFilesEquals(sourceFile, xunit.targetFile)) {
                     isTarget = true;
                     break;
                 }
             }
 
             if (!isTarget) {
-                sourceFile.delete();
+                if (!sourceFile.delete()) {
+                    throw new CayenneRuntimeException("Could not delete file '%s'", sourceFile.getCanonicalPath());
+                }
             }
         }
     }
 
+    private boolean isFilesEquals(File firstFile, File secondFile) throws IOException {
+        boolean isFirstFileExists = firstFile.exists();
+        boolean isSecondFileExists = secondFile.exists();
+
+        String firstFilePath = firstFile.getCanonicalPath();
+        String secondFilePath = secondFile.getCanonicalPath();
+
+        return isFirstFileExists && isSecondFileExists && firstFilePath.equals(secondFilePath);
+    }
+
     class SaveUnit {
 
         private ConfigurationNode node;

Modified: cayenne/main/trunk/framework/cayenne-project/src/test/java/org/apache/cayenne/project/FileProjectSaverTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project/src/test/java/org/apache/cayenne/project/FileProjectSaverTest.java?rev=1420294&r1=1420293&r2=1420294&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project/src/test/java/org/apache/cayenne/project/FileProjectSaverTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-project/src/test/java/org/apache/cayenne/project/FileProjectSaverTest.java
Tue Dec 11 17:20:58 2012
@@ -19,6 +19,7 @@
 package org.apache.cayenne.project;
 
 import java.io.File;
+import java.net.URL;
 import java.util.Arrays;
 
 import javax.xml.xpath.XPath;
@@ -44,10 +45,10 @@ import org.w3c.dom.NodeList;
 
 public class FileProjectSaverTest extends Project2Case {
 
-    public void testSaveAs_Sorted() throws Exception {
-
-        File testFolder = setupTestDirectory("testSaveAs_Sorted");
+    private FileProjectSaver saver;
 
+    @Override
+    public void setUp() throws Exception {
         Module testModule = new Module() {
 
             public void configure(Binder binder) {
@@ -56,9 +57,14 @@ public class FileProjectSaverTest extend
             }
         };
 
-        FileProjectSaver saver = new FileProjectSaver();
+        saver = new FileProjectSaver();
         Injector injector = DIBootstrap.createInjector(testModule);
         injector.injectMembers(saver);
+    }
+
+    public void testSaveAs_Sorted() throws Exception {
+
+        File testFolder = setupTestDirectory("testSaveAs_Sorted");
 
         DataChannelDescriptor rootNode = new DataChannelDescriptor();
         rootNode.setName("test");
@@ -127,4 +133,25 @@ public class FileProjectSaverTest extend
         assertEquals("C", xpath.evaluate("@name", mapRefs.item(2)));
 
     }
+
+    /**
+     * Method test fix for CAY-1780 bug. If specify related fragments (for example ./../)
+     * in target file path then file must be created successfully.
+     * @throws Exception
+     */
+    public void testSaveForRelatedPaths() throws Exception {
+        File testFolder = setupTestDirectory("testSaveForRelatedPaths");
+
+        String mapFilePath = "file:" + testFolder.getCanonicalPath() + "/../test.map.xml";
+        String mapFileName = "test";
+        DataMap testDataMap = new DataMap(mapFileName);
+        testDataMap.setConfigurationSource(new URLResource(new URL(mapFilePath)));
+        Project project = new Project(new ConfigurationTree<DataMap>(testDataMap));
+
+        saver.save(project);
+
+        File target = new File(testFolder.getParentFile(), mapFileName + ".map.xml");
+        assertTrue(target.isFile());
+    }
+
 }



Mime
View raw message