Index: batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java,v retrieving revision 1.32 diff -u -r1.32 ClasspathDirectory.java --- batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java 25 May 2005 14:15:06 -0000 1.32 +++ batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java 21 Jul 2005 15:11:33 -0000 @@ -11,6 +11,7 @@ package org.eclipse.jdt.internal.compiler.batch; import java.io.File; +import java.io.IOException; import java.util.Hashtable; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; @@ -120,6 +121,9 @@ } return null; } +public void initialize() throws IOException { + // nothing to do +} public boolean isPackage(String qualifiedPackageName) { return directoryList(qualifiedPackageName) != null; } Index: batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java,v retrieving revision 1.33 diff -u -r1.33 ClasspathJar.java --- batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java 25 May 2005 14:15:06 -0000 1.33 +++ batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java 21 Jul 2005 15:11:33 -0000 @@ -23,16 +23,17 @@ public class ClasspathJar extends ClasspathLocation { -ZipFile zipFile; -boolean closeZipFileAtEnd; -Hashtable packageCache; +private File file; +private ZipFile zipFile; +private boolean closeZipFileAtEnd; +private Hashtable packageCache; public ClasspathJar(File file) throws IOException { - this(new ZipFile(file), true, null); + this(file, true, null); } -public ClasspathJar(ZipFile zipFile, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet) { +public ClasspathJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet) { super(accessRuleSet); - this.zipFile = zipFile; + this.file = file; this.closeZipFileAtEnd = closeZipFileAtEnd; } @@ -49,6 +50,9 @@ } return null; } +public void initialize() throws IOException { + this.zipFile = new ZipFile(this.file); +} public boolean isPackage(String qualifiedPackageName) { if (this.packageCache != null) return this.packageCache.containsKey(qualifiedPackageName); @@ -75,10 +79,11 @@ public void reset() { if (this.zipFile != null && this.closeZipFileAtEnd) { try { - this.zipFile.close(); + this.zipFile.close(); } catch(IOException e) { // ignore } + this.zipFile = null; } this.packageCache = null; } Index: batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java,v retrieving revision 1.32 diff -u -r1.32 FileSystem.java --- batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java 25 May 2005 14:15:06 -0000 1.32 +++ batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java 21 Jul 2005 15:11:33 -0000 @@ -12,7 +12,6 @@ import java.io.File; import java.io.IOException; -import java.util.zip.ZipFile; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; @@ -39,6 +38,10 @@ * @return a normalized path for file based classpath entries */ String normalizedPath(); + /** + * Initialize the entry + */ + void initialize() throws IOException; } /* classPathNames is a collection is Strings representing the full path of each class path @@ -49,53 +52,61 @@ this(classpathNames, initialFileNames, encoding, null); } public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, int[] classpathDirectoryModes) { - int classpathSize = classpathNames.length; + final int classpathSize = classpathNames.length; this.classpaths = new Classpath[classpathSize]; - int problemsOccured = 0; + int counter = 0; for (int i = 0; i < classpathSize; i++) { - this.classpaths[i] = getClasspath(classpathNames[i], encoding, + Classpath classpath = getClasspath(classpathNames[i], encoding, classpathDirectoryModes == null ? 0 : classpathDirectoryModes[i], null); - if (this.classpaths[i] == null) - problemsOccured++; + try { + classpath.initialize(); + this.classpaths[counter++] = classpath; + } catch (IOException e) { + // ignore + } } - if (problemsOccured > 0) { - Classpath[] newPaths = new Classpath[classpathSize - problemsOccured]; - for (int i = 0, current = 0; i < classpathSize; i++) - if (this.classpaths[i] != null) { - newPaths[current] = this.classpaths[i]; - } - classpathSize = newPaths.length; - this.classpaths = newPaths; + if (counter != classpathSize) { + System.arraycopy(this.classpaths, 0, (this.classpaths = new Classpath[counter]), 0, counter); } initializeKnownFileNames(initialFileNames); } -FileSystem(Classpath[] classpaths, String[] initialFileNames) { - this.classpaths = classpaths; +FileSystem(Classpath[] paths, String[] initialFileNames) { + final int length = paths.length; + int counter = 0; + this.classpaths = new FileSystem.Classpath[length]; + for (int i = 0; i < length; i++) { + final Classpath classpath = paths[i]; + try { + classpath.initialize(); + this.classpaths[counter++] = classpath; + } catch(IOException exception) { + // ignore + } + } + if (counter != length) { + // should not happen + System.arraycopy(this.classpaths, 0, (this.classpaths = new FileSystem.Classpath[counter]), 0, counter); + } initializeKnownFileNames(initialFileNames); } static Classpath getClasspath(String classpathName, String encoding, int classpathDirectoryMode, AccessRuleSet accessRuleSet) { Classpath result = null; - try { - File file = new File(convertPathSeparators(classpathName)); - if (file.isDirectory()) { - if (file.exists()) { - result = new ClasspathDirectory(file, encoding, - classpathDirectoryMode, accessRuleSet); - } - } else { - String lowercaseClasspathName = classpathName.toLowerCase(); - if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar) - || lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) { - result = new ClasspathJar(new ZipFile(file), true, - accessRuleSet); - // will throw an IOException if file does not exist - } - } - } catch (IOException e) { - // result = null; -- this is already the case + File file = new File(convertPathSeparators(classpathName)); + if (file.isDirectory()) { + if (file.exists()) { + result = new ClasspathDirectory(file, encoding, + classpathDirectoryMode, accessRuleSet); } + } else { + String lowercaseClasspathName = classpathName.toLowerCase(); + if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar) + || lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) { + result = new ClasspathJar(file, true, accessRuleSet); + // will throw an IOException if file does not exist + } + } return result; } private void initializeKnownFileNames(String[] initialFileNames) { @@ -174,7 +185,7 @@ return null; } public ClasspathJar getClasspathJar(File file) throws IOException { - return new ClasspathJar(new ZipFile(file), true, null); + return new ClasspathJar(file, true, null); } public boolean isPackage(char[][] compoundName, char[] packageName) { String qualifiedPackageName = new String(CharOperation.concatWith(compoundName, packageName, '/'));