You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/04/10 16:16:01 UTC
[39/59] [abbrv] git commit: [KARAF-2852] Merge package/core and
package/command
[KARAF-2852] Merge package/core and package/command
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/91232f80
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/91232f80
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/91232f80
Branch: refs/heads/master
Commit: 91232f80fede4df8e71b6bd15c3055ce0ab4df7c
Parents: 7f1463c
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Wed Apr 9 23:18:14 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Apr 10 16:02:23 2014 +0200
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
package/NOTICE | 71 +++++++++
.../apache/karaf/packages/command/Exports.java | 132 -----------------
.../apache/karaf/packages/command/Imports.java | 65 ---------
package/core/NOTICE | 71 ---------
package/core/pom.xml | 119 ---------------
.../karaf/packages/core/PackageRequirement.java | 64 ---------
.../karaf/packages/core/PackageService.java | 51 -------
.../karaf/packages/core/PackageVersion.java | 52 -------
.../karaf/packages/core/PackagesMBean.java | 32 -----
.../core/internal/PackageServiceImpl.java | 134 -----------------
.../core/internal/PackagesMBeanImpl.java | 143 -------------------
.../packages/core/internal/osgi/Activator.java | 34 -----
.../src/main/resources/OSGI-INF/bundle.info | 15 --
.../karaf/packages/core/InstallMBeantest.java | 44 ------
.../packages/core/PackageRequirementTest.java | 32 -----
package/pom.xml | 107 ++++++++++++--
.../apache/karaf/packages/command/Exports.java | 132 +++++++++++++++++
.../apache/karaf/packages/command/Imports.java | 65 +++++++++
.../karaf/packages/core/PackageRequirement.java | 64 +++++++++
.../karaf/packages/core/PackageService.java | 51 +++++++
.../karaf/packages/core/PackageVersion.java | 52 +++++++
.../karaf/packages/core/PackagesMBean.java | 32 +++++
.../core/internal/PackageServiceImpl.java | 134 +++++++++++++++++
.../core/internal/PackagesMBeanImpl.java | 143 +++++++++++++++++++
.../packages/core/internal/osgi/Activator.java | 34 +++++
package/src/main/resources/OSGI-INF/bundle.info | 15 ++
.../karaf/packages/core/InstallMBeantest.java | 44 ++++++
.../packages/core/PackageRequirementTest.java | 32 +++++
29 files changed, 967 insertions(+), 998 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 6fa3319..ae6ab68 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -157,7 +157,6 @@
<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>
</feature>
<feature name="service" description="Provide Service support" version="${project.version}">
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/NOTICE
----------------------------------------------------------------------
diff --git a/package/NOTICE b/package/NOTICE
new file mode 100644
index 0000000..b70f1f9
--- /dev/null
+++ b/package/NOTICE
@@ -0,0 +1,71 @@
+Apache Karaf
+Copyright 2010-2014 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 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 includes software developed at
+OW2 (http://www.ow2.org/).
+Licensed under the BSD License.
+
+This product includes software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+Eclipse Foundation (http://www.eclipse.org/).
+Licensed under the EPL.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+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
+AOP Alliance (http://aopalliance.sourceforge.net/).
+Licensed under the Public Domain.
+
+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
+Jasypt (http://jasypt.sourceforge.net/).
+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 uses software developed at
+SpringSource (http://www.springsource.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0
+- BSD License
+- EPL License
+- MIT License
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java
----------------------------------------------------------------------
diff --git a/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java b/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java
deleted file mode 100644
index c09a5f6..0000000
--- a/package/command/src/main/java/org/apache/karaf/packages/command/Exports.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.karaf.packages.core.PackageService;
-import org.apache.karaf.packages.core.PackageVersion;
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.Col;
-import org.apache.karaf.shell.support.table.ShellTable;
-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.BundleRevision;
-
-@Command(scope = "package", name = "exports", description = "Lists exported packages and the bundles that export them")
-@Service
-public class Exports implements Action {
-
- @Option(name = "-d", description = "Only show packages that are exported by more than one bundle", required = false, multiValued = false)
- private boolean onlyDuplicates;
-
- @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
- boolean noFormat;
-
- @Reference
- private PackageService packageService;
-
- @Reference
- private BundleContext bundleContext;
-
- @Override
- public Object execute() throws Exception {
- if (onlyDuplicates) {
- checkDuplicateExports();
- } else {
- showExports();
- }
- return null;
- }
-
- private void showExports() {
- 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, !noFormat);
- }
-
- private void checkDuplicateExports() {
- Bundle[] bundles = bundleContext.getBundles();
- SortedMap<String, PackageVersion> packageVersionMap = getDuplicatePackages(bundles);
- ShellTable table = new ShellTable();
- table.column(new Col("Package Name"));
- table.column(new Col("Version"));
- table.column(new Col("Exporting bundles (ID)"));
-
- for (String key : packageVersionMap.keySet()) {
- PackageVersion pVer = packageVersionMap.get(key);
- if (pVer.getBundles().size() > 1) {
- String pBundles = getBundlesSt(pVer.getBundles());
- table.addRow().addContent(pVer.getPackageName(), pVer.getVersion().toString(), pBundles);
- }
- }
- table.print(System.out, !noFormat);
- }
-
- private String getBundlesSt(Set<Bundle> bundles) {
- StringBuilder st = new StringBuilder();
- for (Bundle bundle : bundles) {
- st.append(bundle.getBundleId() + " ");
- }
- return st.toString();
- }
-
- private SortedMap<String, PackageVersion> getDuplicatePackages(
- Bundle[] bundles) {
- 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;
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java
----------------------------------------------------------------------
diff --git a/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java b/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java
deleted file mode 100644
index 3d086e9..0000000
--- a/package/command/src/main/java/org/apache/karaf/packages/command/Imports.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.api.action.Action;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.table.Col;
-import org.apache.karaf.shell.support.table.ShellTable;
-import org.osgi.framework.Bundle;
-
-@Command(scope = "package", name = "imports", description = "Lists imported packages and the bundles that import them")
-@Service
-public class Imports implements Action {
-
- @Option(name = "-p", description = "Only show package instead of full filter", required = false, multiValued = false)
- boolean onlyPackage;
-
- @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
- boolean noFormat;
-
- @Reference
- private PackageService packageService;
-
- @Override
- public Object execute() 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, !noFormat);
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/NOTICE
----------------------------------------------------------------------
diff --git a/package/core/NOTICE b/package/core/NOTICE
deleted file mode 100644
index b70f1f9..0000000
--- a/package/core/NOTICE
+++ /dev/null
@@ -1,71 +0,0 @@
-Apache Karaf
-Copyright 2010-2014 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 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 includes software developed at
-OW2 (http://www.ow2.org/).
-Licensed under the BSD License.
-
-This product includes software developed at
-OPS4J (http://www.ops4j.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software developed at
-Eclipse Foundation (http://www.eclipse.org/).
-Licensed under the EPL.
-
-This product includes software written by
-Antony Lesuisse.
-Licensed under Public Domain.
-
-
-II. Used Software
-
-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
-AOP Alliance (http://aopalliance.sourceforge.net/).
-Licensed under the Public Domain.
-
-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
-Jasypt (http://jasypt.sourceforge.net/).
-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 uses software developed at
-SpringSource (http://www.springsource.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software from http://www.json.org.
-Copyright (c) 2002 JSON.org
-
-
-III. License Summary
-- Apache License 2.0
-- BSD License
-- EPL License
-- MIT License
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/pom.xml
----------------------------------------------------------------------
diff --git a/package/core/pom.xml b/package/core/pom.xml
deleted file mode 100644
index bc5238f..0000000
--- a/package/core/pom.xml
+++ /dev/null
@@ -1,119 +0,0 @@
-<?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>4.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.apache.karaf</groupId>
- <artifactId>org.apache.karaf.util</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;-noimport:=true
- </Export-Package>
- <Private-Package>
- org.apache.karaf.packages.core.internal,
- org.apache.karaf.packages.core.internal.osgi,
- org.apache.karaf.util.tracker,
- org.apache.felix.utils.version,
- org.apache.felix.utils.manifest
- </Private-Package>
- <Bundle-Activator>
- org.apache.karaf.packages.core.internal.osgi.Activator
- </Bundle-Activator>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java b/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
deleted file mode 100644
index ed8550b..0000000
--- a/package/core/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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() {
- return getPackageName(filter);
- }
-
- public static String getPackageName(String filter) {
- Matcher matcher = packagePattern.matcher(filter);
- matcher.matches();
- return matcher.group(1);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java b/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java
deleted file mode 100644
index d6ccc65..0000000
--- a/package/core/src/main/java/org/apache/karaf/packages/core/PackageService.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.List;
-import java.util.SortedMap;
-
-public interface PackageService {
-
- /**
- * Gets the simplified package exports of a bundle. This does not show the
- * package versions.
- *
- * @param bundleId
- * @return
- */
- List<String> getExports(long bundleId);
-
- List<String> getImports(long bundleId);
-
- /**
- * Gets a map of all exported packages with their version and the bundles that exprot them
- * The key is in the form packagename:version.
- *
- * @return
- */
- SortedMap<String, PackageVersion> getExports();
-
- /**
- * Gets a map of all package imports.
- * The key is the import filter.
- *
- * @return
- */
- SortedMap<String, PackageRequirement> getImports();
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java b/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
deleted file mode 100644
index aed0c48..0000000
--- a/package/core/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.HashSet;
-import java.util.Set;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Version;
-
-public class PackageVersion {
-
- private String packageName;
- private Version version;
- private Set<Bundle> bundles = new HashSet<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 Set<Bundle> getBundles() {
- return this.bundles;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java b/package/core/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java
deleted file mode 100644
index 9f07546..0000000
--- a/package/core/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.List;
-
-import javax.management.openmbean.TabularData;
-
-/**
- * Packages MBean.
- */
-public interface PackagesMBean {
-
- TabularData getExports();
- TabularData getImports();
- List<String> getExports(long bundleId);
- List<String> getImports(long bundleId);
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java b/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
deleted file mode 100644
index a7e7dd1..0000000
--- a/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * 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.ArrayList;
-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;
- }
-
- @Override
- 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;
- }
-
- @Override
- public List<String> getExports(long bundleId) {
- Bundle bundle = bundleContext.getBundle(bundleId);
- BundleRevision rev = bundle.adapt(BundleRevision.class);
- List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
- List<String> exports = new ArrayList<String>();
- for (BundleCapability cap : caps) {
- Map<String, Object> attr = cap.getAttributes();
- String packageName = (String)attr.get(BundleRevision.PACKAGE_NAMESPACE);
- exports.add(packageName);
- }
- return exports ;
- }
-
- @Override
- public List<String> getImports(long bundleId) {
- Bundle bundle = bundleContext.getBundle(bundleId);
- BundleRevision rev = bundle.adapt(BundleRevision.class);
- List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
- List<String> imports = new ArrayList<String>();
- for (BundleRequirement req : reqs) {
- Map<String, String> attr = req.getDirectives();
- String filter = attr.get("filter");
- String name = PackageRequirement.getPackageName(filter);
- imports.add(name);
- }
- return imports;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java b/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java
deleted file mode 100644
index bce7b8f..0000000
--- a/package/core/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.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.OpenDataException;
-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.core.PackagesMBean;
-import org.osgi.framework.Bundle;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of the Packages MBean.
- */
-public class PackagesMBeanImpl extends StandardMBean implements PackagesMBean {
-
- private final static Logger LOGGER = LoggerFactory.getLogger(PackagesMBeanImpl.class);
-
- private final PackageService packageService;
-
- public PackagesMBeanImpl(PackageService packageService) throws NotCompliantMBeanException {
- super(PackagesMBean.class);
- this.packageService = packageService;
- }
-
- public TabularData getExports() {
- 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);
- LOGGER.debug("Adding CompositeDataSupport {} for key: {}", comp, key);
- table.put(comp);
- }
- }
- return table;
- } catch (RuntimeException e) {
- // To avoid the exception gets swallowed by jmx
- LOGGER.error(e.getMessage(), e);
- throw e;
- } catch (OpenDataException e) {
- LOGGER.error(e.getMessage(), e);
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- @Override
- public TabularData getImports() {
- 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 (RuntimeException e) {
- // To avoid the exception gets swallowed by jmx
- LOGGER.error(e.getMessage(), e);
- throw e;
- } catch (OpenDataException e) {
- LOGGER.error(e.getMessage(), e);
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- @Override
- public List<String> getExports(long bundleId) {
- return packageService.getExports(bundleId);
-
- }
-
- @Override
- public List<String> getImports(long bundleId) {
- return packageService.getImports(bundleId);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java b/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java
deleted file mode 100644
index ea8ce1d..0000000
--- a/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.osgi;
-
-import org.apache.karaf.packages.core.PackageService;
-import org.apache.karaf.packages.core.internal.PackageServiceImpl;
-import org.apache.karaf.packages.core.internal.PackagesMBeanImpl;
-import org.apache.karaf.util.tracker.BaseActivator;
-
-public class Activator extends BaseActivator {
-
- @Override
- protected void doStart() throws Exception {
- PackageService packageService = new PackageServiceImpl(bundleContext);
- register(PackageService.class, packageService);
-
- PackagesMBeanImpl mbean = new PackagesMBeanImpl(packageService);
- registerMBean(mbean, "type=package");
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/package/core/src/main/resources/OSGI-INF/bundle.info b/package/core/src/main/resources/OSGI-INF/bundle.info
deleted file mode 100644
index b5747b7..0000000
--- a/package/core/src/main/resources/OSGI-INF/bundle.info
+++ /dev/null
@@ -1,15 +0,0 @@
-h1. Synopsis
-
-${project.name}
-
-${project.description}
-
-Maven URL:
- [mvn:${project.groupId}/${project.artifactId}/${project.version}]
-
-h1. Description
-
-Services for handling packages
-
-h1. See also
-
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/test/java/org/apache/karaf/packages/core/InstallMBeantest.java
----------------------------------------------------------------------
diff --git a/package/core/src/test/java/org/apache/karaf/packages/core/InstallMBeantest.java b/package/core/src/test/java/org/apache/karaf/packages/core/InstallMBeantest.java
deleted file mode 100644
index a9ab11b..0000000
--- a/package/core/src/test/java/org/apache/karaf/packages/core/InstallMBeantest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.lang.management.ManagementFactory;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import org.apache.karaf.packages.core.internal.PackagesMBeanImpl;
-import org.junit.Test;
-
-/**
- * Checks that the PackagesMBean is valid and can be installed in the MBeanServer
- *
- */
-public class InstallMBeantest {
-
- @Test
- public void test() throws Exception {
- MBeanServer server = ManagementFactory.getPlatformMBeanServer();
- PackagesMBeanImpl pack = new PackagesMBeanImpl(null);
- ObjectName oName = new ObjectName("org.apache.karaf:type=package,name=root");
- server.registerMBean(pack, oName);
- server.unregisterMBean(oName);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java
----------------------------------------------------------------------
diff --git a/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java b/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java
deleted file mode 100644
index 2ea1cf8..0000000
--- a/package/core/src/test/java/org/apache/karaf/packages/core/PackageRequirementTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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 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);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/pom.xml
----------------------------------------------------------------------
diff --git a/package/pom.xml b/package/pom.xml
index ae401d8..8c3e1a1 100644
--- a/package/pom.xml
+++ b/package/pom.xml
@@ -10,7 +10,7 @@
(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
+ 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,
@@ -29,13 +29,102 @@
</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>
- </modules>
+ <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.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.core</artifactId>
+ <optional>true</optional>
+ </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;-noimport:=true
+ </Export-Package>
+ <Private-Package>
+ org.apache.karaf.packages.command,
+ org.apache.karaf.packages.core.internal,
+ org.apache.karaf.packages.core.internal.osgi,
+ org.apache.karaf.util.tracker,
+ org.apache.felix.utils.version,
+ org.apache.felix.utils.manifest
+ </Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.packages.core.internal.osgi.Activator
+ </Bundle-Activator>
+ <Karaf-Commands>
+ org.apache.karaf.packages.command
+ </Karaf-Commands>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/command/Exports.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/command/Exports.java b/package/src/main/java/org/apache/karaf/packages/command/Exports.java
new file mode 100644
index 0000000..c09a5f6
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/command/Exports.java
@@ -0,0 +1,132 @@
+/*
+ * 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.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.karaf.packages.core.PackageService;
+import org.apache.karaf.packages.core.PackageVersion;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.Col;
+import org.apache.karaf.shell.support.table.ShellTable;
+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.BundleRevision;
+
+@Command(scope = "package", name = "exports", description = "Lists exported packages and the bundles that export them")
+@Service
+public class Exports implements Action {
+
+ @Option(name = "-d", description = "Only show packages that are exported by more than one bundle", required = false, multiValued = false)
+ private boolean onlyDuplicates;
+
+ @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+ boolean noFormat;
+
+ @Reference
+ private PackageService packageService;
+
+ @Reference
+ private BundleContext bundleContext;
+
+ @Override
+ public Object execute() throws Exception {
+ if (onlyDuplicates) {
+ checkDuplicateExports();
+ } else {
+ showExports();
+ }
+ return null;
+ }
+
+ private void showExports() {
+ 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, !noFormat);
+ }
+
+ private void checkDuplicateExports() {
+ Bundle[] bundles = bundleContext.getBundles();
+ SortedMap<String, PackageVersion> packageVersionMap = getDuplicatePackages(bundles);
+ ShellTable table = new ShellTable();
+ table.column(new Col("Package Name"));
+ table.column(new Col("Version"));
+ table.column(new Col("Exporting bundles (ID)"));
+
+ for (String key : packageVersionMap.keySet()) {
+ PackageVersion pVer = packageVersionMap.get(key);
+ if (pVer.getBundles().size() > 1) {
+ String pBundles = getBundlesSt(pVer.getBundles());
+ table.addRow().addContent(pVer.getPackageName(), pVer.getVersion().toString(), pBundles);
+ }
+ }
+ table.print(System.out, !noFormat);
+ }
+
+ private String getBundlesSt(Set<Bundle> bundles) {
+ StringBuilder st = new StringBuilder();
+ for (Bundle bundle : bundles) {
+ st.append(bundle.getBundleId() + " ");
+ }
+ return st.toString();
+ }
+
+ private SortedMap<String, PackageVersion> getDuplicatePackages(
+ Bundle[] bundles) {
+ 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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/command/Imports.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/command/Imports.java b/package/src/main/java/org/apache/karaf/packages/command/Imports.java
new file mode 100644
index 0000000..3d086e9
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/command/Imports.java
@@ -0,0 +1,65 @@
+/*
+ * 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.api.action.Action;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.Col;
+import org.apache.karaf.shell.support.table.ShellTable;
+import org.osgi.framework.Bundle;
+
+@Command(scope = "package", name = "imports", description = "Lists imported packages and the bundles that import them")
+@Service
+public class Imports implements Action {
+
+ @Option(name = "-p", description = "Only show package instead of full filter", required = false, multiValued = false)
+ boolean onlyPackage;
+
+ @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+ boolean noFormat;
+
+ @Reference
+ private PackageService packageService;
+
+ @Override
+ public Object execute() 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, !noFormat);
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java b/package/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
new file mode 100644
index 0000000..ed8550b
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/core/PackageRequirement.java
@@ -0,0 +1,64 @@
+/*
+ * 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() {
+ return getPackageName(filter);
+ }
+
+ public static String getPackageName(String filter) {
+ Matcher matcher = packagePattern.matcher(filter);
+ matcher.matches();
+ return matcher.group(1);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/core/PackageService.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/core/PackageService.java b/package/src/main/java/org/apache/karaf/packages/core/PackageService.java
new file mode 100644
index 0000000..d6ccc65
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/core/PackageService.java
@@ -0,0 +1,51 @@
+/*
+ * 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.List;
+import java.util.SortedMap;
+
+public interface PackageService {
+
+ /**
+ * Gets the simplified package exports of a bundle. This does not show the
+ * package versions.
+ *
+ * @param bundleId
+ * @return
+ */
+ List<String> getExports(long bundleId);
+
+ List<String> getImports(long bundleId);
+
+ /**
+ * Gets a map of all exported packages with their version and the bundles that exprot them
+ * The key is in the form packagename:version.
+ *
+ * @return
+ */
+ SortedMap<String, PackageVersion> getExports();
+
+ /**
+ * Gets a map of all package imports.
+ * The key is the import filter.
+ *
+ * @return
+ */
+ SortedMap<String, PackageRequirement> getImports();
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java b/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
new file mode 100644
index 0000000..aed0c48
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java
@@ -0,0 +1,52 @@
+/*
+ * 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.HashSet;
+import java.util.Set;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+public class PackageVersion {
+
+ private String packageName;
+ private Version version;
+ private Set<Bundle> bundles = new HashSet<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 Set<Bundle> getBundles() {
+ return this.bundles;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java b/package/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java
new file mode 100644
index 0000000..9f07546
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/core/PackagesMBean.java
@@ -0,0 +1,32 @@
+/*
+ * 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.List;
+
+import javax.management.openmbean.TabularData;
+
+/**
+ * Packages MBean.
+ */
+public interface PackagesMBean {
+
+ TabularData getExports();
+ TabularData getImports();
+ List<String> getExports(long bundleId);
+ List<String> getImports(long bundleId);
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java b/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
new file mode 100644
index 0000000..a7e7dd1
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java
@@ -0,0 +1,134 @@
+/*
+ * 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.ArrayList;
+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;
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ public List<String> getExports(long bundleId) {
+ Bundle bundle = bundleContext.getBundle(bundleId);
+ BundleRevision rev = bundle.adapt(BundleRevision.class);
+ List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
+ List<String> exports = new ArrayList<String>();
+ for (BundleCapability cap : caps) {
+ Map<String, Object> attr = cap.getAttributes();
+ String packageName = (String)attr.get(BundleRevision.PACKAGE_NAMESPACE);
+ exports.add(packageName);
+ }
+ return exports ;
+ }
+
+ @Override
+ public List<String> getImports(long bundleId) {
+ Bundle bundle = bundleContext.getBundle(bundleId);
+ BundleRevision rev = bundle.adapt(BundleRevision.class);
+ List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
+ List<String> imports = new ArrayList<String>();
+ for (BundleRequirement req : reqs) {
+ Map<String, String> attr = req.getDirectives();
+ String filter = attr.get("filter");
+ String name = PackageRequirement.getPackageName(filter);
+ imports.add(name);
+ }
+ return imports;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/91232f80/package/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java
----------------------------------------------------------------------
diff --git a/package/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java b/package/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java
new file mode 100644
index 0000000..bce7b8f
--- /dev/null
+++ b/package/src/main/java/org/apache/karaf/packages/core/internal/PackagesMBeanImpl.java
@@ -0,0 +1,143 @@
+/*
+ * 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.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.OpenDataException;
+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.core.PackagesMBean;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of the Packages MBean.
+ */
+public class PackagesMBeanImpl extends StandardMBean implements PackagesMBean {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(PackagesMBeanImpl.class);
+
+ private final PackageService packageService;
+
+ public PackagesMBeanImpl(PackageService packageService) throws NotCompliantMBeanException {
+ super(PackagesMBean.class);
+ this.packageService = packageService;
+ }
+
+ public TabularData getExports() {
+ 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);
+ LOGGER.debug("Adding CompositeDataSupport {} for key: {}", comp, key);
+ table.put(comp);
+ }
+ }
+ return table;
+ } catch (RuntimeException e) {
+ // To avoid the exception gets swallowed by jmx
+ LOGGER.error(e.getMessage(), e);
+ throw e;
+ } catch (OpenDataException e) {
+ LOGGER.error(e.getMessage(), e);
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public TabularData getImports() {
+ 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 (RuntimeException e) {
+ // To avoid the exception gets swallowed by jmx
+ LOGGER.error(e.getMessage(), e);
+ throw e;
+ } catch (OpenDataException e) {
+ LOGGER.error(e.getMessage(), e);
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public List<String> getExports(long bundleId) {
+ return packageService.getExports(bundleId);
+
+ }
+
+ @Override
+ public List<String> getImports(long bundleId) {
+ return packageService.getImports(bundleId);
+ }
+
+}