Return-Path: X-Original-To: apmail-felix-users-archive@minotaur.apache.org Delivered-To: apmail-felix-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5B68797C1 for ; Tue, 6 Dec 2011 06:26:58 +0000 (UTC) Received: (qmail 25788 invoked by uid 500); 6 Dec 2011 06:26:57 -0000 Delivered-To: apmail-felix-users-archive@felix.apache.org Received: (qmail 25386 invoked by uid 500); 6 Dec 2011 06:26:56 -0000 Mailing-List: contact users-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@felix.apache.org Delivered-To: mailing list users@felix.apache.org Received: (qmail 25372 invoked by uid 99); 6 Dec 2011 06:26:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2011 06:26:55 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW X-Spam-Check-By: apache.org Received-SPF: unknown ipv4:204.13.82.211/32 (athena.apache.org: encountered unrecognized mechanism during SPF processing of domain of dileepa@wso2.com) Received: from [209.85.216.42] (HELO mail-qw0-f42.google.com) (209.85.216.42) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2011 06:26:50 +0000 Received: by qabj40 with SMTP id j40so1580834qab.1 for ; Mon, 05 Dec 2011 22:26:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.224.220.14 with SMTP id hw14mr10844672qab.42.1323152789076; Mon, 05 Dec 2011 22:26:29 -0800 (PST) Received: by 10.229.81.134 with HTTP; Mon, 5 Dec 2011 22:26:29 -0800 (PST) In-Reply-To: References: Date: Tue, 6 Dec 2011 11:56:29 +0530 Message-ID: Subject: Re: Problems when removing dependency jars from section From: Dileepa Jayakody To: users@felix.apache.org Cc: Stuart McCulloch Content-Type: multipart/alternative; boundary=20cf3071d1d4f9fb1a04b366836b --20cf3071d1d4f9fb1a04b366836b Content-Type: text/plain; charset=ISO-8859-1 Thanks a lot for the detailed explanation Stuart. :) On Sat, Dec 3, 2011 at 4:14 AM, Stuart McCulloch wrote: > On 21 October 2011 08:24, Dileepa Jayakody wrote: > > > Hi > > I'm working on a project which requires identification and removal of > > unused > > jar dependencies from the osgi bundles to make them leaner. > > Maven bundle-plugin is used to create the bundle and I'm using a tool > > called > > JBoss tattletale to identify unused > > jars, > > duplicated jars in the project/bundle. However there are some gray areas > I > > need to be clear about; please give me some suggestions/comments on the > > following questions. > > > > Suppose I'm exporting a package foo.*; from a dependency jar (A.jar) in > the > > bundle, as a result all the classes of foo pckg are in-lined/added to the > > bundle classpath. Suppose there's a class foo.Bar.java in th pckg which > > imports a class from B.jar, and I remove B.jar (which is assumed to be an > > unused embedded dependency as per my tool to identify unused jars). > > Now the bundle doesn't have B.jar in it's class-path and it still exports > > foo.* pckg in A.jar in the bundle. > > > > My 1st question is, will the maven bundle plugin throw any compilation > > errors because the transitive dependency of foo.Bar class is not > satisfied > > as B.jar is no longer in the bundle classpath, or will it compile and > > export > > pckg foo.* without any compilation error, which may result in a run-time > > exception when trying to load foo.Bar class in the bundle at runtime? > > > > The maven-bundle-plugin doesn't do any compilation, that's done by the > maven-compiler-plugin. But if your compiled code uses a class (say x.y.Z > from B.jar) and doesn't embed/inline it then it will add the package > containing that class (x.y) to the generated Import-Package statement in > the manifest. Of course you could override the generated Import-Package in > the instructions, but bnd will try to warn you if your bundle references a > package that isn't imported. > > Now if you tried to install the bundle with Import-Package: x.y on an OSGi > framework and no other bundle exported package x.y you'd get a runtime > exception warning about the unsatisfied import constraint. This still > doesn't stop you from marking packages as optional or explicitly excluding > them from Import-Package - in which case your bundle would install, and > you'd get a class exception if anyone tried to use foo.Bar. But this > shouldn't happen when using the default instructions - this should only > happen when you explicitly told bnd that a package wasn't used when in fact > it is... > > Will removing unused embedded dependencies from a bundle cause errors in > > cases like java reflexion used in the bundle ?(eg: Class.forName loading > of > > a class which is removed from the bundle as a result of removing unused > > embedded dependencies) > > > > AFAICT the tattletale plugin scans the bytecode to detect unused > dependencies, which is very similar to what bnd does when calculating the > difference between what's contained in the bundle and what's referenced > from the bundle (which gives you what should be imported). So in an ideal > world removing dependencies marked as unused by tattletale should not > affect the bundle. The main issue is reflection (as you mention above) > because the class name could be computed from the environment or some other > input and cannot be deduced just from the bytecode. In that case both > tattletale and bnd might not detect the reference and you'd end up with a > bundle that would install, but throw an exception at runtime. > > Unfortunately there's no solution that can detect all possibilities - for > example, classloader.loadClass(System.getProperty("some.class.name")) - > but > hopefully these cases are a) uncommon and b) already known by the developer > creating the bundle, in which case they can tweak the generated manifest > accordingly. > > HTH > > Thanks, > > -- > > Dileepa Jayakody, > > > > > > -- > Cheers, Stuart > -- Dileepa Jayakody, Software Engineer, WSO2 Inc. Lean . Enterprise . Middleware --20cf3071d1d4f9fb1a04b366836b--