From 26a41f09e4c808d3555cf8289b3450ad39e21305 Mon Sep 17 00:00:00 2001 From: jkohnlein Date: Wed, 30 Jul 2008 08:41:43 +0000 Subject: [PATCH] Added logging a la Friese --- .../src/org/eclipse/xtext/util/Files.java | 74 ++++++++++++------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/plugins/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Files.java b/plugins/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Files.java index 0a27ea0c6..11b2da7a0 100644 --- a/plugins/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Files.java +++ b/plugins/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Files.java @@ -9,6 +9,7 @@ package org.eclipse.xtext.util; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -24,30 +25,51 @@ public class Files { private static Logger log = Logger.getLogger(Files.class); - public static void copyFiles(String sourceDir, String targetDir, List files) { - File target = new File(targetDir); - if (!target.exists()) { - target.mkdir(); - } - for (String file : files) { - File copy = new File(target.getAbsolutePath() + File.separatorChar + file); - if (!copy.exists()) { - try { - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - String uri = sourceDir + "/" + file; - InputStream is = contextClassLoader.getResourceAsStream(uri); - copy.createNewFile(); - FileOutputStream fwr = new FileOutputStream(copy); - byte[] buff = new byte[1024]; - int read; - while ((read = is.read(buff)) != -1) { - fwr.write(buff, 0, read); - } - log.debug("Copied " + copy); - } catch (IOException e) { - log.error(e); - } - } - } - } + public static void copyFiles(String sourceDir, String targetDir, List files) { + File target = new File(targetDir); + if (!target.exists()) { + target.mkdir(); + } + for (String file : files) { + File copy = new File(target.getAbsolutePath() + File.separatorChar + file); + if (!copy.exists()) { + try { + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + String uri = sourceDir + "/" + file; + InputStream is = contextClassLoader.getResourceAsStream(uri); + copy.createNewFile(); + FileOutputStream fwr = new FileOutputStream(copy); + byte[] buff = new byte[1024]; + int read; + while ((read = is.read(buff)) != -1) { + fwr.write(buff, 0, read); + } + log.debug("Copied " + copy); + } + catch (IOException e) { + log.error(e); + } + } + } + } + + public static void cleanFolder(File f) throws FileNotFoundException { + if (!f.exists()) { + throw new FileNotFoundException(f.getAbsolutePath()); + } + log.info("Cleaning folder " + f.toString()); + final File[] contents = f.listFiles(); + for (int j = 0; j < contents.length; j++) { + final File file = contents[j]; + if (file.isDirectory()) { + cleanFolder(file); + } + else { + if (!file.delete()) { + log.error("Couldn't delete " + file.getAbsolutePath()); + } + } + } + f.delete(); + } }