@Override public BundleFile wrapBundleFile( final BundleFile bundleFile, final Object content, final BaseData data, final boolean base) throws IOException { BundleFile wrapped = null; if (Debug.DEBUG_BUNDLE) Debug.println( "> AspectJBundleFileWrapperFactoryHook.wrapBundleFile() bundle=" + data.getSymbolicName() + " bundleFile=" + bundleFile + ", content=" + content + ", data=" + data + ", base=" + base + ", baseFile=" + bundleFile.getBaseFile()); if (base) { wrapped = new BaseWeavingBundleFile(new BundleAdaptorProvider(data, this), bundleFile); } else { wrapped = new WeavingBundleFile(new BundleAdaptorProvider(data, this), bundleFile); } if (Debug.DEBUG_BUNDLE) Debug.println("< AspectJBundleFileWrapperFactoryHook.wrapBundleFile() wrapped=" + wrapped); return wrapped; }
/** * Extracts a directory and all sub content to disk * * @param dirName the directory name to extract * @return the File used to extract the content to. A value of <code>null</code> is returned if * the directory to extract does not exist or if content extraction is not supported. This * method is derived from ZipBundleFile#extractDirectory(String). */ protected synchronized File extractDirectory(String dirName) { Enumeration<String> entries = delegate.getEntryPaths(dirName); while (entries.hasMoreElements()) { String entryPath = entries.nextElement(); if (entryPath.startsWith(dirName)) { getFile(entryPath, false); } } return getExtractFile(dirName); }
@Override public BundleEntry getEntry(String path) { final BundleEntry original = delegate.getEntry(path); if (data.getBundle() == null || path == null || original == null) { return original; } LazyInputStream stream = new LazyInputStream( new InputStreamProvider() { @Override public InputStream getInputStream() throws IOException { return original.getInputStream(); } }); InputStream wrappedStream = getInputStream(stream, data.getBundle(), path); if (wrappedStream == null) { return original; } return new TransformedBundleEntry(this, original, wrappedStream); }
/** * Creates a ProtectionDomain which uses specified BundleFile and the permissions of the * baseDomain * * @param bundlefile The source bundlefile the domain is for. * @param baseDomain The source domain. * @return a ProtectionDomain which uses specified BundleFile and the permissions of the * baseDomain */ public static ProtectionDomain createProtectionDomain( BundleFile bundlefile, ProtectionDomain baseDomain) { // create a protection domain which knows about the codesource for this classpath entry (bug // 89904) try { // use the permissions supplied by the domain passed in from the framework PermissionCollection permissions; if (baseDomain != null) permissions = baseDomain.getPermissions(); else // no domain specified. Better use a collection that has all permissions // this is done just incase someone sets the security manager later permissions = ALLPERMISSIONS; Certificate[] certs = null; if (bundlefile instanceof CertificateVerifier) { CertificateChain[] chains = ((CertificateVerifier) bundlefile).getChains(); certs = chains == null || chains.length == 0 ? null : chains[0].getCertificates(); } return new ProtectionDomain( new CodeSource(bundlefile.getBaseFile().toURL(), certs), permissions); } catch (MalformedURLException e) { // Failed to create our own domain; just return the baseDomain return baseDomain; } }
@Override public File getBaseFile() { return delegate.getBaseFile(); }
@Override public boolean equals(Object obj) { return delegate.equals(obj); }
@Override public boolean containsDir(String dir) { return delegate.containsDir(dir); }
@Override public void close() throws IOException { delegate.close(); }
@Override public String toString() { return delegate.toString(); }
@Override public void open() throws IOException { delegate.open(); }
@Override public int hashCode() { return delegate.hashCode(); }
/** This file is a copy of {@link ZipBundleFile#getFile(String, boolean)} with modifications. */ @Override public File getFile(String path, boolean nativeCode) { File originalFile = delegate.getFile(path, nativeCode); if (originalFile == null) { return null; } if (!hasTransforms(path)) { return originalFile; } try { File nested = getExtractFile(path); if (nested != null) { if (nested.exists()) { /* the entry is already cached */ if (Debug.DEBUG_GENERAL) { Debug.println("File already present: " + nested.getPath()); // $NON-NLS-1$ } if (nested.isDirectory()) { // must ensure the complete directory is extracted (bug // 182585) extractDirectory(path); } } else { if (originalFile.isDirectory()) { if (!nested.mkdirs()) { if (Debug.DEBUG_GENERAL) { Debug.println("Unable to create directory: " + nested.getPath()); // $NON-NLS-1$ } throw new IOException( NLS.bind( AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath())); } extractDirectory(path); } else { InputStream in = getEntry(path).getInputStream(); if (in == null) { return null; } // if (in instanceof ) /* the entry has not been cached */ if (Debug.DEBUG_GENERAL) { Debug.println("Creating file: " + nested.getPath()); // $NON-NLS-1$ } /* create the necessary directories */ File dir = new File(nested.getParent()); if (!dir.exists() && !dir.mkdirs()) { if (Debug.DEBUG_GENERAL) { Debug.println("Unable to create directory: " + dir.getPath()); // $NON-NLS-1$ } throw new IOException( NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, dir.getAbsolutePath())); } /* copy the entry to the cache */ AdaptorUtil.readFile(in, nested); if (nativeCode) { setPermissions(nested); } } } return nested; } } catch (IOException e) { if (Debug.DEBUG_GENERAL) { Debug.printStackTrace(e); } } return null; }
@Override public Enumeration<String> getEntryPaths(String path) { return delegate.getEntryPaths(path); }