Return-Path: X-Original-To: apmail-clerezza-commits-archive@www.apache.org Delivered-To: apmail-clerezza-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A71B010F89 for ; Thu, 25 Jul 2013 11:56:10 +0000 (UTC) Received: (qmail 3757 invoked by uid 500); 25 Jul 2013 11:56:09 -0000 Delivered-To: apmail-clerezza-commits-archive@clerezza.apache.org Received: (qmail 3710 invoked by uid 500); 25 Jul 2013 11:56:05 -0000 Mailing-List: contact commits-help@clerezza.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@clerezza.apache.org Delivered-To: mailing list commits@clerezza.apache.org Received: (qmail 3696 invoked by uid 99); 25 Jul 2013 11:56:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Jul 2013 11:56:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Jul 2013 11:56:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1A88B23888E7; Thu, 25 Jul 2013 11:55:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1506915 - /clerezza/trunk/permissiondescriptions/src/main/java/org/apache/clerezza/permissiondescriptions/PermissionGatherer.java Date: Thu, 25 Jul 2013 11:55:42 -0000 To: commits@clerezza.apache.org From: reto@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130725115542.1A88B23888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: reto Date: Thu Jul 25 11:55:41 2013 New Revision: 1506915 URL: http://svn.apache.org/r1506915 Log: CLEREZZA-806: fixed as suggested by Giuseppe Miscione but reduced the cpoe of the try to actual class loading Modified: clerezza/trunk/permissiondescriptions/src/main/java/org/apache/clerezza/permissiondescriptions/PermissionGatherer.java Modified: clerezza/trunk/permissiondescriptions/src/main/java/org/apache/clerezza/permissiondescriptions/PermissionGatherer.java URL: http://svn.apache.org/viewvc/clerezza/trunk/permissiondescriptions/src/main/java/org/apache/clerezza/permissiondescriptions/PermissionGatherer.java?rev=1506915&r1=1506914&r2=1506915&view=diff ============================================================================== --- clerezza/trunk/permissiondescriptions/src/main/java/org/apache/clerezza/permissiondescriptions/PermissionGatherer.java (original) +++ clerezza/trunk/permissiondescriptions/src/main/java/org/apache/clerezza/permissiondescriptions/PermissionGatherer.java Thu Jul 25 11:55:41 2013 @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.clerezza.permissiondescriptions; import java.net.URL; @@ -44,39 +43,41 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This binds all implementations of PermissionDescriptionsProvider, - * and gathers their PermissionDescriptions. Furthermore the gatherer - * scans all activaded bundles for Permissions which are annonated with the - * PermissionInfo annotation and generates PermissionDescriptions - * for them. This service provides methods to retrieve the gathered - * PermissionDescriptions and also methods to retrieve all unannotated + * This binds all implementations of + * PermissionDescriptionsProvider, and gathers their + * PermissionDescriptions. Furthermore the gatherer scans all + * activaded bundles for + * Permissions which are annonated with the + * PermissionInfo annotation and generates + * PermissionDescriptions for them. This service provides methods + * to retrieve the gathered + * PermissionDescriptions and also methods to retrieve all + * unannotated * Permission found in the activated bundles. If new bundles are * started then they are also scanned. * * @author mir */ -@Component(immediate=true) +@Component(immediate = true) @Service(PermissionGatherer.class) -@Reference(name="permissionProvider", policy=ReferencePolicy.DYNAMIC, - referenceInterface=PermissionDescriptionsProvider.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE) +@Reference(name = "permissionProvider", policy = ReferencePolicy.DYNAMIC, + referenceInterface = PermissionDescriptionsProvider.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE) public class PermissionGatherer implements BundleListener { private final Logger logger = LoggerFactory.getLogger(getClass()); - private Map>> bundle2PermissionClassesMap = Collections.synchronizedMap(new HashMap>>()); private Map> bundle2PermissionDescriptorsMap = Collections.synchronizedMap(new HashMap>()); - private ComponentContext componentContext; - /** - * stores all ServiceReferences of PermissionDescriptionsProviders - * that were bound before the PermissionGatherer was activated. + * stores all + * ServiceReferences of + * PermissionDescriptionsProviders that were bound before the + * PermissionGatherer was activated. */ private Set serviceReferenceStore = new HashSet(); - public Map> getPermissionDescriptorsPerBundles() { return Collections.unmodifiableMap(bundle2PermissionDescriptorsMap); } @@ -125,8 +126,7 @@ public class PermissionGatherer implemen synchronized protected void unbindPermissionProvider(ServiceReference serviceReference) { if (!serviceReferenceStore.remove(serviceReference)) { - PermissionDescriptionsProvider permissionProvider = (PermissionDescriptionsProvider) - componentContext.locateService("permissionProvider", serviceReference); + PermissionDescriptionsProvider permissionProvider = (PermissionDescriptionsProvider) componentContext.locateService("permissionProvider", serviceReference); Bundle bundle = serviceReference.getBundle(); Collection permissionDescriptiors = @@ -142,8 +142,7 @@ public class PermissionGatherer implemen } private void registerPermissionDescriptorsProvider(ServiceReference serviceReference) { - PermissionDescriptionsProvider permissionProvider = (PermissionDescriptionsProvider) - componentContext.locateService("permissionProvider", serviceReference); + PermissionDescriptionsProvider permissionProvider = (PermissionDescriptionsProvider) componentContext.locateService("permissionProvider", serviceReference); if (permissionProvider == null) { return; } @@ -195,26 +194,29 @@ public class PermissionGatherer implemen Set newPermissionDescriptors = new HashSet(); while (classUrls.hasMoreElements()) { - URL url = classUrls.nextElement(); + URL url = classUrls.nextElement(); + + String className = url.getPath(); + int indexOfLastDot = className.lastIndexOf("."); + className = className.replaceAll("/", ".").substring(1, indexOfLastDot); + Class clazz; try { - String className = url.getPath(); - int indexOfLastDot = className.lastIndexOf("."); - className = className.replaceAll("/", ".").substring(1, indexOfLastDot); - Class clazz = bundle.loadClass(className); - if (Permission.class.isAssignableFrom(clazz)) { - PermissionInfo permissionInfo = clazz.getAnnotation(PermissionInfo.class); - if (permissionInfo != null) { - newPermissionDescriptors.add(new PermissionDescripton(permissionInfo.value(), - permissionInfo.description(), clazz.getResource(permissionInfo.icon()), - (Class) clazz, - getJavaPermissionString(clazz))); - } else { - permissionClassesSet.add((Class) clazz); - } + clazz = bundle.loadClass(className); + } catch (Throwable t) { + //we just ignore classes we coudln't read + continue; + } + if (Permission.class.isAssignableFrom(clazz)) { + PermissionInfo permissionInfo = clazz.getAnnotation(PermissionInfo.class); + if (permissionInfo != null) { + newPermissionDescriptors.add(new PermissionDescripton(permissionInfo.value(), + permissionInfo.description(), clazz.getResource(permissionInfo.icon()), + (Class) clazz, + getJavaPermissionString(clazz))); + } else { + permissionClassesSet.add((Class) clazz); } - } catch (Exception ex) { - } catch (NoClassDefFoundError err) {} - + } } if (!permissionClassesSet.isEmpty()) { bundle2PermissionClassesMap.put(bundle, permissionClassesSet);