1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.avk; 26 27 import java.io.File ; 28 import java.util.Set ; 29 import java.util.Iterator ; 30 import java.lang.reflect.Method ; 31 32 import javax.enterprise.deploy.spi.DeploymentManager ; 33 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 34 35 import org.netbeans.modules.j2ee.sun.ide.Installer; 36 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties; 37 38 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager; 39 40 44 public class FileUtil { 45 46 public static void clearResults(SunDeploymentManagerInterface sunDm, DeploymentManagerProperties dmProps){ 47 String domainDir = dmProps.getLocation() + dmProps.getDomainName(); 48 String resultDir = domainDir + File.separator + "logs" + File.separator + "reporttool"; deleteAllFilesUnder(new File (resultDir), sunDm); 50 } 51 52 private static void deleteAllFilesUnder(File directory, SunDeploymentManagerInterface sunDm) { 53 try { 54 if (directory != null && !directory.exists()) 55 return; 56 57 Set files = getFiles(directory, sunDm); 58 Set dirs = new java.util.HashSet (); 59 Set filesList = new java.util.HashSet (); 60 for (Iterator i = files.iterator(); i.hasNext();) { 61 File actualFile = new File (directory, i.next().toString()); 62 if(actualFile.isDirectory()){ 63 dirs.add(actualFile); 64 } else 65 filesList.add(actualFile); 66 } 67 68 deleteFiles(directory, filesList); 69 deleteFiles(directory, dirs); 70 directory.delete(); 71 } catch (Exception ex) { 72 return; 73 } 74 } 75 76 private static Set getFiles(File resultDir, SunDeploymentManagerInterface sunDm) throws Exception { 77 Set result = null; 78 ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader(); 79 try{ 80 Class [] argClass = new Class [1]; 81 argClass[0] = File .class; 82 Object [] argObject = new Object [1]; 83 argObject[0] = resultDir; 84 85 Class controllerUtilClass = ServerLocationManager.getNetBeansAndServerClassLoader(sunDm.getPlatformRoot()). 86 loadClass("com.sun.enterprise.util.FileUtil"); 88 89 Method method = controllerUtilClass.getMethod("getAllFilesAndDirectoriesUnder", argClass); 90 91 Thread.currentThread().setContextClassLoader( 92 ServerLocationManager.getNetBeansAndServerClassLoader(sunDm.getPlatformRoot())); 93 94 result = (Set )method.invoke(controllerUtilClass.newInstance(), argObject); 95 96 } catch (Exception e){ 97 throw e; 98 } finally { 99 Thread.currentThread().setContextClassLoader(origClassLoader); 100 } 101 return result; 102 } 103 104 private static void deleteFiles(File directory, Set files){ 105 for (Iterator i = files.iterator(); i.hasNext();) { 106 File next = (File ) i.next(); 107 next.delete(); 108 } 109 } 110 111 } 112 | Popular Tags |