/** * Test the layout of a directory against the sieve. * * @param dir the directory to test * @return true if the directory structure matches the sieve's configuration. */ public boolean matches(File dir) { for (String str : includes) { File f = new File(dir, Path.translateFile(str)); if (!f.exists()) return false; } for (String str : excludes) { File f = new File(dir, Path.translateFile(str)); if (f.exists()) return false; } return true; }
protected void addPathFile(final File pathComponent) throws IOException { if (!this.pathComponents.contains(pathComponent)) { this.pathComponents.addElement(pathComponent); } if (pathComponent.isDirectory()) { return; } final String absPathPlusTimeAndLength = pathComponent.getAbsolutePath() + pathComponent.lastModified() + "-" + pathComponent.length(); String classpath = AntClassLoader.pathMap.get(absPathPlusTimeAndLength); if (classpath == null) { JarFile jarFile = null; try { jarFile = new JarFile(pathComponent); final Manifest manifest = jarFile.getManifest(); if (manifest == null) { return; } classpath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH); } finally { if (jarFile != null) { jarFile.close(); } } if (classpath == null) { classpath = ""; } AntClassLoader.pathMap.put(absPathPlusTimeAndLength, classpath); } if (!"".equals(classpath)) { final URL baseURL = AntClassLoader.FILE_UTILS.getFileURL(pathComponent); final StringTokenizer st = new StringTokenizer(classpath); while (st.hasMoreTokens()) { final String classpathElement = st.nextToken(); final URL libraryURL = new URL(baseURL, classpathElement); if (!libraryURL.getProtocol().equals("file")) { this.log( "Skipping jar library " + classpathElement + " since only relative URLs are supported by this" + " loader", 3); } else { final String decodedPath = Locator.decodeUri(libraryURL.getFile()); final File libraryFile = new File(decodedPath); if (!libraryFile.exists() || this.isInPath(libraryFile)) { continue; } this.addPathFile(libraryFile); } } } }
protected URL getResourceURL(final File file, final String resourceName) { try { JarFile jarFile = this.jarFiles.get(file); if (jarFile == null && file.isDirectory()) { final File resource = new File(file, resourceName); if (resource.exists()) { try { return AntClassLoader.FILE_UTILS.getFileURL(resource); } catch (MalformedURLException ex) { return null; } } } else { if (jarFile == null) { if (!file.exists()) { return null; } jarFile = new JarFile(file); this.jarFiles.put(file, jarFile); jarFile = this.jarFiles.get(file); } final JarEntry entry = jarFile.getJarEntry(resourceName); if (entry != null) { try { return new URL("jar:" + AntClassLoader.FILE_UTILS.getFileURL(file) + "!/" + entry); } catch (MalformedURLException ex) { return null; } } } } catch (Exception e) { final String msg = "Unable to obtain resource from " + file + ": "; this.log(msg + e, 1); System.err.println(msg); e.printStackTrace(); } return null; }
private InputStream getResourceStream(final File file, final String resourceName) { try { JarFile jarFile = this.jarFiles.get(file); if (jarFile == null && file.isDirectory()) { final File resource = new File(file, resourceName); if (resource.exists()) { return new FileInputStream(resource); } } else { if (jarFile == null) { if (!file.exists()) { return null; } jarFile = new JarFile(file); this.jarFiles.put(file, jarFile); jarFile = this.jarFiles.get(file); } final JarEntry entry = jarFile.getJarEntry(resourceName); if (entry != null) { return jarFile.getInputStream(entry); } } } catch (Exception e) { this.log( "Ignoring Exception " + e.getClass().getName() + ": " + e.getMessage() + " reading resource " + resourceName + " from " + file, 3); } return null; }