public byte[] getBytes() { if ((hookFlags & FLAG_HOOKSCOMPLETE) == 0) { checkPermission(); return validBytes; // return raw bytes until complete } // we have called all hooks; someone is calling outside of weave call // need to be safe and copy the bytes. byte[] current = validBytes; byte[] results = new byte[current.length]; System.arraycopy(current, 0, results, 0, current.length); return results; }
void setWeavingCompleted(Class<?> clazz) { // weaving has completed; save the class and mark complete this.clazz = clazz; hookFlags |= FLAG_WEAVINGCOMPLETE; // Only notify listeners if weaving hooks were called. if ((hookFlags & FLAG_HOOKCALLED) == 0) return; // Only notify listeners if they haven't already been notified of // the terminal TRANSFORMING_FAILED state. if (error != null) return; // If clazz is null, a class definition failure occurred. setState(clazz == null ? DEFINE_FAILED : DEFINED); notifyWovenClassListeners(); }
public void recordClassDefine(String name, Class<?> clazz, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) { // here we assume the stack contans a woven class with the same name as the class we are defining. List<WovenClassImpl> wovenClasses = wovenClassStack.get(); if (wovenClasses == null || wovenClasses.size() == 0) return; WovenClassImpl wovenClass = wovenClasses.remove(wovenClasses.size() - 1); // inform the woven class about the class that was defined. wovenClass.setWeavingCompleted(clazz); }
newImports = dynamicImports; setHooksComplete(); setState(error == null ? TRANSFORMED : TRANSFORMING_FAILED); notifyWovenClassListeners(); addImpliedImportPackagePermissions(importElements); loader.addDynamicImportPackage(importElements); } catch (BundleException e) {
public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) { ServiceRegistry registry = getRegistry(); if (registry == null) return null; // no registry somehow we are loading classes before the registry has been created ModuleClassLoader classLoader = manager.getClassLoader(); BundleLoader loader = classLoader.getBundleLoader(); // create a woven class object and add it to the thread local stack WovenClassImpl wovenClass = new WovenClassImpl(name, classbytes, entry, classpathEntry, loader, container, blackList); List<WovenClassImpl> wovenClasses = wovenClassStack.get(); if (wovenClasses == null) { wovenClasses = new ArrayList<WovenClassImpl>(6); wovenClassStack.set(wovenClasses); } wovenClasses.add(wovenClass); // call the weaving hooks try { return wovenClass.callHooks(); } catch (Throwable t) { ServiceRegistration<?> errorHook = wovenClass.getErrorHook(); Bundle errorBundle = errorHook != null ? errorHook.getReference().getBundle() : manager.getGeneration().getRevision().getBundle(); container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, errorBundle, t); // fail hard with a class loading error ClassFormatError error = new ClassFormatError("Unexpected error from weaving hook."); //$NON-NLS-1$ error.initCause(t); throw error; } }
private void addImpliedImportPackagePermissions(ManifestElement[] importElements) { ProtectionDomain wovenDomain = ((Generation) ((ModuleRevision) getBundleWiring().getRevision()).getRevisionInfo()).getDomain(); if (wovenDomain != null) { // security is enabled; add the permissions for (ManifestElement clause : importElements) for (String pkg : clause.getValueComponents()) ((BundlePermissions) wovenDomain.getPermissions()).addWovenPermission(new PackagePermission(pkg, PackagePermission.IMPORT)); } }
public WovenClassImpl(String className, byte[] bytes, BundleEntry entry, ClasspathEntry classpathEntry, BundleLoader loader, EquinoxContainer container, Map<ServiceRegistration<?>, Boolean> blacklist) { super(); this.className = className; this.validBytes = this.resultBytes = bytes; this.entry = entry; this.dynamicImports = new DynamicImportList(this); this.classpathEntry = classpathEntry; this.loader = loader; this.registry = container.getServiceRegistry(); this.container = container; this.blackList = blacklist; setState(TRANSFORMING); }
newImports = dynamicImports; setHooksComplete(); setState(error == null ? TRANSFORMED : TRANSFORMING_FAILED); notifyWovenClassListeners(); addImpliedImportPackagePermissions(importElements); loader.addDynamicImportPackage(importElements); } catch (BundleException e) {
public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) { ServiceRegistry registry = getRegistry(); if (registry == null) return null; // no registry somehow we are loading classes before the registry has been created ModuleClassLoader classLoader = manager.getClassLoader(); BundleLoader loader = classLoader.getBundleLoader(); // create a woven class object and add it to the thread local stack WovenClassImpl wovenClass = new WovenClassImpl(name, classbytes, entry, classpathEntry, loader, container, blackList); List<WovenClassImpl> wovenClasses = wovenClassStack.get(); if (wovenClasses == null) { wovenClasses = new ArrayList<WovenClassImpl>(6); wovenClassStack.set(wovenClasses); } wovenClasses.add(wovenClass); // call the weaving hooks try { return wovenClass.callHooks(); } catch (Throwable t) { ServiceRegistration<?> errorHook = wovenClass.getErrorHook(); Bundle errorBundle = errorHook != null ? errorHook.getReference().getBundle() : manager.getGeneration().getRevision().getBundle(); container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, errorBundle, t); // fail hard with a class loading error ClassFormatError error = new ClassFormatError("Unexpected error from weaving hook."); //$NON-NLS-1$ error.initCause(t); throw error; } }
private void addImpliedImportPackagePermissions(ManifestElement[] importElements) { ProtectionDomain wovenDomain = ((Generation) ((ModuleRevision) getBundleWiring().getRevision()).getRevisionInfo()).getDomain(); if (wovenDomain != null) { // security is enabled; add the permissions for (ManifestElement clause : importElements) for (String pkg : clause.getValueComponents()) ((BundlePermissions) wovenDomain.getPermissions()).addWovenPermission(new PackagePermission(pkg, PackagePermission.IMPORT)); } }
public WovenClassImpl(String className, byte[] bytes, BundleEntry entry, ClasspathEntry classpathEntry, BundleLoader loader, EquinoxContainer container, Map<ServiceRegistration<?>, Boolean> blacklist) { super(); this.className = className; this.validBytes = this.resultBytes = bytes; this.entry = entry; this.dynamicImports = new DynamicImportList(this); this.classpathEntry = classpathEntry; this.loader = loader; this.registry = container.getServiceRegistry(); this.container = container; this.blackList = blacklist; setState(TRANSFORMING); }
newImports = dynamicImports; setHooksComplete(); setState(error == null ? TRANSFORMED : TRANSFORMING_FAILED); notifyWovenClassListeners(); addImpliedImportPackagePermissions(importElements); loader.addDynamicImportPackage(importElements); } catch (BundleException e) {
public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) { ServiceRegistry registry = getRegistry(); if (registry == null) return null; // no registry somehow we are loading classes before the registry has been created ModuleClassLoader classLoader = manager.getClassLoader(); BundleLoader loader = classLoader.getBundleLoader(); // create a woven class object and add it to the thread local stack WovenClassImpl wovenClass = new WovenClassImpl(name, classbytes, entry, classpathEntry, loader, container, blackList); List<WovenClassImpl> wovenClasses = wovenClassStack.get(); if (wovenClasses == null) { wovenClasses = new ArrayList<WovenClassImpl>(6); wovenClassStack.set(wovenClasses); } wovenClasses.add(wovenClass); // call the weaving hooks try { return wovenClass.callHooks(); } catch (Throwable t) { ServiceRegistration<?> errorHook = wovenClass.getErrorHook(); Bundle errorBundle = errorHook != null ? errorHook.getReference().getBundle() : manager.getGeneration().getRevision().getBundle(); container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, errorBundle, t); // fail hard with a class loading error ClassFormatError error = new ClassFormatError("Unexpected error from weaving hook."); //$NON-NLS-1$ error.initCause(t); throw error; } }
@Override public String remove(int index) { wovenClass.checkPermission(); return imports.remove(index); }
void setWeavingCompleted(Class<?> clazz) { // weaving has completed; save the class and mark complete this.clazz = clazz; hookFlags |= FLAG_WEAVINGCOMPLETE; // Only notify listeners if weaving hooks were called. if ((hookFlags & FLAG_HOOKCALLED) == 0) return; // Only notify listeners if they haven't already been notified of // the terminal TRANSFORMING_FAILED state. if (error != null) return; // If clazz is null, a class definition failure occurred. setState(clazz == null ? DEFINE_FAILED : DEFINED); notifyWovenClassListeners(); }
public void recordClassDefine(String name, Class<?> clazz, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) { // here we assume the stack contans a woven class with the same name as the class we are defining. List<WovenClassImpl> wovenClasses = wovenClassStack.get(); if (wovenClasses == null || wovenClasses.size() == 0) return; WovenClassImpl wovenClass = wovenClasses.remove(wovenClasses.size() - 1); // inform the woven class about the class that was defined. wovenClass.setWeavingCompleted(clazz); }
private void addImpliedImportPackagePermissions(ManifestElement[] importElements) { ProtectionDomain wovenDomain = ((Generation) ((ModuleRevision) getBundleWiring().getRevision()).getRevisionInfo()).getDomain(); if (wovenDomain != null) { // security is enabled; add the permissions for (ManifestElement clause : importElements) for (String pkg : clause.getValueComponents()) ((BundlePermissions) wovenDomain.getPermissions()).addWovenPermission(new PackagePermission(pkg, PackagePermission.IMPORT)); } }
public WovenClassImpl(String className, byte[] bytes, BundleEntry entry, ClasspathEntry classpathEntry, BundleLoader loader, EquinoxContainer container, Map<ServiceRegistration<?>, Boolean> blacklist) { super(); this.className = className; this.validBytes = this.resultBytes = bytes; this.entry = entry; this.dynamicImports = new DynamicImportList(this); this.classpathEntry = classpathEntry; this.loader = loader; this.registry = container.getServiceRegistry(); this.container = container; this.blackList = blacklist; setState(TRANSFORMING); }
newImports = dynamicImports; setHooksComplete(); setState(error == null ? TRANSFORMED : TRANSFORMING_FAILED); notifyWovenClassListeners(); addImpliedImportPackagePermissions(importElements); loader.addDynamicImportPackage(importElements); } catch (BundleException e) {
BundleLoader loader = classLoader.getBundleLoader(); WovenClassImpl wovenClass = new WovenClassImpl(name, classbytes, entry, classpathEntry, loader, container, blackList); WovenClassContext context = wovenClassContext.get(); if (context == null) { return wovenClass.callHooks(); } catch (Throwable t) { ServiceRegistration<?> errorHook = wovenClass.getErrorHook(); Bundle errorBundle = errorHook != null ? errorHook.getReference().getBundle() : manager.getGeneration().getRevision().getBundle(); container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, errorBundle, t);