static ClasspathLocation forLibrary(IFile library, AccessRuleSet accessRuleSet) { return new ClasspathJar(library, accessRuleSet); }
/** Scan the contained packages and try to locate the module descriptor. */ private void scanContent() { try { if (this.zipFile == null) { if (org.eclipse.jdt.internal.core.JavaModelManager.ZIP_ACCESS_VERBOSE) { System.out.println("(" + Thread.currentThread() + ") [ClasspathJar.isPackage(String)] Creating ZipFile on " + this.zipFilename); //$NON-NLS-1$ //$NON-NLS-2$ } this.zipFile = new ZipFile(this.zipFilename); this.closeZipFileAtEnd = true; this.knownPackageNames = findPackageSet(); } else { this.knownPackageNames = findPackageSet(); } } catch(Exception e) { this.knownPackageNames = new SimpleSet(); // assume for this build the zipFile is empty } }
public String debugPathString() { long time = lastModified(); if (time == 0) return this.zipFilename; return this.zipFilename + '(' + (new Date(time)) + " : " + time + ')'; //$NON-NLS-1$ }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ClasspathJar)) return false; ClasspathJar jar = (ClasspathJar) o; if (this.accessRuleSet != jar.accessRuleSet) if (this.accessRuleSet == null || !this.accessRuleSet.equals(jar.accessRuleSet)) return false; if (!Util.equalOrNull(this.compliance, jar.compliance)) { return false; } return this.zipFilename.equals(jar.zipFilename) && lastModified() == jar.lastModified() && this.isOnModulePath == jar.isOnModulePath && areAllModuleOptionsEqual(jar); }
public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) { if (!isPackage(qualifiedPackageName)) return null; // most common case try { ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName); if (reader != null) { if (this.accessRuleSet == null) return new NameEnvironmentAnswer(reader, null); String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray())); } } catch (IOException e) { // treat as if class file is missing } catch (ClassFormatException e) { // treat as if class file is missing } return null; }
/** * Calculate and cache the package list available in the zipFile. * @return A SimpleSet with the all the package names in the zipFile. */ protected SimpleSet findPackageSet() { String zipFileName = this.zipFilename; PackageCacheEntry cacheEntry = (PackageCacheEntry) PackageCache.get(zipFileName); long timestamp = this.lastModified(); long fileSize = new File(zipFileName).length(); if (cacheEntry != null && cacheEntry.lastModified == timestamp && cacheEntry.fileSize == fileSize) { return cacheEntry.packageSet; } final SimpleSet packageSet = new SimpleSet(41); packageSet.add(""); //$NON-NLS-1$ readJarContent(packageSet); PackageCache.put(zipFileName, new PackageCacheEntry(timestamp, fileSize, packageSet)); return packageSet; } protected String readJarContent(final SimpleSet packageSet) {
@Override public IModule getModule() { if (this.knownPackageNames == null) scanContent(); return this.module; }
@Override public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { // return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); } public Manifest getManifest() {
public static IModule getAutomaticModule(ClasspathLocation location) { if (location instanceof ClasspathJar) { ClasspathJar classpathJar = (ClasspathJar) location; return IModule.createAutomatic(classpathJar.zipFilename, true, classpathJar.getManifest()); } if (location instanceof ClasspathDirectory) { return IModule.createAutomatic(((ClasspathDirectory) location).binaryFolder.getName(), false, null); } return null; } private void initModule(ClasspathLocation location) {
protected String readJarContent(final SimpleSet packageSet) { String modInfo = null; for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { String fileName = ((ZipEntry) e.nextElement()).getName(); if (fileName.startsWith("META-INF/")) //$NON-NLS-1$ continue; if (modInfo == null) { int folderEnd = fileName.lastIndexOf('/'); folderEnd += 1; String className = fileName.substring(folderEnd, fileName.length()); if (className.equalsIgnoreCase(IModule.MODULE_INFO_CLASS)) { modInfo = fileName; } } addToPackageSet(packageSet, fileName, false); } return modInfo; } IModule initializeModule() {
private void initModule(ClasspathLocation location) { IModule mod = null; if (location instanceof ClasspathJar) { mod = ((ClasspathJar) location).initializeModule(); } else if (location instanceof ClasspathDirectory){ mod = ((ClasspathDirectory) location).initializeModule(); } if (mod != null) { this.module = mod; this.isAutomaticModule = false; } else { this.module = getAutomaticModule(location); this.isAutomaticModule = true; } location.setModule(this.module); }
public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) { if (!isPackage(qualifiedPackageName)) return null; // most common case try { ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName); if (reader != null) { if (this.accessRuleSet == null) return new NameEnvironmentAnswer(reader, null); String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray())); } } catch (IOException e) { // treat as if class file is missing } catch (ClassFormatException e) { // treat as if class file is missing } return null; }
/** * Calculate and cache the package list available in the zipFile. * @return A SimpleSet with the all the package names in the zipFile. */ protected SimpleSet findPackageSet() { String zipFileName = this.zipFilename; PackageCacheEntry cacheEntry = (PackageCacheEntry) PackageCache.get(zipFileName); long timestamp = this.lastModified(); long fileSize = new File(zipFileName).length(); if (cacheEntry != null && cacheEntry.lastModified == timestamp && cacheEntry.fileSize == fileSize) { return cacheEntry.packageSet; } final SimpleSet packageSet = new SimpleSet(41); packageSet.add(""); //$NON-NLS-1$ readJarContent(packageSet); PackageCache.put(zipFileName, new PackageCacheEntry(timestamp, fileSize, packageSet)); return packageSet; } protected String readJarContent(final SimpleSet packageSet) {
@Override public IModule getModule() { if (this.knownPackageNames == null) scanContent(); return this.module; }
@Override public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { // return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false, null); } public Manifest getManifest() {
public static IModule getAutomaticModule(ClasspathLocation location) { if (location instanceof ClasspathJar) { ClasspathJar classpathJar = (ClasspathJar) location; return IModule.createAutomatic(classpathJar.zipFilename, true, classpathJar.getManifest()); } if (location instanceof ClasspathDirectory) { return IModule.createAutomatic(((ClasspathDirectory) location).binaryFolder.getName(), false, null); } return null; } private void initModule(ClasspathLocation location) {
protected String readJarContent(final SimpleSet packageSet) { String modInfo = null; for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { String fileName = ((ZipEntry) e.nextElement()).getName(); if (modInfo == null) { int folderEnd = fileName.lastIndexOf('/'); folderEnd += 1; String className = fileName.substring(folderEnd, fileName.length()); if (className.equalsIgnoreCase(IModule.MODULE_INFO_CLASS)) { modInfo = fileName; } } addToPackageSet(packageSet, fileName, false); } return modInfo; } IModule initializeModule() {
private void initModule(ClasspathLocation location) { IModule mod = null; if (location instanceof ClasspathJar) { mod = ((ClasspathJar) location).initializeModule(); } else if (location instanceof ClasspathDirectory){ mod = ((ClasspathDirectory) location).initializeModule(); } if (mod != null) { this.module = mod; this.isAutomaticModule = false; } else { this.module = getAutomaticModule(location); this.isAutomaticModule = true; } location.setModule(this.module); }
@Override public String debugPathString() { long time = lastModified(); if (time == 0) return this.zipFilename; return this.zipFilename + '(' + (new Date(time)) + " : " + time + ')'; //$NON-NLS-1$ }
static ClasspathLocation forLibrary(IFile library, AccessRuleSet accessRuleSet, IPath annotationsPath, boolean autoModule) { return new ClasspathJar(library, accessRuleSet, annotationsPath, autoModule); }