You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2012/03/30 11:13:35 UTC

svn commit: r1307324 - in /karaf/trunk: ./ assemblies/apache-karaf/ assemblies/features/standard/src/main/feature/ package/ package/command/ package/command/src/ package/command/src/main/ package/command/src/main/java/ package/command/src/main/java/org...

Author: cschneider
Date: Fri Mar 30 09:13:33 2012
New Revision: 1307324

URL: http://svn.apache.org/viewvc?rev=1307324&view=rev
Log:
KARAF-1262 package commands

Added:
    karaf/trunk/package/   (with props)
    karaf/trunk/package/command/   (with props)
    karaf/trunk/package/command/NOTICE
    karaf/trunk/package/command/pom.xml
    karaf/trunk/package/command/src/
    karaf/trunk/package/command/src/main/
    karaf/trunk/package/command/src/main/java/
    karaf/trunk/package/command/src/main/java/org/
    karaf/trunk/package/command/src/main/java/org/apache/
    karaf/trunk/package/command/src/main/java/org/apache/karaf/
    karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/
    karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/
    karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java
    karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java
    karaf/trunk/package/command/src/main/resources/
    karaf/trunk/package/command/src/main/resources/OSGI-INF/
    karaf/trunk/package/command/src/main/resources/OSGI-INF/blueprint/
    karaf/trunk/package/command/src/main/resources/OSGI-INF/blueprint/shell-bundles.xml
    karaf/trunk/package/command/src/main/resources/OSGI-INF/bundle.info
    karaf/trunk/package/command/src/test/
    karaf/trunk/package/command/src/test/java/
    karaf/trunk/package/core/   (with props)
    karaf/trunk/package/core/pom.xml
    karaf/trunk/package/core/src/
    karaf/trunk/package/core/src/main/
    karaf/trunk/package/core/src/main/java/
    karaf/trunk/package/core/src/main/java/org/
    karaf/trunk/package/core/src/main/java/org/apache/
    karaf/trunk/package/core/src/main/java/org/apache/karaf/
    karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/
    karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/
    karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
    karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java
    karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
    karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/internal/
    karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
    karaf/trunk/package/core/src/main/resources/
    karaf/trunk/package/core/src/main/resources/OSGI-INF/
    karaf/trunk/package/core/src/main/resources/OSGI-INF/blueprint/
    karaf/trunk/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
    karaf/trunk/package/core/src/main/resources/OSGI-INF/bundle.info
    karaf/trunk/package/core/src/test/
    karaf/trunk/package/core/src/test/java/
    karaf/trunk/package/core/src/test/java/org/
    karaf/trunk/package/core/src/test/java/org/apache/
    karaf/trunk/package/core/src/test/java/org/apache/karaf/
    karaf/trunk/package/core/src/test/java/org/apache/karaf/packages/
    karaf/trunk/package/core/src/test/java/org/apache/karaf/packages/core/
    karaf/trunk/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java
    karaf/trunk/package/management/   (with props)
    karaf/trunk/package/management/NOTICE
    karaf/trunk/package/management/pom.xml
    karaf/trunk/package/management/src/
    karaf/trunk/package/management/src/main/
    karaf/trunk/package/management/src/main/java/
    karaf/trunk/package/management/src/main/java/org/
    karaf/trunk/package/management/src/main/java/org/apache/
    karaf/trunk/package/management/src/main/java/org/apache/karaf/
    karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/
    karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/
    karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/PackageMBean.java
    karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/internal/
    karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/internal/PackageMBeanImpl.java
    karaf/trunk/package/management/src/main/resources/
    karaf/trunk/package/management/src/main/resources/OSGI-INF/
    karaf/trunk/package/management/src/main/resources/OSGI-INF/blueprint/
    karaf/trunk/package/management/src/main/resources/OSGI-INF/blueprint/bundles-management.xml
    karaf/trunk/package/management/src/main/resources/OSGI-INF/bundle.info
    karaf/trunk/package/pom.xml
Modified:
    karaf/trunk/assemblies/apache-karaf/pom.xml
    karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml
    karaf/trunk/pom.xml

Modified: karaf/trunk/assemblies/apache-karaf/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/apache-karaf/pom.xml?rev=1307324&r1=1307323&r2=1307324&view=diff
==============================================================================
--- karaf/trunk/assemblies/apache-karaf/pom.xml (original)
+++ karaf/trunk/assemblies/apache-karaf/pom.xml Fri Mar 30 09:13:33 2012
@@ -185,6 +185,7 @@
                         <feature>config</feature>
                         <feature>deployers</feature>
                         <feature>region</feature>
+                        <feature>package</feature>
                     </bootFeatures>
                 </configuration>
             </plugin>

Modified: karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml?rev=1307324&r1=1307323&r2=1307324&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml (original)
+++ karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml Fri Mar 30 09:13:33 2012
@@ -91,6 +91,12 @@
         <bundle start-level="30">mvn:org.eclipse.jetty.aggregate/jetty-all-server/${jetty.version}</bundle>
     </feature>
 
+    <feature name="package" version="${project.version}" resolver="(obr)" description="Package commands and mbeans">
+        <bundle start-level="30">mvn:org.apache.karaf.package/org.apache.karaf.package.core/${project.version}</bundle>
+        <bundle start-level="30">mvn:org.apache.karaf.package/org.apache.karaf.package.command/${project.version}</bundle>
+        <bundle start-level="30">mvn:org.apache.karaf.package/org.apache.karaf.package.management/${project.version}</bundle>
+    </feature>
+
     <feature name="http" version="${project.version}" resolver="(obr)" description="Implementation of the OSGI HTTP Service">
         <details>Allows to publish servlets using pax web and jetty</details>
     	<configfile finalname="/etc/jetty.xml">mvn:org.apache.karaf/apache-karaf/${project.version}/xml/jettyconfig</configfile>
@@ -174,7 +180,6 @@
         <bundle start-level="30">mvn:org.apache.karaf.system/org.apache.karaf.system.management/${project.version}</bundle>
         <bundle start-level="30">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.management/${project.version}</bundle>
         <bundle start-level="30">mvn:org.apache.karaf.management.mbeans/org.apache.karaf.management.mbeans.services/${project.version}</bundle>
-        <bundle start-level="30">mvn:org.apache.karaf.management.mbeans/org.apache.karaf.management.mbeans.packages/${project.version}</bundle>
         <bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.api/${aries.jmx.version}</bundle>
         <bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.core/${aries.jmx.version}</bundle>
         <bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.blueprint/${aries.jmx.version}</bundle>

Propchange: karaf/trunk/package/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar 30 09:13:33 2012
@@ -0,0 +1,3 @@
+.project
+.settings
+target

Propchange: karaf/trunk/package/command/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar 30 09:13:33 2012
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Added: karaf/trunk/package/command/NOTICE
URL: http://svn.apache.org/viewvc/karaf/trunk/package/command/NOTICE?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/command/NOTICE (added)
+++ karaf/trunk/package/command/NOTICE Fri Mar 30 09:13:33 2012
@@ -0,0 +1,48 @@
+Apache Karaf
+Copyright 2010-2012 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+FUSE Source (http://www.fusesource.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+Tanuki Software (http://www.tanukisoftware.com/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+JLine (http://jline.sourceforge.net).
+Licensed under the BSD License.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0

Added: karaf/trunk/package/command/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/package/command/pom.xml?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/command/pom.xml (added)
+++ karaf/trunk/package/command/pom.xml Fri Mar 30 09:13:33 2012
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.package</groupId>
+        <artifactId>package</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.karaf.package.command</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Package :: Commands</name>
+    <description>Provides shell commands to list package exports and imports</description>
+
+    <properties>
+        <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.package</groupId>
+            <artifactId>org.apache.karaf.package.core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.utils</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.info</include>
+                </includes>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Export-Package>!*</Export-Package>
+                        <Private-Package>
+                            org.apache.karaf.packages.command*,
+                            org.apache.felix.utils.version,
+                            org.apache.felix.utils.manifest,
+                            !*
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java (added)
+++ karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.karaf.packages.command;
+
+import java.util.SortedMap;
+
+import org.apache.karaf.packages.core.PackageService;
+import org.apache.karaf.packages.core.PackageVersion;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.console.table.Col;
+import org.apache.karaf.shell.console.table.ShellTable;
+import org.osgi.framework.Bundle;
+
+@Command(scope = "package", name = "exports", description = "Lists exported packages and the bundles that export them")
+public class Exports extends OsgiCommandSupport {
+
+    private PackageService packageService;
+
+    public Exports(PackageService packageService) {
+        super();
+        this.packageService = packageService;
+    }
+
+    protected Object doExecute() throws Exception {
+        SortedMap<String, PackageVersion> exports = packageService.getExports();
+        ShellTable table = new ShellTable();
+        table.column(new Col("Package Name"));
+        table.column(new Col("Version"));
+        table.column(new Col("ID"));
+        table.column(new Col("Bundle Name"));
+        
+        for (String key : exports.keySet()) {
+            PackageVersion pVer = exports.get(key);
+            for (Bundle bundle : pVer.getBundles()) {
+                table.addRow().addContent(pVer.getPackageName(),pVer.getVersion().toString(), bundle.getBundleId(), bundle.getSymbolicName());
+            }
+        }
+        table.print(System.out);
+        return null;
+    }
+
+}

Added: karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java (added)
+++ karaf/trunk/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,62 @@
+/*
+ * 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.karaf.packages.command;
+
+import java.util.SortedMap;
+
+import org.apache.karaf.packages.core.PackageRequirement;
+import org.apache.karaf.packages.core.PackageService;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.console.table.Col;
+import org.apache.karaf.shell.console.table.ShellTable;
+import org.osgi.framework.Bundle;
+
+@Command(scope = "package", name = "imports", description = "Lists imported packages and the bundles that import them")
+public class Imports extends OsgiCommandSupport {
+    
+    @Option(name = "-p", description = "Only show package instead of full filter", required = false, multiValued = false)
+    boolean onlyPackage;
+
+    private PackageService packageService;
+
+    public Imports(PackageService packageService) {
+        super();
+        this.packageService = packageService;
+    }
+
+    protected Object doExecute() throws Exception {
+        SortedMap<String, PackageRequirement> imports = packageService.getImports();
+        ShellTable table = new ShellTable();
+        table.column(new Col(onlyPackage ? "Package name" : "Filter"));
+        table.column(new Col("Optional"));
+        table.column(new Col("ID"));
+        table.column(new Col("Bundle Name"));
+        table.column(new Col("Resolveable"));
+        
+        for (String filter : imports.keySet()) {
+            PackageRequirement req = imports.get(filter);
+            Bundle bundle = req.getBundle();
+            String firstCol = onlyPackage ? req.getPackageName() : req.getFilter();
+            table.addRow().addContent(firstCol, req.isOptional() ? "optional" : "", bundle.getBundleId(), bundle.getSymbolicName(), req.isResolveable());
+        }
+        table.print(System.out);
+        return null;
+    }
+
+}

Added: karaf/trunk/package/command/src/main/resources/OSGI-INF/blueprint/shell-bundles.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/package/command/src/main/resources/OSGI-INF/blueprint/shell-bundles.xml?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/command/src/main/resources/OSGI-INF/blueprint/shell-bundles.xml (added)
+++ karaf/trunk/package/command/src/main/resources/OSGI-INF/blueprint/shell-bundles.xml Fri Mar 30 09:13:33 2012
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+        
+        <command>
+            <action class="org.apache.karaf.packages.command.Exports">
+                <argument ref="packageService"/>
+            </action>
+        </command>
+        <command>
+            <action class="org.apache.karaf.packages.command.Imports">
+                <argument ref="packageService"/>
+            </action>
+        </command>
+
+    </command-bundle>
+    
+    <reference id="packageService" interface="org.apache.karaf.packages.core.PackageService" />
+
+</blueprint>

Added: karaf/trunk/package/command/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/package/command/src/main/resources/OSGI-INF/bundle.info?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/command/src/main/resources/OSGI-INF/bundle.info (added)
+++ karaf/trunk/package/command/src/main/resources/OSGI-INF/bundle.info Fri Mar 30 09:13:33 2012
@@ -0,0 +1,20 @@
+h1. Synopsis
+
+${project.name}
+
+${project.description}
+
+Maven URL:
+   [mvn:${project.groupId}/${project.artifactId}/${project.version}]
+
+h1. Description
+
+This bundle provides the low level OSGi shell commands.
+
+The following commands are available:
+* package:exports - List exported packages
+* package:imports - List imported packages
+
+h1. See also
+
+Commands and Using the console sections of the Karaf User Guide

Propchange: karaf/trunk/package/core/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar 30 09:13:33 2012
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Added: karaf/trunk/package/core/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/pom.xml?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/pom.xml (added)
+++ karaf/trunk/package/core/pom.xml Fri Mar 30 09:13:33 2012
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.package</groupId>
+        <artifactId>package</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.karaf.package.core</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Package :: Core</name>
+    <description>Package Services and API</description>
+
+    <properties>
+        <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.utils</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.info</include>
+                </includes>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Export-Package>
+                            org.apache.karaf.packages.core
+                        </Export-Package>
+                        <Import-Package>
+                            org.apache.felix.service.command;status=provisional,
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.packages.core.internal,
+                            org.apache.felix.utils.version,
+                            org.apache.felix.utils.manifest
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java (added)
+++ karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,60 @@
+/*
+ * 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.karaf.packages.core;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.Bundle;
+
+public class PackageRequirement {
+    private String filter;
+    private boolean optional;
+    private Bundle bundle;
+    private boolean resolveable;
+    private static Pattern packagePattern  = Pattern.compile(".*" + Pattern.quote("(osgi.wiring.package=") + "(.*?)\\).*");
+    
+    public PackageRequirement(String filter, boolean optional, Bundle bundle, boolean resolveable) {
+        super();
+        this.filter = filter;
+        this.optional = optional;
+        this.bundle = bundle;
+        this.resolveable = resolveable;
+    }
+    
+    public Bundle getBundle() {
+        return bundle;
+    }
+
+    public String getFilter() {
+        return filter;
+    }
+    public boolean isOptional() {
+        return optional;
+    }
+
+    public boolean isResolveable() {
+        return resolveable;
+    }
+
+    public String getPackageName() {
+        Matcher matcher = packagePattern.matcher(filter);
+        matcher.matches();
+        return matcher.group(1);
+    }
+
+}

Added: karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java (added)
+++ karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,24 @@
+/*
+ * 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.karaf.packages.core;
+
+import java.util.SortedMap;
+
+public interface PackageService {
+    SortedMap<String, PackageVersion> getExports();
+    SortedMap<String, PackageRequirement> getImports();
+}

Added: karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java (added)
+++ karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,50 @@
+/*
+ * 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.karaf.packages.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+public class PackageVersion {
+    private String packageName;
+    private Version version;
+    private List<Bundle> bundles = new ArrayList<Bundle>();
+    
+    public PackageVersion(String packageName, Version version) {
+        this.packageName = packageName;
+        this.version = version;
+    }
+    
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public Version getVersion() {
+        return version;
+    }
+    
+    public void addBundle(Bundle bundle) {
+        this.bundles.add(bundle);
+    }
+    
+    public List<Bundle> getBundles() {
+        return this.bundles;
+    }
+}
\ No newline at end of file

Added: karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java (added)
+++ karaf/trunk/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,103 @@
+/*
+ * 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.karaf.packages.core.internal;
+
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.karaf.packages.core.PackageRequirement;
+import org.apache.karaf.packages.core.PackageService;
+import org.apache.karaf.packages.core.PackageVersion;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+
+public class PackageServiceImpl implements PackageService {
+
+    private final BundleContext bundleContext;
+
+    public PackageServiceImpl(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
+    public SortedMap<String, PackageVersion> getExports() {
+        Bundle[] bundles = bundleContext.getBundles();
+        SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<String, PackageVersion>();
+        for (Bundle bundle : bundles) {
+            BundleRevision rev = bundle.adapt(BundleRevision.class);
+            if (rev != null) {
+                List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
+                for (BundleCapability cap : caps) {
+                    Map<String, Object> attr = cap.getAttributes();
+                    String packageName = (String)attr.get(BundleRevision.PACKAGE_NAMESPACE);
+                    Version version = (Version)attr.get("version");
+                    String key = packageName + ":" + version.toString();
+                    PackageVersion pVer = packageVersionMap.get(key);
+                    if (pVer == null) {
+                        pVer = new PackageVersion(packageName, version);
+                        packageVersionMap.put(key, pVer);
+                    }
+                    pVer.addBundle(bundle);
+                }
+            }
+        }
+        return packageVersionMap;
+    }
+
+    public SortedMap<String, PackageRequirement> getImports() {
+        Bundle[] bundles = bundleContext.getBundles();
+        SortedMap<String, PackageRequirement> filterMap = new TreeMap<String, PackageRequirement>();
+        for (Bundle bundle : bundles) {
+            BundleRevision rev = bundle.adapt(BundleRevision.class);
+            if (rev != null) {
+                List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
+                for (BundleRequirement req : reqs) {
+                    Map<String, String> attr = req.getDirectives();
+                    String filter = attr.get("filter");
+                    String resolution = attr.get("resolution");
+                    boolean optional = "optional".equals(resolution);
+                    boolean resolveable = checkResolveAble(req);
+                    PackageRequirement preq = new PackageRequirement(filter, optional, bundle, resolveable);
+                    filterMap.put(filter, preq);
+                }
+            }
+        }
+        return filterMap;
+    }
+
+    private boolean checkResolveAble(BundleRequirement req) {
+        Bundle[] bundles = bundleContext.getBundles();
+        for (Bundle bundle : bundles) {
+            BundleRevision rev = bundle.adapt(BundleRevision.class);
+            if (rev != null) {
+                List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
+                for (BundleCapability cap : caps) {
+                    if (req.matches(cap)) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+}

Added: karaf/trunk/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml (added)
+++ karaf/trunk/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml Fri Mar 30 09:13:33 2012
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <bean id="packageService" class="org.apache.karaf.packages.core.internal.PackageServiceImpl">
+        <argument ref="blueprintBundleContext"/>
+    </bean>
+    <service interface="org.apache.karaf.packages.core.PackageService" ref="packageService"/>
+
+</blueprint>

Added: karaf/trunk/package/core/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/src/main/resources/OSGI-INF/bundle.info?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/src/main/resources/OSGI-INF/bundle.info (added)
+++ karaf/trunk/package/core/src/main/resources/OSGI-INF/bundle.info Fri Mar 30 09:13:33 2012
@@ -0,0 +1,15 @@
+h1. Synopsis
+
+${project.name}
+
+${project.description}
+
+Maven URL:
+   [mvn:${project.groupId}/${project.artifactId}/${project.version}]
+
+h1. Description
+
+Services for handling packages
+
+h1. See also
+

Added: karaf/trunk/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java (added)
+++ karaf/trunk/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,14 @@
+package org.apache.karaf.packages.core;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class PackageRequirementTest {
+    @Test
+    public void testGetPackageName() {
+        PackageRequirement req = new PackageRequirement("(&(osgi.wiring.package=org.osgi.service.useradmin)(version>=1.1.0))", false, null, false);
+        String packageName = req.getPackageName();
+        Assert.assertEquals("org.osgi.service.useradmin", packageName);
+    }
+}

Propchange: karaf/trunk/package/management/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar 30 09:13:33 2012
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Added: karaf/trunk/package/management/NOTICE
URL: http://svn.apache.org/viewvc/karaf/trunk/package/management/NOTICE?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/management/NOTICE (added)
+++ karaf/trunk/package/management/NOTICE Fri Mar 30 09:13:33 2012
@@ -0,0 +1,48 @@
+Apache Karaf
+Copyright 2010-2012 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+FUSE Source (http://www.fusesource.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+Tanuki Software (http://www.tanukisoftware.com/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+JLine (http://jline.sourceforge.net).
+Licensed under the BSD License.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0

Added: karaf/trunk/package/management/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/package/management/pom.xml?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/management/pom.xml (added)
+++ karaf/trunk/package/management/pom.xml Fri Mar 30 09:13:33 2012
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.package</groupId>
+        <artifactId>package</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.karaf.package.management</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Package :: Management</name>
+    <description>Provides a JMX MBean to list exported and imported packages</description>
+
+    <properties>
+        <appendedResourcesDirectory>${basedir}/../../etc/appended-resources/</appendedResourcesDirectory>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.package</groupId>
+            <artifactId>org.apache.karaf.package.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.info</include>
+                </includes>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Export-Package>
+                            org.apache.karaf.packages.management;version=${project.version}
+                        </Export-Package>
+                        <Private-Package>
+                            org.apache.karaf.packages.management.internal,
+                            !*
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file

Added: karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/PackageMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/PackageMBean.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/PackageMBean.java (added)
+++ karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/PackageMBean.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,29 @@
+/*
+ * 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.karaf.packages.management;
+
+import javax.management.openmbean.TabularData;
+
+/**
+ * Package MBean.
+ */
+public interface PackageMBean {
+
+    TabularData getExports() throws Exception;
+    TabularData getImports() throws Exception;
+
+}

Added: karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/internal/PackageMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/internal/PackageMBeanImpl.java?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/internal/PackageMBeanImpl.java (added)
+++ karaf/trunk/package/management/src/main/java/org/apache/karaf/packages/management/internal/PackageMBeanImpl.java Fri Mar 30 09:13:33 2012
@@ -0,0 +1,123 @@
+/*
+ * 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.karaf.packages.management.internal;
+
+import java.util.SortedMap;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+import org.apache.karaf.packages.core.PackageRequirement;
+import org.apache.karaf.packages.core.PackageService;
+import org.apache.karaf.packages.core.PackageVersion;
+import org.apache.karaf.packages.management.PackageMBean;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Bundles MBean implementation.
+ */
+public class PackageMBeanImpl extends StandardMBean implements PackageMBean {
+    private Logger log = LoggerFactory.getLogger(this.getClass());
+
+    private final PackageService packageService;
+
+    public PackageMBeanImpl(PackageService packageService)
+        throws NotCompliantMBeanException {
+        super(PackageMBean.class);
+        this.packageService = packageService;
+    }
+
+    public TabularData getExports() throws Exception {
+        try {
+            String[] names = new String[] {"Name", "Version", "ID", "Bundle Name"};
+            CompositeType bundleType = new CompositeType("PackageExport", "Exported packages", names,
+                                                         new String[] {"Package name", "Version of the Package",
+                                                                       "ID of the Bundle", "Bundle symbolic name"},
+                                                         new OpenType[] {SimpleType.STRING, SimpleType.STRING,
+                                                                         SimpleType.LONG, SimpleType.STRING});
+            TabularType tableType = new TabularType("PackageExports", "Exported packages", bundleType,
+                                                    new String[] {"Name", "Version", "ID"});
+            TabularData table = new TabularDataSupport(tableType);
+
+            SortedMap<String, PackageVersion> exports = packageService.getExports();
+
+            for (String key : exports.keySet()) {
+                PackageVersion export = exports.get(key);
+                for (Bundle bundle : export.getBundles()) {
+                    Object[] data = new Object[] {
+                                         export.getPackageName(),
+                                         export.getVersion().toString(), 
+                                         bundle.getBundleId(),
+                                         bundle.getSymbolicName()};
+                    CompositeData comp = new CompositeDataSupport(bundleType, names, data);
+                    table.put(comp);
+                }
+            }
+            return table;
+        } catch (Exception e) {
+            // To avoid the exception gets swallowed by jmx
+            log.error(e.getMessage(), e);
+            throw e;
+        }
+    }
+
+    @Override
+    public TabularData getImports() throws Exception {
+        try {
+            String[] names = new String[] {"PackageName", "Filter", "Optional", "ID", "Bundle Name", "Resolvable"};
+            CompositeType bundleType = new CompositeType("PackageImports", "Imported packages", 
+                                                         names,
+                                                         names,
+                                                         new OpenType[] {SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN,
+                                                                         SimpleType.LONG, SimpleType.STRING, SimpleType.BOOLEAN});
+            TabularType tableType = new TabularType("PackageImports", "Imported packages", bundleType,
+                                                    new String[] {"Filter", "ID"});
+            TabularData table = new TabularDataSupport(tableType);
+
+            SortedMap<String, PackageRequirement> imports = packageService.getImports();
+
+            for (String key : imports.keySet()) {
+                PackageRequirement req = imports.get(key);
+                Object[] data = new Object[] {
+                                         req.getPackageName(),
+                                         req.getFilter(),
+                                         req.isOptional(), 
+                                         req.getBundle().getBundleId(),
+                                         req.getBundle().getSymbolicName(),
+                                         req.isResolveable()};
+                CompositeData comp = new CompositeDataSupport(bundleType, names, data);
+                table.put(comp);
+             }
+            return table;
+        } catch (Exception e) {
+            // To avoid the exception gets swallowed by jmx
+            log.error(e.getMessage(), e);
+            throw e;
+        }
+    }
+
+}

Added: karaf/trunk/package/management/src/main/resources/OSGI-INF/blueprint/bundles-management.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/package/management/src/main/resources/OSGI-INF/blueprint/bundles-management.xml?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/management/src/main/resources/OSGI-INF/blueprint/bundles-management.xml (added)
+++ karaf/trunk/package/management/src/main/resources/OSGI-INF/blueprint/bundles-management.xml Fri Mar 30 09:13:33 2012
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <!-- Reference to the MBean Server -->
+    <reference id="mbeanServer" interface="javax.management.MBeanServer">
+        <reference-listener ref="mbeanRegistrer" bind-method="registerMBeanServer" unbind-method="unregisterMBeanServer"/>
+    </reference>
+    
+    <reference id="packageService" interface="org.apache.karaf.packages.core.PackageService" />
+    
+    <!-- Bundles MBean -->
+    <bean id="packageMBean" class="org.apache.karaf.packages.management.internal.PackageMBeanImpl">
+        <argument ref="packageService" />
+    </bean>
+
+    <!-- MBean Registrer -->
+    <bean id="mbeanRegistrer" class="org.apache.karaf.management.MBeanRegistrer">
+        <property name="mbeans">
+            <map>
+                <entry value="org.apache.karaf:type=package,name=${karaf.name}" key-ref="packageMBean"/>
+            </map>
+        </property>
+    </bean>
+
+</blueprint>
\ No newline at end of file

Added: karaf/trunk/package/management/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/package/management/src/main/resources/OSGI-INF/bundle.info?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/management/src/main/resources/OSGI-INF/bundle.info (added)
+++ karaf/trunk/package/management/src/main/resources/OSGI-INF/bundle.info Fri Mar 30 09:13:33 2012
@@ -0,0 +1,33 @@
+h1. Synopsis
+
+${project.name}
+
+${project.description}
+
+Maven URL:
+[mvn:${project.groupId}/${project.artifactId}/${project.version}]
+
+h1. Description
+
+The bundles mbean management bundle exposes a Bundles MBean that can be used with any JMX client (for instance JConsole).
+
+The bundles MBean allows quite the same actions that can be performed using bundle:* commands:
+  * list()
+  * getStartLevel(bundleId)
+  * setStartLevel(bundleId, startLevel)
+  * refresh()
+  * refresh(bundleId)
+  * update(bundleId)
+  * update(bundleId, location)
+  * resolve()
+  * resolve(bundleId)
+  * restart(bundleId)
+  * install(url)
+  * install(url, start)
+  * start(bundleId)
+  * stop(bundleId)
+  * uninstall(bundleId)
+
+h1. See also
+
+  * Monitoring and Administration using JMX - section of the Karaf User Guide

Added: karaf/trunk/package/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/package/pom.xml?rev=1307324&view=auto
==============================================================================
--- karaf/trunk/package/pom.xml (added)
+++ karaf/trunk/package/pom.xml Fri Mar 30 09:13:33 2012
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf</groupId>
+        <artifactId>karaf</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.package</groupId>
+    <artifactId>package</artifactId>
+    <packaging>pom</packaging>
+    <name>Apache Karaf :: Bundle</name>
+
+    <modules>
+        <module>core</module>
+        <module>command</module>
+        <module>management</module>
+    </modules>
+
+</project>

Modified: karaf/trunk/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1307324&r1=1307323&r2=1307324&view=diff
==============================================================================
--- karaf/trunk/pom.xml (original)
+++ karaf/trunk/pom.xml Fri Mar 30 09:13:33 2012
@@ -43,6 +43,7 @@
         <module>bundle</module>
         <module>config</module>
         <module>instance</module>
+        <module>package</module>
         <module>deployer</module>
         <module>shell</module>
         <module>jaas</module>
@@ -354,6 +355,22 @@
             </dependency>
 
             <dependency>
+                <groupId>org.apache.karaf.package</groupId>
+                <artifactId>org.apache.karaf.package.core</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.karaf.package</groupId>
+                <artifactId>org.apache.karaf.package.command</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.karaf.package</groupId>
+                <artifactId>org.apache.karaf.package.management</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+
+            <dependency>
                 <groupId>org.apache.karaf.config</groupId>
                 <artifactId>org.apache.karaf.config.core</artifactId>
                 <version>${project.version}</version>