mail[Wesnoth-commits] r43912 - /trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/ResourceUtils.java


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by timotei_cluj on July 04, 2010 - 22:25:
Author: timotei
Date: Sun Jul  4 22:25:50 2010
New Revision: 43912

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43912&view=rev
Log:
eclipse plugin: check for file existance before using it
add the 'overwrite' flag for overwriting existing files if any

Modified:
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/ResourceUtils.java

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/ResourceUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/ResourceUtils.java?rev=43912&r1=43911&r2=43912&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/ResourceUtils.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/ResourceUtils.java
 Sun Jul  4 22:25:50 2010
@@ -54,6 +54,9 @@
 
        public static String getFileContents(File file)
        {
+               if (!file.exists())
+                       return null;
+
                String contentsString = "";
                BufferedReader reader = null;
                try
@@ -135,8 +138,10 @@
         * @param project the project in which the file will be created
         * @param fileName the filename of the file
         * @param fileContentsString the text which will be contained in the 
file
+        * @param overwrite true to overwrite the file if it already exists
         */
-       public static void createFile(IProject project, String fileName, 
String fileContentsString)
+       public static void createFile(IProject project, String fileName, 
String fileContentsString,
+                       boolean overwrite)
        {
                IFile file = project.getFile(fileName);
                if (fileContentsString == null)
@@ -145,6 +150,15 @@
                        Logger.print("file contents are null", 2);
                }
 
+               if (file.exists() && overwrite)
+                       try
+                       {
+                               file.delete(true, null);
+                       } catch (CoreException e)
+                       {
+                               e.printStackTrace();
+                       }
+
                ByteArrayInputStream inputStream = new 
ByteArrayInputStream(fileContentsString.getBytes());
                createResource(file, project, fileName, inputStream);
        }




Related Messages


Powered by MHonArc, Updated Sun Jul 04 22:40:06 2010