1 19 20 package org.netbeans.modules.autoupdate; 21 22 23 import java.io.File ; 24 import java.io.FilenameFilter ; 25 import java.io.IOException ; 26 import java.util.Collection ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import java.util.jar.JarFile ; 32 import java.util.jar.Manifest ; 33 import org.openide.modules.ModuleInfo; 34 35 39 class PatchChecker extends Object { 40 41 private static final String JAR_EXTENSION = ".JAR"; private static final String ZIP_EXTENSION = ".ZIP"; 44 private static ModuleInfo[] patchArray = null; 45 46 47 private PatchChecker() { 48 } 49 50 static ModuleInfo[] getPatches() { 51 52 if ( patchArray == null ) { 53 54 List patchDirectories = Autoupdater.Support.getPatchDirectories (); 55 56 Collection patches = new ArrayList (); 57 58 if (!patchDirectories.isEmpty ()) { 59 Iterator it = patchDirectories.iterator (); 60 while (it.hasNext ()) { 61 addPatches ((File )it.next (), patches); 62 } 63 } 64 65 patchArray = new ModuleInfo[ patches.size() ]; 66 patches.toArray( patchArray ); 67 } 68 69 return patchArray; 70 } 71 72 private static void addPatches( File directory, Collection result ) { 73 74 File dirList[] = directory.listFiles( new FilenameFilter () { 75 public boolean accept( File dir, String name ) { 76 return name.toUpperCase().endsWith( JAR_EXTENSION ) || 77 name.toUpperCase().endsWith( ZIP_EXTENSION ); 78 } 79 }); 80 if (dirList == null) return; 82 83 for ( int i = 0; i < dirList.length; i++ ) { 84 85 JarFile jarFile = null; 86 try { 87 jarFile = new JarFile ( dirList[i] ); 88 Manifest manifest = jarFile.getManifest(); 89 90 91 if ( manifest == null ) 92 continue; 94 ModuleInfo md = new DummyModuleInfo(manifest.getMainAttributes()); 95 96 Iterator it = result.iterator(); 97 boolean found = false; 98 while( it.hasNext() ) { 99 ModuleInfo td = (ModuleInfo)it.next(); 100 101 if ( md.getCodeNameBase().equals( td.getCodeNameBase() ) ) { 102 found = true; 103 break; 104 } 105 106 } 107 108 if ( !found ) 109 result.add( md ); 110 } 111 catch ( IOException e ) { 112 } 113 catch ( IllegalArgumentException e ) { 114 } 115 finally { 116 try { 117 if ( jarFile != null ) 118 jarFile.close(); 119 } catch ( IOException ie ) { 120 } 121 } 122 123 } 124 } 125 } 126 | Popular Tags |