Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 59720 invoked from network); 28 Mar 2009 05:18:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Mar 2009 05:18:27 -0000 Received: (qmail 10552 invoked by uid 500); 28 Mar 2009 05:18:27 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 10486 invoked by uid 500); 28 Mar 2009 05:18:27 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 10477 invoked by uid 99); 28 Mar 2009 05:18:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Mar 2009 05:18:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Sat, 28 Mar 2009 05:18:25 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F3BA3238889E; Sat, 28 Mar 2009 05:18:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r759431 - in /felix/trunk/shell/src/main/java/org/apache/felix/shell/impl: Activator.java ExportsCommandImpl.java ImportsCommandImpl.java RequirersCommandImpl.java RequiresCommandImpl.java Date: Sat, 28 Mar 2009 05:18:02 -0000 To: commits@felix.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090328051803.F3BA3238889E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rickhall Date: Sat Mar 28 05:18:00 2009 New Revision: 759431 URL: http://svn.apache.org/viewvc?rev=759431&view=rev Log: Implement "requires" and "requirers" commands. (FELIX-1009) Added: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequirersCommandImpl.java felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequiresCommandImpl.java Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ExportsCommandImpl.java felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ImportsCommandImpl.java Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java?rev=759431&r1=759430&r2=759431&view=diff ============================================================================== --- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java (original) +++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/Activator.java Sat Mar 28 05:18:00 2009 @@ -80,7 +80,7 @@ // been registered (i.e., we didn't see their service events). initializeCommands(); - // Register "exports" command service. + // Register "bundlelevel" command service. context.registerService( org.apache.felix.shell.Command.class.getName(), new BundleLevelCommandImpl(m_context), null); @@ -127,6 +127,16 @@ org.apache.felix.shell.Command.class.getName(), new RefreshCommandImpl(m_context), null); + // Register "requires" command service. + context.registerService( + org.apache.felix.shell.Command.class.getName(), + new RequiresCommandImpl(m_context), null); + + // Register "requirers" command service. + context.registerService( + org.apache.felix.shell.Command.class.getName(), + new RequirersCommandImpl(m_context), null); + // Register "resolve" command service. context.registerService( org.apache.felix.shell.Command.class.getName(), Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ExportsCommandImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ExportsCommandImpl.java?rev=759431&r1=759430&r2=759431&view=diff ============================================================================== --- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ExportsCommandImpl.java (original) +++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ExportsCommandImpl.java Sat Mar 28 05:18:00 2009 @@ -55,13 +55,7 @@ // Get package admin service. ServiceReference ref = m_context.getServiceReference( org.osgi.service.packageadmin.PackageAdmin.class.getName()); - if (ref == null) - { - out.println("PackageAdmin service is unavailable."); - return; - } - - PackageAdmin pa = (PackageAdmin) m_context.getService(ref); + PackageAdmin pa = (ref == null) ? null : (PackageAdmin) m_context.getService(ref); if (pa == null) { out.println("PackageAdmin service is unavailable."); Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ImportsCommandImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ImportsCommandImpl.java?rev=759431&r1=759430&r2=759431&view=diff ============================================================================== --- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ImportsCommandImpl.java (original) +++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/ImportsCommandImpl.java Sat Mar 28 05:18:00 2009 @@ -19,8 +19,6 @@ package org.apache.felix.shell.impl; import java.io.PrintStream; -import java.util.List; -import java.util.ArrayList; import java.util.StringTokenizer; import org.apache.felix.shell.Command; Added: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequirersCommandImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequirersCommandImpl.java?rev=759431&view=auto ============================================================================== --- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequirersCommandImpl.java (added) +++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequirersCommandImpl.java Sat Mar 28 05:18:00 2009 @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.shell.impl; + +import java.io.PrintStream; +import java.util.StringTokenizer; + +import org.apache.felix.shell.Command; +import org.osgi.framework.*; +import org.osgi.service.packageadmin.PackageAdmin; +import org.osgi.service.packageadmin.RequiredBundle; + +public class RequirersCommandImpl implements Command +{ + private BundleContext m_context = null; + + public RequirersCommandImpl(BundleContext context) + { + m_context = context; + } + + public String getName() + { + return "requirers"; + } + + public String getUsage() + { + return "requirers ..."; + } + + public String getShortDescription() + { + return "list requiring bundles."; + } + + public void execute(String s, PrintStream out, PrintStream err) + { + // Get package admin service. + ServiceReference ref = m_context.getServiceReference( + org.osgi.service.packageadmin.PackageAdmin.class.getName()); + PackageAdmin pa = (ref == null) ? null : (PackageAdmin) m_context.getService(ref); + if (pa == null) + { + out.println("PackageAdmin service is unavailable."); + return; + } + + // Parse command line. + StringTokenizer st = new StringTokenizer(s, " "); + + // Ignore the command name. + st.nextToken(); + + if (st.hasMoreTokens()) + { + boolean separatorNeeded = false; + while (st.hasMoreTokens()) + { + String id = st.nextToken(); + try + { + long l = Long.parseLong(id); + Bundle bundle = m_context.getBundle(l); + RequiredBundle[] rbs = pa.getRequiredBundles(bundle.getSymbolicName()); + for (int i = 0; (rbs != null) && (i < rbs.length); i++) + { + if (rbs[i].getBundle() == bundle) + { + if (separatorNeeded) + { + out.println(""); + } + printRequiredBundles(out, bundle, rbs[i].getRequiringBundles()); + separatorNeeded = true; + } + } + } + catch (NumberFormatException ex) + { + err.println("Unable to parse id '" + id + "'."); + } + catch (Exception ex) + { + err.println(ex.toString()); + } + } + } + } + + private void printRequiredBundles(PrintStream out, Bundle target, Bundle[] requirers) + { + String title = target + " required by:"; + out.println(title); + out.println(Util.getUnderlineString(title)); + if ((requirers != null) && (requirers.length > 0)) + { + for (int i = 0; i < requirers.length; i++) + { + out.println(requirers[i]); + } + } + else + { + out.println("Nothing"); + } + } +} \ No newline at end of file Added: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequiresCommandImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequiresCommandImpl.java?rev=759431&view=auto ============================================================================== --- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequiresCommandImpl.java (added) +++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RequiresCommandImpl.java Sat Mar 28 05:18:00 2009 @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.shell.impl; + +import java.io.PrintStream; +import java.util.StringTokenizer; + +import org.apache.felix.shell.Command; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.PackageAdmin; +import org.osgi.service.packageadmin.RequiredBundle; + +public class RequiresCommandImpl implements Command +{ + private final BundleContext m_context; + private ServiceReference m_ref = null; + + public RequiresCommandImpl(BundleContext context) + { + m_context = context; + } + + public String getName() + { + return "requires"; + } + + public String getUsage() + { + return "requires ..."; + } + + public String getShortDescription() + { + return "list required bundles."; + } + + public void execute(String s, PrintStream out, PrintStream err) + { + StringTokenizer st = new StringTokenizer(s, " "); + + // Ignore the command name. + st.nextToken(); + + if (st.hasMoreTokens()) + { + boolean separatorNeeded = false; + while (st.hasMoreTokens()) + { + String id = st.nextToken().trim(); + + try + { + long l = Long.parseLong(id); + Bundle bundle = m_context.getBundle(l); + if (bundle != null) + { + if (separatorNeeded) + { + out.println(""); + } + getImportedPackages(bundle, out, err); + separatorNeeded = true; + } + else + { + err.println("Bundle ID " + id + " is invalid."); + } + } + catch (NumberFormatException ex) + { + err.println("Unable to parse id '" + id + "'."); + } + catch (Exception ex) + { + err.println(ex.toString()); + } + } + } + } + + private void getImportedPackages(Bundle bundle, PrintStream out, PrintStream err) + { + // Get package admin service. + PackageAdmin pa = getPackageAdmin(); + if (pa == null) + { + out.println("PackageAdmin service is unavailable."); + } + else + { + RequiredBundle[] rbs = pa.getRequiredBundles(null); + String title = bundle + " requires:"; + out.println(title); + out.println(Util.getUnderlineString(title)); + boolean found = false; + for (int rbIdx = 0; rbIdx < rbs.length; rbIdx++) + { + Bundle[] requirers = rbs[rbIdx].getRequiringBundles(); + for (int reqIdx = 0; (requirers != null) && (reqIdx < requirers.length); reqIdx++) + { + if (requirers[reqIdx] == bundle) + { + out.println(rbs[reqIdx]); + found = true; + } + } + } + if (!found) + { + out.println("Nothing"); + } + ungetPackageAdmin(); + } + } + + private PackageAdmin getPackageAdmin() + { + PackageAdmin pa = null; + m_ref = m_context.getServiceReference( + org.osgi.service.packageadmin.PackageAdmin.class.getName()); + if (m_ref != null) + { + pa = (PackageAdmin) m_context.getService(m_ref); + } + return pa; + } + + private void ungetPackageAdmin() + { + m_context.ungetService(m_ref); + } +} \ No newline at end of file