Search in sources :

Example 1 with WeavingException

use of org.osgi.framework.hooks.weaving.WeavingException in project aries by apache.

the class ProxyWeavingHook method weave.

public final void weave(WovenClass wovenClass) {
    BundleWiring bw = wovenClass.getBundleWiring();
    if (bw != null) {
        Bundle b = bw.getBundle();
        if (b.getBundleId() == 0 || b.getSymbolicName().startsWith("org.apache.aries.proxy") || b.getSymbolicName().startsWith("org.apache.aries.util")) {
            return;
        }
    }
    if (!isEnabled(wovenClass.getClassName()) || isDisabled(wovenClass.getClassName())) {
        return;
    }
    if (shouldWeave(wovenClass)) {
        byte[] bytes = null;
        try {
            bytes = WovenProxyGenerator.getWovenProxy(wovenClass.getBytes(), wovenClass.getBundleWiring().getClassLoader());
        } catch (Exception e) {
            if (e instanceof RuntimeException && e.getCause() instanceof UnableToProxyException) {
                //This is a weaving failure that should be logged, but the class
                //can still be loaded
                LOGGER.trace(String.format("The class %s cannot be woven, it may not be possible for the runtime to proxy this class.", wovenClass.getClassName()), e);
            } else {
                throw weavingException(wovenClass, e);
            }
        }
        if (bytes != null && bytes.length != 0) {
            wovenClass.setBytes(bytes);
            List<String> imports = wovenClass.getDynamicImports();
            imports.add(IMPORT_A);
            imports.add(IMPORT_B);
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) UnableToProxyException(org.apache.aries.proxy.UnableToProxyException) WeavingException(org.osgi.framework.hooks.weaving.WeavingException) UnableToProxyException(org.apache.aries.proxy.UnableToProxyException)

Aggregations

UnableToProxyException (org.apache.aries.proxy.UnableToProxyException)1 Bundle (org.osgi.framework.Bundle)1 WeavingException (org.osgi.framework.hooks.weaving.WeavingException)1 BundleWiring (org.osgi.framework.wiring.BundleWiring)1