1 25 package org.objectweb.petals.jbi.management.autoload; 26 27 import java.io.File ; 28 import java.io.FilenameFilter ; 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 import java.util.List ; 32 import java.util.TimerTask ; 33 34 41 public class InstalledDirectoryScanner extends TimerTask { 42 43 50 private class ArchiveFileFilter implements FilenameFilter { 51 52 55 public boolean accept(File dir, String name) { 56 57 String lcName = name.toLowerCase(); 58 59 if (lcName.endsWith("jar") || lcName.endsWith("zip")) { 60 return true; 61 } 62 return false; 63 } 64 65 } 66 67 ArchiveFileFilter archiveFilter; 68 69 AutoLoaderImpl autoLoader; 70 71 File installedDir; 72 73 List <File > previousFileList = new ArrayList <File >(); 74 75 public InstalledDirectoryScanner(AutoLoaderImpl autoLoader, 76 File installedDir) { 77 this.installedDir = installedDir; 78 79 this.autoLoader = autoLoader; 80 81 archiveFilter = new ArchiveFileFilter(); 82 } 83 84 public void run() { 85 86 List <File > newFileList = null; 87 File [] files = installedDir.listFiles(archiveFilter); 88 if(files != null){ 89 newFileList = Arrays.asList(files); 90 }else{ 91 newFileList = new ArrayList <File >(); 92 } 93 List <File > filesToUninstall = new ArrayList <File >(); 94 95 for (File file : previousFileList) { 96 if (!newFileList.contains(file)) { 97 filesToUninstall.add(file); 98 } 99 } 100 101 if (filesToUninstall != null && !filesToUninstall.isEmpty()) { 102 autoLoader.uninstall(filesToUninstall); 103 } 104 105 previousFileList.clear(); 106 previousFileList.addAll(newFileList); 107 } 108 } 109 | Popular Tags |