public void weave(WovenClass wovenClass) { tracked.weave(wovenClass); }
private WeavingException weavingException(WovenClass wovenClass, Exception e) { String msg = format("There was a serious error trying to weave the class %s. See the associated exception for more information.", wovenClass.getClassName()); // This is a failure that should stop the class loading! LOGGER.error(msg, e); return new WeavingException(msg, e); } }
private static boolean transformClass(WovenClass wovenClass, ClassLoader cl, ClassTransformer transformer) throws ThreadDeath, OutOfMemoryError { try { byte[] result = transformer .transform(cl, wovenClass.getClassName(), wovenClass.getDefinedClass(), wovenClass.getProtectionDomain(), wovenClass.getBytes()); if (result != null) { wovenClass.setBytes(result); wovenClass.getDynamicImports().add("org.eclipse.persistence.*"); wovenClass.getDynamicImports().add("org.apache.openjpa.*"); return true; } } catch (Exception t) { Bundle b = wovenClass.getBundleWiring().getBundle(); String msg = String.format("Weaving failure on class %s in bundle %s/%s using transformer %s", wovenClass.getClassName(), b.getSymbolicName(), b.getVersion(), transformer); throw new WeavingException(msg, t); } return false; }
public boolean isSuperClassWoven(WovenClass wovenClass) { ClassReader cReader = new ClassReader(wovenClass.getBytes()); try { Class<?> superClass = Class.forName(cReader.getSuperName().replace('/', '.'), false, wovenClass.getBundleWiring().getClassLoader()); return WovenProxy.class.isAssignableFrom(superClass); } catch (ClassNotFoundException e) { String failureMessage = NLS.MESSAGES.getMessage("fatal.weaving.failure", wovenClass.getClassName()); //This is a failure that should stop the class loading! LOGGER.error(failureMessage, e); throw new WeavingException(failureMessage, e); } }
@Override public void weave(WovenClass wovenClass) { BundleWiring wiring = wovenClass.getBundleWiring(); Bundle bundle = wiring.getBundle(); Boolean seen = bundleMap.get(wiring); if (seen != null) { return; } boolean requiresWeaving = false; if (isBeanBundle(bundle) || isExtension(bundle)) { log.debug("weaving {}", wovenClass.getClassName()); wovenClass.getDynamicImports().add("org.jboss.weld.*"); requiresWeaving = true; } bundleMap.put(wiring, requiresWeaving); }
public void invokeWovenClassListener( org.osgi.framework.hooks.weaving.WovenClassListener wcl, org.osgi.framework.hooks.weaving.WovenClass wc) throws Exception { if (System.getSecurityManager() != null) { Actions actions = (Actions) m_actions.get(); actions.set(Actions.INVOKE_WOVEN_CLASS_LISTENER, wcl, wc); try { AccessController.doPrivileged(actions, m_acc); } catch (PrivilegedActionException e) { throw e.getException(); } } else { wcl.modified(wc); } }
@Override public void weave(WovenClass wovenClass) { BundleWiring wiring = wovenClass.getBundleWiring(); Bundle bundle = wiring.getBundle(); ClassLoader cl = wiring.getClassLoader(); Collection<ClassTransformer> transformersToTry = getTransformers(bundle); for (ClassTransformer transformer : transformersToTry) { if (transformClass(wovenClass, cl, transformer)) { LOGGER.info("Weaving " + wovenClass.getClassName() + " using " + transformer.getClass().getName()); break; } } Class<?> dClass = wovenClass.getDefinedClass(); if (transformersToTry.isEmpty() && dClass != null && dClass.getAnnotation(Entity.class) != null) { LOGGER.warn("Loading " + wovenClass.getClassName() + " before transformer is present"); } }
public boolean isSuperClassWoven(WovenClass wovenClass) { ClassReader cReader = new ClassReader(wovenClass.getBytes()); try { Class<?> superClass = Class.forName(cReader.getSuperName().replace('/', '.'), false, wovenClass.getBundleWiring().getClassLoader()); return WovenProxy.class.isAssignableFrom(superClass); } catch (ClassNotFoundException e) { throw weavingException(wovenClass, e); } }
@Override public void weave(WovenClass wovenClass) { if (wovenClass.getBundleWiring().getBundle() == puInfo.getBundle() && managedClasses.contains(wovenClass.getClassName())) { try { synchronized (this) { LOG.debug("weaving {}", wovenClass.getClassName()); byte[] transformed = transformer.transform(cl, wovenClass.getClassName(), wovenClass.getDefinedClass(), wovenClass.getProtectionDomain(), wovenClass.getBytes()); wovenClass.setBytes(transformed); /* * * TODO Hard-coded list of packages for OpenJPA and Eclipselink. We should only * add the ones required for the given provider. */ wovenClass.getDynamicImports().add("org.apache.openjpa.enhance"); wovenClass.getDynamicImports().add("org.apache.openjpa.util"); wovenClass.getDynamicImports().add("org.eclipse.persistence.*"); wovenClass.getDynamicImports().add("org.hibernate.*"); wovenClass.getDynamicImports().add("javassist.util.proxy"); } } catch (IllegalClassFormatException exc) { throw new WeavingException("cannot transform " + wovenClass.getClassName(), exc); } } }
public void call(final Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (error != null) return; // do not call any other hooks once an error has occurred. if (hook instanceof WeavingHook) { if (blackList.containsKey(hookRegistration)) return; // black listed hook hookFlags |= FLAG_HOOKCALLED; try { ((WeavingHook) hook).weave(this); } catch (WeavingException e) { error = e; errorHook = hookRegistration; // do not blacklist on weaving exceptions } catch (Throwable t) { error = t; // save the error to fail later errorHook = hookRegistration; // put the registration on the black list blackList.put(hookRegistration, Boolean.TRUE); } } }
@Override public void call(Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (!(hook instanceof WovenClassListener)) return; try { ((WovenClassListener) hook).modified(WovenClassImpl.this); } catch (Exception e) { WovenClassImpl.this.container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, hookRegistration.getReference().getBundle(), e); } }
public void call(final Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (error != null) return; // do not call any other hooks once an error has occurred. if (hook instanceof WeavingHook) { if (blackList.containsKey(hookRegistration)) return; // black listed hook if ((hookFlags & FLAG_HOOKCALLED) == 0) { hookFlags |= FLAG_HOOKCALLED; // only do this check on the first weaving hook call if (!validBytes(validBytes)) { validBytes = StorageUtil.getBytes(entry.getInputStream(), (int) entry.getSize(), 8 * 1024); } } try { ((WeavingHook) hook).weave(this); } catch (WeavingException e) { error = e; errorHook = hookRegistration; // do not blacklist on weaving exceptions } catch (Throwable t) { error = t; // save the error to fail later errorHook = hookRegistration; // put the registration on the black list blackList.put(hookRegistration, Boolean.TRUE); } } }
@Override public void call(Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (!(hook instanceof WovenClassListener)) return; try { ((WovenClassListener) hook).modified(WovenClassImpl.this); } catch (Exception e) { WovenClassImpl.this.container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, hookRegistration.getReference().getBundle(), e); } }
public void call(final Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (error != null) return; // do not call any other hooks once an error has occurred. if (hook instanceof WeavingHook) { if (blackList.containsKey(hookRegistration)) return; // black listed hook if ((hookFlags & FLAG_HOOKCALLED) == 0) { hookFlags |= FLAG_HOOKCALLED; // only do this check on the first weaving hook call if (!validBytes(validBytes)) { validBytes = StorageUtil.getBytes(entry.getInputStream(), (int) entry.getSize(), 8 * 1024); } } try { ((WeavingHook) hook).weave(this); } catch (WeavingException e) { error = e; errorHook = hookRegistration; // do not blacklist on weaving exceptions } catch (Throwable t) { error = t; // save the error to fail later errorHook = hookRegistration; // put the registration on the black list blackList.put(hookRegistration, Boolean.TRUE); } } }
@Override public void call(Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (!(hook instanceof WovenClassListener)) return; try { ((WovenClassListener) hook).modified(WovenClassImpl.this); } catch (Exception e) { WovenClassImpl.this.container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, hookRegistration.getReference().getBundle(), e); } }
public void call(final Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (error != null) return; // do not call any other hooks once an error has occurred. if (hook instanceof WeavingHook) { if (blackList.containsKey(hookRegistration)) return; // black listed hook if ((hookFlags & FLAG_HOOKCALLED) == 0) { hookFlags |= FLAG_HOOKCALLED; // only do this check on the first weaving hook call if (!validBytes(validBytes)) { validBytes = StorageUtil.getBytes(entry.getInputStream(), (int) entry.getSize(), 8 * 1024); } } try { ((WeavingHook) hook).weave(this); } catch (WeavingException e) { error = e; errorHook = hookRegistration; // do not blacklist on weaving exceptions } catch (Throwable t) { error = t; // save the error to fail later errorHook = hookRegistration; // put the registration on the black list blackList.put(hookRegistration, Boolean.TRUE); } } }
@Override public void call(Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (!(hook instanceof WovenClassListener)) return; try { ((WovenClassListener) hook).modified(WovenClassImpl.this); } catch (Exception e) { WovenClassImpl.this.container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, hookRegistration.getReference().getBundle(), e); } }
public void call(final Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (error != null) return; // do not call any other hooks once an error has occurred. if (hook instanceof WeavingHook) { if (blackList.containsKey(hookRegistration)) return; // black listed hook if ((hookFlags & FLAG_HOOKCALLED) == 0) { hookFlags |= FLAG_HOOKCALLED; // only do this check on the first weaving hook call if (!validBytes(validBytes)) { validBytes = StorageUtil.getBytes(entry.getInputStream(), (int) entry.getSize(), 8 * 1024); } } try { ((WeavingHook) hook).weave(this); } catch (WeavingException e) { error = e; errorHook = hookRegistration; // do not blacklist on weaving exceptions } catch (Throwable t) { error = t; // save the error to fail later errorHook = hookRegistration; // put the registration on the black list blackList.put(hookRegistration, Boolean.TRUE); } } }
@Override public void call(Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (!(hook instanceof WovenClassListener)) return; try { ((WovenClassListener) hook).modified(WovenClassImpl.this); } catch (Exception e) { WovenClassImpl.this.container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, hookRegistration.getReference().getBundle(), e); } }
@Override public void call(Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (!(hook instanceof WovenClassListener)) return; try { ((WovenClassListener) hook).modified(WovenClassImpl.this); } catch (Exception e) { WovenClassImpl.this.container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, hookRegistration.getReference().getBundle(), e); } }